/* The application never scrolls. Only long sheets/editors own a scroll area. */
:root{--safe-top:env(safe-area-inset-top,0px);--safe-right:env(safe-area-inset-right,0px);--safe-bottom:env(safe-area-inset-bottom,0px);--safe-left:env(safe-area-inset-left,0px)}
html{position:fixed;inset:0;width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
body{position:fixed;inset:0;width:100%;height:100%;height:100dvh;max-height:100%;overflow:hidden;overscroll-behavior:none}
#world,.overlay,#hud{position:absolute;inset:0;max-width:100%;max-height:100%}
#world{width:100%;height:100%;touch-action:none}
#hud{pointer-events:none}
#hud button,#hud a{pointer-events:auto}
.workshop-card,.help-card,.editor-main{overscroll-behavior:contain}
#viewport-safe-area{position:absolute;inset:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);pointer-events:none;visibility:hidden}
#notification-zone{position:fixed;z-index:12;top:calc(88px + var(--safe-top));right:max(20px,var(--safe-right));width:clamp(190px,30vw,310px);display:flex;flex-direction:column;align-items:stretch;gap:7px;pointer-events:none}
#notification-zone #save-status,#notification-zone #achievement-toast{position:relative;inset:auto;transform:none;width:100%;max-width:none;margin:0;flex:none;white-space:normal;overflow-wrap:anywhere}
#notification-zone #save-status{min-height:0;padding:8px 12px;font-size:11px;text-align:left;display:none}
#notification-zone #save-status.visible{display:block;pointer-events:auto}
#notification-zone #achievement-toast{padding:12px 14px;display:none}
#notification-zone #achievement-toast.visible{display:flex}
#notification-zone #achievement-toast strong{font-size:clamp(11px,1.25vw,14px);line-height:1.4}
#notification-zone #achievement-toast small{font-size:8px;letter-spacing:.06em}
#orientation-guide{display:none}
#viewport-debug,#viewport-readout{display:none;pointer-events:none;position:fixed;z-index:30}
body[data-developer].framing-debug #viewport-debug{display:block;border:1px solid #80f7bc;background:#80f7bc05}
body[data-developer].framing-debug #viewport-safe-area{visibility:visible;border:1px dashed #f5c879;z-index:29}
body[data-developer].framing-debug #viewport-readout{display:block;right:max(12px,var(--safe-right));bottom:80px;max-width:330px;margin:0;padding:8px;background:#071923e8;font:10px/1.5 monospace;white-space:pre-wrap;color:#bce9d3}
/* Compact means touch input, limited width, or limited landscape height. */
body.touch-layout header{height:calc(56px + var(--safe-top));padding:var(--safe-top) max(14px,var(--safe-right)) 0 max(14px,var(--safe-left))}
body.touch-layout .brand{font-size:clamp(19px,3.5vh,25px)}
body.touch-layout .brand::before{width:16px;height:20px;margin-right:9px}
body.touch-layout .header-right{gap:4px}body.touch-layout .header-right button,body.touch-layout .header-right #help{min-width:44px;min-height:44px;height:44px;padding:7px;font-size:11px}
body.touch-layout .chapter{top:calc(60px + var(--safe-top));left:max(16px,var(--safe-left));max-width:min(55vw,480px)}
body.touch-layout .chapter h2{font-size:clamp(16px,3.6vh,23px);line-height:1.2;margin:4px 0}
body.touch-layout .chapter .eyebrow{font-size:clamp(8px,1.7vh,10px);letter-spacing:.08em}
body.touch-layout .chapter p{display:none}body.touch-layout #fragments{display:flex;margin-top:5px;gap:9px}
body.touch-layout #boss-phase{top:var(--chapter-bottom);left:max(16px,var(--safe-left));right:auto;max-width:55vw;padding:0;border:0;font-size:9px;letter-spacing:.02em;line-height:1.4}
body.touch-layout #blue-status,body.touch-layout.on-map #blue-status,body.touch-layout.secret-level #blue-status,body.touch-layout.platines-world:not(.secret-level) #blue-status{top:auto;left:auto;right:max(14px,var(--safe-right));bottom:calc(68px + var(--safe-bottom));font-size:10px;max-width:34vw;text-align:right}
body.touch-layout .dimension{display:none}
body.touch-layout .bottom{position:absolute;left:max(12px,var(--safe-left));right:max(12px,var(--safe-right));bottom:calc(8px + var(--safe-bottom));display:flex;align-items:center;justify-content:space-between;gap:8px;height:48px}
body.touch-layout .mobile-navigation{display:flex;order:0;gap:4px;flex:none}
body.touch-layout .mobile-navigation button{width:44px;height:44px;min-width:44px;min-height:44px;padding:0;font-size:22px}
body.touch-layout .hint-button{order:1;margin-left:auto;min-width:44px;min-height:44px;padding:8px;font-size:11px}
body.touch-layout .controls{order:2;position:static;transform:none;display:flex;flex:none;margin:0;max-width:none}
body.touch-layout .controls button{height:44px;min-width:44px;padding:0 8px;gap:5px}
body.touch-layout .controls #fold{width:clamp(112px,18vw,170px);min-width:0;font-size:11px}
body.touch-layout .controls b{font-size:11px}body.touch-layout .controls kbd{display:none}
body.touch-layout #message,body.touch-layout #tutorial,body.touch-layout.with-resonances #message,body.touch-layout.with-platines #message,body.touch-layout.printing-station #message{position:absolute;top:auto;bottom:calc(66px + var(--safe-bottom));left:50%;right:auto;transform:translateX(-50%);width:max-content;max-width:min(540px,70vw);min-height:0;margin:0;padding:7px 12px;font-size:clamp(10px,2.7vh,13px);line-height:1.4;overflow-wrap:anywhere}
body.touch-layout #message{background:#10232fee}body.touch-layout #message:not(.visible){visibility:hidden}
body.touch-layout.in-prologue #tutorial{max-width:min(550px,76vw)}
body.touch-layout #mechanic-note,body.touch-layout.printing-station #mechanic-note{top:var(--chapter-bottom);left:max(16px,var(--safe-left));right:auto;bottom:auto;width:auto;max-width:min(440px,55vw);margin:0;font-size:10px;line-height:1.4}
body.touch-layout #mechanic-actions,body.touch-layout.two-actions #mechanic-actions{position:absolute;top:auto;left:auto;right:max(12px,var(--safe-right));bottom:calc(62px + var(--safe-bottom));width:auto;max-width:45vw;display:flex;gap:6px;transform:none;align-items:stretch}
body.touch-layout #mechanic-actions #imprint,body.touch-layout #mechanic-actions #turn-platine,body.touch-layout #mechanic-actions #resonate{position:static;inset:auto;transform:none;min-height:44px;width:auto;min-width:0;max-width:100%;margin:0;padding:8px 12px;font-size:11px;line-height:1.3}
body.touch-layout #mechanic-actions small{display:none}
body.touch-layout.has-context-action #message{left:max(12px,var(--safe-left));transform:none;max-width:45vw}
body.touch-layout .discovery-action,body.touch-layout #read-inscription{position:absolute;top:auto;left:auto;right:max(12px,var(--safe-right));bottom:calc(112px + var(--safe-bottom));transform:none;min-height:44px;max-width:42vw;padding:8px 12px;font-size:11px}
body.touch-layout #enter-gate{position:absolute;top:auto;bottom:calc(62px + var(--safe-bottom));left:auto;right:max(12px,var(--safe-right));transform:none;min-height:44px;min-width:0;padding:10px 16px;font-size:12px}
body.touch-layout.on-map .bottom{justify-content:flex-start}body.touch-layout.on-map #message{left:max(12px,var(--safe-left));transform:none;max-width:60vw;bottom:calc(66px + var(--safe-bottom))}
body.touch-layout.on-map #world-travel{position:absolute;top:var(--chapter-bottom);left:max(16px,var(--safe-left));right:max(calc(36vw + 12px),var(--safe-right));bottom:auto;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;width:auto;max-width:690px;overflow:visible;transform:none;margin:0}
body.touch-layout.on-map #world-travel button{width:100%;min-width:0;min-height:44px;padding:6px 5px;font-size:clamp(9px,1.3vw,12px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
body.touch-layout #notification-zone{top:calc(62px + var(--safe-top));right:max(14px,var(--safe-right));width:clamp(170px,32vw,280px)}
body.touch-layout.on-map #notification-zone{top:calc(62px + var(--safe-top));right:max(14px,var(--safe-right));width:clamp(150px,30vw,240px)}
body.touch-layout.on-map #notification-zone #achievement-toast{padding:7px 10px}
body.touch-layout .workshop{inset:0;padding:calc(60px + var(--safe-top)) max(18px,var(--safe-right)) calc(12px + var(--safe-bottom)) max(18px,var(--safe-left))}
body.touch-layout .workshop-card{width:100%;max-width:1040px;max-height:100%;overflow-y:auto;overflow-x:hidden;padding:8px 6px 18px 0}
body.touch-layout .workshop #workshop-title{font-size:clamp(22px,4vh,32px);margin:10px 0 14px}
body.touch-layout .workshop #close-workshop{top:calc(8px + var(--safe-top));right:max(16px,var(--safe-right));min-height:44px;padding:8px 14px}
body.touch-layout #workshop-nav{display:flex;flex-wrap:wrap;overflow:visible;gap:5px;margin:0 0 12px;padding:0}
body.touch-layout #workshop-nav button{min-width:0;min-height:44px;font-size:11px;padding:8px 10px}
body.touch-layout .help-panel{padding:calc(12px + var(--safe-top)) max(18px,var(--safe-right)) calc(12px + var(--safe-bottom)) max(18px,var(--safe-left));display:flex;overflow:hidden}
body.touch-layout .help-card{max-height:100%;overflow-y:auto;overflow-x:hidden;padding:16px 20px;width:min(560px,100%)}
body.touch-layout .help-card h2{font-size:clamp(22px,5vh,32px);margin:8px 0}
body.touch-layout .help-card p{font-size:12px;line-height:1.5;margin:12px 0}
/* The title is a fixed composition, including its footer, never a scroll sheet. */
body.touch-layout .intro .intro-content{inset:calc(64px + var(--safe-top)) max(24px,var(--safe-right)) calc(12px + var(--safe-bottom)) max(24px,var(--safe-left));transform:none;width:auto;max-width:1000px;max-height:none;height:auto;overflow:hidden;padding:0;display:grid;grid-template-columns:minmax(0,.9fr) minmax(0,1.1fr);grid-template-rows:minmax(0,1fr) auto;gap:6px 6vw;align-items:center}
body.touch-layout .intro .intro-identity{grid-column:1;grid-row:1;min-width:0;align-self:center}
body.touch-layout .intro .intro-actions{grid-column:2;grid-row:1/3;min-width:0;align-self:center}
body.touch-layout .intro .intro-content h1{font-size:clamp(65px,18vh,140px);margin:8px 0;line-height:.96}
body.touch-layout .intro .intro-content .eyebrow{font-size:clamp(7px,1.8vh,10px);line-height:1.4;letter-spacing:.08em}
body.touch-layout .intro .intro-content .subtitle{display:block;font-size:clamp(13px,3.5vh,20px);margin:10px 0}
body.touch-layout .intro .intro-copy{display:block;font-size:clamp(10px,2.7vh,13px);line-height:1.5;margin:10px 0}
body.touch-layout .intro #start.primary,body.touch-layout .intro #resume.primary,body.touch-layout .intro #start.text-button{min-height:44px;padding:9px 12px;font-size:12px;margin:0 0 6px}
body.touch-layout .intro .menu-nav{display:grid;grid-template-columns:1fr 1fr;gap:5px;margin:6px 0}
body.touch-layout .intro .menu-nav button{min-height:44px;padding:6px 9px;font-size:11px;gap:6px}
body.touch-layout .intro .meta{font-size:8px;line-height:1.4;margin-top:8px}
body.touch-layout .intro .pli-version{grid-column:1;grid-row:2;min-height:44px;margin:0;padding:5px 0;font-size:10px;align-self:end}
body.touch-layout .intro-caption{display:none}
@media(max-height:520px) and (orientation:landscape){
 body.touch-layout .chapter .eyebrow{font-size:8px}body.touch-layout .chapter h2{font-size:17px}
 body.touch-layout .intro .intro-copy{display:none}body.touch-layout .intro .intro-content .subtitle{font-size:15px}
 body.touch-layout .intro .meta{display:none}body.touch-layout .intro .menu-nav{gap:4px}
 body.touch-layout .intro .menu-nav button{font-size:10px}
 body.touch-layout #fragments{margin-top:3px}
}
@media(max-width:740px){
 body.touch-layout .mobile-navigation{gap:2px}body.touch-layout .bottom{gap:5px;left:max(8px,var(--safe-left));right:max(8px,var(--safe-right))}
 body.touch-layout .controls #fold{width:112px}body.touch-layout .controls button{padding:0 5px}
 body.touch-layout.on-map #world-travel .world-name{display:none}
 body.touch-layout.on-map #world-travel button{font-size:12px}
 body.touch-layout .intro .intro-content{column-gap:20px}
 body.touch-layout .intro .intro-content .eyebrow{font-size:7px}
}
@media(orientation:portrait) and (pointer:coarse){
 #orientation-guide{position:fixed;inset:0;z-index:40;display:flex;flex-direction:column;justify-content:center;align-items:center;gap:18px;text-align:center;padding:30px;background:#101e28;font-size:16px;color:var(--cream)}
 #orientation-guide span{font-size:42px;color:var(--gold)}
}

@media(max-height:520px) and (orientation:landscape){
 body.touch-layout .intro .intro-content{top:calc(58px + var(--safe-top));bottom:calc(8px + var(--safe-bottom))}
 body.touch-layout .intro .intro-actions:has(#resume:not([hidden])){display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;align-items:stretch}
 body.touch-layout .intro .intro-actions #resume.primary{grid-column:1;grid-row:1;margin:0;font-size:11px;padding:8px}
 body.touch-layout .intro .intro-actions #start.text-button{grid-column:2;grid-row:1;margin:0;font-size:11px;padding:8px}
 body.touch-layout .intro .intro-actions .menu-nav{grid-column:1/-1;grid-row:2;gap:4px;margin:0}
 body.touch-layout .intro .menu-nav button:first-child,body.touch-layout .intro .menu-nav #menu-multiplayer{grid-column:auto}
 body.touch-layout .intro .menu-nav #menu-multiplayer{font-size:9px;letter-spacing:0}
}

body.touch-layout .help-card #close-help{position:sticky;bottom:0;z-index:2;min-height:44px;padding:10px 14px;margin-top:8px}

body.touch-layout #dev-badge{top:calc(6px + var(--safe-top));left:calc(max(14px,var(--safe-left)) + 110px);right:auto;bottom:auto;min-height:44px;min-width:44px;padding:8px}

body.touch-layout #blue-status{white-space:normal;overflow-wrap:anywhere}
body.touch-layout.secret-level #blue-status{display:none}
body.touch-layout #message,body.touch-layout.with-resonances #message,body.touch-layout.with-platines #message,body.touch-layout.printing-station #message{left:max(12px,var(--safe-left));transform:none;max-width:60vw}
body.touch-layout.has-context-action #message{max-width:45vw}

/* Landscape identity shares the header, leaving the vertical space to the puzzle. */
@media(orientation:landscape){
 body.touch-layout .chapter{top:calc(8px + var(--safe-top));left:calc(max(14px,var(--safe-left)) + 110px);max-width:min(410px,calc(var(--header-actions-left,70vw) - max(14px,var(--safe-left)) - 122px))}
 body.touch-layout .chapter h2{font-size:clamp(14px,3.6vh,19px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:2px 0}
 body.touch-layout .chapter .eyebrow{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:8px}
 body.touch-layout #fragments{margin-top:2px;gap:7px}
 body.touch-layout #mechanic-note{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}
 body.touch-layout:has(#dev-badge:not([hidden])) .chapter{left:calc(max(14px,var(--safe-left)) + 166px);max-width:min(360px,calc(var(--header-actions-left,70vw) - max(14px,var(--safe-left)) - 178px))}
}

/* Map metadata shares the header; the portal CTA owns the context row below. */
body.touch-layout.on-map #blue-status{top:calc(29px + var(--safe-top));bottom:auto;left:calc(var(--chapter-right,40vw) + 12px);right:calc(100% - var(--header-actions-left,80vw) + 12px);max-width:none;width:auto;text-align:left;white-space:nowrap;overflow:hidden;font-size:0}
body.touch-layout.on-map #blue-status::before{content:attr(data-compact);display:inline-block;font-size:10px;line-height:1.5}
body.touch-layout.has-context-action:not(.on-map) #blue-status{display:none}

/* Sheets own the focus. Preserve queued notices until the player returns. */
body:has(#help-panel:not([hidden])) #notification-zone,body:has(#workshop:not([hidden])) #notification-zone,body.editing-level #notification-zone{visibility:hidden}
body.touch-layout:has(#intro:not([hidden])) #notification-zone{top:calc(6px + var(--safe-top));left:calc(max(14px,var(--safe-left)) + 110px);right:calc(100% - var(--header-actions-left,80vw) + 12px);width:auto;max-width:400px}
