You do not need to be in a surplus.

You need the stimulus (training) and then to be able to feed that with amino acids.

So you need enough macronutrients and calories that your body isn’t cannabalizing muscle tissue/the protein that you eat for energy requirements. Thats it.

Clearly, it’s more complex that this but until someone is very lean (sub 10%) it’s more than possible to gain muscle and lose fat at the same time. Whether that is a bit much of a competing priority for optimal progress is beyond the scope of this medium.