/* Use the visible browser viewport, including when mobile browser bars move. */
html{height:100%;overflow:hidden}
body{min-height:0;height:100%;overflow:hidden;overscroll-behavior:none}
main{height:var(--app-height,100dvh);display:flex;flex-direction:column;min-height:0;padding-left:max(10px,env(safe-area-inset-left));padding-right:max(10px,env(safe-area-inset-right));padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom)}
header{height:72px;min-height:52px;flex:0 0 auto;gap:12px}
#stage{flex:1 1 0;min-height:0;width:100%;height:auto;max-height:none;aspect-ratio:auto}
canvas{object-fit:contain}
footer{flex:0 0 auto;min-height:48px;flex-wrap:wrap;gap:8px}
.tools{flex-shrink:0;gap:6px}.tools button{min-height:44px}
#fullscreen{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-width:44px}
#fullscreen svg{width:20px;height:20px;flex-shrink:0}
#fullscreen .collapse-icon{display:none}body[data-expanded="true"] #fullscreen .expand-icon{display:none}body[data-expanded="true"] #fullscreen .collapse-icon{display:block}
#screen-status{position:fixed;top:max(58px,env(safe-area-inset-top));left:50%;transform:translateX(-50%);z-index:20;max-width:calc(100% - 24px);padding:10px 14px;border-radius:10px;background:#132c40;color:#e2f7ee;font-size:14px;pointer-events:none;text-align:center}
#screen-status:empty{display:none}
/* Root fullscreen keeps the toolbar and modal dialogs available. */
body[data-expanded="true"] main{max-width:none;padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right)}
body[data-expanded="true"] header{height:50px;padding:0 10px}
body[data-expanded="true"] footer{display:none}
body[data-expanded="true"] #stage{border-radius:0;border:0;box-shadow:none}
body[data-expanded="true"] .chapter{display:none}
.overlay{overflow-y:auto;overscroll-behavior:contain;align-items:flex-start}
.intro{flex-shrink:0;margin-top:auto;margin-bottom:auto}
@media(max-width:950px){.chapter{display:none}header{height:56px}footer{min-height:36px}.controls{gap:10px}}
@media(max-width:650px){
 header,body[data-replay-unlocked="true"] header{height:52px;min-height:52px;flex-wrap:nowrap;padding:0;gap:6px}
 .brand{font-size:0;flex-shrink:1}.brand>span:last-child{font-size:0;margin:0}.brand-icon{font-size:28px;margin-right:0}
 .tools{margin-left:auto}.tools button{font-size:11px;padding:0 8px}.fullscreen-label{display:none}
 footer{display:none}
 .intro{margin:0 6%;padding:18px 0}.intro h1{font-size:clamp(38px,10vw,60px);margin:12px 0}
 .intro p{font-size:15px;line-height:1.45;margin:12px 0}.primary{min-width:0;width:100%;font-size:13px;padding:14px 16px}.start-note{margin-top:12px}
 .save-actions{margin-top:10px;gap:8px}.save-actions button{padding:8px 12px}
}
@media(any-pointer:coarse){
 header{height:52px}footer{display:none}
 .scene-caption{display:none}
 .touch-controls{left:max(12px,env(safe-area-inset-left));right:max(12px,env(safe-area-inset-right));bottom:10px}
}
@media(any-pointer:coarse) and (orientation:portrait){
 #stage{--control-space:166px;background:linear-gradient(#101723 calc(100% - var(--control-space)),#132638 calc(100% - var(--control-space)))}
 #game{height:calc(100% - var(--control-space))}
 .touch-controls .direction-pad{grid-template:58px 34px 58px / 58px 34px 58px}
 .direction-pad button{width:62px;height:62px;justify-self:center;align-self:center;border-radius:50%;font-size:28px}
}
@media(any-pointer:coarse) and (orientation:portrait) and (max-width:360px){
 #stage{--control-space:144px}.touch-controls{left:max(8px,env(safe-area-inset-left));right:max(8px,env(safe-area-inset-right))}
 .touch-controls .direction-pad{grid-template:52px 28px 52px / 52px 28px 52px}
 .direction-pad button{width:56px;height:56px;font-size:27px}
}
/* A shallow lower deck keeps thumbs off the full-width play window. */
@media(any-pointer:coarse) and (orientation:landscape){
 #stage{--control-space:112px;background:linear-gradient(#101723 calc(100% - var(--control-space)),#132638 calc(100% - var(--control-space)))}
 #game{width:100%;height:calc(100% - var(--control-space));margin-left:0}
 .hud{left:10px;right:10px;top:6px;gap:4px}
 .hud>div{padding:5px 6px}.eyebrow{font-size:9px;margin-bottom:3px}#fuses{font-size:17px}#score{font-size:19px}
 .touch-controls{left:12px;right:12px;bottom:4px;gap:12px}
 .touch-controls .direction-pad{position:static;grid-template:48px 8px 48px / 48px 32px 48px;background:transparent}
 .direction-pad button{width:48px;height:48px;justify-self:center;align-self:center;border-radius:50%;font-size:26px}
 .touch-controls .action-controls{position:static;flex-direction:row;align-items:center;gap:10px;padding:0 0 14px}
 .action-controls button{width:64px;height:64px;font-size:12px}.action-controls .jump{width:72px;height:72px;font-size:14px;margin:0}
}
@media(any-pointer:coarse) and (orientation:landscape) and (max-height:600px){
 header{height:48px;min-height:48px}.fullscreen-label{display:none}
 .overlay{align-items:flex-start}.intro,body[data-mode="paused"] .intro{margin:0 5%;padding:12px 0;max-width:580px}
 .intro h1{font-size:36px;margin:8px 0}.intro h1 br{display:none}.intro h1 span{margin-left:8px}.intro p{font-size:14px;line-height:1.4;margin:8px 0}
 .start-note{margin-top:8px}.save-actions{margin-top:8px}.level-stamp{display:none}
}

/* One shared hint row directly below the objective in every world. */
.hud{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);align-items:start;column-gap:6px;row-gap:5px}
.hud .health{justify-self:start}.hud .objective{justify-self:center}.hud .tokens{justify-self:end}
#toast{position:static;inset:auto;transform:none;grid-column:1 / -1;justify-self:center;width:max-content;max-width:min(100%,560px);margin:0;padding:6px 11px;border-radius:8px;font-size:13px;line-height:1.35;font-weight:400;letter-spacing:0;box-shadow:none;background:#10283ae8;pointer-events:none}
#toast:empty{display:none}
@media(any-pointer:coarse) and (orientation:landscape){
 .touch-controls{align-items:center}
 .touch-controls .action-controls{padding-bottom:0}
 /* No empty up/down rows in levels that only use left and right. */
 body:not([data-level="3"]):not([data-free-move="true"]) #stage{--control-space:88px}
 body:not([data-level="3"]):not([data-free-move="true"]) .touch-controls{bottom:8px}
 body:not([data-level="3"]):not([data-free-move="true"]) .direction-pad{grid-template:56px / 56px 24px 56px}
 body:not([data-level="3"]):not([data-free-move="true"]) .direction-pad button{width:56px;height:56px}
 body:not([data-level="3"]):not([data-free-move="true"]) .direction-pad [data-key="left"]{grid-area:1 / 1}
 body:not([data-level="3"]):not([data-free-move="true"]) .direction-pad [data-key="right"]{grid-area:1 / 3}
 body:not([data-level="3"]):not([data-free-move="true"]) .vertical-direction{display:none}
}

/* Invisible margin accepts slightly off-edge taps without taking more layout space. */
.touch-controls .direction-pad{position:relative}
.direction-pad::before{content:"";position:absolute;inset:-6px;border-radius:inherit;pointer-events:auto;touch-action:none}
.direction-pad button{position:relative;z-index:1}
