Your gut has its own local clock genes (PER, CRY, BMAL1). These regulate enzyme secretion, motility, barrier permeability on a 24h cycle.
Eating late at night when these clocks are in rest phase → ↓ digestive enzyme output → ↓ motility → food sits longer → more fermentation → bloating.
WHAT you eat matters. (of course it does). But WHEN you eat also matters cus your gut literally processes food differently depending on time of day (and personal consistency is key here as well).