:root {
  --green: #0c2a22; --green2: #14463a; --red: #c8232b; --red2: #8f141b; --gold: #f3d27a; --snow: #f4f7fb; --ink: #0a1512;
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); --st: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--green); color: var(--snow);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }

.scr { position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(10px + var(--st)) calc(14px + var(--sr)) calc(10px + var(--sb)) calc(14px + var(--sl)); gap: 2vh; }
.scr.on { display: flex; }
.scr > header { position: absolute; top: calc(8px + var(--st)); left: calc(12px + var(--sl)); right: calc(12px + var(--sr)); display: flex; align-items: center; gap: 12px; z-index: 2; }
.scr > header h2 { font-size: clamp(18px, 5.4vh, 30px); font-weight: 800; letter-spacing: .01em; text-shadow: 0 2px 0 rgba(0,0,0,.35); }

.btn { background: linear-gradient(var(--red), var(--red2)); padding: 12px 26px; border-radius: 999px; font-weight: 800; font-size: 17px; letter-spacing: .02em;
  box-shadow: 0 4px 0 #5d0c11, 0 8px 18px rgba(0,0,0,.35); border: 2px solid rgba(255,255,255,.25); min-height: 46px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #5d0c11; }
.btn.big { font-size: 21px; padding: 14px 44px; }
.btn.ghost { background: rgba(8,24,20,.6); box-shadow: 0 4px 0 rgba(0,0,0,.4); border-color: var(--gold); color: var(--gold); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.btn[disabled] { opacity: .5; }
.icon { width: 46px; height: 46px; border-radius: 50%; background: rgba(8,24,20,.6); border: 2px solid rgba(255,255,255,.3); font-size: 20px; font-weight: 800; line-height: 1;
  display: grid; place-items: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); flex: none; }
.icon.back { font-size: 30px; padding-bottom: 4px; }
.icon.tr { position: absolute; top: calc(10px + var(--st)); right: calc(14px + var(--sr)); }
.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

/* title */
#title { justify-content: flex-start; padding-top: 5vh; padding-bottom: calc(2vh + var(--sb)); background: radial-gradient(ellipse at 50% 120%, transparent 40%, rgba(5,18,15,.55)); }
.logo { text-align: center; margin-bottom: auto; }
.logo small { display: block; color: var(--gold); font-weight: 700; letter-spacing: .32em; text-transform: uppercase; font-size: clamp(10px, 3vh, 15px); }
.logo h1 { font-size: clamp(44px, 19vh, 120px); line-height: .95; font-weight: 900; font-style: italic; letter-spacing: -.02em; color: var(--snow);
  text-shadow: 0 3px 0 #b9c6d6, 0 7px 0 var(--red2), 0 12px 24px rgba(0,0,0,.5); transform: skewX(-6deg); }
.logo h1 span { color: var(--red); text-shadow: 0 3px 0 #fff, 0 7px 0 var(--red2), 0 12px 24px rgba(0,0,0,.5); }
.hint { font-size: 11px; opacity: .7; text-align: center; margin-top: -1vh; }

/* cards */
.cards { display: flex; gap: 12px; width: 100%; max-width: 980px; margin-top: 8vh; align-items: stretch; justify-content: center; }
.card { flex: 1 1 0; min-width: 0; background: linear-gradient(rgba(12,42,34,.9), rgba(8,24,20,.92)); border: 2px solid rgba(255,255,255,.16); border-radius: 18px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 5px; text-align: left; max-height: 78vh; overflow: hidden; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.card.sel { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(243,210,122,.25); }
.card.locked { opacity: .55; }
.card .hd { display: flex; gap: 10px; align-items: center; }
.card .hd svg { width: clamp(46px, 17vh, 84px); height: auto; flex: none; }
.card h3 { font-size: clamp(16px, 5vh, 24px); font-weight: 900; line-height: 1.05; }
.card .tt { color: var(--gold); font-weight: 800; font-size: clamp(11px, 3.2vh, 14px); text-transform: uppercase; letter-spacing: .06em; }
.card .meta { font-size: clamp(10px, 2.9vh, 13px); opacity: .8; }
.card p { font-size: clamp(10.5px, 3vh, 13.5px); line-height: 1.3; opacity: .92; }
.card .map { width: 100%; height: clamp(60px, 26vh, 130px); }
.card .map path { fill: none; stroke: var(--snow); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; }
.card .lock { font-size: clamp(11px, 3.2vh, 14px); font-weight: 800; color: var(--gold); margin-top: auto; }
.stat { display: grid; grid-template-columns: 5.6em 1fr; align-items: center; gap: 8px; font-size: clamp(10px, 2.9vh, 13px); font-weight: 700; }
.stat i { height: clamp(6px, 1.9vh, 9px); border-radius: 9px; background: rgba(255,255,255,.14); position: relative; overflow: hidden; display: block; }
.stat i::after { content: ""; position: absolute; inset: 0; width: var(--v); background: linear-gradient(90deg, var(--gold), #fff3c9); border-radius: 9px; }

/* car select */
#cars { align-items: flex-end; }
.panel { width: min(44%, 420px); margin-top: 7vh; background: linear-gradient(rgba(12,42,34,.9), rgba(8,24,20,.92)); border: 2px solid rgba(255,255,255,.16); border-radius: 18px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.panel h3 { font-size: clamp(17px, 5.4vh, 26px); font-weight: 900; line-height: 1.05; }
.panel .tt { color: var(--gold); font-weight: 700; font-size: clamp(11px, 3.1vh, 14px); }
.panel .own { font-size: clamp(10.5px, 3vh, 13px); padding: 3px 9px; border-radius: 99px; background: rgba(243,210,122,.16); color: var(--gold); font-weight: 800; align-self: flex-start; }
.panel .btn { margin-top: 4px; }
.arrow { position: absolute; top: 50%; width: 52px; height: 52px; margin-top: -10px; border-radius: 50%; background: rgba(8,24,20,.6); border: 2px solid var(--gold); color: var(--gold); font-size: 32px; font-weight: 800; line-height: 1; padding-bottom: 5px; z-index: 2; }
.arrow.l { left: calc(12px + var(--sl)); } .arrow.r { left: calc(50% - 64px); }

/* sheets */
.sheet { width: min(94%, 640px); max-height: 92vh; overflow: auto; background: linear-gradient(rgba(12,42,34,.94), rgba(8,24,20,.96)); border: 2px solid var(--gold); border-radius: 22px; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 9px; box-shadow: 0 18px 50px rgba(0,0,0,.5); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); touch-action: pan-y; }
.sheet.small { width: min(88%, 340px); text-align: center; }
.sheet h2 { font-size: clamp(20px, 6.4vh, 32px); font-weight: 900; line-height: 1.05; }
.sheet .tt { color: var(--gold); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; font-size: 12px; }
.sheet p { font-size: clamp(12px, 3.5vh, 15.5px); line-height: 1.35; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: rgba(255,255,255,.1); border-radius: 99px; padding: 4px 11px; font-size: 12.5px; font-weight: 700; }
.chip b { color: var(--gold); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.grid div { background: rgba(255,255,255,.08); border-radius: 12px; padding: 6px 9px; }
.grid small { display: block; font-size: 10.5px; opacity: .75; text-transform: uppercase; letter-spacing: .06em; }
.grid b { font-size: clamp(15px, 4.6vh, 21px); font-variant-numeric: tabular-nums; }
.medal { font-size: 13px; font-weight: 800; color: var(--gold); }
input.name { font: inherit; font-weight: 800; font-size: 16px; padding: 10px 14px; border-radius: 99px; border: 2px solid rgba(255,255,255,.3); background: rgba(0,0,0,.3); color: var(--snow); width: 9.5em; min-height: 46px;
  -webkit-user-select: text; user-select: text; }

/* HUD */
#hud { pointer-events: none; padding: 0; }
#hud > * { pointer-events: auto; }
#hud .top { position: absolute; top: calc(8px + var(--st)); left: calc(12px + var(--sl)); right: calc(12px + var(--sr)); display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
#hud .top > * { pointer-events: auto; }
#hud .tl { display: flex; gap: 8px; }
.clock { text-align: center; background: rgba(8,24,20,.62); border: 2px solid rgba(255,255,255,.22); border-radius: 16px; padding: 3px 16px 5px; min-width: 132px; }
.clock b { display: block; font-size: clamp(24px, 8.6vh, 38px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.05; }
.clock small { font-size: 11px; opacity: .8; font-weight: 700; }
.clock.low { border-color: var(--red); } .clock.low b { color: #ff6b6b; }
.spd { text-align: right; background: rgba(8,24,20,.62); border: 2px solid rgba(255,255,255,.22); border-radius: 16px; padding: 3px 12px 7px; min-width: 106px; }
.spd b { font-size: clamp(22px, 7.6vh, 34px); font-weight: 900; font-variant-numeric: tabular-nums; }
.spd small { font-size: 11px; opacity: .8; margin-left: 4px; font-weight: 700; }
.bar { height: 6px; background: rgba(255,255,255,.18); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--gold); }
#h-toast { position: absolute; top: calc(22vh + var(--st)); left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.94); color: var(--ink); font-weight: 800; font-size: clamp(12px, 3.8vh, 16px);
  padding: 7px 15px; border-radius: 16px; max-width: 72vw; text-align: center; opacity: 0; transition: opacity .25s; pointer-events: none; box-shadow: 0 6px 16px rgba(0,0,0,.3); }
#h-toast.on { opacity: 1; }
#h-count { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: 26vh; font-weight: 900; font-style: italic; color: var(--snow); text-shadow: 0 6px 0 var(--red2), 0 14px 30px rgba(0,0,0,.5); pointer-events: none; }
#pad { position: absolute; left: calc(18px + var(--sl)); bottom: calc(16px + var(--sb)); width: clamp(170px, 30vw, 250px); height: clamp(84px, 27vh, 112px); border-radius: 999px; background: rgba(8,24,20,.42);
  border: 2px solid rgba(255,255,255,.35); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; font-size: 38px; font-weight: 900; color: rgba(255,255,255,.75); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 30%; aspect-ratio: 1; margin: -15% 0 0 -15%; border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 4px 10px rgba(0,0,0,.35); pointer-events: none; }
.ctl { position: absolute; border-radius: 50%; font-weight: 900; font-size: 13px; letter-spacing: .04em; line-height: 1.05; border: 3px solid rgba(255,255,255,.55); touch-action: none; }
.ctl.on { filter: brightness(1.5); transform: scale(.94); }
#b-gas { right: calc(18px + var(--sr)); bottom: calc(14px + var(--sb)); width: clamp(84px, 28vh, 112px); height: clamp(84px, 28vh, 112px); background: rgba(37,150,86,.72); font-size: 17px; }
#b-brake { right: calc(clamp(84px, 28vh, 112px) + 30px + var(--sr)); bottom: calc(14px + var(--sb)); width: clamp(68px, 22vh, 88px); height: clamp(68px, 22vh, 88px); background: rgba(200,35,43,.72); }
#b-hb { right: calc(34px + var(--sr)); bottom: calc(clamp(84px, 28vh, 112px) + 26px + var(--sb)); width: clamp(62px, 20vh, 80px); height: clamp(62px, 20vh, 80px); background: rgba(243,210,122,.8); color: var(--ink); font-size: 11px; }

#pause, #result, #brief, #loading { background: rgba(5,18,15,.5); }

/* leaderboard */
#board { justify-content: flex-start; padding-top: calc(64px + var(--st)); background: rgba(5,18,15,.6); }
.tabs { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.tabs button { padding: 7px 13px; border-radius: 99px; background: rgba(8,24,20,.6); border: 2px solid rgba(255,255,255,.25); font-weight: 800; font-size: 12.5px; }
.tabs button.sel { border-color: var(--gold); color: var(--gold); }
.table { width: 100%; max-width: 860px; flex: 1; overflow: auto; background: rgba(8,24,20,.82); border: 2px solid rgba(255,255,255,.16); border-radius: 18px; padding: 6px 10px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.table table { width: 100%; border-collapse: collapse; font-size: clamp(11.5px, 3.3vh, 14.5px); }
.table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; padding: 6px; position: sticky; top: 0; background: rgba(8,24,20,.95); }
.table td { padding: 6px; border-top: 1px solid rgba(255,255,255,.08); font-variant-numeric: tabular-nums; }
.table td.t { font-weight: 900; color: var(--gold); }
.table tr.me td { background: rgba(243,210,122,.14); }
.table .note { padding: 8px 6px; font-size: 12px; opacity: .75; }

#rotate { position: fixed; inset: 0; background: var(--green); display: none; place-items: center; text-align: center; z-index: 50; font-weight: 800; font-size: 20px; }
#rotate b { font-size: 70px; display: block; color: var(--gold); }
@media (orientation: portrait) and (max-width: 820px) { #rotate { display: grid; } }
@media (max-height: 400px) { .card { padding: 8px 10px; gap: 3px; } .sheet { padding: 11px 16px; gap: 6px; } }
