:root {
  --red: #e10600;
  --red-dim: #9f0503;
  --ink: #060809;
  --paper: #f4f6f8;
  --muted: rgba(235, 240, 245, 0.56);
  --line: rgba(255, 255, 255, 0.14);
  --display: "SF Pro Display", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --num: "DIN Alternate", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  background: var(--ink);
}

#hud {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 6;
  pointer-events: none;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(ellipse at 50% 46%, rgba(0, 0, 0, 0) 38%, rgba(0, 0, 0, 0.5) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.42), transparent 16%, transparent 82%, rgba(0, 0, 0, 0.45));
}

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.45s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 72% 54%, rgba(3, 5, 7, 0) 26%, rgba(3, 5, 7, 0.28) 82%),
    linear-gradient(90deg, rgba(3, 5, 7, 0.98) 0%, rgba(3, 5, 7, 0.9) 27%, rgba(3, 5, 7, 0.34) 51%, rgba(3, 5, 7, 0.08) 100%),
    linear-gradient(180deg, rgba(3, 5, 7, 0.48), transparent 30%, transparent 76%, rgba(3, 5, 7, 0.44));
}

.title-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(490px, 42vw);
  height: 100%;
  padding: clamp(28px, 4vh, 52px) 0 clamp(24px, 3.4vh, 44px) clamp(28px, 4.7vw, 74px);
  margin-right: auto;
}

.race-brand { flex: 0 0 auto; }

.kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: rgba(240, 244, 248, 0.62);
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 12px rgba(225, 6, 0, 0.9);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.title-inner h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: clamp(18px, 3.2vh, 34px) 0 0;
  font-size: clamp(62px, 7.3vw, 112px);
  line-height: .82;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.055em;
  color: #fff;
  text-shadow: 0 12px 45px rgba(0, 0, 0, .55);
}

.title-inner h1 i {
  width: 13px;
  height: .9em;
  background: var(--red);
  transform: skewX(-17deg);
  box-shadow: 9px 0 0 rgba(225, 6, 0, .38);
}

.brand-subtitle {
  margin: 14px 0 0 28px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .46em;
  color: rgba(255,255,255,.58);
}

.tagline {
  margin: clamp(16px, 2.4vh, 28px) 0 0;
  max-width: 430px;
  font-size: clamp(12px, 1.05vw, 15px);
  line-height: 1.65;
  letter-spacing: 0.05em;
  color: rgba(240, 244, 248, 0.68);
}

.meta-row {
  display: flex;
  gap: 24px;
  margin: 0;
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 58px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.meta-k {
  font-family: var(--num);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
}

.meta-l {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.primary-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: min(332px, 100%);
  gap: 24px;
  padding: 20px 26px 20px 30px;
  border-radius: 2px;
  background: linear-gradient(112deg, #ff241c 0%, var(--red) 62%, #a80000 100%);
  color: #fff;
  font-family: var(--display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.2em;
  box-shadow:
    0 18px 52px rgba(225, 6, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.primary-btn span {
  font-size: 17px;
  transition: transform 0.18s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow:
    0 20px 50px rgba(225, 6, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.primary-btn:hover span {
  transform: translateX(4px);
}

.primary-btn:active {
  transform: translateY(1px) scale(0.99);
}

.primary-btn:disabled {
  cursor: default;
  opacity: 0.42;
  filter: saturate(0.25);
  box-shadow: none;
}

.primary-btn:disabled:hover,
.primary-btn:disabled:active {
  transform: none;
  filter: saturate(0.25);
  box-shadow: none;
}

.asset-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(235, 240, 245, 0.5);
  transition: opacity 0.5s ease;
}

.asset-bar {
  display: block;
  width: 92px;
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.asset-bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--red), #ff8a5c);
  transition: width 0.25s ease;
}

.asset-status.done {
  opacity: 0.45;
}

.asset-status.error {
  color: #ff6b61;
}

.file-notice {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  display: none;
  max-width: min(560px, calc(100% - 32px));
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 110, 96, 0.4);
  background: rgba(20, 8, 8, 0.92);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
  font-size: 11px;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: rgba(255, 226, 222, 0.9);
}

.file-notice.show {
  display: block;
}

.file-notice strong {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: #fff;
}

.file-notice code {
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  font-family: var(--num);
  font-size: 10px;
}

#gamepad-status {
  margin: 8px 0 0;
  color: #cbd4de;
  font-size: 11px;
  line-height: 1.5;
}

#gamepad-settings,
#yas-guide-settings {
  margin: 8px 0 0;
  color: #cbd4de;
  font-size: 11px;
  line-height: 1.5;
}

#gamepad-settings summary {
  width: fit-content;
  cursor: pointer;
}

.gamepad-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
}

.gamepad-options label {
  display: grid;
  gap: 3px;
}

.gamepad-options select,
#yas-guide-settings select {
  padding: 6px 8px;
  border: 1px solid #ffffff30;
  border-radius: 3px;
  background: #202530;
  color: #fff;
  font: inherit;
}

#yas-guide-settings:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: rgba(240, 244, 248, 0.72);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  height: 23px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--num);
  font-size: 12px;
  color: #fff;
}

.footnote {
  margin-top: 12px;
  font-size: 8px;
  letter-spacing: 0.16em;
  color: rgba(235, 240, 245, 0.28);
}

/* ---------------------------------------------------------------- results */

.results-card {
  position: relative;
  width: min(520px, calc(100% - 40px));
  padding: 38px 40px 30px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(18, 22, 28, 0.92), rgba(8, 10, 14, 0.94));
  box-shadow:
    0 40px 120px rgba(0, 0, 0, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.result-pos {
  margin-top: 10px;
  font-family: var(--num);
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #fff;
}

.result-pos.lost {
  color: var(--red);
}

.result-sub {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 30px 0 14px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-limits {
  margin-bottom: 24px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(235, 240, 245, 0.46);
}

.result-limits strong {
  margin-left: 8px;
  font-family: var(--num);
  font-size: 14px;
  color: rgba(255, 255, 255, 0.92);
}

.classification-wrap {
  margin-bottom: 24px;
}

.classification-title {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--muted);
  margin-bottom: 10px;
}

#result-classification {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 232px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.45);
}

#result-classification li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 14px;
  font-family: var(--num);
  font-size: 12px;
  color: rgba(235, 240, 245, 0.78);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#result-classification li:last-child {
  border-bottom: none;
}

#result-classification li.you {
  background: rgba(213, 29, 52, 0.16);
  color: #fff;
}

#result-classification .cls-pos {
  width: 30px;
  font-weight: 700;
}

#result-classification .cls-name {
  flex: 1;
  letter-spacing: 0.12em;
}

#result-classification .cls-gap {
  font-weight: 600;
  color: rgba(190, 255, 205, 0.85);
}

#result-classification li.you .cls-gap {
  color: #ffd27a;
}

.result-grid > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-grid .label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.result-grid span:last-child {
  font-family: var(--num);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #fff;
}

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

#touch-controls {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

body.touch #touch-controls {
  display: block;
}

.touch-cluster {
  position: absolute;
  bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
  pointer-events: auto;
}

.touch-cluster.left {
  left: calc(18px + env(safe-area-inset-left));
}

.touch-cluster.right {
  right: calc(18px + env(safe-area-inset-right));
  align-items: flex-end;
}

.touch-btn {
  appearance: none;
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(12, 16, 21, 0.5);
  color: rgba(255, 255, 255, 0.92);
  font-family: var(--display);
  font-size: 21px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
  transition: transform 0.08s ease, background 0.08s ease;
}

.touch-btn:active,
.touch-btn.pressed {
  transform: scale(0.93);
  background: rgba(255, 255, 255, 0.24);
}

.touch-btn.gas {
  width: 86px;
  height: 86px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  border-color: rgba(255, 88, 70, 0.6);
  background: radial-gradient(circle at 34% 26%, rgba(255, 52, 42, 0.92), rgba(126, 5, 0, 0.72));
  box-shadow: 0 10px 30px rgba(225, 6, 0, 0.3);
}

.touch-btn.brake {
  width: 58px;
  height: 58px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

#sound-toggle {
  position: fixed;
  z-index: 18;
  left: 24px;
  bottom: 20px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgba(235, 240, 245, 0.42);
  cursor: pointer;
  transition: color 0.2s ease;
}

#sound-toggle:hover {
  color: rgba(235, 240, 245, 0.8);
}

body.touch #sound-toggle {
  display: none;
}

@media (max-width: 680px) {
  .title-inner {
    padding: 24px 26px;
  }

  .title-inner h1 {
    letter-spacing: -0.055em;
  }

  .meta-row {
    gap: 16px;
    margin: 0;
  }

  .controls {
    gap: 16px;
  }

  .footnote {
    max-width: 250px;
    line-height: 1.6;
  }

  .results-card {
    padding: 30px 26px 26px;
  }

  .result-grid {
    gap: 10px;
  }

  .result-grid span:last-child {
    font-size: 15px;
  }
}

/* Pre-race control tower */
.circuit-picker { display: flex; flex-direction: column; width: min(340px, 100%); margin-top: clamp(16px, 2.7vh, 30px); counter-reset: circuit; border-top: 1px solid rgba(255,255,255,.16); }
.circuit-picker a { position: relative; display: grid; grid-template-columns: 30px 1fr 18px; grid-template-rows: auto auto; align-items: center; min-height: 54px; padding: 10px 12px 10px 0; border-bottom: 1px solid rgba(255,255,255,.13); color: var(--paper); text-decoration: none; background: transparent; transition: padding .2s ease, background .2s ease, border-color .2s ease; }
.circuit-picker b { grid-row: 1 / 3; align-self: center; font: 600 8px var(--num); letter-spacing: .12em; color: rgba(255,255,255,.28); }
.circuit-picker strong { grid-column: 2; font-size: 11px; letter-spacing: .13em; }
.circuit-picker span { grid-column: 2; margin-top: 4px; font-size: 9px; letter-spacing: .08em; color: rgba(235,240,245,.42); }
.circuit-picker em { grid-column: 3; grid-row: 1 / 3; font: 300 24px var(--display); color: rgba(255,255,255,.34); }
.circuit-picker a::before { content: ""; position: absolute; left: -12px; top: 0; bottom: 0; width: 3px; background: transparent; }
.circuit-picker a[aria-current="page"] { padding-left: 13px; border-color: rgba(255,54,44,.45); background: linear-gradient(90deg, rgba(184,6,2,.28), rgba(40,4,4,.08)); }
.circuit-picker a[aria-current="page"]::before { background: #ff2c24; box-shadow: 0 0 18px rgba(255,35,27,.7); }
.circuit-picker a[aria-current="page"] b, .circuit-picker a[aria-current="page"] em { color: #ff5c54; }
.circuit-picker a:hover, .circuit-picker a:focus-visible { padding-left: 13px; background: rgba(255,255,255,.055); outline: none; }
.race-setup { display: flex; align-items: stretch; gap: 20px; width: min(420px, 100%); margin: clamp(12px, 2vh, 20px) 0 16px; }
.mode-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); flex: 1; gap: 6px; }
.mode-picker a { display: flex; flex-direction: column; justify-content: center; min-height: 52px; padding: 9px 12px; border: 1px solid rgba(255,255,255,.15); border-radius: 2px; color: var(--paper); text-decoration: none; background: rgba(5,8,11,.44); transition: border-color .2s, background .2s; }
.mode-picker strong { display: block; font-size: 11px; letter-spacing: .1em; }
.mode-picker span { display: block; margin-top: 4px; font-size: 7px; letter-spacing: .16em; color: var(--muted); }
.mode-picker a[aria-current="page"] { border-color: #ff4b42; background: rgba(142,10,7,.26); box-shadow: inset 0 -2px #ff342c; }
.mode-picker a:hover, .mode-picker a:focus-visible { border-color: rgba(255,255,255,.5); outline: none; }
.race-setup .meta-row { padding: 5px 0; }
.showcase-link { display: grid; grid-template-columns: 30px 1fr 20px; align-items: center; width: min(332px, 100%); min-height: 52px; margin: 0 0 10px; padding: 9px 13px; border: 1px solid rgba(120,220,226,.3); border-radius: 2px; color: var(--paper); text-decoration: none; background: linear-gradient(110deg, rgba(20,72,76,.46), rgba(5,8,11,.54)); transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.showcase-link:hover, .showcase-link:focus-visible { transform: translateY(-2px); border-color: rgba(140,239,244,.72); background: linear-gradient(110deg, rgba(24,91,96,.58), rgba(8,13,16,.66)); outline: none; }
.showcase-icon { font-size: 23px; color: #77e0e5; text-shadow: 0 0 16px rgba(84,213,221,.55); }
.showcase-link > span:nth-child(2) { display: flex; flex-direction: column; gap: 4px; }
.showcase-link strong { font-size: 11px; letter-spacing: .1em; }
.showcase-link small { font-size: 7px; font-weight: 700; letter-spacing: .15em; color: rgba(181,232,235,.62); }
.showcase-link em { justify-self: end; font: 400 16px var(--display); color: #77e0e5; }
.result-pos.time { font-size: 54px; letter-spacing: .02em; }
.daylight #vignette { opacity: .46; }
.daylight .live-dot { background: #54d5dd; box-shadow: 0 0 12px #54d5dd80; }
.results-card a { color: #b9eef1; }
@media (max-height: 760px) { .title-inner { overflow-y: auto; } .title-inner h1 { font-size: clamp(54px, 7vw, 82px); } .brand-subtitle { margin-top: 9px; } .tagline { margin-top: 12px; } .circuit-picker { margin-top: 12px; } .circuit-picker a { min-height: 47px; padding-top: 7px; padding-bottom: 7px; } .race-setup { margin: 10px 0 12px; } .controls { margin-top: 18px; } }
@media (max-width: 820px) { .scrim { background: linear-gradient(90deg, rgba(3,5,7,.96), rgba(3,5,7,.7)); } .title-inner { width: min(520px, 100%); padding-right: 26px; } .race-brand { padding-top: env(safe-area-inset-top); } .title-inner h1 { font-size: clamp(62px, 18vw, 98px); } .circuit-picker { width: 100%; } }
