I got the expression $\cos \theta \cos ( \theta-
\varphi) = \sin \theta \sin ( \theta-\varphi) $ from the derivative to solve for $\theta$. This gets expanded out to
$$ \cos \theta ( \cos \varphi \cos \theta + \sin \varphi \sin \theta) = \sin \theta ( \cos \varphi \sin \theta - \sin \varphi \cos \theta) \tag{1} $$
Now apply the tangent-half-angle substitution(s) of
$$ \begin{array}{c|c}
z = \tan \left( \tfrac{\varphi}{2} \right) & t = \tan \left( \tfrac{\theta}{2} \right) \\
\varphi = 2 \tan^{-1}(z) & \theta = 2 \tan^{-1}(t) \\ \hline
\cos(\varphi) = \tfrac{1-z^2}{1+z^2} & \cos(\theta) = \tfrac{1-t^2}{1+t^2} \\
\sin(\varphi) = \tfrac{2 z}{1+z^2} & \sin(\theta) = \tfrac{2 t}{1+t^2}
\end{array} \tag{2}$$
The result is
$$\small \frac{1-t^2}{1+t^2} \left( \frac{(1-z^2)(1-t^2)}{(1+z^2)(1+t^2)} + \frac{(2 z)(2 t)}{(1+z^2)(1+t^2)} \right) = \frac{2 t}{1+t^2} \left( \frac{(2 t)(1-z^2)}{(1+z^2)(1+t^2)} - \frac{(1-t^2)(2 z)}{(1+z^2)(1+t^2)} \right) $$
which is simplified by eliminating common terms down to
$$ (1-t^2)(z^2 (1-t^2)-4 t z + t^2-1) = 4 t (t z^2 + (1-t)^2 z -t) $$
Finally, bring both sides together to get
$$ (1-z^2) t^4 -8 z t^3 - 6 (1-z^2) t^2 + (8 z) t + (1-z^2) = 0 \tag{3} $$
which is a solvable quatric polynomial in terms of $t$ and hence $\theta = 2 \tan^{-1}(t)$
If you restict $\varphi = 0 \ldots \pi/2$ then $z (1-z^2) \ge 0$ and the four solutions of $t$ are
$$ \large t = \begin{cases}
\text{-} \frac{ \sqrt{2} (1-z) \sqrt{1+z^2}-z^2-2z-1}{1-z^2} \\
\text{+} \frac{ \sqrt{2} (1-z) \sqrt{1+z^2}+z^2+2z+1}{1-z^2} \\
\text{-} \frac{ \sqrt{2} (1+z) \sqrt{1+z^2}+z^2-2z+1}{1-z^2} \\
\text{+} \frac{ \sqrt{2} (1+z) \sqrt{1+z^2}-z^2+2z-1}{1-z^2} \\
\end{cases} \tag{4} $$
Expanded out, the above is also written as
$$ \large \tan \left( \frac{\theta}{2} \right) = \begin{cases}
\frac{(1+\sin(\varphi))\sqrt{1+\cos(\varphi)}-\cos(\varphi)+\sin(\varphi)-1}{\cos(\varphi)\sqrt{1+\cos(\varphi)}} \\
\frac{(1+\sin(\varphi))\sqrt{1+\cos(\varphi)}+\cos(\varphi)-\sin(\varphi)+1}{\cos(\varphi)\sqrt{1+\cos(\varphi)}} \\
\frac{(\sin(\varphi)-1)\sqrt{1+\cos(\varphi)}-\cos(\varphi)-\sin(\varphi)-1}{\cos(\varphi)\sqrt{1+\cos(\varphi)}} \\
\frac{(\sin(\varphi)-1)\sqrt{1+\cos(\varphi)}+\cos(\varphi)+\sin(\varphi)+1}{\cos(\varphi)\sqrt{1+\cos(\varphi)}} \\
\end{cases}$$