Context: We have not yet defined open and closed sets (in fact, their definition comes right after this proposition). I'll provide below the exact definitions we are using for this course:
Definition. Let $\left(X,d_X\right)$ and $\left(Y,d_Y\right)$ be metric spaces, and let $f:X\to Y$ be a function. We say $f$ is continuous at $x\in X$ if $\forall \varepsilon>0$, $\exists \delta > 0$ such that if $d_X\left(x,x'\right)<\delta$ then $d_Y\left(f(x),f\left(x'\right)\right)<\varepsilon$.
Definition. Let $(X,d)$ be a metric space, $x\in X$ and $r>0$. We define the open ball $B_{(X,d)}(x,r)$ in $X$ ,centred at $x$, and with radius $r$, in the metric $d$, to be the set \begin{equation*} B_{(X,d)}(x,r) := \{y\in X: d(x,y)<r\}. \end{equation*} The closed ball $B_{(X,d)}[x,r]$ is defined analogously: \begin{equation*} B_{(X,d)}[x,r] := \{y\in X: d(x,y)\leq r\}. \end{equation*}
Definition. A neighbourhood of a point $x\in X$ is a subset $N\subseteq X$ containing $B_r(x)$ for some $r>0$, i.e., $N\supseteq B_r(x)$.
The statement to be proven is
Statement. $f:X\to Y$ is continuous at $x\in X$ if and only if given any neighbourhood $N$ of $f(x)$ then $f^{-1}(N)$ is a neighbourhood of $x$.
My proof. $(\Longrightarrow)$. Suppose $f$ is continuous at $x\in X$ and that $N$ is a neighbourhood of $f(x)$. Then there exists an open ball $B_{\varepsilon}\left(f(x)\right)\subseteq N$. This means $\exists \varepsilon>0$ such that $y\in N$ if $d_Y \left(f(x),y\right)<\varepsilon$. Because $f$ is continuous at $x$, $\exists \delta > 0$ such that if $d_X \left(x,x'\right)<\delta$ then $d_Y \left(f(x),f\left(x'\right)\right)<\varepsilon$. Therefore $f^{-1}(N)$ is a neighbourhood of $x$, since it contains the ball $B_{\delta}(x)$.
$(\Longleftarrow)$. Suppose that given any neighbourhood $N$ of $f(x)$, $f^{-1}(N)$ is a neighbourhood of $x$. Then by the definition of neighbourhood, there exist (arbitrary) balls $B_{\varepsilon}\left(f(x)\right)$ and $B_{\delta}(x)$ in $N$ and $f^{-1}(N)$ respectively. In other words, $\forall \varepsilon>0$, $\exists \delta>0$ such that if $d_X\left(x,x'\right)<\delta$ then $d_Y\left(f(x),f\left(x'\right)\right)<\varepsilon$, which is the definition of continuity.
Question. Is my proof correct? And is there a better (clearer/more concise) way to prove this? Because I'm almost certain that this could be done much more elegantly (and potentially correctly).
Any help would be much appreciated.
For the first implication, try to show more clearly why the ball $B_{\delta}(x)$ is contained in $f^{-1}(N)$. It can be done as follows
If $y \in B_{\delta}(x)$, then $f(y)\in f(B_{\delta}(x)) \underbrace{\subseteq}_{\text{continuity}}B_{\epsilon}(f(x))\subseteq N \iff y \in f^{-1}(N)$ and thus $B_{\delta}(x)\subseteq f^{-1}(N)$.
Another way of doing the second part is let $x \in X$ and let $\epsilon>0$. Take $N=B(f(x),\epsilon)$ which is clearly a neighborhood of $f(x)$, by hypothesis we conclude that $f^{-1}(N)$ is a neighborhood of $x$.
Thus, $\exists \delta>0$ such that $B_{\delta}(x)\subseteq f^{-1}(N)$. Then for all $y \in X$ with $d(x,y)<\delta$,
$$f(y) \in f(f^{-1}(N))\subseteq N=B(f(x),\epsilon) \iff d(f(x),f(y))<\epsilon$$ Which is the definition of continuity in $x$.