:root {
  --ink: #fff7ef;
  --muted: #d9c4c9;
  --glass: rgba(24, 10, 30, 0.72);
  --glass2: rgba(40, 16, 46, 0.86);
  --line: rgba(255, 220, 200, 0.16);
  --sun: #ff8a2a;
  --sun2: #ffcf4a;
  --pink: #ff4f8b;
  --green: #22c55e;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #12061a; color: var(--ink); font: 600 15px/1.3 var(--font);
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

/* screens */
.screen { position: absolute; inset: 0; display: none; flex-direction: column; z-index: 5; }
.screen.show { display: flex; }

/* boot */
#boot { background: radial-gradient(120% 80% at 50% 100%, #ff7a2f 0%, #b8306a 38%, #2a0f3d 72%, #12061a 100%);
  align-items: center; justify-content: center; gap: 22px; z-index: 20; }
.boot-logo, .logo { display: flex; flex-direction: column; align-items: center; line-height: .86; transform: skewX(-8deg); }
.boot-logo span, .logo span { font-weight: 800; letter-spacing: .5em; font-size: 15px; padding-left: .5em; color: #ffe2c7; }
.boot-logo b, .logo b { font-weight: 900; font-style: italic; font-size: 76px; letter-spacing: -2px;
  background: linear-gradient(180deg, #fff3c4 0%, #ffb23f 45%, #ff4f8b 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(60, 10, 40, .55)); }
.boot-bar { width: 180px; height: 6px; border-radius: 9px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 5%; background: linear-gradient(90deg, var(--sun2), var(--pink)); transition: width .2s; }
.boot-note { margin: 0; color: #ffd9c0; font-size: 13px; }

/* identity */
.who { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; z-index: 12; display: flex; align-items: center; gap: 8px;
  background: var(--glass); border: 1px solid var(--line); padding: 4px 12px 4px 4px; border-radius: 99px; font-size: 13px; backdrop-filter: blur(6px); max-width: 70vw; }
#hiName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--sun), var(--pink)) center/cover no-repeat;
  display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; box-shadow: 0 0 0 2px rgba(255, 207, 74, .8); }
.pill { background: #ffcf4a; color: #2a0f3d; font-size: 10px; font-weight: 900; padding: 2px 7px; border-radius: 99px; letter-spacing: .06em; }
body.in-run .who { top: auto; bottom: 214px; left: 50%; transform: translateX(-50%) scale(.85); opacity: .0; pointer-events: none; }

/* title */
#title { justify-content: space-between; padding: 64px 18px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(18, 6, 26, .55) 0%, rgba(18, 6, 26, 0) 28%, rgba(18, 6, 26, 0) 50%, rgba(18, 6, 26, .78) 78%, rgba(18, 6, 26, .95) 100%); }
.title-top { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.title-top .logo b { font-size: 70px; }
.tag { margin: 0; font-size: 12px; color: #ffe2c7; background: rgba(0, 0, 0, .25); padding: 4px 10px; border-radius: 99px; }
.garage { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.arrow { width: 44px; height: 64px; font-size: 34px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); flex: none; }
.car-card { flex: 1; text-align: center; background: var(--glass); border: 1px solid var(--line); border-radius: 18px; padding: 10px 12px; backdrop-filter: blur(6px); }
.car-name { font-size: 20px; font-weight: 900; font-style: italic; letter-spacing: .02em; }
.car-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.car-stats { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; margin-top: 8px; font-size: 11px; color: var(--muted); text-align: left; }
.car-stats i { display: block; height: 6px; border-radius: 9px; background: rgba(255, 255, 255, .12); margin-top: 4px; overflow: hidden; }
.car-stats i::after { content: ""; display: block; height: 100%; width: var(--w); background: linear-gradient(90deg, var(--sun2), var(--pink)); }
.car-lock { margin-top: 8px; color: var(--sun2); font-size: 13px; }
.paint-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0 4px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); position: relative; flex: none; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 207, 74, .7); }
.swatch.locked::after { content: "🔒"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; background: rgba(0, 0, 0, .45); border-radius: 50%; }
.paint-label { width: 100%; text-align: center; font-size: 11px; color: var(--muted); }
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn { flex: 1; }
.btn { min-height: 52px; border-radius: 16px; padding: 10px 16px; font-weight: 800; font-size: 17px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; transition: transform .08s; }
.btn:active { transform: scale(.97); }
.btn small { font-size: 11px; font-weight: 600; opacity: .8; }
.btn.primary { background: linear-gradient(180deg, #ffd25a, #ff8a2a); color: #2a0f1a; box-shadow: 0 6px 0 #a3441a, 0 10px 24px rgba(255, 120, 40, .35); }
.btn.hot { background: linear-gradient(180deg, #ff6aa0, #d9306c); color: #fff; box-shadow: 0 6px 0 #7e1541, 0 10px 24px rgba(255, 60, 120, .3); }
.btn.ghost { background: var(--glass); border: 1px solid var(--line); font-size: 15px; min-height: 46px; }
.btn.icon { flex: 0 0 56px; font-size: 20px; }
.btn:disabled { opacity: .5; }

/* sheets */
.sheet-screen { background: rgba(10, 3, 14, .55); justify-content: flex-end; z-index: 15; backdrop-filter: blur(2px); }
.sheet { background: linear-gradient(180deg, #2b1236, #1a0b22); border-top: 1px solid var(--line); border-radius: 24px 24px 0 0;
  padding: 18px 18px max(20px, env(safe-area-inset-bottom)); max-height: 92%; overflow-y: auto; touch-action: pan-y; animation: up .22s ease-out; }
.sheet.tall { min-height: 74%; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0 0 8px; font-size: 22px; font-weight: 900; font-style: italic; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.x { width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .08); font-size: 16px; }
.fine { font-size: 12px; color: var(--muted); font-weight: 500; margin: 6px 0 12px; }
.lbl { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; letter-spacing: .04em; text-transform: uppercase; }
.seg { display: flex; background: rgba(255, 255, 255, .06); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 10px 6px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.seg button.on { background: linear-gradient(180deg, #ffd25a, #ff8a2a); color: #2a0f1a; }

/* results */
.big-score { font-size: 54px; font-weight: 900; font-style: italic; text-align: center; background: linear-gradient(180deg, #fff3c4, #ffb23f 50%, #ff4f8b);
  -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.05; }
#results h2 { text-align: center; }
.r-sub { text-align: center; color: var(--sun2); font-size: 14px; min-height: 18px; }
.r-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 6px; }
.r-grid div { background: rgba(255, 255, 255, .06); border-radius: 12px; padding: 8px 10px; }
.r-grid small { display: block; font-size: 11px; color: var(--muted); }
.r-grid b { font-size: 18px; }
.r-note { text-align: center; font-size: 13px; color: var(--muted); min-height: 18px; margin: 6px 0; }

/* board */
.board-me { background: linear-gradient(90deg, rgba(255, 138, 42, .25), rgba(255, 79, 139, .2)); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 6px 0 10px; display: flex; justify-content: space-between; }
.board-list { list-style: none; padding: 0; margin: 0; }
.board-list li { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.board-list li .rk { width: 30px; color: var(--sun2); font-weight: 900; font-style: italic; }
.board-list li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list li .sc { font-variant-numeric: tabular-nums; }
.board-list li.muted { color: var(--muted); justify-content: center; }

/* shop */
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
.item .ic { width: 52px; height: 52px; border-radius: 14px; flex: none; display: grid; place-items: center; font-size: 26px; }
.item .tx { flex: 1; min-width: 0; }
.item .tx b { display: block; font-size: 15px; }
.item .tx small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.item .buy { min-width: 76px; height: 40px; border-radius: 12px; background: linear-gradient(180deg, #ffd25a, #ff8a2a); color: #2a0f1a; font-weight: 900; }
.item .buy.own { background: rgba(34, 197, 94, .2); color: #86efac; }

/* battle */
.chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { flex: 1; min-width: 64px; padding: 10px 6px; border-radius: 12px; background: rgba(255, 255, 255, .07); border: 1px solid var(--line); font-size: 14px; }
.chip.on { background: linear-gradient(180deg, #ff6aa0, #d9306c); border-color: transparent; }
#bSetup .btn { margin-bottom: 10px; width: 100%; }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; min-width: 0; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: #fff;
  font: 900 20px var(--font); letter-spacing: .3em; text-align: center; text-transform: uppercase; user-select: text; -webkit-user-select: text; }
.join-row .btn { flex: 0 0 96px; }
.code-box { font-size: 40px; font-weight: 900; letter-spacing: .25em; text-align: center; padding: 16px; border-radius: 16px; background: rgba(0, 0, 0, .3); border: 1px dashed rgba(255, 207, 74, .6); color: var(--sun2); margin: 10px 0; user-select: text; -webkit-user-select: text; }
.wait-status { text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; margin: 10px auto 18px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--sun2); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#bWait .btn { width: 100%; }
.toast-inline { min-height: 18px; font-size: 13px; color: var(--sun2); text-align: center; margin: 10px 0; }
#bFallbackFree { width: 100%; }

/* HUD */
#hud { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.hud-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.hud-box { background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 5px 12px; min-width: 96px; }
.hud-box.right { text-align: right; margin-right: 44px; }
.hud-box small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .1em; }
.hud-box b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; font-style: italic; }
.hud-timer { font-size: 34px; font-weight: 900; font-style: italic; text-shadow: 0 2px 0 rgba(60, 10, 40, .6); font-variant-numeric: tabular-nums; margin-top: 2px; }
.hud-timer.low { color: #ff6b6b; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
.pause-btn { position: absolute; right: 0; top: 0; width: 40px; height: 40px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); pointer-events: auto; font-size: 12px; letter-spacing: -2px; }
.hype { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 54px); left: 50%; transform: translateX(-50%); width: 62%; display: flex; align-items: center; gap: 8px; }
.hype small { font-size: 10px; letter-spacing: .12em; color: #ffd9c0; font-weight: 900; }
.hype-bar { flex: 1; height: 9px; border-radius: 9px; background: rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .15); overflow: hidden; }
.hype-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffcf4a, #ff8a2a, #ff3d7f); box-shadow: 0 0 12px #ff8a2a; transition: width .15s; }
.vs { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 74px); left: 50%; transform: translateX(-50%); font-size: 12px; background: var(--glass); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.combo { position: absolute; top: 25%; left: 0; right: 0; text-align: center; transition: opacity .25s; }
.combo-pts { font-size: 34px; font-weight: 900; font-style: italic; color: #fff; text-shadow: 0 3px 0 rgba(120, 30, 60, .7), 0 0 18px rgba(255, 140, 60, .5); font-variant-numeric: tabular-nums; }
.combo-mult { display: inline-block; font-size: 22px; font-weight: 900; font-style: italic; color: #2a0f1a; background: linear-gradient(180deg, #ffe36a, #ffad33); padding: 0 10px; border-radius: 10px; margin-top: 4px; }
.combo-mult:empty { display: none; }
.combo-angle { font-size: 13px; color: #ffe2c7; margin-top: 4px; font-weight: 800; letter-spacing: .08em; text-shadow: 0 1px 3px #000; }
.pops { position: absolute; top: 37%; left: 0; right: 0; height: 0; }
.pop { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; font-weight: 900; font-style: italic; font-size: 24px; text-shadow: 0 3px 0 rgba(0, 0, 0, .45); animation: pop 1.1s ease-out forwards; }
.pop.good { color: #ffe36a; } .pop.great { color: #7CFF9B; font-size: 30px; } .pop.bad { color: #ff6b6b; } .pop.info { color: #fff; font-size: 18px; }
@keyframes pop { 0% { transform: translate(-50%, 10px) scale(.6); opacity: 0; } 15% { transform: translate(-50%, 0) scale(1.15); opacity: 1; } 30% { transform: translate(-50%, 0) scale(1); } 100% { transform: translate(-50%, -60px) scale(1); opacity: 0; } }
.count { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: 96px; font-weight: 900; font-style: italic; color: #ffe36a; text-shadow: 0 6px 0 rgba(120, 30, 60, .7); }
.count:empty { display: none; }
.controls { position: absolute; left: 0; right: 0; bottom: 0; height: 200px; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 12px max(14px, env(safe-area-inset-bottom)); pointer-events: none; }
.steer { display: flex; gap: 10px; pointer-events: auto; }
.pedals { display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: auto; }
.pad { width: 84px; height: 112px; border-radius: 22px; background: rgba(20, 8, 26, .48); border: 2px solid rgba(255, 230, 210, .28); display: grid; place-items: center;
  font-size: 30px; color: rgba(255, 240, 230, .9); touch-action: none; backdrop-filter: blur(3px); transition: transform .05s, background .05s; }
.pad.on { background: rgba(255, 138, 42, .55); border-color: #ffcf4a; transform: scale(.95); }
.pad.hb { width: 112px; height: 112px; border-radius: 50%; font-size: 13px; font-weight: 900; text-align: center; letter-spacing: .06em; line-height: 1.15;
  background: rgba(200, 30, 70, .45); border-color: rgba(255, 120, 150, .6); }
.pad.hb.on { background: rgba(255, 60, 110, .8); }
.pad.gas { width: 88px; height: 70px; font-size: 14px; font-weight: 900; border-radius: 18px; background: rgba(30, 140, 70, .45); border-color: rgba(120, 255, 160, .5); }
.pad.gas.on { background: rgba(40, 200, 90, .8); }
body.tilt .steer { visibility: hidden; }
.tilt-hint { position: absolute; bottom: 60px; left: 20px; font-size: 13px; color: var(--muted); }

.toast { position: absolute; left: 50%; bottom: 22%; transform: translate(-50%, 20px); background: rgba(20, 8, 26, .92); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 30; opacity: 0; pointer-events: none; transition: all .25s; max-width: 86vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
