:root{--rail-space:144px}
#cabinet{width:min(100vw,calc((100vh - var(--rail-space))*1.778125))}
#cabinet main{width:100%;aspect-ratio:16/9}

#top-rail{height:52px;display:flex;align-items:stretch;justify-content:space-between;margin-bottom:8px;border:1px solid #71f5ff55;background:#080a17f2;color:#eef9ff;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;overflow:hidden}
#topbuttons{position:static;inset:auto;z-index:auto;display:flex;align-items:stretch;gap:0;min-width:0;flex:1 1 auto}
.top-readout{min-width:168px;display:flex;flex-direction:column;justify-content:center;gap:3px;padding:7px 14px;border-right:1px solid #71f5ff26;text-align:left;overflow:hidden}
.top-readout small{color:#9eb6c4;font-size:10px;line-height:1;font-weight:850;letter-spacing:.12em}
#audio-status{overflow:hidden;color:#eef9ff;font-size:9px;line-height:1.1;font-weight:750;letter-spacing:.055em;text-overflow:ellipsis;white-space:nowrap}
#topbuttons button{width:auto;height:auto;min-width:58px;margin:0;padding:0 12px;border:0;border-right:1px solid #71f5ff26;border-radius:0;background:transparent;color:#c9dae3;box-shadow:none;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;font-size:10px;line-height:1;font-weight:850;letter-spacing:.075em}
#topbuttons button:hover,#topbuttons button:focus-visible{background:#111a2b;color:#fff}
#topbuttons button[aria-pressed="true"]{background:#16152b;color:#ffcf5b}
#music-toggle[aria-pressed="true"]{color:#ff8eaa}
#pause{font-size:15px!important}

#top-rail #wallet-rail{position:static;inset:auto;z-index:auto;min-width:310px;min-height:0;max-width:44%;flex:0 1 390px;gap:9px;margin:0;padding:5px 6px 5px 12px;border:0;border-left:1px solid #71f5ff55;border-radius:0;background:transparent;box-shadow:none}
#top-rail #wallet-open{min-height:34px;border-radius:4px;background:#111a2b;box-shadow:0 2px 0 #02040a}

#controls-rail{height:76px;display:grid;grid-template-columns:repeat(6,minmax(0,1fr));align-items:stretch;margin-top:8px;border:1px solid #71f5ff55;background:#080a17f2;color:#eef9ff;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;overflow:hidden}
.control{min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:7px;padding:8px 10px;border-right:1px solid #71f5ff26;text-align:center}
.control:last-child{border-right:0}
.control strong{display:block;color:#9eb6c4;font-size:clamp(12px,1vw,14px);line-height:1;font-weight:850;letter-spacing:.09em}
.control span{min-width:0;display:flex;align-items:center;justify-content:center;gap:5px;white-space:nowrap}
.control small{display:block;max-width:100%;overflow:hidden;color:#78909d;font-size:9px;line-height:1;letter-spacing:.02em;text-overflow:ellipsis;white-space:nowrap}
kbd{display:inline-flex;align-items:center;justify-content:center;min-height:24px;padding:4px 7px;border:1px solid #72cbd877;border-bottom-color:#72cbd8b8;border-radius:4px;background:#111a2b;color:#f7fdff;font-family:ui-monospace,"SFMono-Regular",Consolas,monospace;font-size:11px;line-height:1;font-weight:800;letter-spacing:.01em;box-shadow:0 2px 0 #02040a}
.control i{color:#627986;font-size:10px;font-style:normal}
.control.system{display:flex}
#fullscreen{display:flex;position:fixed;z-index:10002;top:60px;right:8px;align-items:center;justify-content:center;min-width:96px;height:38px;padding:0 12px;border:2px solid #71f5ff;border-radius:5px;background:#10182bf2;color:#efffff;box-shadow:0 0 0 2px #03040baa,0 4px 14px #03040bcc;font:900 11px/1 system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:.09em;pointer-events:auto}

canvas{image-rendering:auto}
#portrait-hud{display:none}

@media(pointer:coarse),(max-width:780px),(max-height:560px){
  :root{--rail-space:58px}
  #controls-rail{display:none}
  #top-rail{height:50px;margin-bottom:8px}
  .top-readout{min-width:0;max-width:106px;padding-inline:8px}
  .top-readout small{display:none}
  #audio-status{font-size:8px;white-space:normal}
  #topbuttons button{min-width:48px;padding-inline:7px;font-size:9px}
  #top-rail #wallet-rail{min-width:0;max-width:none;flex:1 1 auto;padding-left:8px}
  #top-rail .wallet-summary{min-width:72px}
  #top-rail #wallet-open{min-height:40px;padding-inline:8px;font-size:10px}
}
@media(max-width:620px){
  .top-readout{display:none}
  #topbuttons{flex:0 0 auto}
  #topbuttons #motion,#topbuttons #mute{display:none}
  #topbuttons button{min-width:52px}
  #top-rail #wallet-rail{border-left:1px solid #71f5ff26}
  #wallet-session-alert{display:none}
}
@media(max-width:440px){
  #topbuttons button{min-width:46px;padding-inline:5px;font-size:8px}
  #top-rail .wallet-summary{display:none}
  #top-rail #wallet-rail{justify-content:flex-end;padding-left:5px}
}

@media (max-width:700px), (pointer:coarse) and (max-aspect-ratio:4/3){
  :root{--rail-space:192px}
  html,body{width:100%;min-height:100svh;height:100dvh;overflow:hidden;overscroll-behavior:none}
  body{display:block;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}
  #cabinet{width:100%;height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));display:grid;grid-template-rows:44px minmax(0,1fr) 148px;gap:0;padding:0}
  #top-rail{grid-row:1;height:44px;margin:0;border-inline:0}
  #cabinet main{grid-row:2;width:100%;max-width:100%;height:min(100vw,calc(100dvh - 192px));aspect-ratio:auto;align-self:start;overflow:hidden;box-shadow:0 0 30px #3421a744}
  #cabinet main #game{position:absolute;left:0;top:0;width:177.8125%;height:100%;transform:translateX(var(--portrait-camera-x,0px));transform-origin:left center}
  #cabinet main #portrait-hud{display:block;position:absolute;left:0;top:0;width:100%;height:84px;transform:none;z-index:3;pointer-events:none;background:#050415}
  #controls-rail{display:none}
  .top-readout,#topbuttons #music-toggle,#topbuttons #motion,#topbuttons #mute{display:none}
  #topbuttons{flex:0 0 auto}
  #topbuttons button{min-width:44px;padding-inline:6px}
  #top-rail #wallet-rail{min-width:0;max-width:none;flex:1 1 auto;padding:3px 4px 3px 7px}
  #top-rail #wallet-open{min-height:34px;padding-inline:7px}
  #touch{position:fixed;left:0;right:0;bottom:env(safe-area-inset-bottom);height:148px;display:flex;align-items:center;padding:14px max(20px,env(safe-area-inset-right)) 16px max(20px,env(safe-area-inset-left));background:linear-gradient(180deg,#09071aee,#03020cf7);border-top:1px solid #71f5ff44;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
  #start:not(.hidden)~#touch,#end:not(.hidden)~#touch{display:none}
  #stick{width:108px;height:108px;touch-action:none}
  #stick i{width:46px;height:46px;left:50%;top:50%;margin:-23px 0 0 -23px}
  .touch-actions{gap:10px}
  .touch-actions button{width:64px;height:64px;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
  .touch-actions #touchMissile{width:60px;height:60px}
  .touch-actions #touchBoost{width:64px;height:64px}
  .touch-actions #touchFire{width:76px;height:76px;font-size:17px;box-shadow:0 0 0 5px #ff6f9a1f,0 0 22px #ff4e8466}
}

html.handheld-landscape{--rail-space:116px;width:100%;min-height:100svh;height:100dvh;overflow:hidden;overscroll-behavior:none}
html.handheld-landscape body{width:100%;min-height:100svh;height:100dvh;overflow:hidden;overscroll-behavior:none;display:block;padding:0}
html.handheld-landscape #cabinet{position:relative;width:100vw;height:100dvh;display:block;overflow:hidden;padding:0}
html.handheld-landscape #top-rail{position:absolute;z-index:30;left:0;right:0;top:0;width:100%;height:44px;margin:0;border-inline:0;background:#080a17e8}
html.handheld-landscape #cabinet main{position:absolute;inset:50% auto auto 50%;width:min(100vw,calc(100dvh*1.778125));height:auto;max-height:100dvh;aspect-ratio:16/9;transform:translate(-50%,-50%);overflow:hidden;box-shadow:0 0 34px #3421a744}
html.handheld-landscape #cabinet main #game{position:static;width:100%;height:100%;transform:none}
html.handheld-landscape #cabinet main #portrait-hud{display:none}
html.handheld-landscape #controls-rail{position:absolute;z-index:30;left:0;right:0;bottom:0;display:grid;height:72px;margin:0;border-inline:0;background:#080a17e8}
html.handheld-landscape .control{gap:4px;padding:5px 7px}
html.handheld-landscape .control strong{font-size:clamp(11px,1.2vh,12px)}
html.handheld-landscape .control span{gap:4px}
html.handheld-landscape .control small{font-size:clamp(10px,1.05vh,11px)}
html.handheld-landscape kbd{min-height:22px;padding:3px 6px;font-size:clamp(11px,1.15vh,12px);box-shadow:0 1px 0 #02040a}
html.handheld-landscape #touch{display:none!important}
html.handheld-landscape:not(.fullscreen-focus) #fullscreen{position:fixed;z-index:35;top:52px;right:8px;left:auto;bottom:auto}

/* Shared desktop + handheld focus mode. Wallet/reward dialogs remain inside
   the fullscreen document; only persistent cabinet chrome is collapsed. */
@media (min-aspect-ratio:4/3){
  html.fullscreen-focus,html.fullscreen-focus body{width:100vw;height:100dvh;overflow:hidden;background:#050415}
  html.fullscreen-focus #cabinet{position:fixed;inset:0;width:100vw;height:100dvh;display:block;overflow:hidden;padding:0}
  html.fullscreen-focus #cabinet main{position:absolute;inset:50% auto auto 50%;width:min(100vw,calc(100dvh*1.778125));height:auto;max-width:none;max-height:100dvh;aspect-ratio:16/9;transform:translate(-50%,-50%);overflow:hidden;box-shadow:none}
  html.fullscreen-focus #cabinet main #game{position:static;width:100%;height:100%;transform:none}
  html.fullscreen-focus #controls-rail{display:none!important}
  html.fullscreen-focus #top-rail{position:fixed;z-index:10000;inset:0 0 auto auto;width:0;height:0;margin:0;border:0;background:transparent;overflow:visible;pointer-events:none}
  html.fullscreen-focus #topbuttons{display:block;position:static;pointer-events:none}
  html.fullscreen-focus #topbuttons > *{display:none!important}
  html.fullscreen-focus #fullscreen{top:8px;min-width:48px;width:auto;height:34px;padding:0 9px;border-width:1px;opacity:.38}
  html.fullscreen-focus #fullscreen:hover,html.fullscreen-focus #fullscreen:focus-visible{opacity:1;background:#10182be8}
}
