Let
$$
y=\frac{x^2+x\sin\theta+1}{x^2+x\cos\theta+1}.
$$
(i) Given that $x$ is real, show that
$$
(y\cos\theta-\sin\theta)^2\geqslant 4(y-1)^2.
$$
Deduce that
$$
y^2+1\geqslant 4(y-1)^2,
$$
and hence that
$$
\frac{4-\sqrt7}{3}\leqslant y\leqslant\frac{4+\sqrt7}{3}.
$$
(ii) In the case $y=\dfrac{4+\sqrt7}{3}$, show that
$$
\sqrt{y^2+1}=2(y-1)
$$
and find the corresponding values of $x$ and $\tan\theta$.