A Theory of Solar-Wind/Magnetosphere Coupling Derived from First Principles