I am embarrassed to ask but I don't get something really basic.
When molecular oxygen and hydrogen react to produce water, we say the oxygen has been reduced and the hydrogen has been oxidised. Reduction, I understand, is the gain of electrons.
So I look at the oxygen atoms prior to the reaction and it seems to me each has six of its own plus two more that are shared.
And I look at the oxygen in the water molecule and it has... six of its own and two that are shared.
So in what sense has it gained electrons?
Of course, before posting this question I have searched and read for several hours. All I can find is talk of half-reactions. The clue here seems to be that the oxygen is ionised to $\ce{O_2-}$ prior to reacting with $\ce{2H+}$. But this just confuses me. Maybe this intermediate step does involve reduced oxygen but the end point is still the same number of electrons as we started with, so if it does get reduced it must be oxidised again immediately afterwards, for no net effect.
Where am I going wrong?