  We present a detailed theoretical study of the electronic, magnetic, and
structural properties of magnesiow\"ustite Fe$_{1-x}$Mg$_x$O with $x$ in the
range between 0$-$0.875 using a fully charge self-consistent implementation of
the density functional theory plus dynamical mean-field theory (DFT+DMFT)
method. In particular, we compute the electronic structure and phase stability
of the rock-salt B1-structured (Fe,Mg)O at high pressures relevant for the
Earth's lower mantle. We obtain that upon compression paramagnetic (Fe,Mg)O
exhibits a spin-state transition of Fe$^{2+}$ ions from a high-spin to low-spin
(HS-LS) state which is accompanied by a collapse of local magnetic moments. The
HS-LS transition results in a substantial drop of the lattice volume by about
4$-$8 %, implying a complex interplay between electronic and lattice degrees of
freedom. Our results reveal a strong sensitivity of the calculated transition
pressure $P_{\rm tr.}$ upon addition of Mg. While for Fe-rich
magnesiow\"ustite, Mg $x < 0.5$, $P_{\rm tr.}$ exhibits a rather weak variation
at $\sim$80 GPa, for Fe-poor (Fe,Mg)O it drops, e.g., by about 35 % to 52 GPa
for Mg $x=0.75$. This behavior is accompanied by a substantial change of the
spin transition range from 50$-$140 GPa in FeO to 30$-$90 GPa for $x=0.75$. In
addition, the calculated bulk modulus (in the HS state) is found to increase by
$\sim$12 % from 142 GPa in FeO to 159 GPa in (Fe,Mg)O with Mg $x=0.875$. We
find that the pressure-induced HS-LS transition has different consequences for
the electronic properties of the Fe-rich and poor (Fe,Mg)O. For the Fe-rich
(Fe,Mg)O, the transition is found to be accompanied by a Mott insulator to
(semi-) metal phase transition. In contrast to that, for $x>0.25$, (Fe,Mg)O
remains insulating up to the highest studied pressures, implying a Mott
insulator to band insulator phase transition at the HS-LS transformation.
