:root {
  --bg: #0a0618; --panel: rgba(14, 10, 34, 0.9); --line: rgba(255, 255, 255, 0.14);
  --pink: #ff2e88; --cyan: #19e3ff; --gold: #ffd24a; --text: #f3f1ff; --dim: #a9a4c9;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; touch-action: none;
}
.hidden { display: none !important; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; font-style: italic; font-weight: 800; }
.hud-top {
  position: absolute; top: calc(8px + var(--sat)); left: calc(10px + var(--sal)); right: calc(10px + var(--sar));
  display: flex; gap: 8px; align-items: center;
}
.chip {
  background: rgba(8, 6, 22, 0.62); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 12px; display: flex; flex-direction: column; line-height: 1.1; min-width: 64px;
}
.chip .lbl { font-size: 10px; color: var(--cyan); letter-spacing: 1px; }
.chip .val { font-size: clamp(16px, 2.6vw, 24px); font-variant-numeric: tabular-nums; }
.icon-btn {
  pointer-events: auto; margin-left: auto; width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(8, 6, 22, 0.62); color: var(--text);
  font-weight: 900; font-size: 16px; cursor: pointer;
}
.hud-speed {
  position: absolute; left: 50%; top: calc(8px + var(--sat)); transform: translateX(-50%);
  text-align: center; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
.speed { font-size: clamp(30px, 6vw, 58px); line-height: 1; font-variant-numeric: tabular-nums; }
.speed small { font-size: 0.26em; margin-left: 6px; color: var(--cyan); }
.nitro {
  position: relative; width: clamp(130px, 22vw, 240px); height: 14px; margin: 6px auto 0;
  border-radius: 8px; background: rgba(8, 6, 22, 0.7); border: 1px solid var(--line); overflow: hidden;
}
.nitro div {
  position: absolute; inset: 0; transform-origin: left center;
  background: linear-gradient(90deg, #2a6bff, var(--cyan));
}
.nitro.lock div { background: #6b6b80; }
.nitro span { position: relative; font-size: 9px; letter-spacing: 2px; line-height: 12px; display: block; }

/* ---------- touch controls */
#touch { position: fixed; inset: 0; pointer-events: none; }
.pad { position: absolute; bottom: calc(14px + var(--sab)); display: flex; gap: 14px; align-items: flex-end; }
.pad.left { left: calc(14px + var(--sal)); }
.pad.right { right: calc(14px + var(--sar)); }
.tbtn {
  pointer-events: auto; touch-action: none; width: clamp(64px, 12vw, 96px); height: clamp(64px, 12vw, 96px);
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(10, 8, 28, 0.45);
  color: #fff; font-size: 26px; font-weight: 900; font-style: italic;
}
.tbtn.brake, .tbtn.nitro { font-size: 12px; letter-spacing: 1px; }
.tbtn.brake { border-color: rgba(255, 90, 90, 0.7); }
.tbtn.nitro { border-color: var(--cyan); width: clamp(76px, 14vw, 112px); height: clamp(76px, 14vw, 112px); }
.tbtn.down { background: rgba(255, 255, 255, 0.3); transform: scale(0.94); }

.pad.left { display: none; }
body.ctrl-arrows .pad.left { display: flex; }
/* Brake sits bottom-left, nitro bottom-right. With on-screen arrows, brake moves up above them. */
.pad.brakepad { left: calc(14px + var(--sal)); }
body.ctrl-arrows .pad.brakepad { bottom: calc(28px + var(--sab) + clamp(64px, 12vw, 96px)); }
.touch-only { display: none; }
body.touch .touch-only { display: inline-block; }

/* ---------- banner */
#banner {
  position: fixed; left: 0; right: 0; top: 30%; text-align: center; pointer-events: none;
  font-size: clamp(44px, 12vw, 120px); font-weight: 900; font-style: italic; letter-spacing: 2px;
  color: #fff; text-shadow: 0 0 22px var(--pink), 0 4px 0 rgba(0, 0, 0, 0.5);
}
#banner.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(1.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- screens */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) calc(8px + var(--sab)) calc(10px + var(--sal));
  background: rgba(5, 3, 15, 0.5); overflow-y: auto; touch-action: pan-y;
}
.panel {
  width: min(860px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: clamp(10px, 2.4vh, 22px) clamp(12px, 2.4vw, 26px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.panel.narrow { width: min(460px, 100%); display: flex; flex-direction: column; gap: 10px; }
.title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 {
  margin: 0; font-size: clamp(24px, 6vh, 46px); font-style: italic; font-weight: 900; letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(255, 46, 136, 0.7);
}
h1 span { color: var(--pink); }
h2 { margin: 0 0 4px; font-size: 11px; letter-spacing: 3px; color: var(--cyan); font-weight: 700; }
h2.big { font-size: clamp(22px, 5vh, 34px); font-style: italic; font-weight: 900; color: var(--text); letter-spacing: 1px; text-align: center; margin: 0; }
.credits { font-weight: 800; color: var(--gold); border: 1px solid rgba(255, 210, 74, 0.5); border-radius: 999px; padding: 4px 14px; white-space: nowrap; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(8px, 1.6vw, 16px); margin: clamp(6px, 1.6vh, 14px) 0; }
.card { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 14px; padding: clamp(8px, 1.6vh, 14px); display: flex; flex-direction: column; gap: 6px; }
.picker { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#carPreview { width: auto; height: clamp(54px, 15vh, 120px); aspect-ratio: 512 / 300; }
.chip.loc { position: absolute; top: 54px; left: 0; }
.chip.loc .val { font-size: clamp(12px, 1.8vw, 16px); }
#carPreview.locked { filter: grayscale(1) brightness(0.55); }
.arrow {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 15px; cursor: pointer;
}
.name { font-size: clamp(16px, 3.4vh, 22px); font-weight: 900; font-style: italic; text-align: center; }
.sub { font-size: 12px; color: var(--dim); text-align: center; }
.sub.best { color: var(--gold); }
.track-info { flex: 1; min-width: 0; }
.thumb {
  position: relative; height: clamp(34px, 9vh, 70px); border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); margin-bottom: 4px;
}
.thumb-road {
  position: absolute; left: 50%; bottom: 0; width: 0; height: 0; transform: translateX(-50%);
  border-left: 46px solid transparent; border-right: 46px solid transparent; border-bottom: 34px solid #333;
}
.stat { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; font-size: 10px; letter-spacing: 1px; color: var(--dim); }
.bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.bar div { height: 100%; transform-origin: left center; background: linear-gradient(90deg, var(--pink), var(--gold)); transition: transform 0.2s; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.row > * { flex: 1; }
.btn {
  display: inline-block; text-align: center; text-decoration: none; cursor: pointer; font: inherit;
  font-weight: 800; font-style: italic; letter-spacing: 1px; color: var(--text); min-height: 44px;
  padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07);
}
.btn.small { font-size: 12px; min-height: 38px; padding: 8px 8px; }
.btn.ghost { color: var(--dim); line-height: 20px; }
.btn.primary {
  background: linear-gradient(90deg, var(--pink), #7a2cff); border-color: transparent; font-size: clamp(16px, 3.6vh, 22px);
  box-shadow: 0 6px 22px rgba(255, 46, 136, 0.4); margin-top: auto;
}
.btn.on { background: var(--cyan); color: #06121a; border-color: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible, .arrow:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
@media (hover: hover) { .btn:not(:disabled):hover, .arrow:hover { filter: brightness(1.25); } }

.help { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.5; color: var(--dim); }
.help b { color: var(--text); }
.res-head { display: flex; align-items: center; justify-content: center; gap: 14px; }
.res-pos { font-size: clamp(34px, 9vh, 60px); font-weight: 900; font-style: italic; color: var(--gold); }
.res-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 14px; color: var(--dim); }
.res-grid b { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.res-grid .gold { color: var(--gold); }
.res-list { margin: 0; padding: 0; list-style: none; columns: 2; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.res-list .me { color: var(--cyan); font-weight: 800; }

/* ---------- rotate hint (phones held upright) */
#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; background: var(--bg);
  align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: 18px; padding: 24px;
}
#rotate b { display: block; font-size: 64px; color: var(--pink); }
@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) { #rotate { display: flex; } }
.noscript { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; text-align: center; }

/* ---------- short landscape phones */
@media (max-height: 430px) {
  .stat { display: none; }
  .thumb { height: 26px; }
  .thumb-road { border-bottom-width: 12px; border-left-width: 20px; border-right-width: 20px; }
  .card { gap: 4px; }
  .foot .btn { min-height: 32px; padding: 5px 6px; }
  h2 { font-size: 9px; margin: 0; }
  .btn.small { min-height: 32px; padding: 5px 8px; }
  .btn.primary { min-height: 38px; padding: 6px 10px; }
  .hud-speed { top: calc(4px + var(--sat)); }
}
@media (max-width: 560px) and (orientation: portrait) { .cards { grid-template-columns: 1fr; } }

/* ---------- privacy page */
body.doc { overflow: auto; -webkit-user-select: text; user-select: text; touch-action: auto; height: auto; }
.doc main { max-width: 760px; margin: 0 auto; padding: 28px 18px 60px; line-height: 1.65; }
.doc h1 { font-size: 30px; margin-bottom: 6px; }
.doc h2 { font-size: 15px; margin: 26px 0 6px; }
.doc p, .doc li { color: #d6d2ee; }
.doc a { color: var(--cyan); }
