Line numbers in grid get confusing quickly. With named areas I can see the layout in the stylesheet, almost like a little ASCII drawing.
.page {
display: grid;
grid-template-columns: 14rem 1fr;
grid-template-areas:
"header header"
"nav main"
"footer footer";
}
.page > header { grid-area: header; }
.page > nav { grid-area: nav; }
.page > main { grid-area: main; }
.page > footer { grid-area: footer; }
@media (width < 40rem) {
.page {
grid-template-columns: 1fr;
grid-template-areas: "header" "main" "nav" "footer";
}
}
Each quoted string is a row and each word a cell. Repeat a name to let an area span cells, and use a dot for an empty cell. The children only say which area they belong in, so for the phone layout you rewrite the strings and leave the rest alone.
The areas have to be rectangles. An L shape makes the whole declaration invalid, and then nothing is placed.
The bigger caveat is order. Moving nav below main on screen does not change the DOM, so keyboard users still tab through the navigation first and screen readers read it first. That is fine here, but do not use areas to put content in an order that contradicts the source.
Further reading: MDN: grid-template-areas