9. (16 points) For $t \in[0, \pi]$, let $S=\sin ^{2} x+\sin ^{2} y+\left(8 \sin ^{2} t+2\right) \sin x \sin y$ have the maximum value $M(t)$ and the minimum value $N(t)$, where $x$ and $y$ are non-negative real numbers, and $x+y=t$. Let $g(t)=M(t)-N(t)$, find the maximum value of $g(t)$, and indicate the value of $t$ at that time.
9. First, we have
$$
\begin{aligned}
S & =\sin ^{2} x+\sin ^{2} y+2 \cos t \cdot \sin x \cdot \sin y+\left(8 \sin ^{2} t-2 \cos t+2\right) \sin x \sin y \\
& =\sin ^{2} t+\left(10-8 \cos ^{2} t-2 \cos t\right) \sin x \sin y \\
& =\sin ^{2} t+\left(5-4 \cos ^{2} t-\cos t\right)(\cos (x-y)-\cos t) .
\end{aligned}
$$

It is easy to see that \(5-4 \cos ^{2} t-\cos t \geqslant 0\), so \(M(t)=\sin ^{2} t+\left(5-4 \cos ^{2} t-\cos t\right)(1-\cos t)\), \(N(t)=\sin ^{2} t\). Therefore,
$$
\begin{aligned}
g(t) & =\left(5-4 \cos ^{2} t-\cos t\right)(1-\cos t) \\
& =(4 \cos t+5)(1-\cos t)(1-\cos t) \\
& =2\left(2 \cos t+\frac{5}{2}\right)(1-\cos t)(1-\cos t) \\
& \leqslant 2\left(\frac{\left(2 \cos t+\frac{5}{2}\right)+(1-\cos t)+(1-\cos t)}{3}\right)^{3} \\
& =2\left(\frac{3}{2}\right)^{3}=\frac{27}{4} .
\end{aligned}
$$

Equality holds if and only if \(2 \cos t+\frac{5}{2}=1-\cos t\), i.e., \(\cos t=-\frac{1}{2}\), which is when \(t=\frac{2}{3} \pi\).