The Complexity Dynamics of Grokking