Hamiltonian patterns of age-dependent adaptation to novel environments