Text this: A Variational Approach to Nonsmooth Dynamics