Spectra of solar energetic particle and galactic cosmic rays over a million years reconstructed using aluminium-26 data from lunar rocks