Photon-Mediated Peierls Transition of a 1D Gas in a Multimode Optical Cavity