A neuronal least-action principle for real-time learning in cortical circuits