/* SPI-19 BeanBot TEST: DexRun short-landscape layout (phones turned sideways).
   Every rule is inside one media query, so portrait and tall desktop windows
   are unchanged. dexrun.html draws the world at VIEW_SCALE=(h-68)/520 in the
   same condition, putting the y=520 floor just above an 84px control band
   (SPI-31: 72px buttons, 1.5x the old 48px, + 6px margin + 6px clearance).
   Controls: one compact bottom row for ALL 16 levels (#wrap #controls beats the
   Level 1/2 square-pad overrides by specificity; colours/skins are untouched). */
/* Force field (Signal Defence Shield ◈) lives in the left pad, directly above
   ◀ ▶, in every orientation. Absolute, so the ◀ ▶ row does not move. */
#wrap #controls .pad{position:relative!important}
#wrap #controls .pad #signalShieldBtn{position:absolute!important;left:0;bottom:calc(100% + 8px);margin:0!important;grid-column:auto!important;grid-row:auto!important}
/* Combined device notch + Telegram Mini App insets. telegram-web-app.js also
   sets --tg-safe-area-inset-* and --tg-content-safe-area-inset-*. When those
   are 0 (outside Telegram), these equal env(safe-area-inset-*), so portrait
   stays pixel-identical. HUD, HUB, sound, the coin counter and the control
   row all honour the combined insets so Telegram's chrome and the notch stay
   clear. */
#dexrunHudPills{display:contents}
:root{
 --dexrun-safe-top:calc(max(env(safe-area-inset-top,0px),var(--tg-safe-area-inset-top,0px)) + var(--tg-content-safe-area-inset-top,0px));
 --dexrun-safe-right:calc(max(env(safe-area-inset-right,0px),var(--tg-safe-area-inset-right,0px)) + var(--tg-content-safe-area-inset-right,0px));
 --dexrun-safe-bottom:calc(max(env(safe-area-inset-bottom,0px),var(--tg-safe-area-inset-bottom,0px)) + var(--tg-content-safe-area-inset-bottom,0px));
 --dexrun-safe-left:calc(max(env(safe-area-inset-left,0px),var(--tg-safe-area-inset-left,0px)) + var(--tg-content-safe-area-inset-left,0px));
}
#dexrunTopHUD{
 top:max(8px,var(--dexrun-safe-top));
 left:calc(6px + var(--dexrun-safe-left));
 right:calc(56px + var(--dexrun-safe-right));
 max-width:calc(100% - 62px - var(--dexrun-safe-left) - var(--dexrun-safe-right));
 padding-left:0;
 padding-right:0;
 box-sizing:border-box;
}
#soundToggle{
 top:max(8px,var(--dexrun-safe-top));
 margin-right:var(--dexrun-safe-right);
}
#dexrunTopHUD #dexLevelCounter{
 top:0;
 right:0;
}
#state{
 top:calc(max(8px,var(--dexrun-safe-top)) + 44px);
}
#dexrunGateReminder{
 /* Portrait: sit just under the wrapped HUD / HUB stack, in the sky. */
 top:calc(max(8px,var(--dexrun-safe-top)) + 114px);
 width:min(280px,68vw);
 max-width:280px;
 max-height:calc(1.25em * 3 + 8px);
}


/* Rotate-back gate: shown on a phone in short landscape when Telegram
   fullscreen is not available. Not tied to html.dexrun-landscape. */
#dexrunRotateGate{
 position:fixed;inset:0;z-index:30;display:flex;align-items:center;justify-content:center;
 padding:16px;background:rgba(2,8,5,.86);color:#f4fff1;text-align:center;
}
#dexrunRotateGate[hidden]{display:none!important}
#dexrunRotateGate .card{
 width:min(420px,92vw);padding:22px 20px;border-radius:16px;
 background:rgba(3,12,8,.94);border:1px solid #7cff38;
 box-shadow:0 12px 40px #000a;
}
#dexrunRotateGate h2{margin:0 0 10px;font-size:22px;letter-spacing:.02em}
#dexrunRotateGate p{margin:0;font-size:15px;line-height:1.4;font-weight:650;color:#d7ffe8}
html.dexrun-rotate-gate #controls,html.dexrun-rotate-gate #overlay{pointer-events:none}

@media (orientation:landscape) and (max-height:639px){

 /* Top-right cluster: [HUB][audio][Dex counter], inside the insets.
    Audio stays immediately right of HUB in the same pill style. The left
    HUD pill row is reserved clear of that cluster and does not wrap. */
 html.dexrun-landscape{
  --dexrun-tr-counter:52px;
  --dexrun-tr-audio:48px;
  --dexrun-tr-hub:68px;
  --dexrun-tr-gap:4px;
  --dexrun-tr-cluster:calc(var(--dexrun-tr-counter) + var(--dexrun-tr-gap) + var(--dexrun-tr-audio) + var(--dexrun-tr-gap) + var(--dexrun-tr-hub) + 8px);
 }
 html.dexrun-landscape #dexrunTopHUD{
  left:calc(6px + var(--dexrun-safe-left));
  right:calc(var(--dexrun-tr-cluster) + var(--dexrun-safe-right));
  max-width:calc(100% - 8px - var(--dexrun-tr-cluster) - var(--dexrun-safe-left) - var(--dexrun-safe-right));
 }
 html.dexrun-landscape #dexrunTopHUD #hud{
  flex-wrap:nowrap!important;
  gap:2px!important;
  width:100%;
  min-width:0;
 }
 html.dexrun-landscape #dexrunHudPills{
  display:flex!important;
  flex-wrap:nowrap!important;
  align-items:center;
  gap:2px!important;
  min-width:0;
  flex:1 1 auto;
  width:100%;
 }
 html.dexrun-landscape #dexrunTopHUD #hud .hudbox,
 html.dexrun-landscape #dexrunTopHUD #dexusCityVitals{
  backdrop-filter:none!important;-webkit-backdrop-filter:none!important;
  font-size:8px!important;
  letter-spacing:0!important;
  padding:2px 4px!important;
  min-height:24px!important;
  gap:2px!important;
 }
 html.dexrun-landscape #dexrunTopHUD #dexrunThemeIdentity{
  min-width:0!important;
  min-height:24px!important;
  font-size:8px!important;
  padding:2px 4px!important;
 }
 html.dexrun-landscape #dexrunTopHUD #dexrunThemeIdentity::before{
  width:14px;height:14px;flex-basis:14px;font-size:11px;
 }
 html.dexrun-landscape #dexrunTopHUD #dexusCityVitals progress{width:22px!important}
 html.dexrun-landscape #dexrunTopHUD #dexLevelCounter,
 html.dexrun-landscape #dexLevelCounter{
  position:fixed!important;
  top:max(8px,var(--dexrun-safe-top))!important;
  right:max(8px,var(--dexrun-safe-right))!important;
  left:auto!important;
  height:42px;
  z-index:6;
  pointer-events:none;
 }
 html.dexrun-landscape .dexrun-exit,
 html.dexrun-landscape #soundToggle{
  position:fixed!important;
  top:max(8px,var(--dexrun-safe-top))!important;
  margin:0!important;
  white-space:nowrap!important;
  z-index:6;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  min-height:42px!important;
  height:42px!important;
  width:auto!important;
  padding:0 12px!important;
  border-radius:10px!important;
  border:1px solid #ffe18b!important;
  background:#07090c!important;
  color:#ffe18b!important;
  font:800 12px/1 system-ui,sans-serif!important;
  box-shadow:0 0 14px rgba(255,225,139,.24)!important;
  line-height:1!important;
  left:auto!important;
  transform:none!important;
 }
 html.dexrun-landscape #soundToggle{
  right:calc(max(8px,var(--dexrun-safe-right)) + var(--dexrun-tr-counter))!important;
  min-width:0!important;
  max-width:none!important;
  pointer-events:auto;
 }
 html.dexrun-landscape .dexrun-exit{
  right:calc(max(8px,var(--dexrun-safe-right)) + var(--dexrun-tr-counter) + var(--dexrun-tr-gap) + var(--dexrun-tr-audio))!important;
 }
 html.dexrun-landscape #state{
  top:calc(max(8px,var(--dexrun-safe-top)) + 46px);
 }
 html.dexrun-landscape #dexrunGateReminder{
  /* SPI-32: compact top-centre strip under the HUD/#state row, clear of
     corner plates, the floor and the controls. Not a mid-arena banner. */
  top:calc(max(8px,var(--dexrun-safe-top)) + 70px);
  width:min(260px,38vw);
  max-width:260px;
  font-size:10px;
  padding:3px 8px;
  max-height:calc(1.25em * 3 + 6px);
 }

 html.dexrun-landscape #wrap #controls{
  /* SPI-31: 1.5x the old clamp(44px,12vh,48px); visual and hit area. */
  --dexrun-land-btn:clamp(66px,18vh,72px);
  position:fixed!important;
  inset:auto 0 max(6px,var(--dexrun-safe-bottom))!important;
  padding:0 max(6px,var(--dexrun-safe-right)) 0 max(6px,var(--dexrun-safe-left))!important;
  display:flex!important;justify-content:space-between!important;align-items:flex-end!important;
  gap:8px!important;
 }
 html.dexrun-landscape #wrap #controls .pad{
  position:relative!important;display:flex!important;flex-direction:row!important;
  align-items:flex-end!important;gap:12px!important;margin:0!important;
 }
 html.dexrun-landscape #wrap #controls .actions{
  position:static!important;display:flex!important;flex-direction:row!important;
  flex-wrap:nowrap!important;align-items:flex-end!important;justify-content:flex-end!important;
  gap:9px!important;grid-template-columns:none!important;grid-template-rows:none!important;
  right:auto!important;bottom:auto!important;
 }
 html.dexrun-landscape #wrap #controls .dexus-utility-buttons,
 html.dexrun-landscape #wrap #controls .dexus-primary-buttons{
  display:flex!important;flex-direction:row!important;align-items:flex-end!important;gap:9px!important;
 }
 html.dexrun-landscape #wrap #controls .ctl{
  grid-column:auto!important;grid-row:auto!important;
  width:var(--dexrun-land-btn)!important;height:var(--dexrun-land-btn)!important;
  min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;
  font-size:calc(var(--dexrun-land-btn) * .46)!important;line-height:1!important;padding:0!important;
  border-radius:10px!important;
  /* SPI-31: no live blur over the game canvas in landscape (iOS re-blurs it every frame). */
  backdrop-filter:none!important;-webkit-backdrop-filter:none!important;
 }
 html.dexrun-landscape #wrap #controls .actions .ctl.hidebtn{display:none!important}
 html.dexrun-landscape #wrap #controls #aegisBtn,html.dexrun-landscape #wrap #controls #signalShieldBtn{font-size:calc(var(--dexrun-land-btn) * .4)!important}

 /* Status text sits under the top HUD row so it stays off HUB/audio and the runner. */
 html.dexrun-landscape #boss{top:calc(max(8px,var(--dexrun-safe-top)) + 80px)}

 /* Opening scene: art, hint and START all fit in a ~375px-tall view. */
 html.dexrun-landscape #dexrunOpening{padding:8px calc(12px + var(--dexrun-safe-right)) 8px calc(12px + var(--dexrun-safe-left))}
 html.dexrun-landscape #dexrunOpening .card{width:min(680px,92vw);max-height:calc(100dvh - 16px);padding:10px 14px}
 html.dexrun-landscape #dexrunOpening h2{margin:2px 0 4px;font-size:18px}
 html.dexrun-landscape #dexrunOpening img{max-height:36vh;margin-bottom:6px}
 html.dexrun-landscape #dexrunOpening .hint{font-size:14px;line-height:1.3}
 html.dexrun-landscape #dexrunOpening button{min-height:42px;margin-top:8px}

 /* Menus: compact fixed nav bar; the card and HUB footer fit the short view. */
 html.dexrun-landscape body:not(.beaniverse-playing) .beaniverse-global-nav{
  position:fixed!important;top:0;left:0;right:0;margin:0!important;
  padding:3px max(10px,var(--dexrun-safe-right)) 3px max(10px,var(--dexrun-safe-left))!important;
 }
 html.dexrun-landscape .beaniverse-global-nav a,html.dexrun-landscape .beaniverse-global-nav button{min-height:34px!important}
 html.dexrun-landscape #overlay{
  justify-content:flex-start;gap:6px;
  padding:calc(46px + var(--dexrun-safe-top)) calc(10px + var(--dexrun-safe-right)) max(6px,var(--dexrun-safe-bottom)) calc(10px + var(--dexrun-safe-left));
 }
 html.dexrun-landscape #overlay .card{
  width:min(900px,96vw);padding:10px 16px;border-radius:16px;
  max-height:calc(100dvh - 46px - 54px - var(--dexrun-safe-top) - var(--dexrun-safe-bottom));
 }
 html.dexrun-landscape #overlay .dexrun-nav-footer{width:min(900px,96vw);display:flex;gap:8px;padding-bottom:0}
 html.dexrun-landscape #overlay .dexrun-nav-footer>*{flex:1}
 html.dexrun-landscape #overlay .dexrun-nav-footer .dexrun-menu-link,html.dexrun-landscape #overlay .dexrun-nav-footer button{min-height:40px;padding:8px 12px}
 html.dexrun-landscape #overlay .card .brand{font-size:10px}
 html.dexrun-landscape #overlay .card .dex-menu-hero{height:72px;width:min(110px,20vw);margin:0 auto}
 html.dexrun-landscape #overlay .card .dex-menu-hero.idlehero{height:72px}
 html.dexrun-landscape #overlay .card h1{font-size:34px;margin:2px 0}
 html.dexrun-landscape #overlay .card>p{margin:4px 0;font-size:12px}
 html.dexrun-landscape #overlay #menuMusicBtn{margin:4px 4px 6px}
 html.dexrun-landscape #overlay #beanbotGraphicsToggle{display:inline-block;margin:4px 4px 6px}
 html.dexrun-landscape #overlay .dexrun-home-actions{grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:8px 0}
 html.dexrun-landscape #overlay .dexrun-home-actions button{min-height:44px;padding:8px 10px;font-size:14px}
 html.dexrun-landscape #overlay .dexrun-panel{margin:4px 0}
 html.dexrun-landscape #overlay .dexrun-panel h2{margin:2px 0 6px;font-size:15px}
 html.dexrun-landscape #overlay .levels{grid-template-columns:repeat(2,minmax(0,1fr))}
 html.dexrun-landscape #overlay .shopgrid{grid-template-columns:repeat(3,minmax(0,1fr))}

}
