/* Antigrav Racer 3D - stage, HUD and menus. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
#stage { --bg: #0b0e2a; --ink: #eaf0ff; --muted: #9aa6d6; --acc: #6c4dff; --cyan: #35d6ff; --gold: #ffd34d; --green: #3cff9a; --pink: #ff5d73;
  position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: linear-gradient(#1b1450, #0b0e2a); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; container-type: inline-size; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
html.pip-immersive .game-wrap.pip-stage #stage { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .game-wrap.pip-stage .ag-bar, html.pip-immersive .game-wrap.pip-stage .ag-keys { display: none; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; touch-action: none; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage #ui button, #stage #ui .panel, #stage #ui input, #stage #ui .screenhost, #stage #ui .dragzone { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage [hidden] { display: none !important; }

#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#1b1450, #0b0e2a); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 3px; }
#stage .load-in span { font-size: 14px; opacity: .85; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.25); border-top-color: var(--cyan); animation: agspin .8s linear infinite; }
@keyframes agspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(11,14,42,.92); color: #fff; font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; font-size: 14px; }
#stage .dragzone { position: absolute; inset: 0; touch-action: none; }
#stage .hud.btnmode .dragzone { display: none; }
#stage .hud::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s; background: radial-gradient(ellipse at 50% 55%, rgba(53,214,255,0) 45%, rgba(53,214,255,.38) 100%); }
#stage.boosting .hud::before { opacity: 1; }
#stage .hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 10px 0; pointer-events: none; }
#stage .pos { display: flex; align-items: baseline; gap: 2px; background: rgba(8,10,36,.62); border-radius: 12px; padding: 4px 10px; }
#stage .pos b { font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; color: var(--gold); text-shadow: 0 2px 0 rgba(0,0,0,.4); }
#stage .pos span { font-size: 14px; opacity: .8; }
#stage .lapbox { display: flex; flex-direction: column; gap: 2px; background: rgba(8,10,36,.62); border-radius: 12px; padding: 5px 10px; font-weight: 800; font-size: 13px; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
#stage .lapbox span:last-child { font-weight: 600; opacity: .85; }
#stage #h-map { margin-left: auto; width: 76px; height: 76px; background: rgba(8,10,36,.5); border-radius: 12px; }
#stage .icon { position: absolute; right: 10px; top: calc(max(8px, env(safe-area-inset-top)) + 82px); width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(8,10,36,.7); color: #fff; font-weight: 900; font-size: 15px; letter-spacing: 2px; pointer-events: auto; }
#stage .count { position: absolute; left: 0; right: 0; top: 24%; text-align: center; font-size: clamp(64px, 24vw, 120px); font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(108,77,255,.8), 0 0 24px rgba(53,214,255,.8); opacity: 0; pointer-events: none; }
#stage .count.show { opacity: 1; }
#stage .count.pop { animation: agpop .5s ease-out; }
@keyframes agpop { 0% { transform: scale(1.6); opacity: 0; } 40% { opacity: 1; } 100% { transform: scale(1); } }
#stage .banner { position: absolute; left: 0; right: 0; top: 18%; text-align: center; font-size: clamp(24px, 8vw, 38px); font-weight: 900; letter-spacing: 3px; color: #fff; text-shadow: 0 3px 0 rgba(108,77,255,.9); opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s; pointer-events: none; }
#stage .banner.show { opacity: 1; transform: none; }
#stage .hint { position: absolute; left: 14px; right: 14px; top: 38%; margin: 0 auto; max-width: 320px; text-align: center; padding: 10px 14px; border-radius: 14px; background: rgba(8,10,36,.82); border: 2px solid var(--cyan); font-weight: 700; font-size: 14px; pointer-events: none; }
#stage .hud-low { position: absolute; left: 10px; right: 10px; bottom: 92px; display: flex; gap: 10px; align-items: flex-end; pointer-events: none; }
#stage .hud.btnmode .hud-low { bottom: 158px; }
#stage .gauge { background: rgba(8,10,36,.62); border-radius: 12px; padding: 4px 10px; display: flex; align-items: baseline; gap: 4px; min-width: 92px; }
#stage .gauge span { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
#stage .gauge small { font-size: 10px; opacity: .75; letter-spacing: 1px; }
#stage .energy { flex: 1; background: rgba(8,10,36,.62); border-radius: 12px; padding: 5px 10px 6px; }
#stage .energy small { display: block; font-size: 10px; letter-spacing: 1.5px; opacity: .85; margin-top: 3px; }
#stage .meter { height: 9px; border-radius: 6px; background: rgba(255,255,255,.16); overflow: hidden; }
#stage .meter i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--green), var(--cyan)); transition: width .1s linear; }
#stage .meter i.low { background: linear-gradient(90deg, var(--pink), #ffb02e); }
#stage .controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 10px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#stage .crow { display: flex; gap: 8px; }
#stage .crow.steer { display: none; }
#stage .hud.btnmode .crow.steer { display: flex; }
#stage .cbtn { flex: 1; min-height: 62px; border-radius: 16px; border: 2px solid rgba(255,255,255,.35); background: rgba(8,10,36,.62); color: #fff; font-weight: 900; font-size: 14px; letter-spacing: 1px; line-height: 1.1; pointer-events: auto; touch-action: none; }
#stage .cbtn.air { flex: 0.8; }
#stage .cbtn.boost { flex: 1.5; background: linear-gradient(#35d6ff, #6c4dff); border-color: #fff; font-size: 18px; }
#stage .crow.steer .cbtn { font-size: 24px; min-height: 58px; }
#stage .cbtn.on { background: rgba(255,255,255,.35); transform: scale(.97); }
#stage .cbtn.boost.on { filter: brightness(1.3); }
#stage .flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
#stage .flash.boost.go { background: radial-gradient(circle, rgba(53,214,255,0) 30%, rgba(53,214,255,.5)); animation: agflash .45s ease-out; }
#stage .flash.hit.go { background: radial-gradient(circle, rgba(255,93,115,0) 35%, rgba(255,93,115,.55)); animation: agflash .4s ease-out; }
@keyframes agflash { 0% { opacity: 1; } 100% { opacity: 0; } }
#stage .toast { position: absolute; left: 12px; right: 12px; bottom: 90px; z-index: 30; margin: 0 auto; max-width: 320px; text-align: center; padding: 10px 14px; border-radius: 12px; background: rgba(8,10,36,.92); border: 2px solid var(--gold); font-weight: 700; font-size: 14px; pointer-events: none; }

/* menus */
#stage .screenhost { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; background: linear-gradient(rgba(11,14,42,.7), rgba(11,14,42,.93)); touch-action: manipulation; }
#stage .screen { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; display: flex; flex-direction: column; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom)); }
#stage .scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; }
#stage .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 8px 16px; border-radius: 14px; border: 2px solid rgba(255,255,255,.28); background: rgba(255,255,255,.1); color: #fff; font-weight: 800; font-size: 15px; text-decoration: none; }
#stage .btn:active { transform: translateY(1px); }
#stage .btn.primary { background: linear-gradient(#7f63ff, #5b3ee8); border-color: #b6a6ff; }
#stage .btn.big { min-height: 52px; font-size: 18px; flex: 1; }
#stage .btn.ghost { background: rgba(255,255,255,.06); }
#stage .btn.danger { background: #c4304a; border-color: #ff9aa9; }
#stage .btn.dim { opacity: .55; }
#stage .btn[disabled] { opacity: .5; }
#stage .btn.back { padding: 0 12px; font-size: 20px; }
#stage .bar { display: flex; align-items: center; gap: 10px; }
#stage .bar h2 { flex: 1; font-size: 20px; letter-spacing: .5px; }
#stage .wallet { display: inline-flex; align-items: center; gap: 5px; font-weight: 800; font-variant-numeric: tabular-nums; background: rgba(0,0,0,.35); padding: 5px 10px; border-radius: 999px; font-size: 14px; }
#stage .coin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 55%, #d19a12); box-shadow: 0 0 0 2px rgba(0,0,0,.25) inset; }
#stage .logo { text-align: center; margin-top: 4px; display: flex; flex-direction: column; align-items: center; }
#stage .logo small { letter-spacing: 3px; font-size: 11px; color: var(--cyan); font-weight: 800; }
#stage .logo b { font-size: clamp(34px, 11vw, 50px); line-height: 1; letter-spacing: 3px; background: linear-gradient(#fff, #9fd2ff 60%, #7f63ff); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 3px 0 rgba(0,0,0,.45)); }
#stage .logo b.l2 { font-size: clamp(24px, 8vw, 34px); letter-spacing: 8px; }
#stage .rankrow { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; }
#stage .rankrow .meter { flex: 1; }
#stage .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#stage .tile { flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: 70px; text-align: left; padding: 10px 12px; }
#stage .tile b { font-size: 17px; }
#stage .tile small { font-size: 11px; font-weight: 600; opacity: .8; }
#stage .tile.glow { border-color: var(--gold); box-shadow: 0 0 12px rgba(255,211,77,.45); }
#stage .goal { background: rgba(255,255,255,.08); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
#stage .goal b { color: var(--gold); }
#stage .row { display: flex; gap: 8px; align-items: center; }
#stage .row.spread { justify-content: space-between; }
#stage .muted { color: var(--muted); font-size: 12px; }
#stage .chips, #stage .seg { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#stage .chip { min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.07); font-weight: 800; font-size: 14px; }
#stage .chip.on { background: var(--acc); border-color: #b6a6ff; }
#stage .chip.lock { opacity: .55; }
#stage .row-card { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; min-height: 56px; padding: 8px 10px; border-radius: 14px; border: 2px solid rgba(255,255,255,.16); background: rgba(255,255,255,.06); }
#stage .row-card.on { border-color: var(--cyan); background: rgba(53,214,255,.12); }
#stage .row-card.lock { opacity: .55; }
#stage .swatch { flex: none; width: 36px; height: 36px; border-radius: 10px; border: 2px solid rgba(255,255,255,.3); }
#stage .rc-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#stage .rc-main small { font-size: 11px; opacity: .8; }
#stage .rc-side { display: flex; flex-direction: column; align-items: flex-end; font-size: 11px; }
#stage .medal { font-size: 18px; }
#stage .m-bronze { color: #d98b4a; } #stage .m-silver { color: #cfd6e6; } #stage .m-gold { color: var(--gold); } #stage .m-none { color: #6a739c; }
#stage .chk { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 700; }
#stage .chk input { width: 22px; height: 22px; accent-color: var(--acc); }
#stage .cup-card, #stage .card { background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.14); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#stage .cup-card.lock { opacity: .6; }
#stage .cc-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; }
#stage .card.center { text-align: center; align-items: center; }
#stage .card h3 { font-size: 22px; }
#stage .card h4, #stage .scroll h4 { font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--cyan); margin: 4px 0; }
#stage .stand { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.05); font-size: 14px; }
#stage .stand.me { background: rgba(108,77,255,.45); }
#stage .stands { display: flex; flex-direction: column; gap: 4px; }
#stage .ship-pick { display: flex; align-items: center; gap: 8px; }
#stage .ship-card { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.07); }
#stage .ship-card b { font-size: 22px; }
#stage .ship-card small { font-size: 12px; opacity: .85; }
#stage .ship-dot { width: 54px; height: 24px; border-radius: 60% 60% 40% 40%; box-shadow: 0 0 18px currentColor; }
#stage .statbars { display: flex; flex-direction: column; gap: 6px; }
#stage .sb { display: grid; grid-template-columns: 74px 1fr; gap: 8px; align-items: center; font-size: 13px; }
#stage .up { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; }
#stage .up small { opacity: .75; }
#stage .pips { display: flex; gap: 4px; margin-top: 4px; }
#stage .pips i { width: 22px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.18); }
#stage .pips i.on { background: var(--gold); }
#stage .mission, #stage .award { display: grid; gap: 4px; padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,.06); font-size: 14px; }
#stage .mission.done, #stage .award.got { background: rgba(60,255,154,.14); }
#stage .award { grid-template-columns: 1fr auto; }
#stage .award small { grid-column: 1; opacity: .8; }
#stage .award span { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 800; color: var(--gold); }
#stage .set { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; font-weight: 700; }
#stage .how p { font-size: 14px; line-height: 1.45; }
#stage .note { background: rgba(255,255,255,.08); padding: 8px 10px; border-radius: 10px; font-size: 13px; }
#stage .gold { color: var(--gold); }
#stage .res-head { text-align: center; padding: 6px 0; }
#stage .res-head h2 { font-size: 34px; color: var(--gold); text-shadow: 0 3px 0 rgba(0,0,0,.4); }
#stage .res-head.p1 h2, #stage .res-head.p2 h2 { color: #cfd6e6; }
#stage .res-head.p3 h2 { color: #fff; }
#stage .rewards { display: flex; gap: 14px; justify-content: center; font-weight: 900; font-size: 18px; }
#stage .rewards span { display: inline-flex; align-items: center; gap: 5px; }
#stage .rew-detail { text-align: center; opacity: .85; }
#stage .pause { justify-content: center; }
#stage .pause .card .btn { width: 100%; }

@media (max-height: 560px) {
  #stage .hud-low { bottom: 82px; } #stage .hud.btnmode .hud-low { bottom: 140px; } #stage .cbtn { min-height: 52px; } #stage .count { top: 14%; }
}
/* narrow stage (small phones in portrait): keep position, lap box and minimap on one row */
@container (max-width: 300px) {
  #stage .hud-top { gap: 5px; padding-left: 6px; padding-right: 6px; }
  #stage .pos { padding: 3px 7px; } #stage .pos b { font-size: 28px; }
  #stage .lapbox { padding: 4px 7px; letter-spacing: 0; font-size: 12px; }
  #stage #h-map { width: 62px; height: 62px; }
  #stage .icon { top: calc(max(8px, env(safe-area-inset-top)) + 68px); right: 6px; }
  #stage .hud-low { left: 6px; right: 6px; gap: 6px; } #stage .gauge { min-width: 78px; }
}
@media (prefers-reduced-motion: reduce) { #stage .count.pop, #stage .flash.go { animation: none; } }

.ag-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.ag-bar .btn { min-height: 44px; min-width: 44px; }
.ag-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.ag-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.ag-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.ag-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.ag-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* wave3b: full screen fills the stage on phones (immersive and native). The 3D view simply grows to the free area. */
html.pip-immersive .game-wrap.pip-stage, html.pip-native .game-wrap.pip-stage, .game-wrap.pip-stage:fullscreen { display: flex; flex-direction: column; padding: 0; margin: 0; overflow: hidden; }
html.pip-native .game-wrap.pip-stage, .game-wrap.pip-stage:fullscreen { width: 100%; height: 100%; background: #0b0e2a; }
html.pip-immersive .game-wrap.pip-stage #stage, html.pip-native .game-wrap.pip-stage #stage, .game-wrap.pip-stage:fullscreen #stage {
  flex: 1 1 auto; min-height: 0; width: 100%; height: auto; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive .game-wrap.pip-stage > .game-title, html.pip-native .game-wrap.pip-stage > .game-title,
html.pip-immersive .game-wrap.pip-stage .ag-bar, html.pip-native .game-wrap.pip-stage .ag-bar,
html.pip-immersive .game-wrap.pip-stage .ag-keys, html.pip-native .game-wrap.pip-stage .ag-keys,
.game-wrap.pip-stage:fullscreen > .game-title, .game-wrap.pip-stage:fullscreen .ag-bar, .game-wrap.pip-stage:fullscreen .ag-keys { display: none; }
html.pip-immersive #stage .hud-top, html.pip-native #stage .hud-top { padding-top: max(6px, env(safe-area-inset-top)); }
html.pip-immersive #stage .hud-low, html.pip-native #stage .hud-low { padding-bottom: max(0px, env(safe-area-inset-bottom)); }
@media (orientation: landscape) and (max-height: 500px) {
  html.pip-immersive #stage .hud-low, html.pip-native #stage .hud-low { bottom: 8px; }
  html.pip-immersive #stage .cbtn, html.pip-native #stage .cbtn { min-height: 48px; }
}
