  Using the optimal fluctuation method, we evaluate the short-time probability
distribution $P (\bar{H}, L, t=T)$ of the spatially averaged height $\bar{H} =
(1/L) \int_0^L h(x, t=T) \, dx$ of a one-dimensional interface $h(x, t)$
governed by the Kardar-Parisi-Zhang equation $$ \partial_th=\nu
\partial_x^2h+\frac{\lambda}{2} \left(\partial_xh\right)^2+\sqrt{D}\xi(x,t) $$
on a ring of length $L$. The process starts from a flat interface,
$h(x,t=0)=0$. Both at $\lambda \bar{H} < 0$, and at sufficiently small positive
$\lambda \bar{H}$ the optimal (that is, the least-action) path $h(x,t)$ of the
interface, conditioned on $\bar{H}$, is uniform in space, and the distribution
$P (\bar{H}, L, T)$ is Gaussian. However, at sufficiently large $\lambda
\bar{H} > 0$ the spatially uniform solution becomes sub-optimal and gives way
to non-uniform optimal paths. We study them, and the resulting non-Gaussian
distribution $P (\bar{H}, L, T)$, analytically and numerically. The loss of
optimality of the uniform solution occurs via a dynamical phase transition of
either first, or second order, depending on the rescaled system size $\ell =
L/\sqrt{\nu T}$, at a critical value $\bar{H}=\bar{H}_{\text{c}}(\ell)$. At
large but finite $\ell$ the transition is of first order. Remarkably, it
becomes an "accidental" second-order transition in the limit of $\ell \to
\infty$, where a large-deviation behavior $-\ln P (\bar{H}, L, T) \simeq (L/T)
f(\bar{H})$ (in the units $\lambda=\nu=D=1$) is observed. At small $\ell$ the
transition is of second order, while at $\ell =O(1)$ transitions of both types
occur.
