3. The solution set of the equation $x^{2}+x-1=x \pi^{x^{2}-1}+\left(x^{2}-1\right) \pi^{x}$ is $A$ (where $\pi$ is an irrational number, $\pi=3.141 \cdots$, and $x$ is a real number). Then the sum of the squares of all elements in $A$ is ( ).
(A) 0
(B) 1
(C) 2
(D) 4
3.C.

Let $y=x^{2}-1$, then the original equation becomes
$$
x\left(\pi^{y}-1\right)+y\left(\pi^{x}-1\right)=0.
$$

When $x>0$, we have $\pi^{x}-1>0$.
Thus, $x$ and $\pi^{x}-1$ have the same sign.
Similarly, $y$ and $\pi^{y}-1$ have the same sign.
Therefore, when $x y \neq 0$, we have $x\left(\pi^{x}-1\right) y\left(\pi^{y}-1\right)>0$, which means $x\left(\pi^{y}-1\right) y\left(\pi^{x}-1\right)>0$.
Hence, $x\left(\pi^{y}-1\right)$ and $y\left(\pi^{\tau}-1\right)$ have the same sign.
From equation (1), we know that $x=0$ or $y=0$.
The roots of the original equation are $-1,0,1$, i.e., $A=\{-1,0,1\}$. Therefore, the sum of the squares of its elements is 2.