/* Each playable page owns one viewport. Chapter menus and the cover keep their layouts. */
body.playing-page:not(.book-closed){height:100svh;height:100dvh;overflow:hidden}
.playing-page #gameContent{height:100svh;height:100dvh;display:flex;flex-direction:column;padding-top:env(safe-area-inset-top,0px)}
.playing-page .masthead{width:100%;height:48px;min-height:48px;flex:0 0 48px;margin:0 auto;padding:0 max(12px,env(safe-area-inset-left,0px));gap:10px}
.playing-page .wordmark{gap:8px}
.playing-page .wordmark>svg{width:19px;height:28px}
.playing-page .wordmark span{font-size:19px;letter-spacing:3px}
.playing-page .wordmark small{display:none}
.playing-page .masthead nav{gap:4px}
.playing-page .masthead .navbutton,.playing-page .masthead .iconbutton{width:44px;height:44px;min-height:44px;padding:10px;border:0}
.playing-page .masthead .navbutton span{display:none}
.playing-page .story-pages{width:100%;flex:1 1 0%;min-height:0;margin:0 auto;display:flex}
.playing-page .site-footer{display:none}
/* The same class is retained on outgoing burn/turn snapshots. */
.story-pages>#puzzlePanel.level-page,.level-page{display:flex;flex-direction:column;justify-content:flex-start;width:100%;height:100%;min-height:0;max-width:560px;margin:0 auto;padding:8px 12px max(8px,env(safe-area-inset-bottom,0px));gap:5px;border:0}
.level-page[hidden]{display:none!important}
.level-page>*{flex-shrink:0;min-width:0}
.level-page .puzzle-top{height:18px;margin:0}
.level-page .puzzle-top .eyebrow{font-size:9px;letter-spacing:2px}
.level-page .page-icon{font-size:21px;line-height:18px}
.level-page .page-dots{gap:6px}
.level-page .puzzle-heading h2{font-size:clamp(20px,5.7vw,26px);line-height:1.12;margin:0;letter-spacing:-.4px}
.level-page .puzzle-heading p{font-size:12px;line-height:1.25;margin:3px 0 0}
.level-page .link-guide{margin:0;padding:0;border:0;background:none}
.level-page .link-guide-heading,.level-page .link-guide>p,.level-page .pair-mode{display:none}
.level-page .link-guide small{position:absolute;width:1px;height:1px;min-height:0;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.level-page .link-pairs{display:flex;flex-wrap:nowrap;gap:5px}
.level-page .pair-key{flex:1;min-width:0;height:44px;min-height:44px;justify-content:center;padding:3px 4px;gap:4px}
.level-page .pair-key .water-pair-key{width:19px;height:24px}
.level-page .pair-key>span{gap:1px}
.level-page .pair-key>span>strong{font-size:10px}
.level-page .pair-key .pair-direction-arrows{width:29px;height:18px}
.level-page .board-stage{container-type:size;flex:1 1 0%;width:100%;min-height:0;padding:8px;display:grid;place-items:center}
/* Both axes constrain the square, including changing browser bars and 6×6 boards. */
.level-page .board-shell{width:min(100cqw,100cqh);height:min(100cqw,100cqh);max-width:480px;max-height:480px;aspect-ratio:1;padding:6px;margin:0;flex:none}
.level-page .board{gap:2px;height:100%;min-height:0}
.level-page .tile{min-height:0}
.level-page .board-status{height:18px;min-height:18px;margin:0;font-size:11px;letter-spacing:0}
.level-page .flow-feedback{font-size:11px;line-height:18px}
.level-page .toolstrip{height:auto;min-height:44px;margin:0;padding:0;border:0;gap:6px}
.level-page .toolstrip button{min-height:44px;font-size:12px;gap:6px}
.level-page .next-inline{height:44px;min-height:44px;margin:0;padding:0 14px;font-size:13px}
.level-page.is-complete .toolstrip{display:none}
.level-page .tip{display:none}
.level-page .puzzle-footer{height:44px;margin:0;gap:6px;flex-wrap:nowrap;justify-content:flex-start;font-size:10px;line-height:1.3}
.level-page .footer-flower{display:none}
.level-page .puzzle-footer .quick-sound{height:44px;min-height:44px;min-width:80px;flex-shrink:0;font-size:11px;margin-left:auto}
.level-page .puzzle-footer #helpButton{height:44px;width:44px;min-width:44px;margin:0;font-size:18px}
.level-help{padding:12px 14px;border:1px solid var(--border);border-radius:8px;background:#9ed6dd0b}
.level-help h3{font:20px/1.2 Georgia,serif;margin:0 0 8px;color:var(--paper)}
.level-help p{font:12px/1.6 Arial,sans-serif;margin:6px 0;color:#b9d3d4}
/* Very short portrait windows retain the whole board and the same 44px controls. */
@media(max-height:620px){
 .level-page .puzzle-heading p{display:none}
 .story-pages>#puzzlePanel.level-page,.level-page{gap:3px;padding-top:5px;padding-bottom:max(5px,env(safe-area-inset-bottom,0px))}
}
@media(max-width:340px){
 .level-page .pair-key .water-pair-key{width:14px;height:21px}
 .level-page .pair-key>span>strong{font-size:9px}
 .level-page .pair-key .pair-direction-arrows{width:26px}
 .level-page .pair-key{gap:2px;padding-inline:2px}
}
/* In landscape, keep the board beside the title, color keys and controls. */
@media(min-width:480px) and (max-height:560px){
 .story-pages>#puzzlePanel.level-page,.level-page{max-width:960px;display:grid;grid-template-columns:minmax(0,1.15fr) minmax(200px,.85fr);grid-template-rows:18px auto auto minmax(0,1fr) minmax(44px,auto) minmax(44px,auto);grid-template-areas:"board page" "board heading" "board pairs" "board ." "board tools" "status footer";column-gap:14px;row-gap:4px}
 .level-page .puzzle-top{grid-area:page}
 .level-page .puzzle-heading{grid-area:heading}
 .level-page .puzzle-heading h2{font-size:23px}
 .level-page .puzzle-heading p{display:none}
 .level-page .link-guide{grid-area:pairs}
 .level-page .pair-key .water-pair-key,.level-page .toolstrip button svg{display:none}
 .level-page .board-stage{grid-area:board;height:100%}
 .level-page .board-status{grid-area:status;align-self:center}
 .level-page .toolstrip,.level-page .next-inline{grid-area:tools}
 .level-page .puzzle-footer{grid-area:footer}
 .level-page .puzzle-footer>span{display:none}
}
/* Chapter openers teach through the existing puzzle, without an extra page or overlay. */
.level-page .tutorial-guide{height:auto;min-height:64px;margin:0;padding:8px 10px;border:1px solid #dfca8866;border-radius:7px;background:linear-gradient(110deg,#d2ba681c,#0a252a44)}
.tutorial-guide[hidden]{display:none!important}
.tutorial-top{display:flex;align-items:center;gap:8px;line-height:13px}
.tutorial-top>span{font:9px/13px Arial,sans-serif;letter-spacing:.7px;color:var(--gold);white-space:nowrap}
.tutorial-top>strong{font:600 11px/13px Arial,sans-serif;color:var(--paper)}
.tutorial-guide p{font:11px/14px Arial,sans-serif;color:#d0dfd6;margin:5px 0 0}
.level-page.has-tutorial .puzzle-heading p{display:none}
.level-page .tile.tutorial-target{outline:2px solid #ffe5a5;outline-offset:-3px;box-shadow:inset 0 0 14px #ffd8772e,0 0 9px #fff0aa40}
.page-entry .tutorial-label{display:inline-block;font:9px/1.4 Arial,sans-serif;letter-spacing:.4px;border:1px solid #d6c18a66;border-radius:3px;padding:2px 5px;margin-right:5px;color:#f4daa0;vertical-align:middle}
@media(min-width:480px) and (max-height:560px){
 .level-page.has-tutorial{grid-template-rows:18px auto minmax(64px,auto) auto minmax(44px,1fr) minmax(44px,auto);grid-template-areas:"board page" "board heading" "board lesson" "board pairs" "board tools" "status footer"}
 .level-page .tutorial-guide{grid-area:lesson}
 .level-page.has-tutorial .toolstrip,.level-page.has-tutorial .next-inline{align-self:end}
 .level-page .tutorial-guide{padding:5px 7px}
 .tutorial-top{gap:5px;flex-wrap:wrap;row-gap:0}
 .tutorial-top>span{font-size:8px}
 .tutorial-top>strong{font-size:10px}
 .tutorial-guide p{font-size:10px;line-height:12px;margin-top:3px}
}
/* Hard adds a clock and a larger supply row. Give both explicit places in
   landscape, and allow vertical travel instead of clipping controls or tiles. */
@media(min-width:480px) and (max-height:560px){
 body.hard-mode.playing-page:not(.book-closed){height:auto;min-height:100dvh;overflow-y:auto}
 body.hard-mode.playing-page #gameContent{height:auto;min-height:100dvh}
 body.hard-mode.playing-page .story-pages{flex:none;display:block}
 body.hard-mode.playing-page .story-pages>#puzzlePanel.level-page{
  height:auto;min-height:calc(100dvh - 52px);grid-template-rows:18px auto auto auto auto minmax(44px,auto) minmax(44px,auto) auto;
  grid-template-areas:"board page" "board heading" "board wallet" "board pairs" "board timer" "board tools" "status footer" "competition competition";
 }
 body.hard-mode.playing-page .story-pages>#bossPanel.mosaic-page{
  height:auto;min-height:calc(100dvh - 52px);grid-template-rows:18px auto auto auto minmax(30px,auto) minmax(44px,auto) minmax(44px,auto) auto;
  grid-template-areas:"picture page" "picture heading" "picture wallet" "picture timer" "picture feedback" "picture preview" "status tools" "competition competition";
 }
 body.hard-mode .level-page .hard-timer{grid-area:timer;margin:0;min-height:44px;flex-wrap:wrap}
 body.hard-mode .level-page .hard-timer button{min-height:44px}
 body.hard-mode .level-page .ranked-link{grid-area:competition;margin:0;min-height:44px}
 body.hard-mode .level-page .economy-strip{height:auto;min-height:44px}
 body.hard-mode .level-page .board-stage,body.hard-mode .mosaic-page .mosaic-stage{container-type:inline-size;height:auto;align-self:start}
 body.hard-mode .level-page .board-shell{width:min(100cqw,480px);height:auto;max-height:none;aspect-ratio:1}
 body.hard-mode .mosaic-page .mosaic-frame{width:100%;height:auto}
}
/* Adventure content can grow, including Page 01 with no supplies shown.
   Keep lessons, wrapped controls and competition in their own intrinsic rows. */
@media(min-width:480px) and (max-height:560px){
 body.playing-page:not(.hard-mode):not(.book-closed){height:auto;min-height:100dvh;overflow-y:auto}
 body.playing-page:not(.hard-mode) #gameContent{height:auto;min-height:100dvh}
 body.playing-page:not(.hard-mode) .story-pages{flex:none;display:block}
 body.playing-page:not(.hard-mode) .story-pages>#puzzlePanel.level-page{
  height:auto;min-height:calc(100dvh - 52px);grid-template-rows:18px auto auto auto minmax(44px,auto) minmax(44px,auto) auto;
  grid-template-areas:"board page" "board heading" "board wallet" "board pairs" "board tools" "status footer" "competition competition";
 }
 body.playing-page:not(.hard-mode) .story-pages>#puzzlePanel.level-page.has-tutorial{
  grid-template-rows:18px auto auto auto auto minmax(44px,auto) minmax(44px,auto) auto;
  grid-template-areas:"board page" "board heading" "board wallet" "board lesson" "board pairs" "board tools" "status footer" "competition competition";
 }
 body.playing-page:not(.hard-mode) .story-pages>#bossPanel.mosaic-page{
  height:auto;min-height:calc(100dvh - 52px);grid-template-rows:18px auto auto minmax(30px,auto) minmax(44px,auto) minmax(44px,auto) auto;
  grid-template-areas:"picture page" "picture heading" "picture wallet" "picture feedback" "picture preview" "status tools" "competition competition";
 }
 body.playing-page:not(.hard-mode) .level-page .ranked-link{grid-area:competition;margin:0;min-height:44px}
 body.playing-page:not(.hard-mode) .level-page :is(.board-stage,.mosaic-stage){container-type:inline-size;height:auto;align-self:start}
 body.playing-page:not(.hard-mode) .level-page .board-shell{width:min(100cqw,480px);height:auto;max-height:none;aspect-ratio:1}
 body.playing-page:not(.hard-mode) .mosaic-page .mosaic-frame{width:100%;height:auto}
}

/* Private candidate: a lesson's growing content must not shrink its puzzle.
   Short landscape keeps its existing two-column rules. */
@media(min-height:561px){
 body.playing-page:not(.book-closed):has(#puzzlePanel.has-tutorial:not([hidden])){height:auto;min-height:100dvh;overflow-y:auto}
 body.playing-page:has(#puzzlePanel.has-tutorial:not([hidden])) #gameContent{height:auto;min-height:100dvh}
 body.playing-page:has(#puzzlePanel.has-tutorial:not([hidden])) .story-pages{flex:none;display:block}
 .story-pages>#puzzlePanel.level-page.has-tutorial{height:auto;min-height:calc(100dvh - 52px)}
 #puzzlePanel.level-page.has-tutorial .board-stage{container-type:inline-size;flex:none;height:auto}
 #puzzlePanel.level-page.has-tutorial .board-shell{width:min(100cqw,480px);height:auto;max-height:none;aspect-ratio:1}
}
