:root {
  --bg: #07080d;
  --panel: rgba(13, 16, 24, 0.94);
  --text: #f6f7fb;
  --muted: #a9b0c1;
  --red: #ff233d;
  --green: #28e07a;
  --amber: #ffbf3d;
  --cyan: #58d1ff;
  --purple: #b85cff;
  --line: rgba(255, 255, 255, 0.15);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 0, rgba(255, 35, 61, 0.12), transparent 24rem),
    radial-gradient(circle at 80% 14%, rgba(88, 209, 255, 0.1), transparent 26rem),
    #07080d;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  display: flex;
  justify-content: center;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  cursor: pointer;
  font: 800 0.9rem/1 Arial, Helvetica, sans-serif;
  letter-spacing: 0.04em;
  padding: 0.95rem 1.25rem;
  text-transform: uppercase;
}

button:hover,
button:focus-visible {
  background: #ff4058;
  outline: 2px solid #fff;
  outline-offset: 3px;
}

button:disabled {
  cursor: wait;
  opacity: 0.64;
}

select {
  background: #0d1018;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: 700 0.95rem/1 Arial, Helvetica, sans-serif;
  padding: 0.75rem 0.8rem;
  width: 100%;
}

.game-shell {
  width: min(100%, 1420px);
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

.game-header {
  align-items: end;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.eyebrow,
.label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  margin: 0 0 0.35rem;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 3.2rem);
  line-height: 0.94;
  margin-bottom: 0;
  text-transform: uppercase;
}

h2 {
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  line-height: 1;
  margin-bottom: 0.8rem;
  text-transform: uppercase;
}

.header-times {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.header-times span,
.hud-grid > div {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.header-times span {
  font-family: "Courier New", monospace;
  font-weight: 700;
  min-width: 6.5rem;
  padding: 0.55rem 0.7rem;
  text-align: center;
}

.game-stage {
  aspect-ratio: 16 / 9;
  background: #06080c;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

canvas {
  display: block;
  height: 100%;
  touch-action: none;
  width: 100%;
}

.overlay {
  align-items: center;
  background: rgba(2, 4, 8, 0.68);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1rem;
  position: absolute;
  z-index: 8;
}

.overlay.is-hidden {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  max-width: 780px;
  padding: clamp(1rem, 3vw, 2rem);
  width: min(100%, 780px);
}

.panel p {
  color: var(--muted);
  line-height: 1.55;
}

.panel__header {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.1rem;
}

.setup-card,
.car-card,
.briefing-card {
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.setup-card {
  display: grid;
  gap: 1rem;
  padding: 0.9rem;
}

.setup-controls {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.setup-field {
  display: grid;
  gap: 0.45rem;
}

.setup-field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.briefing-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.briefing-card {
  display: grid;
  gap: 0.25rem;
  padding: 0.8rem;
}

.briefing-card strong {
  display: block;
  font-size: 0.98rem;
  line-height: 1.15;
  text-transform: uppercase;
}

.briefing-card span {
  color: var(--muted);
  font-family: "Courier New", monospace;
  font-size: 0.76rem;
  line-height: 1.35;
}

.car-card {
  align-items: center;
  display: grid;
  gap: 0.85rem;
  grid-template-columns: 4.6rem 1fr;
  padding: 0.8rem;
}

.car-card strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.car-card span {
  color: var(--muted);
  display: block;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

.car-card__swatch {
  aspect-ratio: 1.55;
  background:
    linear-gradient(90deg, transparent 0 14%, #f6f7fb 14% 22%, transparent 22% 100%),
    linear-gradient(135deg, #ff233d, #58d1ff);
  border-radius: 6px;
  box-shadow: 0 0 24px rgba(255, 35, 61, 0.22);
}

.panel__actions {
  display: grid;
  gap: 0.8rem;
}

.panel__actions button {
  min-height: 3.1rem;
  width: 100%;
}

.start-lights {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(5, minmax(2.5rem, 1fr));
}

.start-lights span {
  aspect-ratio: 1;
  background: #24060b;
  border: 3px solid #4a111a;
  border-radius: 50%;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.55);
}

.start-lights span.is-on {
  background: var(--red);
  box-shadow: 0 0 22px rgba(255, 35, 61, 0.9), inset 0 0 8px #fff;
}

.hud-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1.45fr repeat(4, minmax(0, 1fr));
  margin-top: 0.8rem;
}

.hud-grid > div {
  min-height: 76px;
  padding: 0.75rem;
}

.hud-grid p:last-child {
  color: var(--text);
  font-family: "Courier New", monospace;
  font-size: clamp(0.78rem, 1.4vw, 0.98rem);
  font-weight: 700;
  margin-bottom: 0;
}

.touch-controls {
  display: none;
  gap: 0.75rem;
  grid-template-columns: 0.7fr 1.3fr;
  inset: auto 0 0;
  padding: 0 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  pointer-events: none;
  position: absolute;
  touch-action: none;
  user-select: none;
  z-index: 5;
}

.touch-controls__steer,
.touch-controls__pedals {
  display: grid;
  gap: 0.65rem;
  pointer-events: auto;
}

.touch-controls__steer {
  grid-template-columns: 1fr 1fr;
}

.touch-controls__pedals {
  grid-template-columns: 0.9fr 1fr 1.15fr;
}

.touch-btn {
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  min-height: 68px;
  opacity: 0.9;
  padding: 0.65rem;
  touch-action: none;
  user-select: none;
}

.touch-btn--steer {
  background: rgba(35, 41, 54, 0.86);
  opacity: 0.72;
}

.touch-btn--go {
  background: rgba(40, 224, 122, 0.9);
  color: #06100a;
}

.touch-btn--brake,
.touch-btn--handbrake {
  background: rgba(255, 191, 61, 0.9);
  color: #160f03;
}

.touch-btn--handbrake {
  background: rgba(184, 92, 255, 0.9);
  color: #fff;
}

.touch-btn.is-pressed {
  filter: brightness(1.2);
  transform: translateY(1px);
}

.results {
  border-top: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 0.7rem;
  margin-top: 1.25rem;
  overflow-x: auto;
  padding-top: 1rem;
}

.results table {
  border-collapse: collapse;
  width: 100%;
}

.results th,
.results td {
  border-bottom: 1px solid var(--line);
  font-family: "Courier New", monospace;
  padding: 0.45rem 0.3rem;
  text-align: left;
}

.results th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.green {
  color: var(--green);
}

.amber {
  color: var(--amber);
}

@media (max-width: 920px) {
  .game-header {
    align-items: start;
    flex-direction: column;
  }

  .hud-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (pointer: coarse), (max-width: 760px) {
  body {
    overflow-x: hidden;
    overscroll-behavior: none;
  }

  body.is-running {
    overflow: hidden;
  }

  .game-stage {
    aspect-ratio: auto;
    height: min(66svh, 600px);
    min-height: 390px;
  }

  .touch-controls {
    display: grid;
  }

  body.is-menu .touch-controls,
  body.is-finished .touch-controls {
    display: none;
  }

  body.is-running .hud-grid {
    display: none;
  }

  .overlay {
    align-items: stretch;
    padding: 0.65rem;
  }

  .panel {
    max-height: 100%;
    overflow: auto;
  }
}

@media (max-width: 560px) {
  .game-shell {
    padding: 0.5rem;
  }

  h1 {
    font-size: clamp(1.35rem, 8vw, 2rem);
  }

  .header-times {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .header-times span {
    font-size: 0.78rem;
    min-width: 0;
    padding: 0.5rem 0.35rem;
  }

  .setup-controls,
  .briefing-grid,
  .car-card {
    grid-template-columns: 1fr;
  }

  .hud-grid > div:first-child {
    grid-column: 1 / -1;
  }

  .touch-controls {
    gap: 0.45rem;
    grid-template-columns: 0.72fr 1.28fr;
    padding: 0 0.45rem max(0.55rem, env(safe-area-inset-bottom));
  }

  .touch-controls__steer,
  .touch-controls__pedals {
    gap: 0.4rem;
  }

  .touch-btn {
    font-size: 0.72rem;
    min-height: clamp(64px, 11svh, 90px);
  }
}
