:root {
  --bg: #070b16;
  --surface: #11182c;
  --surface-alt: #18233f;
  --border: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --cyan: #22d3ee;
  --gold: #fbbf24;
  --lime: #a3e635;
  --coral: #fb7185;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top center, #131c38 0%, var(--bg) 70%);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-bar {
  background: rgba(17, 24, 44, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  backdrop-filter: blur(8px);
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.direction-pill {
  background: rgba(34, 211, 238, 0.14);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: #cffafe;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.draft-pill {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  transition: all 120ms ease;
}

.draft-pill.active {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.28), rgba(163, 230, 53, 0.28));
  border-color: var(--cyan);
  color: #ecfeff;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.45);
}

.hud-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.metric-chip {
  background: var(--surface-alt);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 8px;
  padding: 4px 9px;
  display: flex;
  flex-direction: column;
  min-width: 72px;
}

.metric-chip-wide {
  min-width: 145px;
}

.metric-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 700;
}

.metric-value {
  font-size: 0.88rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hud-stamina-wrap {
  min-width: 142px;
  flex: 1 1 140px;
  max-width: 210px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stamina-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stamina-state {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--lime);
}

.stamina-track {
  height: 10px;
  background: #0b1120;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, #22d3ee 0%, #a3e635 100%);
  transition: width 80ms linear;
}

.stamina-fill.boosting {
  background: linear-gradient(90deg, #fbbf24 0%, #fb7185 100%);
}

.stamina-fill.low {
  background: linear-gradient(90deg, #ef4444 0%, #f97316 100%);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 90ms ease;
}

.hud-btn:hover {
  border-color: var(--cyan);
  background: #203056;
}

.hud-btn:active {
  transform: translateY(1px);
}

.hud-btn[aria-pressed="true"] {
  border-color: var(--coral);
  color: #fecdd3;
}

.minimap-panel {
  background: rgba(17, 24, 44, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.minimap-anchor {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.minimap-west {
  text-align: left;
}

.minimap-east {
  text-align: right;
}

.city-code {
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--gold);
}

.city-name {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.minimap-track-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.minimap-segments {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.minimap-seg {
  font-size: 0.64rem;
  font-weight: 700;
  text-align: center;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.14);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.minimap-seg.active {
  color: #0b1020;
  background: var(--gold);
  border-color: #fde68a;
}

.minimap-seg.done {
  color: #cffafe;
  background: rgba(34, 211, 238, 0.22);
  border-color: rgba(34, 211, 238, 0.45);
}

.minimap-rail {
  position: relative;
  height: 10px;
  background: #0a0f1f;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.22);
}

.minimap-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22d3ee, #fbbf24);
}

.minimap-markers {
  position: absolute;
  inset: 0;
}

.map-pin {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid #070b16;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
  transition: left 60ms linear;
}

.map-pin.player {
  width: 16px;
  height: 16px;
  z-index: 3;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.85);
}

.map-pin.rival {
  z-index: 2;
  opacity: 0.92;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  min-height: 360px;
  background: #080c19;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 11, 22, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
  z-index: 10;
}

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

.modal-card {
  width: 100%;
  max-width: 780px;
  margin: auto;
  background: rgba(17, 24, 44, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
}

.menu-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.menu-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.direction-toggle {
  display: inline-flex;
  background: #0b1120;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.dir-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 140ms ease;
}

.dir-btn.active {
  background: var(--cyan);
  color: #070b16;
}

.section-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.leg-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.leg-pill {
  background: var(--surface-alt);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 8px;
  padding: 6px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: #e2e8f0;
}

.leg-pill-num {
  display: block;
  font-size: 0.62rem;
  color: var(--gold);
  margin-bottom: 2px;
}

.athlete-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.athlete-card {
  background: var(--surface-alt);
  border: 2px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 140ms ease, transform 110ms ease, background 140ms ease;
}

.athlete-card:hover {
  border-color: rgba(34, 211, 238, 0.6);
  transform: translateY(-1px);
}

.athlete-card.selected {
  border-color: var(--gold);
  background: rgba(30, 41, 59, 0.96);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.4);
}

.athlete-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.athlete-name {
  font-size: 0.95rem;
  font-weight: 800;
}

.athlete-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.athlete-trait {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--cyan);
}

.stat-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.stat-bar-bg {
  height: 6px;
  background: #0b1120;
  border-radius: 999px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.menu-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.controls-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 90ms ease, filter 120ms ease;
}

.primary-btn {
  background: linear-gradient(90deg, #fbbf24 0%, #f97316 100%);
  color: #070b16;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.secondary-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary-btn:hover {
  border-color: var(--cyan);
}

.finish-header {
  text-align: center;
}

.finish-rank-badge {
  display: inline-block;
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.08em;
}

.finish-banner {
  margin: 6px auto 2px;
  display: inline-block;
  padding: 4px 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #b91c1c, #ea580c);
  color: #fff7ed;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.35);
}

.finish-header h2 {
  margin: 6px 0 2px;
  font-size: 1.35rem;
}

.finish-subline {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.finish-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-box {
  background: var(--surface-alt);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
}

.stat-box-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.stat-box-value {
  font-size: 1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.finish-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.finish-panel {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  padding: 9px 12px;
}

.podium-list,
.splits-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.76rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.finish-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.controls-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.ctrl-btn {
  background: rgba(17, 24, 44, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: border-color 120ms ease, transform 70ms ease, background 120ms ease;
}

.ctrl-btn:hover {
  border-color: var(--cyan);
}

.ctrl-btn:active {
  transform: scale(0.97);
  background: #1d2a4c;
}

.ctrl-btn-accent {
  border-color: rgba(34, 211, 238, 0.45);
}

.ctrl-btn-surge {
  border-color: rgba(251, 191, 36, 0.45);
}

.ctrl-key {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ctrl-name {
  font-size: 0.9rem;
  font-weight: 800;
}

@media (max-width: 780px) {
  .app-shell {
    padding: 8px 10px 12px;
  }

  .leg-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .athlete-grid {
    grid-template-columns: 1fr;
  }

  .finish-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .finish-details-grid {
    grid-template-columns: 1fr;
  }

  .minimap-segments {
    grid-template-columns: repeat(3, 1fr);
  }

  .stage-wrap {
    aspect-ratio: 16 / 10;
    min-height: 280px;
  }
}
