12. Given the ellipse $C: \frac{x^{2}}{a^{2}}+\frac{y^{2}}{b^{2}}=1(a>b>0)$ with an eccentricity of $\frac{1}{2}$, the distance from the right focus $F$ to the line $x-y+2=0$ is $2 \sqrt{2}$, and $A_{1}$ and $A_{2}$ are the left and right vertices of the ellipse $C$ respectively.
(1) Find the equation of the ellipse $C$.
(2) A line $l$ passing through point $F$ intersects the ellipse $C$ at points $A$ and $B$ (point $A$ is above the $x$-axis), and $T$ is the intersection of the lines $A_{1} A$ and $A_{2} B$. When the $y$-coordinate of point $T$ is $6 \sqrt{3}$, find the equation of the line $l$.
12. (1) From the distance from the right focus $F(c, 0)$ to $x-y+2=0$ being $2 \sqrt{2}$, we have
$$
\frac{|c-0+2|}{\sqrt{2}}=2 \sqrt{2} \text {. }
$$

Combining with $c>0$, we get $c=2$.
Given that the eccentricity of the ellipse is $\frac{1}{2}$, we have
$$
a=2 c=4, b=2 \sqrt{3} \text {. }
$$

Thus, the equation of the ellipse $C$ is $\frac{x^{2}}{16}+\frac{y^{2}}{12}=1$.
(2) As shown in Figure 6.
It is easy to see that the slope of the line $l$ is

not 0, so let $l: x=m y+2$.
Combining the equations of the ellipse $C$ and the line $l$, we get
$$
\begin{array}{l}
\left(3 m^{2}+4\right) y^{2}+ \\
12 m y-36=0 .
\end{array}
$$

Thus, the discriminant $\Delta>0$ of equation (1), indicating two distinct real roots.
Let $A\left(x_{1}, y_{1}\right), B\left(x_{2}, y_{2}\right)$. Then
$$
y_{1}+y_{2}=\frac{-12 m}{3 m^{2}+4}, y_{1} y_{2}=\frac{-36}{3 m^{2}+4} \text {. }
$$

Let $T(t, 6 \sqrt{3})$.
From the collinearity of $A_{1} 、 A 、 T$, we have
$\frac{6 \sqrt{3}-0}{t+4}=\frac{y_{1}-0}{x_{1}+4}$
$\Rightarrow t+4=\frac{6 \sqrt{3}\left(x_{1}+4\right)}{y_{1}}=6 \sqrt{3}\left(m+\frac{6}{y_{1}}\right)$.
From the collinearity of $A_{2} 、 B 、 T$, we have
$\frac{6 \sqrt{3}-0}{t-4}=\frac{y_{2}-0}{x_{2}-4}$
$\Rightarrow t-4=\frac{6 \sqrt{3}\left(x_{2}-4\right)}{y_{2}}=6 \sqrt{3}\left(m-\frac{2}{y_{2}}\right)$.
Combining the above two equations to eliminate $t$, we get
$8=6 \sqrt{3}\left(\frac{6}{y_{1}}+\frac{2}{y_{2}}\right) \Rightarrow \frac{3}{y_{1}}+\frac{1}{y_{2}}=\frac{2}{3 \sqrt{3}}$.
Thus, $\frac{3}{y_{1}}+\frac{1}{y_{2}}=\frac{\left(y_{1}+y_{2}\right)+2 y_{2}}{y_{1} y_{2}}=\frac{2}{3 \sqrt{3}}$
$\Rightarrow \frac{-12 m}{3 m^{2}+4}+2 y_{2}=\frac{2}{3 \sqrt{3}} \times \frac{-36}{3 m^{2}+4}$.
Hence, $y_{2}=\frac{6 m-4 \sqrt{3}}{3 m^{2}+4}, y_{1}=\frac{-18 m+4 \sqrt{3}}{3 m^{2}+4}$.
Substituting $y_{1} y_{2}=\frac{-36}{3 m^{2}+4}$, we get
$\frac{-4(3 m-2 \sqrt{3})(9 m-2 \sqrt{3})}{\left(3 m^{2}+4\right)^{2}}=\frac{-36}{3 m^{2}+4}$
$\Rightarrow m=-\frac{\sqrt{3}}{3}$.
Therefore, the equation of the line $l$ is $x=-\frac{\sqrt{3}}{3} y+2$, or
$$
\sqrt{3} x+y-2 \sqrt{3}=0 .
$$