:root {
  --bg: #05070a;
  --panel: rgba(10, 13, 18, 0.84);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f3f5f8;
  --muted: #8b95a3;
  --accent: #e10600;
  --accent-soft: #ff2b1f;
  --cyan: #34e3ff;
  --font: "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  user-select: none;
}

.hud-top {
  position: absolute;
  top: clamp(12px, 2vw, 26px);
  left: clamp(12px, 2vw, 26px);
  display: flex;
  align-items: stretch;
  gap: 9px;
}

.hud-card {
  position: relative;
  padding: 9px 14px 10px;
  background: linear-gradient(160deg, rgba(15, 19, 26, 0.92), rgba(7, 9, 13, 0.7));
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.hud-label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-big {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: clamp(26px, 3vw, 36px);
  font-weight: 800;
  font-style: italic;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.hud-sub {
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.pos-card .hud-big { color: #fff; }

.time-card { min-width: 178px; }

.time-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.time-row + .time-row { margin-top: 3px; }

.time-value {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.time-value.best { color: #c6ff4f; }

.lights-hud {
  position: absolute;
  top: clamp(14px, 2.4vw, 30px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(5, 7, 10, 0.66);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.lights-hud.show { opacity: 1; }

.lights-hud i {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #1a1d22;
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: background 0.12s linear, box-shadow 0.12s linear;
}

.lights-hud i.on {
  background: #ff1912;
  border-color: #ff5c56;
  box-shadow: 0 0 14px rgba(255, 25, 18, 0.9), 0 0 30px rgba(255, 25, 18, 0.4);
}

.race-msg {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  font-size: clamp(34px, 7vw, 92px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  color: #fff;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.75), 0 0 2px rgba(0, 0, 0, 0.8);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.race-msg.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.race-msg.final { color: #ffd84d; }

.hud-bottom {
  position: absolute;
  left: clamp(12px, 2vw, 26px);
  right: clamp(12px, 2vw, 26px);
  bottom: clamp(12px, 2vw, 24px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.hint-card {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #aeb7c4;
  background: rgba(6, 8, 11, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
}

.hint-card b { color: #fff; font-weight: 700; }

.speedo {
  position: relative;
  width: min(340px, 46vw);
  padding: 10px 18px 12px;
  background: linear-gradient(150deg, rgba(15, 18, 24, 0.95), rgba(5, 6, 9, 0.92));
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  clip-path: polygon(14px 0, 100% 0, 100% 100%, 0 100%, 0 14px);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
}

.speedo::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 0 62%, rgba(225, 6, 0, 0.1) 62% 78%, transparent 78%);
  pointer-events: none;
}

.speedo-top {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.drs-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.drs-track {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#drsFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #19c37d, #c6ff4f);
  transform-origin: left center;
  transition: width 0.12s linear, background 0.2s linear;
}

#drsFill.hot { background: linear-gradient(90deg, #ff9100, #ff2b1f); }

.broadcast-tag {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #ff5b52;
}

.broadcast-tag::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 5px;
  border-radius: 50%;
  background: #ff2b1f;
  vertical-align: middle;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.speedo-main {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.gear-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 6px 4px 7px;
  margin-bottom: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.03);
}

#gearValue {
  font-size: 28px;
  font-weight: 800;
  font-style: italic;
  line-height: 1;
  color: #fff;
}

.gear-label {
  margin-top: 3px;
  font-size: 7px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.speed-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-left: auto;
}

#speedValue {
  font-size: clamp(46px, 6vw, 62px);
  font-weight: 800;
  font-style: italic;
  line-height: 0.88;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 26px rgba(225, 6, 0, 0.28);
}

.speed-unit {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.shift-lights {
  display: flex;
  gap: 3px;
  margin-top: 6px;
}

.shift-lights i {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.09);
  transition: background 0.06s linear, box-shadow 0.06s linear;
}

.shift-lights i.on { background: #37e07c; box-shadow: 0 0 8px rgba(55, 224, 124, 0.55); }
.shift-lights i.warn.on { background: #ffd23f; box-shadow: 0 0 8px rgba(255, 210, 63, 0.6); }
.shift-lights i.max.on { background: #ff2b1f; box-shadow: 0 0 10px rgba(255, 43, 31, 0.8); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 80% 0%, rgba(225, 6, 0, 0.22), transparent 55%),
    radial-gradient(90% 80% at 10% 100%, rgba(20, 72, 120, 0.35), transparent 60%),
    linear-gradient(150deg, #070a0f 0%, #06080c 55%, #04060a 100%);
}

.overlay::before {
  content: "";
  position: absolute;
  inset: -10%;
  background-image: repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 90px);
  animation: slide 22s linear infinite;
}

@keyframes slide {
  from { transform: translateX(-40px); }
  to { transform: translateX(40px); }
}

.overlay-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(75% 65% at 50% 50%, transparent 40%, rgba(0, 0, 0, 0.6) 100%);
  pointer-events: none;
}

.start-panel, .results {
  position: relative;
  width: min(760px, 100%);
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.kicker {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: #ff6a61;
}

.start-panel h1 {
  margin: 0;
  font-size: clamp(64px, 14vw, 148px);
  font-weight: 900;
  font-style: italic;
  line-height: 0.82;
  letter-spacing: -0.055em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffffff 20%, #b9c2cd 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 22px 50px rgba(0, 0, 0, 0.65));
}

.start-panel h1 em {
  font-style: italic;
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
}

.tagline {
  margin: 14px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #98a2b0;
}

.start-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: clamp(24px, 4vw, 42px) 0 0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.start-grid > div {
  padding: 14px 16px;
  background: rgba(7, 9, 13, 0.72);
}

.start-grid span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.start-grid small {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--muted);
}

.cta {
  margin-top: clamp(24px, 4vw, 38px);
  padding: 16px 46px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer;
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  box-shadow: 0 12px 34px rgba(225, 6, 0, 0.32);
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.cta:hover {
  background: #ff1e12;
  transform: translateY(-2px);
  box-shadow: 0 18px 44px rgba(225, 6, 0, 0.44);
}

.cta:active { transform: translateY(0); }

.fineprint {
  margin: 14px 0 0;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6e7783;
}

.results h2 {
  margin: 4px 0 0;
  font-size: clamp(90px, 18vw, 190px);
  font-weight: 900;
  font-style: italic;
  line-height: 0.8;
  letter-spacing: -0.06em;
  color: #ffd84d;
}

.result-line {
  margin: 18px 0 0;
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #c3cad4;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 28px auto 0;
  max-width: 460px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.result-grid > div {
  padding: 14px 16px;
  background: rgba(7, 9, 13, 0.72);
}

.result-grid span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-grid strong {
  display: block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
}

#loading {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 30;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #6f7885;
}

@media (max-width: 760px) {
  .hint-card { display: none; }
  .hud-bottom { justify-content: flex-end; }
  .speedo { width: min(300px, 78vw); }
  .start-grid { grid-template-columns: 1fr; }
  .start-grid small { margin-top: 2px; }
  .time-card { min-width: 148px; }
  .lights-hud { top: 8px; padding: 7px 10px; }
  .lights-hud i { width: 11px; height: 11px; }
}
