I'm looking at a derivation of the Euler-Lagrange equations in a field setting, and one step in the proof is continually eluding me. Let $\phi(\vec x,t)$ be a field and $\mathscr L(\phi,\partial_\mu\phi)$ be a Lagrangian density where $\partial_\mu \equiv (c^{-1}\frac{\partial}{\partial t},\vec\nabla)$ is the indexed covariant spacetime differential operator. We define the action of $\mathscr L$ $$\mathcal S[\phi(\vec x,t)]\equiv \int dt\,d^d x\mathscr L.$$
We now pick a field $\phi'(\vec x,t) = \phi(\vec x, t) + \delta\phi(\vec x, t)$ and wish to extremize $\mathcal S$ - in particular, to solve the principle of least/extremal action $$\delta\mathcal S=0+\mathcal O(\delta\phi^2)$$ (here the higher order terms will be implicitly ignored).
$$\begin{align}0 = \delta\mathcal S \equiv \mathcal S[\phi']-\mathcal S[\phi] \\ = \int dt\,d^d x\left[\mathscr L(\phi+\delta\phi,\partial_\mu\phi+\partial_\mu\delta\phi) - \mathscr L(\phi,\partial_\mu\phi)\right] \\ = \int dt\, d^d x\left[\frac{\partial\mathscr L}{\partial\phi}\delta\phi+\frac{\partial \mathscr L}{\partial \partial_\mu\phi}\delta\partial_\mu\phi\right] \\\delta\mathcal S = \int dt\, d^d x\left[\frac{\partial\mathscr L}{\partial\phi}\delta\phi+\frac{\partial \mathscr L}{\partial \partial_\mu\phi}\partial_\mu(\delta\phi)\right]\tag{1} \end{align}$$
The majority of this is essentially trivial. However, I can't make heads nor tails of the next step - the only justification given for it is "we now integrate the second term by parts several times to split $(1)$ into two integrals". I know that in the regular Euler-Lagrange derivation you integrate by parts once w.r.t time and end up with a vanishing surface term, but this generalization for some reason makes me uneasy.
$$\delta\mathcal S = \int dt\,d^d x\left[\frac{\partial\mathscr L}{\partial\phi} - \partial_\mu\left(\frac{\partial\mathscr L}{\partial\partial_\mu\phi}\right)\right]\delta\phi\color{red}{+\int dt\,d^d x\left[\partial_\mu\left(\frac{\partial\mathscr L}{\partial\partial_\mu\phi}\delta\phi\right)\right]}$$
My question is simply: how did the red term come about, and why is it itself an integral? Did we somehow perform integration by parts a continuum of times?