/* Redline Strip 3D - stage and UI. Everything lives under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
.dr-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.dr-bar .btn { min-height: 44px; min-width: 44px; background: #D9382B; }
.dr-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.dr-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.dr-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.dr-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.dr-guide p { margin-bottom: .5rem; font-size: .95rem; }

#stage { --red:#d9382b; --red2:#ff6a3d; --gold:#ffc21a; --ink:#0e1330; --panel:rgba(14,19,48,.9); --pale:#eaf0ff; --good:#3ddc5a; --bad:#ff4b5c; --cy:#27c9ff;
  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: #0e1330; color: #fff; font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; touch-action: none; }
#stage.is-big, #stage:fullscreen, #stage:-webkit-full-screen { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; -webkit-appearance: none; appearance: none; }
#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(#0e1330, #2a1245 60%, #5a1d3a); }
#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: .9; }
#stage .spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: var(--gold); animation: drspin 0.9s linear infinite; }
@keyframes drspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; left: 12px; right: 12px; top: 40%; z-index: 60; background: rgba(0,0,0,.8); padding: 14px; border-radius: 12px; text-align: center; font-size: 14px; }

/* ---------- screens */
#stage .screen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px; pointer-events: none; z-index: 10; }
#stage .screen > * { pointer-events: auto; width: 100%; max-width: 520px; margin-left: auto; margin-right: auto; }
#stage .screen .spacer { flex: 1 1 0; min-height: 0; pointer-events: none; }
#stage .topbar { display: flex; align-items: center; gap: 6px; background: var(--panel); border-radius: 12px; padding: 6px 8px; min-height: 44px; }
#stage .topbar .rank { font-size: 12px; font-weight: 800; letter-spacing: 1px; white-space: nowrap; }
#stage .topbar .rank b { font-size: 16px; color: var(--gold); }
#stage .meter { flex: 1; height: 8px; background: rgba(255,255,255,.15); border-radius: 6px; overflow: hidden; }
#stage .meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--red2)); }
#stage .chip { font-size: 12px; font-weight: 800; padding: 4px 8px; border-radius: 10px; background: rgba(255,255,255,.12); white-space: nowrap; }
#stage .chip.cash { color: #9dffb0; }
#stage .chip.bolts { color: #9fd8ff; }
#stage .topbar .back { margin-right: auto; }
#stage .title { display: flex; flex-direction: column; align-items: center; line-height: .95; padding-top: 6px; text-shadow: 0 3px 0 rgba(0,0,0,.45); pointer-events: none; }
#stage .title b { font-size: clamp(30px, 11vw, 54px); letter-spacing: 4px; font-style: italic; }
#stage .title b.y { color: var(--gold); }
#stage .h { margin: 0; font-size: 18px; padding: 0 4px; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
#stage h3 { margin: 10px 0 4px; font-size: 14px; color: var(--gold); }
#stage .panel { background: var(--panel); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#stage .panel.home { margin-top: auto; }
#stage .panel.center { margin: auto; }
#stage .scroll { overflow-y: auto; overflow-x: hidden; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; min-height: 0; flex: 1 1 auto; background: var(--panel); border-radius: 14px; padding: 10px; }
#stage .panel .scroll { background: transparent; padding: 0; }
#stage .scroll.small { flex: 0 1 auto; max-height: 52vh; }
#stage .note { font-size: 12px; color: #b9c4ea; margin: 4px 0 8px; }
#stage .sub { font-size: 12px; color: #c9d3f5; margin: 3px 0; }
#stage .ok { color: var(--good); } #stage .bad { color: var(--bad); } #stage .mid { color: var(--gold); }
#stage .row { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }

#stage .btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 46px; min-width: 46px; padding: 8px 12px; border: 0; border-radius: 12px; background: #2b3566; color: #fff; font-size: 15px; font-weight: 800; position: relative; text-decoration: none; }
#stage .btn small { font-size: 11px; font-weight: 600; opacity: .85; }
#stage .btn.primary { background: linear-gradient(#ff6a3d, #d9382b); box-shadow: 0 3px 0 #8f1f16; }
#stage .btn.big { min-height: 58px; font-size: 18px; width: 100%; }
#stage .btn.small { min-height: 44px; font-size: 13px; padding: 6px 10px; }
#stage .btn.ghost { background: rgba(255,255,255,.1); }
#stage .btn.danger { background: #7a1f2a; }
#stage .btn[disabled] { opacity: .4; cursor: default; }
#stage .btn:active:not([disabled]) { transform: translateY(2px); }
#stage .badge { position: absolute; top: -6px; right: -4px; background: var(--gold); color: #000; border-radius: 10px; padding: 1px 7px; font-size: 12px; font-style: normal; }
#stage .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#stage .carline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#stage .carline .btn { margin-left: auto; }
#stage .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; flex: none; }
#stage .tag { font-size: 11px; font-weight: 800; background: rgba(255,255,255,.14); padding: 2px 8px; border-radius: 8px; white-space: nowrap; }

#stage .tabs { display: flex; gap: 6px; }
#stage .tab { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: #232b57; color: #fff; font-weight: 800; font-size: 16px; }
#stage .tab.on { background: var(--red); }
#stage .tab[disabled] { opacity: .35; }
#stage .card { background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px; margin-bottom: 8px; border: 2px solid transparent; }
#stage .card.next { border-color: var(--gold); }
#stage .card.done { opacity: .85; }
#stage .card.lock { opacity: .5; }
#stage .cardhead { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 14px; }
#stage .cardfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; }
#stage .cardfoot .btn { flex: none; }
#stage .bar { height: 8px; background: rgba(255,255,255,.14); border-radius: 6px; overflow: hidden; margin: 6px 0; flex: 1; }
#stage .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cy), var(--good)); }
#stage .medals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
#stage .medal { background: rgba(255,255,255,.08); border-radius: 10px; padding: 6px; text-align: center; display: flex; flex-direction: column; font-size: 12px; }
#stage .medal.got { background: rgba(61,220,90,.22); }
#stage .medal em { font-style: normal; color: #9dffb0; }
#stage .achs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#stage .ach { background: rgba(255,255,255,.06); border-radius: 10px; padding: 7px; font-size: 11px; display: flex; flex-direction: column; gap: 2px; opacity: .6; }
#stage .ach.got { opacity: 1; background: rgba(255,194,26,.18); }
#stage .ach b { font-size: 12px; } #stage .ach em { font-style: normal; color: #9dffb0; }
#stage .setrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 2px; border-bottom: 1px solid rgba(255,255,255,.1); font-size: 14px; }
#stage .segs { display: flex; gap: 4px; }
#stage .seg { min-height: 44px; min-width: 52px; border: 0; border-radius: 10px; background: #232b57; color: #fff; font-weight: 700; font-size: 13px; padding: 0 10px; }
#stage .seg.on { background: var(--red); }
#stage .helpbox p { margin: 0 0 8px; font-size: 13px; color: #dbe3ff; }

/* garage */
#stage .panel.garage { flex: 0 0 62%; min-height: 0; }
#stage .carnav { display: flex; align-items: center; gap: 8px; }
#stage .carname { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 16px; }
#stage .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
#stage .stat { display: flex; align-items: center; gap: 6px; font-size: 11px; } #stage .stat span { width: 42px; }
#stage .etrow { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; } #stage .etrow b { color: var(--gold); }
#stage .part { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid rgba(255,255,255,.08); }
#stage .pname { display: flex; flex-direction: column; font-size: 12px; } #stage .pname b { font-size: 14px; } #stage .pname span { color: #aab6e6; }
#stage .pips { display: flex; gap: 3px; margin-top: 3px; } #stage .pips i { width: 16px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.2); } #stage .pips i.on { background: var(--gold); }
#stage .tune { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; }
#stage .tname { display: flex; flex-direction: column; font-size: 11px; color: #aab6e6; } #stage .tname b { font-size: 14px; color: #fff; }
#stage .tctl { display: flex; align-items: center; gap: 6px; } #stage .tval { width: 48px; text-align: center; font-size: 14px; }

/* results */
#stage .panel.results { margin-top: auto; }
#stage .verdict { margin: 0; text-align: center; font-size: 30px; font-style: italic; letter-spacing: 2px; }
#stage .results.win .verdict { color: var(--good); } #stage .results.lose .verdict { color: var(--bad); }
#stage .kv { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
#stage .rewards { text-align: center; font-size: 17px; font-weight: 800; color: #9dffb0; padding: 8px 0 2px; white-space: pre; }
#stage .extra { text-align: center; font-size: 12px; color: var(--gold); padding: 2px 0; }
#stage .goal { margin-top: 6px; text-align: center; font-size: 13px; font-weight: 800; color: var(--cy); background: rgba(39,201,255,.12); border-radius: 10px; padding: 7px; }

#stage #toasts { position: absolute; left: 0; right: 0; top: 64px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
#stage .toast { background: rgba(0,0,0,.82); padding: 7px 12px; border-radius: 12px; font-size: 13px; font-weight: 700; max-width: 90%; text-align: center; animation: drtoast .25s ease-out; }
#stage .toast.good { color: #9dffb0; } #stage .toast.bad { color: #ff9aa4; }
@keyframes drtoast { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
#stage #flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s; z-index: 25; background: transparent; }

/* ---------- HUD */
#stage .hud { position: absolute; inset: 0; pointer-events: none; z-index: 8; }
#stage .hud-top { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
#stage .tree { display: flex; flex-direction: column; gap: 4px; background: rgba(0,0,0,.55); border-radius: 10px; padding: 6px; }
#stage .tree i { width: 16px; height: 16px; border-radius: 50%; background: #3a3a3a; display: block; }
#stage .tree i.on { background: #ffb000; box-shadow: 0 0 10px #ffb000; }
#stage .tree i.g.on { background: #22e05a; box-shadow: 0 0 12px #22e05a; }
#stage .hud.foul .tree i.g { background: #ff2020; box-shadow: 0 0 12px #ff2020; }
#stage .hud-stats { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-shadow: 0 2px 0 rgba(0,0,0,.6); margin-left: auto; margin-right: 6px; }
#stage .hud-stats b { font-size: 24px; font-variant-numeric: tabular-nums; } #stage .hud-stats span { font-size: 11px; margin-left: 3px; opacity: .85; }
#stage .pause-btn { pointer-events: auto; width: 46px; height: 46px; border-radius: 12px; border: 0; background: rgba(0,0,0,.55); color: #fff; font-weight: 900; font-size: 16px; letter-spacing: 1px; }
#stage .hud-prog { position: absolute; left: 62px; right: 70px; top: 12px; display: flex; flex-direction: column; gap: 5px; }
#stage .hud-prog .lane { height: 12px; background: rgba(0,0,0,.5); border-radius: 7px; position: relative; overflow: hidden; }
#stage .hud-prog i { position: absolute; inset: 0; background: var(--good); transform-origin: left; transform: scaleX(0); display: block; }
#stage .hud-prog .r i { background: var(--red2); }
#stage .hud-prog em { position: absolute; left: 5px; top: -1px; font-size: 9px; font-style: normal; font-weight: 800; line-height: 12px; text-shadow: 0 1px 0 #000; }
#stage .hud.solo .hud-prog .r { display: none; }
#stage .hud-pop { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 26px; font-weight: 900; font-style: italic; letter-spacing: 1px; opacity: 0; text-shadow: 0 3px 0 rgba(0,0,0,.6); }
#stage .hud-pop.show { opacity: 1; animation: drpop .9s ease-out forwards; }
#stage .hud-pop.good { color: var(--good); } #stage .hud-pop.ok { color: var(--gold); } #stage .hud-pop.bad { color: var(--bad); }
@keyframes drpop { 0% { transform: scale(.6); opacity: 0; } 15% { transform: scale(1.08); opacity: 1; } 100% { transform: translateY(-14px) scale(1); opacity: 0; } }
#stage .hud-hint { position: absolute; left: 12px; right: 12px; top: 40%; text-align: center; font-size: 14px; font-weight: 700; background: rgba(0,0,0,.7); border-radius: 12px; padding: 8px 10px; opacity: 0; transition: opacity .2s; }
#stage .hud-hint.show { opacity: 1; }
#stage .gauge { position: absolute; left: 50%; bottom: calc(19% + 18px); transform: translateX(-50%); width: min(58%, 240px); aspect-ratio: 240 / 140; }
#stage .gauge canvas { width: 100%; height: 100%; display: block; }
#stage .gear { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); text-align: center; line-height: 1; }
#stage .gear small { display: block; font-size: 9px; opacity: .8; } #stage .gear b { font-size: 26px; }
#stage .pads { position: absolute; left: 8px; right: 8px; bottom: 8px; height: 19%; min-height: 76px; display: grid; grid-template-columns: 1fr .62fr 1fr; gap: 8px; }
#stage .pad { pointer-events: auto; touch-action: none; border: 0; border-radius: 16px; color: #fff; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: #2b3566; box-shadow: 0 4px 0 rgba(0,0,0,.45); min-height: 76px; }
#stage .pad b { font-size: 22px; letter-spacing: 1px; } #stage .pad small { font-size: 10px; font-weight: 600; opacity: .85; }
#stage .pad.gas { background: linear-gradient(#2fb85a, #1c8a3f); }
#stage .pad.shift { background: linear-gradient(#ff6a3d, #d9382b); }
#stage .pad.nos { background: linear-gradient(#3aa0ff, #1d62c9); }
#stage .pad.down { transform: translateY(3px); filter: brightness(1.2); }
#stage .pad.off { opacity: .45; }
#stage .pad.cue { box-shadow: 0 0 0 4px #3ddc5a, 0 0 18px #3ddc5a; }

@media (orientation: landscape) and (max-height: 520px) {
  #stage .gauge { width: min(30%, 200px); bottom: calc(19% + 8px); }
  #stage .pad b { font-size: 18px; }
  #stage .hud-hint { top: 30%; }
  #stage .scroll.small { max-height: 40vh; }
}
@media (max-height: 560px) { #stage .title b { font-size: 30px; } #stage .verdict { font-size: 24px; } }
@media (prefers-reduced-motion: reduce) { #stage * { animation: none !important; transition: none !important; } }

/* Full screen: the shell fixes #stage over the page. Keep canvas and HUD below the dock, hide the duplicate Play big control. */
html.pip-immersive #stage #app, html.pip-immersive #stage #ui { top: calc(var(--pip-dock-h, 0px) + env(safe-area-inset-top, 0px)); }
html.pip-immersive #stage #ctxlost { top: 45%; }
html.pip-immersive .dr-bar, html.pip-immersive .dr-keys, html.dr-shell .dr-bar { display: none; }
#stage #app::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(5,8,24,.38) 100%); }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .pad { min-height: 48px; }
}

html.pip-immersive .game-wrap.pip-stage { display: flex; flex-direction: column; padding: 0; margin: 0; max-width: none; overflow: hidden; }
html.pip-immersive #stage, html.pip-immersive #stage.is-big { position: relative; inset: auto; flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; height: auto; aspect-ratio: auto; border-radius: 0; z-index: auto; }
