A puzzling step in a solution for "Find $\sin(x)$ and $\cos(x)$, if $a\sin(x)+b\cos(x)=c$" A textbook problem:

Find $\sin(x)$ and $\cos(x)$, if $a\sin(x)+b\cos(x)=c$

The solution from the textbook:

Let's divide each term of this equation by $\sqrt{a^2+b^2}$:
  $$\frac{a}{\sqrt{a^2+b^2}}\sin(x)+\frac{b}{\sqrt{a^2+b^2}}\cos(x)=\frac{c}{\sqrt{a^2+b^2}}$$
  Since the sum of squares of $\frac{a}{\sqrt{a^2+b^2}}$ and $\frac{b}{\sqrt{a^2+b^2}}$ equals 1, then there will always exist an angle, let's call it $\phi$, for which 
  $$\sin(\phi)=\frac{a}{\sqrt{a^2+b^2}};$$
  $$\cos(\phi)=\frac{b}{\sqrt{a^2+b^2}}$$
  Using this, let's transform our equation to
  $$\sin(\phi)sin(x)+cos(\phi)cos(x)=\frac{c}{\sqrt{a^2+b^2}}$$
  This will bring us to
  $$\cos(x-\phi)=\frac{c}{\sqrt{a^2+b^2}}$$ 

This I understand. But the next step is:

It is evident from this that 
  $$\sin(x-\phi)=\pm\frac{\sqrt{a^2+b^2-c^2}}{\sqrt{a^2+b^2}}$$

Could you give me a hint regarding this last transformation? 

Let's say you posted like this:
~~~~~
for which 
$$\cos(\phi)=\frac{a}{\sqrt{a^2+b^2}};$$
$$\sin(\phi)=\frac{b}{\sqrt{a^2+b^2}}$$
Using this, let's transform our equation to
$$\cos(\phi)\sin(x)+\sin(\phi)\cos(x)=\frac{c}{\sqrt{a^2+b^2}}$$
This will bring us to
$$ \sin(x+\phi)=\frac{c}{\sqrt{a^2+b^2}}$$ 
This I understand. But the next step is:

It is evident from this that

$$\cos(x+\phi)=\pm\frac{\sqrt{a^2+b^2-c^2}}{\sqrt{a^2+b^2}}$$
Could you give me a hint regarding this last transformation? 
~~~~
You can see not immediately catching the $\sin, \cos $ Pythagorean relationship.
