Let $\Phi\subseteq\mathcal{P}(\mathcal{X})$ be a collection of subsets of $\mathcal{X}$. We say $\Phi$ is $\Pi_1^1$ on $\Pi_1^1$ if for $A\subseteq\mathbb{N}\times\mathcal{X}$, $A\in \Pi_1^1$, the set of sections $\{n:A_n\in\Phi\}$ is $\Pi_1^1$. Similarly define what it means for $\Phi$ to be $\Pi_1^1$ on $\Sigma_1^1$. So $\Phi$ can be thought of as a "property" of sets
The first reflection theorem states the following: If $\Phi$ is $\Pi_1^1$ on $\Pi_1^1$ and $A$ is a $\Pi_1^1$ set, then $$\Phi(A)\implies\exists B\in\Delta_1^1 (B\subseteq A \wedge \Phi(B)).$$ An equivalent formulation is that if $\Phi$ is $\Pi_1^1$ on $\Sigma_1^1$, and $A$ is $\Sigma_1^1$, then $$\Phi(A)\implies\exists B\in\Delta_1^1(B\supseteq A\wedge\Phi(B)).$$ This easily follows from the first formulation by taking $\Phi'(A)=\Phi(\neg A)$.
The proof of this theorem is given as follows:
Proof: Suppose not. Take $W\subseteq\mathbb{N}$, $W\in\Pi_1^1\setminus\Delta_1^1$. Let $U\subseteq\mathcal{N}$ be $\Pi_1^1$-complete, and let $\varphi:U\to\operatorname{Ordinals}$ be a $\Pi_1^1$-rank on $U$. Then, there are total recursive functions $f$ and $g$ such that $x\in A\iff f(x)\in U$ and $n\in W\iff g(n)\in U$ (this is just the definition of completeness). Now, here is the part that I am having trouble wrapping my head around. The proof goes on to say that all this means that
$$n\notin W\iff\Phi(\{x:f(x)<_{\varphi}^*g(n)\}),$$
which means $W$ is $\Delta_1^1$, a contradiction.
The statement $n\in W\iff g(n)\in U$ gives us a $\Pi_1^1$ definition of $W$, so I understand that we are trying to get a $\Sigma_1^1$ definition of $W$ to arrive at a contradiction. What confuses me is how we arrive at the highlighted statement by assuming the contrary of the statement of the theorem, and why that means the complement of $W$ is $\Pi_1^1$. I would also appreciate it if someone could give an intuitive explanation of being $\Pi_1^1$ on $\Pi_1^1$. I've also been unable to find any reference on any of this -- the closest is Moschovakis' Descriptive Set Theory text, but even that doesn't seem to contain this result. Any help is greatly appreciated.
EDIT: The document here gives a proof of the boldface result, but seems to be structured differently(?)