/*
 * Nightline Racer interface.
 *
 * One dark, neon-lit system shared by the garage and the HUD: glass panels over the live 3D scene,
 * a cyan/gold/red accent set, and layouts that collapse to a phone without losing the race data.
 */

:root {
  color-scheme: dark;
  --ink: #f6f3ea;
  --muted: #98a3ab;
  --dim: #6d7780;
  --panel: rgba(8, 12, 16, 0.72);
  --panel-strong: rgba(6, 9, 13, 0.92);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.26);
  --red: #ff3e3e;
  --cyan: #00d8ff;
  --gold: #ffd166;
  --green: #6eff7a;
  --violet: #b07bff;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #04060a;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  background: #04060a;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------------------------------------------------------------- boot --- */

.boot {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 45%, #0d1620 0%, #04060a 68%);
  z-index: 40;
  transition: opacity 0.5s ease;
}

.boot.is-done {
  opacity: 0;
  pointer-events: none;
}

.boot-mark {
  font-size: clamp(28px, 6vw, 54px);
  font-weight: 800;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  background: linear-gradient(96deg, var(--cyan), var(--ink) 45%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.boot-bar {
  width: min(320px, 60vw);
  height: 3px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

.boot-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  transition: width 0.35s ease;
}

.boot small {
  color: var(--dim);
  letter-spacing: 0.2em;
  font-size: 11px;
  text-transform: uppercase;
}

/* -------------------------------------------------------------- overlay --- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
}

.overlay.is-visible {
  display: flex;
}

.panel {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(9, 16, 22, 0.82), rgba(3, 5, 8, 0.94));
  backdrop-filter: blur(14px);
  text-align: center;
}

.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- menu --- */

/*
 * The garage is a window onto the showroom, not a wall in front of it: the panels hug the edges and
 * the middle column stays clear so the selected car is visible on its turntable behind the UI.
 */
.menu {
  flex-direction: column;
  padding: clamp(14px, 2.2vw, 30px);
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(4, 6, 10, 0.94) 0%, rgba(4, 6, 10, 0.35) 26%, rgba(4, 6, 10, 0.2) 62%, rgba(4, 6, 10, 0.88) 100%),
    linear-gradient(90deg, rgba(4, 6, 10, 0.9) 0%, rgba(4, 6, 10, 0.55) 30%, rgba(4, 6, 10, 0) 46%, rgba(4, 6, 10, 0) 56%, rgba(4, 6, 10, 0.6) 74%, rgba(4, 6, 10, 0.92) 100%);
  overflow: hidden;
}

.menu-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.brand-lockup h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 4.2vw, 46px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.career-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.career-strip div {
  min-width: 92px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  display: grid;
  gap: 2px;
}

.career-strip span {
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--dim);
}

.career-strip strong {
  font-size: 17px;
  font-weight: 700;
}

.tab-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.tab {
  padding: 8px 18px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid transparent;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line-strong);
}

.menu-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 30vw) minmax(0, 1fr) minmax(300px, 24vw);
  gap: 16px;
}

/* Deliberately empty: it reserves the centre of the screen for the car itself. */
.showroom-window {
  pointer-events: none;
}

.tab-panel {
  display: none;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
}

.tab-panel.is-active {
  display: block;
}

.garage-grid,
.event-grid,
.upgrade-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  align-content: start;
}

.garage-card,
.event-card,
.upgrade-card {
  position: relative;
  display: grid;
  gap: 6px;
  padding: 14px 90px 14px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color 0.2s, transform 0.2s, background 0.2s;
}

.garage-card:hover,
.event-card:hover,
.upgrade-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.garage-card.is-selected,
.event-card.is-selected {
  border-color: var(--cyan);
  background: linear-gradient(140deg, rgba(0, 216, 255, 0.14), var(--panel) 62%);
}

.garage-card.is-locked,
.event-card.is-locked {
  opacity: 0.55;
}

.garage-card .swatch {
  height: 5px;
  border-radius: 3px;
  background: currentColor;
}

.garage-card strong,
.event-card strong,
.upgrade-card strong {
  font-size: 15px;
  font-weight: 700;
}

.garage-card small,
.event-card small,
.upgrade-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.garage-card em,
.event-card em {
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--gold);
  text-transform: uppercase;
}

.card-tag {
  position: absolute;
  bottom: 12px;
  right: 12px;
  font-size: 10px;
  letter-spacing: 0.2em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.card-tag.owned {
  color: var(--green);
  border-color: rgba(110, 255, 122, 0.4);
}

.card-tag.locked {
  color: var(--red);
  border-color: rgba(255, 62, 62, 0.4);
}

.upgrade-card {
  padding-right: 14px;
}

.upgrade-card .levels {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.upgrade-card .levels i {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
}

.upgrade-card .levels i.is-on {
  background: linear-gradient(90deg, var(--cyan), var(--green));
}

.buy-button {
  margin-top: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: background 0.2s, color 0.2s;
}

.buy-button:hover:not(:disabled) {
  background: var(--cyan);
  color: #04070a;
}

.buy-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* ------------------------------------------------------------ spec rail --- */

.spec-rail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.spec-head span {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--cyan);
}

.spec-head strong {
  display: block;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 2px;
}

.spec-head small {
  color: var(--muted);
  font-size: 12px;
}

.spec-sheet {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.spec-sheet div {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
}

.spec-sheet dt {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.spec-sheet dd {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.build-meter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.build-meter i {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.build-meter b {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  transition: width 0.3s ease;
}

.build-meter strong {
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0;
}

.car-action:empty {
  display: none;
}

.event-summary {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  border-left: 2px solid var(--cyan);
  padding-left: 10px;
}

.control-row {
  display: flex;
  gap: 6px;
}

.pill {
  flex: 1;
  padding: 9px 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: all 0.2s;
}

.pill.is-active {
  color: #05080b;
  background: var(--ink);
  border-color: var(--ink);
}

.menu-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-action,
.secondary-action {
  flex: 1;
  min-width: 118px;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
  text-transform: uppercase;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

.primary-action {
  color: #04070a;
  background: linear-gradient(96deg, var(--cyan), var(--green));
  box-shadow: 0 12px 34px rgba(0, 216, 255, 0.28);
}

.primary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 40px rgba(0, 216, 255, 0.38);
}

.secondary-action {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
}

.secondary-action:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ----------------------------------------------------------------- hud --- */

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  padding: clamp(10px, 1.6vw, 22px);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
}

.hud.is-live {
  opacity: 1;
}

.hud.is-photo {
  opacity: 0;
}

.hud-top {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-self: center;
}

.hud-module {
  min-width: 74px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  gap: 1px;
  text-align: center;
  backdrop-filter: blur(6px);
}

.hud-module span {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--dim);
}

.hud-module strong {
  font-size: 16px;
  font-weight: 700;
}

.hud-module.position strong {
  color: var(--gold);
}

.hud-module.pursuit.is-hot {
  border-color: var(--red);
  animation: pulse 0.9s infinite;
}

.hud-module.delta.is-fast strong {
  color: var(--green);
}

.hud-module.delta.is-slow strong {
  color: var(--red);
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(255, 62, 62, 0);
  }
  50% {
    box-shadow: 0 0 22px rgba(255, 62, 62, 0.55);
  }
}

.telemetry-strip {
  justify-self: center;
  display: flex;
  gap: 6px;
}

.telemetry-strip div {
  position: relative;
  min-width: 86px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: center;
  overflow: hidden;
}

.telemetry-strip span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--dim);
}

.telemetry-strip strong {
  font-size: 14px;
}

#gripFill {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
  transition: width 0.12s linear;
}

.objective-bar {
  justify-self: center;
  align-self: start;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: var(--panel-strong);
}

.objective-bar span {
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--gold);
}

.objective-bar strong {
  font-size: 20px;
}

.hud-bottom {
  grid-row: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.speed-cluster {
  position: relative;
  width: clamp(130px, 15vw, 190px);
  aspect-ratio: 1;
}

.speed-cluster canvas {
  width: 100%;
  height: 100%;
}

.speed-readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.speed-readout strong {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  line-height: 1;
}

.speed-readout span {
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--dim);
}

.race-stack {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.boost-meter,
.slipstream-meter {
  width: clamp(140px, 16vw, 200px);
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
}

.boost-meter span,
.slipstream-meter span {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.boost-meter i,
.slipstream-meter i {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  width: 100%;
  transition: width 0.12s linear;
}

.slipstream-meter i {
  background: linear-gradient(90deg, var(--violet), var(--cyan));
}

#miniMap {
  width: clamp(120px, 13vw, 170px);
  height: clamp(120px, 13vw, 170px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
}

.director-feed {
  position: absolute;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  display: grid;
  gap: 4px;
  justify-items: center;
  pointer-events: none;
}

.director-feed p {
  margin: 0;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  animation: rise 0.3s ease;
}

.director-feed p.style {
  color: var(--gold);
  border-color: rgba(255, 209, 102, 0.5);
}

.director-feed p.danger {
  color: var(--red);
  border-color: rgba(255, 62, 62, 0.5);
}

.director-feed p.warn {
  color: var(--gold);
}

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

.countdown {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  place-content: center;
  font-size: clamp(80px, 18vw, 200px);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-shadow: 0 0 60px rgba(0, 216, 255, 0.6);
  pointer-events: none;
}

.countdown.is-visible {
  display: grid;
  animation: countPop 0.4s ease;
}

@keyframes countPop {
  from {
    transform: scale(1.5);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* ------------------------------------------------------- pause / finish --- */

.pause-panel h2,
.finish-panel h2 {
  margin: 0;
  font-size: clamp(24px, 4vw, 40px);
}

.pause-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.chip.is-on {
  color: var(--ink);
  border-color: var(--cyan);
}

.finish-stars {
  font-size: 34px;
  letter-spacing: 0.2em;
  color: var(--gold);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 0;
  width: min(760px, 92vw);
}

.results-grid div {
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
}

.results-grid dt {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.results-grid dd {
  margin: 3px 0 0;
  font-size: 17px;
  font-weight: 700;
}

.pause-panel .menu-actions,
.finish-panel .menu-actions {
  width: min(620px, 92vw);
}

/* ------------------------------------------------------------- chrome --- */

.quick-settings {
  position: absolute;
  top: clamp(10px, 1.6vw, 22px);
  right: clamp(10px, 1.6vw, 22px);
  z-index: 15;
  display: grid;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.quick-settings.is-live {
  opacity: 1;
  pointer-events: auto;
}

.icon-button {
  width: 44px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--dim);
}

.icon-button.is-on {
  color: var(--cyan);
  border-color: rgba(0, 216, 255, 0.5);
}

.status-line {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 12;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  pointer-events: none;
}

.touch-pad {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 16;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}

.touch-pad button {
  padding: 16px 0;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: rgba(9, 13, 18, 0.72);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}

.touch-pad button.is-pressed {
  background: rgba(0, 216, 255, 0.28);
}

.fallback {
  display: none;
  z-index: 60;
  place-content: center;
  text-align: center;
  padding: 30px;
  background: #04060a;
}

.fallback.is-visible {
  display: grid;
}

.fallback p {
  color: var(--muted);
  max-width: 46ch;
}

/* ------------------------------------------------------------ responsive --- */

@media (max-width: 1080px) {
  .menu {
    background: linear-gradient(180deg, rgba(4, 6, 10, 0.94) 0%, rgba(4, 6, 10, 0.72) 40%, rgba(4, 6, 10, 0.94) 100%);
  }

  .menu-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .showroom-window {
    display: none;
  }

  .garage-grid,
  .event-grid,
  .upgrade-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .spec-rail {
    max-height: 46vh;
  }
}

@media (max-width: 780px) {
  .hud-top {
    gap: 4px;
  }

  .hud-module {
    min-width: 58px;
    padding: 4px 8px;
  }

  .hud-module strong {
    font-size: 13px;
  }

  .hud-module.delta,
  .hud-module.combo {
    display: none;
  }

  .hud-bottom {
    align-items: flex-end;
    padding-bottom: 116px;
  }

  #miniMap {
    display: none;
  }

  .touch-pad {
    display: grid;
  }

  .director-feed {
    bottom: 34%;
  }

  .career-strip div {
    min-width: 74px;
    padding: 6px 10px;
  }

  .garage-grid,
  .event-grid,
  .upgrade-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

@media (pointer: coarse) {
  .touch-pad {
    display: grid;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
