Proof (dimension of closed subvariety)
Recall dimension equals transcendence degree of the function field.
By restricting to an affine patch (which does not change the function field so dimension), WLOG assume $Y\subseteq Z\subseteq \mathbb{A}^r$ are affine.
Let $y_1, \ldots, y_n\in k(Y)$ be a transcendence basis of $k(Y)/k$, and by clearing denominators, WLOG assume $y_1, \ldots, y_n\in A(Y)$. Viewing in $A(Z)$, $y_1, \ldots, y_n\in A(Z)$ is still algebraically independent. Suppose $\op{trdeg}_k Y = \op{trdeg}_k Z$, so $y_1, \ldots, y_n$ is a transcendence basis of $k(X)/k$.
As $Y\subsetneq Z$, there exists some $g\in I(Y)\setminus I(Z)$. Viewing in $k(Z)$, $g\neq 0$ , so there exists a minimal polynomial $f\in k[Y_1, \ldots, Y_n, T]$ such that $$f(y_1, \ldots, y_n, g) = 0 \qquad \text{in }k(Z).$$ Now viewing this in $k(Y)$, we get $$f(y_1, \ldots, y_n, 0) = 0 \qquad \text{in }k(Y),$$ which is a non-zero algebraic relation as $T \not\mid f$ by irreducibility. This contradicts that $y_1, \ldots, y_n$ are algebraically independent.