It has been realized long ago that spacetime singularities generically appear in the classical theory of general relativity, and it is expected that such singularities will be resolved through quantum effects. The classical BKL analysis leads to a cosmological billiards description of space-time near the singularity, which is in general not integrable, but instead chaotic. The shape of the billiard tables is determined by the given theory and can in the most relevant cases be identified with the Weyl chamber of an infinite-dimensional Kac-Moody Lie algebra, and also with (half) the fundamental domain of the modular group with respect to different kinds of integers. This implies that the wavefunction of the universe has to be an (odd) Maass waveform automorphic under the (generalized) modular group. For example, in the case of D=4 pure gravity, the billiard is taking place in the fundamental domain of the modular group PSL(2,Z), whereas in D=11 supergravity, it is given by the fundamental domain of the modular group with respect to integer octonions. The wavefunction goes to zero in the limit towards the singularity, and it is generically complex and oscillating, an analytic continuation is impossible. Numerical as well as analytical investigations of the dynamics of semiclassical wavepackets confirm these results.