Copolymer with pinning: variational characterization of the phase diagram