:root {
  --red: #e31937;
  --white: #f4f4f2;
  --dim: rgba(244, 244, 242, 0.62);
  --faint: rgba(244, 244, 242, 0.38);
  --panel: rgba(12, 12, 14, 0.52);
  --line: rgba(255, 255, 255, 0.12);
  --gold: #d6b06b;
  --font: "Inter", "Helvetica Neue", "Segoe UI", Roboto, Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0a0b;
  color: var(--white);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  outline: none;
}

.hidden { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.12em 0.42em;
  margin: 0 0.12em;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 600 0.78em/1.3 var(--font);
  text-align: center;
  color: var(--white);
  background: rgba(255, 255, 255, 0.06);
}

button {
  font: 600 13px/1 var(--font);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 13px 22px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); }
button:active { transform: scale(0.98); }
button.primary { background: var(--white); color: #0b0b0c; border-color: var(--white); }
button.primary:hover { background: #fff; }

a { color: var(--white); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
}
.overlay.dim {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 6, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 60%, #1a1213 0%, #0a0a0b 70%);
  gap: 18px;
}

.logo {
  font-weight: 800;
  font-size: clamp(44px, 7vw, 92px);
  letter-spacing: 0.32em;
  margin-right: -0.32em;
  line-height: 1;
}
.sub { color: var(--dim); font-size: 14px; letter-spacing: 0.04em; }

/* ---------- title screen ---------- */

#menu {
  display: flex;
  align-items: stretch;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(6, 6, 7, 0.86) 0%, rgba(6, 6, 7, 0.55) 46%, rgba(6, 6, 7, 0) 70%);
}
.menu-panel {
  pointer-events: auto;
  width: min(640px, 100%);
  padding: clamp(24px, 5vh, 56px) clamp(20px, 4vw, 56px);
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow-y: auto;
}
.menu-panel header .logo { font-size: clamp(48px, 6.5vw, 84px); }
.menu-panel header .sub { margin-top: 12px; }

#trims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.trim-card {
  position: relative;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  padding: 16px 14px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trim-card.selected {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5), 0 10px 40px rgba(0, 0, 0, 0.45);
}
.trim-card .key {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; color: var(--faint); font-weight: 700;
}
.trim-title { font-size: 22px; font-weight: 600; letter-spacing: 0.02em; }
.trim-tag { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.trim-stat { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--dim); border-top: 1px solid var(--line); padding-top: 6px; }
.trim-stat b { color: var(--white); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.trim-hw { font-size: 11px; color: var(--faint); margin-top: 4px; line-height: 1.35; }

.menu-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.menu-actions .primary { padding: 15px 44px; font-size: 14px; }
.menu-keys { color: var(--dim); font-size: 13px; margin: 0; }
.menu-panel footer { color: var(--faint); font-size: 11.5px; line-height: 1.5; margin-top: auto; }

/* ---------- dialogs ---------- */

.dialog {
  background: rgba(14, 14, 16, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 300px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog.wide { width: min(980px, 94vw); }
.dialog h2 { margin: 0 0 8px; font-weight: 600; letter-spacing: 0.02em; }
.dialog h3 { margin: 6px 0 4px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.dialog p { margin: 4px 0; font-size: 14px; color: var(--dim); line-height: 1.55; }
.dialog .cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.dialog .tip { margin: 12px 0; padding: 12px 14px; border-left: 2px solid var(--red); background: rgba(227, 25, 55, 0.08); color: var(--white); }
.dialog > button { align-self: flex-start; margin-top: 6px; }

.spec-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.spec-table th, .spec-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.spec-table thead th { color: var(--dim); font-weight: 600; letter-spacing: 0.06em; }
.spec-table tbody th { color: var(--dim); font-weight: 500; white-space: nowrap; }
.spec-table td.src { color: var(--faint); font-size: 11.5px; }
.note { font-size: 13px; }
.sources { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.8; color: var(--dim); }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px 14px;
}

#hud-tl { top: 16px; left: 16px; min-width: 210px; }
#trim-name { font-size: 22px; font-weight: 300; letter-spacing: 0.28em; }
.tags { display: flex; gap: 6px; margin: 8px 0 6px; flex-wrap: wrap; }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; padding: 4px 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); }
#aero { background: rgba(227, 25, 55, 0.85); }
.small { font-size: 11.5px; color: var(--dim); letter-spacing: 0.04em; }

#hud-tr { top: 16px; right: 16px; min-width: 230px; }
#timer-live { font-size: 30px; font-weight: 300; font-variant-numeric: tabular-nums; min-height: 0; }
#timer-live:empty { display: none; }
#splits { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
#splits td { padding: 3px 10px 3px 0; color: var(--white); white-space: nowrap; }
#splits td:last-child { padding-right: 0; }
#splits td:first-child { color: var(--dim); letter-spacing: 0.06em; width: 54px; }
#splits td:last-child { text-align: right; color: var(--faint); }
#splits i { font-style: normal; }
#rings-line { margin-top: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.1em; color: var(--gold); }
#rings-line:empty { display: none; }
.score-row { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; color: var(--dim); letter-spacing: 0.12em; }
.score-row b { color: var(--white); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

#hud-bottom {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 70vw);
  text-align: center;
}
#speedo { display: flex; align-items: baseline; justify-content: center; gap: 12px; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55); }
#speed { font-size: clamp(56px, 7vw, 84px); font-weight: 200; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2.2em; }
#speed-unit { font-size: 13px; letter-spacing: 0.22em; color: var(--dim); width: 3.4em; text-align: left; }
#gear { font-size: 16px; font-weight: 700; color: var(--dim); width: 3.4em; text-align: right; }
#power-bar { position: relative; height: 4px; margin-top: 10px; background: rgba(255, 255, 255, 0.16); border-radius: 2px; overflow: hidden; }
#power-fill { position: absolute; left: 50%; top: 0; bottom: 0; width: 0; background: var(--white); max-width: 50%; transform-origin: left; }
#regen-fill { position: absolute; right: 50%; top: 0; bottom: 0; width: 0; background: #3ccf6e; max-width: 50%; }
.power-row { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--dim); margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }

#copv { right: 16px; bottom: 18px; display: flex; gap: 12px; align-items: stretch; }
.copv-gauge { width: 10px; height: 74px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); position: relative; overflow: hidden; }
#gas-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: linear-gradient(0deg, var(--gold), #f3e4bf); }
#copv.low #gas-fill { background: var(--red); }
.copv-info { display: flex; flex-direction: column; justify-content: space-between; }
.label { font-size: 10.5px; color: var(--dim); letter-spacing: 0.14em; text-transform: uppercase; }
#gas-val { font-size: 16px; font-variant-numeric: tabular-nums; }
.nozzles { display: flex; gap: 5px; }
.nozzles span { font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; padding: 3px 5px; border-radius: 3px; color: var(--faint); border: 1px solid rgba(255, 255, 255, 0.14); }
.nozzles span.on { color: #0b0b0c; background: var(--white); border-color: var(--white); box-shadow: 0 0 12px rgba(255, 255, 255, 0.7); }
#n-comp.on { background: #6fb7ff; border-color: #6fb7ff; box-shadow: 0 0 10px rgba(111, 183, 255, 0.6); }

#callouts {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(640px, 92vw);
}
.callout {
  text-align: center;
  padding: 10px 22px 12px;
  border-radius: 10px;
  background: rgba(10, 10, 12, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: callout 3.8s ease forwards;
}
.c-title { font-size: 22px; font-weight: 700; letter-spacing: 0.12em; }
.c-detail { font-size: 13px; color: var(--dim); margin-top: 4px; }
.c-score { font-size: 13px; font-weight: 700; color: var(--gold); margin-top: 4px; letter-spacing: 0.08em; }
.callout.great .c-title { color: #fff; text-shadow: 0 0 18px rgba(255, 210, 120, 0.7); }
.callout.great { border-color: rgba(214, 176, 107, 0.55); }
.callout.bad .c-title { color: #ff5a6e; }
.callout.info .c-title { font-size: 16px; }
@keyframes callout {
  0% { opacity: 0; transform: translateY(-10px) scale(0.96); }
  7% { opacity: 1; transform: translateY(0) scale(1); }
  82% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

#hint {
  position: absolute;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--white);
  letter-spacing: 0.06em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
#help-hint { position: absolute; left: 18px; bottom: 18px; font-size: 12px; color: var(--faint); }

/* ---------- touch ---------- */

#touch { position: fixed; inset: auto 0 0 0; height: 46vh; z-index: 6; pointer-events: none; }
#touch-steer {
  pointer-events: auto;
  position: absolute; left: 3vw; bottom: 4vh;
  width: min(42vw, 300px); height: 96px;
  border-radius: 48px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: 11px; letter-spacing: 0.2em;
  touch-action: none;
}
.touch-buttons { pointer-events: auto; position: absolute; right: 3vw; bottom: 4vh; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.touch-row { display: flex; gap: 8px; align-items: end; }
.touch-buttons button { touch-action: none; padding: 0; }
.touch-buttons button.small { height: 34px; font-size: 10px; padding: 0 10px; }
.touch-buttons button.big { width: 70px; height: 70px; border-radius: 35px; font-size: 11px; }
.touch-buttons .go { background: rgba(255, 255, 255, 0.85); color: #000; }
.touch-buttons .boost { border-color: var(--gold); }
.touch-buttons .lift { border-color: #9cc9ff; }

@media (max-width: 760px) {
  #trims { grid-template-columns: 1fr; }
  .dialog .cols { grid-template-columns: 1fr; }
  #hud-tr { display: none; }
  #menu { background: rgba(6, 6, 7, 0.7); }
  #hint { bottom: 50vh; white-space: normal; text-align: center; width: 90vw; }
}
body.trim-0 .touch-buttons .boost,
body.trim-0 .touch-buttons .lift,
body.trim-1 .touch-buttons .lift { display: none; }

@media (pointer: coarse) {
  #help-hint { display: none; }
  .panel { padding: 8px 10px; }
  #hud-tl { transform: scale(0.78); transform-origin: top left; top: 10px; left: 10px; }
  #hud-tr { transform: scale(0.78); transform-origin: top right; top: 10px; right: 10px; min-width: 0; }
  #splits { display: none; }
  #hud-bottom { bottom: auto; top: 8px; width: 30vw; }
  #speed { font-size: 44px; }
  #power-bar, .power-row { display: none; }
  #copv { transform: scale(0.78); transform-origin: top right; bottom: auto; top: 96px; right: 10px; }
  #callouts { top: 24%; }
  .c-title { font-size: 17px; }
  #hint { bottom: 46vh; }
}
