Accretion by magnetic neutron stars. I. Magnetospheric structure and stability.