We present an analysis of the phase-resolved 2-30 keV X-ray spectrum of the prototype magnetic cataclysmic variable AM Herculis obtained with the Ginga satellite. The bremsstrahlung flux varies by more than a factor of 7 as a function of orbital phase, demonstrating that the X-ray orbital intensity variation is due to partial occultation which varies with the viewing angle. The spectrum is hardest when the source is brightest in its orbital cycle, and the phase-resolved spectra are not well fitted by simple models with a narrow line plus continuum. The derived high and variable bremsstrahlung temperature cannot account for the observed line emission, and the residuals to these fits indicate complex behaviour at high and low energies. The latter is shown to be consistent with a complex absorber, and both partial covering and partial ionization give a good description of the soft spectrum. The residuals above 6 keV are well modelled by reflection from the white dwarf surface, where the amount of reflection varies with phase as predicted by the changing inclination of the white dwarf surface. The inclusion of this hard and variable spectral component gives a temperature for the post-shock region of ~13.5 keV, which is constant with phase. This value is considerably lower than previous estimates, allowing the high equivalent width of the iron line to be explained as a combination of a thermal line blend at 6.8 keV and a 6.4-keV fluorescent component. This new low bremsstrahlung temperature suggests that the hard X-ray luminosities of AM Her systems may have been overestimated, exacerbating the soft X-ray problem. The detailed modelling of the complex low-energy spectrum affects the derived ionization state of the reflector: with partial covering of cold material the reflection spectrum is significantly ionized, but with an ionized absorber the reflecting surface is cold.