Why it feels “broken”
-
You worked out the wrap-point like this
450 px (main) + 250 px (sidebar) + 24 px (gap) = 724 px.
-
What you forgot to add to that sum is the 1.5 rem left padding and the 1.5 rem right padding that you put on the BODY:
1.5 rem + 1.5 rem ≈ 24 px + 24 px = 48 px (on a 16 px root font-size).
-
So the two flex items actually need
450 + 250 + 24 + 48 = 772 px of viewport width
before they can sit next to each other.
• Below ±772 px they wrap (so visually the layout already looks “mobile”).
• But the viewport is still wider than 724 px, therefore
@media (max-width: 724px) is still FALSE,
and everything inside that block is ignored.
That is why you observe:
• The column layout appears earlier than expected (≈ 770 px).
• The styles inside the media query do not kick in until the window is squeezed
all the way down to 724 px.
Where to see it
Open DevTools → Console and resize the window; log window.innerWidth.
You will notice that the media-query styles start applying exactly at 724 px,
but the flex wrap happens about 48 px earlier.
How to fix it
A) Adjust the breakpoint so it matches the real wrap-point
/* 724 + 48 = 772 (round it to whatever feels right) */
@media (max-width: 772px) { … }
B) Move the padding off the BODY so it no longer influences the breakpoint
body { margin:0; } /* no horizontal padding here */
.layout-container { padding:1.5rem; } /* keep your visual spacing */
Now the original 724 px media query will work.
C) Use a container query (modern browsers) so the rule depends on the width
of .layout-container itself and not on the viewport width at all.
@container (max-width: 724px) {
/* ...same rules... */
}
(You’d add container-type:inline-size; to .layout-container to enable this.)
The CSS inside the @media block is perfectly valid; it just never
matched while the viewport was still wider than the declared 724 px because
of the extra 48 px of body padding.