/* Dustline Rally 3D - stage + in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
.rr-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.rr-bar .btn { min-height: 44px; min-width: 44px; }
.rr-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.rr-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.rr-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.rr-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.rr-guide p { margin-bottom: .5rem; font-size: .95rem; }

#stage { --rust:#d9541e; --rust-d:#a93d12; --sand:#ffd9a8; --ink:#1f2a3a; --glass:rgba(20,26,38,.84); --gold:#ffc21a; --good:#4ad46a; --bad:#ff5a4a;
  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(#9fd3ff, #dff2ff); color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif; touch-action: none; 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; }
.game-wrap.pip-stage #stage { width: min(100%, calc((100vh - 60px) * 0.5625)); width: min(100%, calc((100svh - 60px) * 0.5625)); }
#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 #ui .ctl, #stage #ui .panel, #stage #ui button, #stage #ui input { pointer-events: auto; }
#stage button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
#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(#d9541e, #ff9a5a 60%, #ffd9a8); }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; text-shadow: 0 3px 0 rgba(90,30,0,.4); text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 30px); letter-spacing: 2px; }
#stage .load-in span { font-size: 14px; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.35); border-top-color: #fff; animation: rrspin .8s linear infinite; }
@keyframes rrspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(20,26,38,.9); font-weight: 700; }

/* HUD */
#stage .hud { position: absolute; inset: 0; padding: max(8px, env(safe-area-inset-top)) 10px 8px; pointer-events: none; }
#stage .hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
#stage .spd, #stage .tm { background: rgba(20,26,38,.55); border-radius: 12px; padding: 5px 10px; text-shadow: 0 1px 0 rgba(0,0,0,.5); }
#stage .spd { min-width: 86px; }
#stage .spd-n { font-size: 26px; font-variant-numeric: tabular-nums; }
#stage .spd small { font-size: 11px; margin-left: 3px; opacity: .8; }
#stage .dmgrow { display: flex; align-items: center; gap: 5px; margin-top: 2px; }
#stage .dmgrow em { font-style: normal; font-size: 9px; letter-spacing: 1px; opacity: .8; }
#stage .bar { display: inline-block; flex: 1; height: 8px; min-width: 40px; background: rgba(255,255,255,.2); border-radius: 5px; overflow: hidden; vertical-align: middle; }
#stage .bar i { display: block; height: 100%; background: var(--rust); border-radius: 5px; }
#stage .bar.dmg i { background: var(--good); } #stage .bar.dmg.mid i { background: var(--gold); } #stage .bar.dmg.bad i { background: var(--bad); }
#stage .tm { text-align: center; flex: 1; max-width: 150px; }
#stage .time { display: block; font-size: 22px; font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
#stage .delta { display: block; font-size: 13px; min-height: 16px; font-weight: 700; }
#stage .delta.good { color: var(--good); } #stage .delta.bad { color: var(--bad); }
#stage .surf { display: block; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; opacity: .8; }
#stage .pausebtn { width: 46px; height: 46px; border-radius: 14px; border: 0; background: rgba(20,26,38,.65); color: #fff; font-size: 18px; font-weight: 800; letter-spacing: 1px; }
#stage .prog { position: relative; height: 6px; margin: 8px 2px 6px; border-radius: 4px; background: rgba(20,26,38,.5); overflow: hidden; }
#stage .prog i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--rust); }
#stage .prog u { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.55); }
#stage .notes { display: flex; gap: 6px; justify-content: center; }
#stage .chip { display: flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 12px; background: rgba(20,26,38,.7); border: 2px solid #fff; min-width: 74px; justify-content: center; }
#stage .chip .na { font-size: 18px; } #stage .chip b { font-size: 19px; } #stage .chip small { font-size: 11px; opacity: .9; }
#stage .chip.g1, #stage .chip.g2 { border-color: var(--bad); background: rgba(150,30,20,.78); }
#stage .chip.g3, #stage .chip.g4 { border-color: #ff9a2a; background: rgba(140,80,10,.75); }
#stage .chip.g5 { border-color: var(--gold); }
#stage .chip.flat { border-color: var(--good); } #stage .chip.rock { border-color: #bbb; background: rgba(70,70,70,.8); }
#stage .banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: 46px; font-weight: 900; letter-spacing: 2px; text-shadow: 0 4px 0 rgba(0,0,0,.45); pointer-events: none; }
#stage .banner.cd { font-size: 84px; color: var(--gold); } #stage .banner.go { font-size: 76px; color: var(--good); }
#stage .banner.cp { font-size: 24px; } #stage .banner.bad { font-size: 22px; color: var(--bad); } #stage .banner.fin { font-size: 52px; color: var(--gold); }
#stage .hint { position: absolute; left: 12px; right: 12px; bottom: 44%; padding: 9px 12px; border-radius: 12px; background: rgba(20,26,38,.88); text-align: center; font-size: 14px; pointer-events: none; border: 2px solid var(--gold); }
#stage .toast { position: absolute; left: 14px; right: 14px; top: 12%; padding: 8px 12px; border-radius: 12px; background: rgba(20,26,38,.92); text-align: center; font-size: 14px; pointer-events: none; z-index: 20; }
#stage .flash { position: absolute; inset: 0; pointer-events: none; }

/* Controls */
#stage .controls { position: absolute; left: 0; right: 0; bottom: 0; height: 44%; }
#stage .zone { position: absolute; top: 0; bottom: 0; width: 50%; display: flex; align-items: flex-end; padding-bottom: 14px; touch-action: none; }
#stage .zl { left: 0; justify-content: flex-start; padding-left: 14px; background: linear-gradient(to right, rgba(255,255,255,.12), rgba(255,255,255,0)); }
#stage .zr { right: 0; justify-content: flex-end; padding-right: 14px; background: linear-gradient(to left, rgba(255,255,255,.12), rgba(255,255,255,0)); }
#stage .zi { width: 64px; height: 64px; border-radius: 50%; background: rgba(20,26,38,.45); border: 3px solid rgba(255,255,255,.65); display: flex; align-items: center; justify-content: center; font-size: 28px; pointer-events: none; }
#stage .pedals { position: absolute; left: 50%; bottom: 10px; width: 30%; min-width: 96px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; }
#stage .pedal { min-height: 52px; border-radius: 14px; border: 3px solid rgba(255,255,255,.75); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: 1px; touch-action: none; line-height: 1.05; }
#stage .pedal small { display: block; font-size: 11px; }
#stage .p-br { background: rgba(200,50,40,.82); min-height: 64px; } #stage .p-hb { background: rgba(230,130,20,.82); }
#stage .p-gas { background: rgba(40,160,70,.85); min-height: 64px; }
#stage .pedal:active { filter: brightness(1.25); }

/* Screens */
#stage .screen { position: absolute; inset: 0; z-index: 30; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: max(10px, env(safe-area-inset-top)) 10px 12px; background: rgba(15,20,30,.55); pointer-events: auto; overscroll-behavior: contain; }
#stage .panel { background: var(--glass); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; gap: 9px; min-height: min-content; pointer-events: auto; }
#stage .panel h2 { text-align: center; font-size: 24px; } #stage .panel h3 { font-size: 14px; opacity: .85; margin-top: 4px; }
#stage .tbar { display: flex; align-items: center; gap: 8px; }
#stage .tbar .ttl { flex: 1; font-size: 17px; text-align: center; } #stage .tbar .sp { width: 44px; }
#stage .wal { display: flex; gap: 8px; font-size: 13px; font-weight: 700; }
#stage .coin::before { content: "\25CF  "; color: var(--gold); } #stage .star::before { content: "\2605  "; color: var(--gold); }
#stage .btn { display: block; width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: #fff; font-size: 15px; font-weight: 700; text-align: center; }
#stage .btn.primary { background: var(--rust); border-color: #ffb48a; }
#stage .btn.big { min-height: 54px; font-size: 17px; }
#stage .btn.hot { background: #2c8f4a; border-color: #8ef0a8; }
#stage .btn.dim { opacity: .55; } #stage .btn.danger { background: #b3261e; border-color: #ff9a90; }
#stage .btn.on { background: var(--rust); border-color: #ffb48a; }
#stage .btn.back, #stage .btn.nav { width: 46px; min-width: 46px; padding: 0; }
#stage .btn.buy { width: auto; min-width: 74px; padding: 8px 10px; min-height: 44px; font-size: 14px; }
#stage .row2 { display: flex; gap: 8px; } #stage .row2 .btn { flex: 1; padding-left: 4px; padding-right: 4px; }
#stage .mini { font-size: 12px; opacity: .8; } #stage .lead { font-size: 14px; } #stage .ok { color: var(--good); font-weight: 700; font-size: 14px; text-align: center; }
#stage .lock { color: #ffb48a; font-size: 13px; }
#stage .title { background: rgba(15,20,30,.62); padding-top: 18px; }
#stage .logo { text-align: center; text-shadow: 0 4px 0 rgba(0,0,0,.4); }
#stage .logo b { display: block; font-size: 38px; letter-spacing: 3px; color: #ffcf9a; } #stage .logo span { display: block; font-size: 24px; letter-spacing: 8px; color: #fff; }
#stage .tag { text-align: center; font-size: 13px; opacity: .85; }
#stage .menu { display: flex; flex-direction: column; gap: 8px; }
#stage .card { background: rgba(255,255,255,.08); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
#stage .card.locked { opacity: .65; } #stage .ch { display: flex; justify-content: space-between; align-items: baseline; } #stage .ch b { font-size: 16px; }
#stage .stc { font-size: 13px; color: var(--gold); } #stage .cm { display: flex; justify-content: space-between; font-size: 12px; opacity: .8; }
#stage .grp { display: flex; flex-direction: column; gap: 6px; }
#stage .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; min-height: 54px; padding: 8px 10px; border-radius: 12px; border: 2px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #fff; text-align: left; }
#stage .row.locked { opacity: .45; } #stage .rn { display: flex; flex-direction: column; gap: 3px; font-size: 14px; } #stage .rm { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; }
#stage .stars { color: var(--gold); letter-spacing: 1px; font-size: 15px; }
#stage .chips { display: inline-flex; gap: 4px; flex-wrap: wrap; } #stage .sc { font-style: normal; font-size: 10px; padding: 2px 6px; border-radius: 8px; background: #555; }
#stage .sc.gravel { background: #9c7448; } #stage .sc.snow { background: #6b8fb0; } #stage .sc.tarmac { background: #4a5260; }
#stage .ach { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.06); opacity: .65; font-size: 13px; }
#stage .ach.done { opacity: 1; background: rgba(74,212,106,.15); } #stage .ach span { grid-column: 1; font-size: 12px; opacity: .85; } #stage .ach em { grid-row: 1 / span 2; grid-column: 2; font-style: normal; color: var(--gold); align-self: center; }
#stage .set { display: flex; flex-direction: column; gap: 6px; font-size: 14px; } #stage .set input[type=range] { width: 100%; min-height: 44px; accent-color: var(--rust); }
#stage .seg { display: flex; gap: 6px; } #stage .seg .btn { flex: 1; min-height: 44px; padding: 6px 4px; font-size: 13px; }
#stage .cars { display: flex; align-items: center; gap: 8px; } #stage .cname { flex: 1; text-align: center; } #stage .cname b { font-size: 20px; display: block; } #stage .cname small { font-size: 11px; opacity: .8; }
#stage .stats { display: flex; flex-direction: column; gap: 5px; } #stage .stat { display: flex; align-items: center; gap: 8px; font-size: 12px; } #stage .stat span { width: 78px; }
#stage .up { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,.07); } #stage .un { flex: 1; display: flex; flex-direction: column; } #stage .un small { font-size: 11px; opacity: .75; }
#stage .pips { display: flex; gap: 3px; } #stage .pips i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.25); } #stage .pips i.on { background: var(--gold); } #stage .up em { font-style: normal; color: var(--gold); font-weight: 800; }
#stage .ih { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
#stage .medals { display: flex; gap: 6px; } #stage .medal { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 2px; border-radius: 10px; font-size: 12px; background: rgba(255,255,255,.08); } #stage .medal b { font-size: 14px; font-variant-numeric: tabular-nums; }
#stage .medal.gold { border-top: 4px solid #ffc21a; } #stage .medal.silver { border-top: 4px solid #d3dbe6; } #stage .medal.bronze { border-top: 4px solid #cd7f32; }
#stage .results { text-align: center; } #stage .big-time { font-size: 40px; font-weight: 900; font-family: "JetBrains Mono", ui-monospace, monospace; }
#stage .medal-badge { align-self: center; padding: 6px 18px; border-radius: 20px; font-weight: 800; background: #555; } #stage .m1 { background: #cd7f32; } #stage .m2 { background: #9aa6b5; } #stage .m3 { background: #e0a800; color: #2a1d00; }
#stage .coins { font-size: 20px; color: var(--gold); font-weight: 800; } #stage .goal { font-size: 14px; padding: 8px; border-radius: 10px; background: rgba(255,255,255,.08); }
#stage .tbl { display: flex; flex-direction: column; gap: 3px; } #stage .tr { display: grid; grid-template-columns: 24px 1fr auto 52px; gap: 6px; padding: 5px 8px; border-radius: 8px; font-size: 13px; text-align: left; background: rgba(255,255,255,.06); } #stage .tr.me { background: rgba(217,84,30,.45); } #stage .tr em { font-style: normal; font-variant-numeric: tabular-nums; } #stage .tr small { text-align: right; opacity: .8; }
#stage .pause { padding: 16px 12px; }
@media (max-height: 520px) { #stage .logo b { font-size: 28px; } #stage .banner { top: 24%; } }
@media (prefers-reduced-motion: reduce) { #stage .spinner { animation-duration: 2s; } }
#stage .target { display: block; font-size: 11px; font-weight: 800; letter-spacing: .5px; min-height: 14px; }
#stage .target.tg { color: var(--gold); } #stage .target.ts { color: #d3dbe6; } #stage .target.tb { color: #e09a5a; } #stage .target.tn { color: rgba(255,255,255,.6); font-weight: 600; }
#stage .banner.cp.good { color: var(--good); } #stage .banner.cp.bad { color: var(--bad); }
#stage .speedfx { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .25s linear; background: linear-gradient(90deg, rgba(255,255,255,.22), rgba(255,255,255,0) 14%, rgba(255,255,255,0) 86%, rgba(255,255,255,.22)); }
#stage .dmgvig { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .3s linear; box-shadow: inset 0 0 70px 14px rgba(255,60,40,.6); }
#stage .speedfx[hidden], #stage .dmgvig[hidden] { display: none; }
#stage .ladder { margin: 4px 0 8px; }
#stage .medal.miss { opacity: .45; } #stage .medal.hit { background: rgba(255,255,255,.18); font-weight: 800; }
@keyframes rr-pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
#stage .results .medal-badge { animation: rr-pop .5s ease-out both; } #stage .results .medal.hit { animation: rr-pop .45s ease-out .15s both; }
@media (prefers-reduced-motion: reduce) { #stage .results .medal-badge, #stage .results .medal.hit { animation: none; } #stage .speedfx { display: none; } #stage .speedfx, #stage .dmgvig { transition: none; } }

/* Full screen (shell immersive on iPhone, native on Android): the 3D view fills the stage below the dock. */
html.pip-immersive .game-wrap.pip-stage, html.pip-native .game-wrap.pip-stage, .game-wrap.pip-stage:fullscreen { display: flex; flex-direction: column; overflow: hidden !important; }
html.pip-immersive .game-wrap.pip-stage > .rr-bar, html.pip-immersive .game-wrap.pip-stage > .rr-keys, html.pip-immersive .game-wrap.pip-stage > noscript,
html.pip-native .game-wrap.pip-stage > .rr-bar, html.pip-native .game-wrap.pip-stage > .rr-keys, html.pip-native .game-wrap.pip-stage > noscript,
.game-wrap.pip-stage:fullscreen > .rr-bar, .game-wrap.pip-stage:fullscreen > .rr-keys { display: none !important; }
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%; max-width: none; height: auto; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-native .game-wrap.pip-stage { padding-top: 0; }
@media (orientation: landscape) and (max-height: 520px) {
  html.pip-immersive #stage .hud, html.pip-native #stage .hud { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  html.pip-immersive #stage .spd-n, html.pip-native #stage .spd-n { font-size: 22px; }
  html.pip-immersive #stage .chip, html.pip-native #stage .chip { padding: 2px 8px; }
}
