Electromagnetic radiation as a probe of the initial state and of viscous dynamics in relativistic nuclear collisions