Can you lose fat and gain muscle at the same time?
Yes, but mainly in specific situations: beginners, people returning after a long break, and those carrying higher body fat. For a trained person in a calorie deficit, gaining meaningful muscle is slow and difficult, which is why most structured plans alternate phases. If you are new, you can expect both to happen for several months on adequate protein and consistent resistance training, without needing to choose. The practical advice for most people is to stop optimising this question and instead train consistently, eat enough protein, and give it six months.
Answers
'Stop optimising and give it six months' applies to most fitness questions honestly.
Beginners getting both for free is the best argument for not overthinking the first year.