/* Interface geometry is in CSS pixels. The world keeps its pixel-art grid. */
:root{padding:0;height:100%;--edge:12px;--touch-size:116px;--knob-size:46px}
*,*::before,*::after{box-sizing:border-box}
html,body{width:100%;height:100%;height:100dvh;min-height:0;overscroll-behavior:none}
#game{position:fixed;inset:0;width:100%;height:100%;image-rendering:pixelated}
.screen{padding:calc(60px + env(safe-area-inset-top,0px)) max(16px,env(safe-area-inset-right,0px)) calc(24px + env(safe-area-inset-bottom,0px)) max(16px,env(safe-area-inset-left,0px));justify-content:flex-start;gap:16px;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;background:rgba(13,10,26,.76);z-index:30}
.screen>.panel{flex:0 0 auto;margin-block:auto;min-width:0}
.screen>.panel::after{content:"";display:block;height:4px}
#title{justify-content:safe center;background:transparent}
.panel{max-width:820px;padding:20px;line-height:1.7;overflow-wrap:anywhere}
.panel h2{line-height:1.8}
.hint{line-height:1.9;font-size:clamp(9px,1.15vw,11px);overflow-wrap:anywhere}
.btn{font-size:clamp(10px,1.4vw,14px);line-height:1.5;min-height:44px;max-width:100%;padding:12px 18px}
.mbtns{gap:14px 18px;align-items:center}
.row{gap:12px;min-width:0}
.row .lab{flex:0 0 46px}
.sws{flex-wrap:wrap;justify-content:center;max-width:100%;gap:9px}
.sw{width:32px;height:32px;flex:0 0 32px}
.cards{gap:12px;align-items:stretch}
.card{min-width:104px;max-width:100%;padding:12px;flex-shrink:0}
.card small{font-size:8px;line-height:1.7}
.card .buy{min-height:36px;min-width:64px}
input.tin{max-width:100%;width:min(240px,100%);min-height:46px;font-size:16px}
.shoptop{flex-wrap:wrap;gap:14px}
.shoptop>div{flex:1 1 200px;min-width:0}
.tab{min-height:40px;line-height:1.5}
.plist,.glist{width:100%;max-width:500px}
.pitem,.gitem{line-height:1.8;overflow-wrap:anywhere}
.code{font-size:clamp(24px,7vw,40px);letter-spacing:5px}
#mute,#charBtn,#bagBtn,#bootBtn{position:fixed;top:calc(8px + env(safe-area-inset-top,0px));left:auto;min-width:40px;height:40px;border-radius:7px;z-index:40;box-shadow:0 3px 0 rgba(0,0,0,.35);touch-action:manipulation}
#skipTut{font-size:9px;min-height:36px;padding:8px 10px;z-index:20;max-width:calc(100% - 24px)}
#touch{z-index:15}
#stick{width:var(--touch-size);height:var(--touch-size);left:calc(16px + env(safe-area-inset-left,0px));bottom:calc(16px + env(safe-area-inset-bottom,0px));border-width:3px;background:rgba(37,23,67,.8)}
#knob{width:var(--knob-size);height:var(--knob-size);left:calc((var(--touch-size) - var(--knob-size))/2 - 3px);top:calc((var(--touch-size) - var(--knob-size))/2 - 3px);border-width:2px}
.tb{border-width:3px;width:48px;height:48px;min-width:44px;min-height:44px;font-size:20px;opacity:.95}
#ba{width:64px;height:64px;right:calc(16px + env(safe-area-inset-right,0px));bottom:calc(66px + env(safe-area-inset-bottom,0px));font-size:12px}
#bb{width:48px;height:48px;right:calc(88px + env(safe-area-inset-right,0px));bottom:calc(18px + env(safe-area-inset-bottom,0px));font-size:22px}
#bp{width:48px;height:48px;right:calc(24px + env(safe-area-inset-right,0px));bottom:calc(140px + env(safe-area-inset-bottom,0px));font-size:22px}
#bs{width:44px;height:44px;right:calc(94px + env(safe-area-inset-right,0px));bottom:calc(88px + env(safe-area-inset-bottom,0px));font-size:19px}
#touch.is-dialog #stick,#touch.is-dialog #bb,#touch.is-dialog #bp,#touch.is-dialog #bs{display:none}
#touch.is-dialog #ba{bottom:calc(18px + env(safe-area-inset-bottom,0px));width:64px;height:52px}
body[data-scene="hub"] #bp,body[data-scene="hub"] #bb,body[data-scene="hub"] #bs,body[data-scene="hub"] #ba{display:none}
#hubStatus{font-size:9px;line-height:1.8;color:#9ef5f0}
#hubActions{display:flex;flex-wrap:wrap;gap:12px;align-items:center}
#endUI{z-index:31}
#exitRoom{position:fixed;left:max(10px,env(safe-area-inset-left,0px));top:calc(8px + env(safe-area-inset-top,0px));z-index:20;min-height:40px;max-width:calc(100% - 224px);padding:8px 10px;border:2px solid #8a6ad0;border-radius:7px;background:#2a1c4a;color:#fff;font:8px/1.5 'Press Start 2P',monospace;cursor:pointer}
#connectionUI{z-index:45;background:rgba(13,10,26,.94)}
#connectionUI .hint{font-size:11px}
@media(max-width:480px){
  .screen{padding-inline:12px;gap:12px}.panel{padding:16px 12px}.card{min-width:96px;padding:10px 8px}.cards{gap:10px}.mbtns{gap:12px}.row{gap:10px}.row .lab{width:100%;flex-basis:100%;text-align:center}.btn{padding:11px 13px}.shoptop canvas{max-width:90px;height:auto}
}
@media(max-height:500px) and (min-width:500px){
  :root{--touch-size:88px;--knob-size:38px}.screen{padding-top:54px;padding-bottom:18px}.panel{padding:14px}.card{padding:8px}.card canvas{max-height:80px;width:auto}.card small{font-size:7px}.screen h2{margin-block:4px 8px}.row{margin-top:10px}.tb{width:44px;height:44px}
  #stick{left:calc(14px + env(safe-area-inset-left,0px));bottom:calc(12px + env(safe-area-inset-bottom,0px))}#ba{width:56px;height:56px;right:calc(14px + env(safe-area-inset-right,0px));bottom:calc(12px + env(safe-area-inset-bottom,0px))}#bb{right:calc(78px + env(safe-area-inset-right,0px));bottom:calc(12px + env(safe-area-inset-bottom,0px))}#bp{right:calc(18px + env(safe-area-inset-right,0px));bottom:calc(80px + env(safe-area-inset-bottom,0px))}#bs{right:calc(78px + env(safe-area-inset-right,0px));bottom:calc(64px + env(safe-area-inset-bottom,0px))}
}
/* Fixed interface bands share a layout with the world; nothing floats over actors. */
#gameHUD,#gameNotice,#storyDialog{position:fixed;z-index:16;font-family:'Press Start 2P',ui-monospace,monospace;box-sizing:border-box;border-radius:0}
#gameHUD{display:grid;grid-template-columns:minmax(116px,1fr) minmax(130px,1fr) 80px;grid-template-rows:auto auto auto;gap:6px 16px;padding:10px 14px;border:3px solid #665095;box-shadow:inset 0 0 0 2px #1b1226;background:#201637;font-size:10px;line-height:1.5;color:#fff}
#gameHUD canvas,#storyDialog canvas{image-rendering:pixelated;display:block}
.hud-vitals{grid-column:1;grid-row:1}.hud-vitals>canvas{width:108px;height:18px}.hud-treasure{display:flex;align-items:center;gap:10px;margin-top:4px}.hud-treasure canvas{width:100px;height:22px}.hud-treasure span{color:#f5d36a;font-size:9px}
.hud-clock{grid-column:2;grid-row:1;display:flex;flex-direction:column;gap:4px;text-align:center;align-items:center;justify-content:center}.hud-clock strong{font-size:14px;color:#f5d36a}.hud-clock span{font-size:9px}#hudRoom{color:#8af4ff}
#hudMap{grid-column:3;grid-row:1/4;width:80px;height:64px;align-self:start;outline:2px solid #8a6ad0}
.hud-power{grid-column:1/3;grid-row:2;display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:9px}.hud-power canvas{width:24px;height:24px}#hudEffects{color:#8af4ff;font-size:8px}
#hudQuest{grid-column:1/3;grid-row:3;color:#fff1b3;font-size:10px;line-height:1.6;overflow-wrap:anywhere}
#hudBoss{grid-column:1/-1;display:flex;gap:12px;align-items:center;font-size:10px;color:#ffb5df}#hudBossHealth{flex:1;min-width:30px;height:10px;accent-color:#f07ad8}
#gameNotice{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:8px 16px;padding:10px 14px;border:3px solid #8a6ad0;box-shadow:inset 0 0 0 2px #1b1226;background:#2a1c4a;color:#fff;text-align:center;font-size:11px;line-height:1.7;white-space:pre-line}
#gameNotice strong{color:#f5d36a;font-size:11px}#gameNotice[data-kind="tutorial"]{text-align:left;justify-content:flex-start}#gameNotice[data-kind="tutorial"] #noticeText{flex:1 1 180px}
#gameNotice #skipTut{position:static;transform:none;font-size:9px;line-height:1.5;min-height:36px;padding:7px 10px;max-width:none;margin-left:auto;flex:0 0 auto}
#storyDialog{display:grid;grid-template-columns:64px minmax(0,1fr) auto;gap:12px 16px;align-items:start;padding:18px;color:#4a1e08;background:#f4bc66;border:4px solid #50270f;box-shadow:inset 0 0 0 3px #b66a31,inset 0 0 0 6px #f8d088;font-size:clamp(11px,1.35vw,15px);line-height:1.65}
#storyDialog.no-portrait{grid-template-columns:minmax(0,1fr) auto}#storyDialog.no-portrait .speaker-column{display:none}
#dialogPortrait{width:64px;height:64px;background:#fbe2a8;outline:3px solid #a8582a;outline-offset:1px}
#dialogName{display:block;font-size:12px;line-height:1.5;margin-bottom:7px;color:#6a2a18}.dialog-copy{min-width:0}#dialogText{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}#dialogRemaining{visibility:hidden}
#dialogNext{align-self:end;background:#f8d088;border:2px solid #7a3a18;box-shadow:0 3px 0 #a8582a;color:#5a2a10;font:10px/1.5 'Press Start 2P',monospace;padding:10px 12px;min-width:88px;min-height:40px;cursor:pointer}
#dialogNext:focus-visible{outline:3px solid #5af0f0;outline-offset:3px}
#mute,#charBtn,#bagBtn,#bootBtn,#exitRoom{border-radius:0}
@media(min-width:700px){#gameHUD{grid-template-columns:220px minmax(180px,1fr) 80px;grid-template-rows:auto auto;padding:8px 14px}.hud-power{grid-column:2;grid-row:2;justify-content:center}#hudQuest{grid-column:1;grid-row:2}#hudMap{grid-row:1/3}}
@media(max-width:599px){#gameHUD{grid-template-columns:minmax(110px,1fr) minmax(110px,1fr) 64px;gap:5px 8px;padding:8px}.hud-treasure{flex-wrap:wrap;gap:2px}.hud-clock strong{font-size:11px}.hud-clock span{font-size:8px}#hudMap{width:64px;height:51.2px}#hudQuest{font-size:9px}#storyDialog{grid-template-columns:64px minmax(0,1fr);gap:10px;padding:14px;font-size:11px}#storyDialog.no-portrait{grid-template-columns:1fr}#dialogNext{grid-column:1/-1;justify-self:end;min-height:36px;padding:7px 10px}#dialogName{font-size:10px}#gameNotice{font-size:10px;padding:8px 10px}#gameNotice strong{font-size:10px}}
@media(max-height:500px) and (min-width:500px){#gameHUD{grid-template-columns:200px minmax(150px,1fr) 80px;grid-template-rows:auto auto;gap:2px 10px;padding:5px 10px}.hud-vitals{display:flex;flex-wrap:wrap;align-items:center;gap:8px}.hud-treasure{margin:0;gap:5px}.hud-vitals>canvas{width:81px;height:13.5px}.hud-treasure canvas{width:75px;height:16.5px}.hud-clock{flex-direction:row;flex-wrap:wrap;gap:5px 10px}.hud-clock strong{font-size:11px}#hudMap{grid-row:1/3;width:60px;height:48px;justify-self:end}.hud-power{grid-column:2;grid-row:2;font-size:8px}.hud-power canvas{width:12px;height:12px}#hudQuest{grid-column:1;grid-row:2;font-size:8px}#gameNotice{font-size:9px;line-height:1.5;padding:6px 10px}#gameNotice strong{font-size:9px}#storyDialog{font-size:11px;line-height:1.5;padding:12px;gap:10px}#dialogPortrait{width:64px;height:64px}#dialogName{font-size:10px;margin-bottom:3px}#dialogNext{font-size:9px;padding:7px 9px;min-width:78px;min-height:36px}}

/* Sprite surfaces use complete source pixels at one or two CSS pixels each. */
@media(max-width:599px){#gameHUD{grid-template-columns:minmax(100px,1fr) minmax(94px,1fr) 80px;gap:5px 6px}#hudMap{width:80px;height:64px}}
@media(max-height:500px) and (min-width:500px){.hud-vitals>canvas{width:108px;height:18px}.hud-treasure canvas{width:100px;height:22px}#hudMap{width:80px;height:64px}}
#storyDialog{font-size:14px}@media(max-width:699px),(max-height:500px){#storyDialog{font-size:11px}}
/* Announcements replace secondary HUD detail while they are on screen. */
body:not([data-ui-mode="normal"]) #gameHUD{grid-template-columns:minmax(110px,1fr) minmax(110px,1fr);grid-template-rows:auto;gap:6px;padding:7px 10px}
body:not([data-ui-mode="normal"]) #gameHUD .hud-vitals{display:flex;align-items:center;min-height:24px}
body:not([data-ui-mode="normal"]) #gameHUD .hud-clock{grid-column:2;grid-row:1;flex-direction:row;justify-content:flex-end}
body:not([data-ui-mode="normal"]) #gameHUD .hud-treasure,body:not([data-ui-mode="normal"]) #hudLevel,body:not([data-ui-mode="normal"]) #hudRoom,body:not([data-ui-mode="normal"]) #hudMap,body:not([data-ui-mode="normal"]) #gameHUD .hud-power,body:not([data-ui-mode="normal"]) #hudQuest,body:not([data-ui-mode="normal"]) #hudBoss{display:none}
#gameNotice[data-kind="tutorial"]{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:5px 10px}
#gameNotice[data-kind="tutorial"] #noticeHeading{grid-column:1;grid-row:1;font-size:9px}
#gameNotice[data-kind="tutorial"] #noticeText{grid-column:1/-1;grid-row:2;font-size:10px;line-height:1.5}
#gameNotice[data-kind="tutorial"] #skipTut{grid-column:2;grid-row:1;min-height:30px;font-size:8px;margin:0;padding:5px 8px}
#dialogNext{width:118px}
