:root {
  --racing-bg: #0a0a14;
  --racing-surface: #0f0f1e;
  --racing-accent: #ff6b35;
  --racing-accent2: #ffd700;
  --racing-danger: #ff3333;
  --racing-text: #f0e8ff;
  --racing-muted: #9a8faa;
  --racing-border: rgba(255, 107, 53, 0.35);
  --racing-boost-color: #00cfff;
  --hud-h: 0px;
}

html,
body {
  background: var(--racing-bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  min-height: 100dvh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ─── Overlay base ───────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
}

.overlay-card {
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
}

.overlay-card.racing-panel {
  background: linear-gradient(180deg, rgba(15, 15, 30, 0.97), rgba(15, 15, 30, 0.90));
  border: 2px solid var(--racing-border);
  box-shadow: 0 0 40px rgba(255, 107, 53, 0.18);
}

.overlay-card.racing-panel h1 {
  color: var(--racing-accent);
  letter-spacing: 0.06em;
  margin-bottom: 18px;
}

/* ─── Logo ───────────────────────────────────────────────────── */
.racing-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.racing-logo-car {
  position: relative;
  display: inline-block;
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 0 18px rgba(255, 107, 53, 0.55));
}

.racing-logo-car::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 22px;
  width: 56px;
  height: 32px;
  background: linear-gradient(180deg, #ff8c55 0%, #ff6b35 100%);
  border-radius: 6px 6px 4px 4px;
}

.racing-logo-car::after {
  content: "";
  position: absolute;
  left: 22px;
  top: 14px;
  width: 36px;
  height: 24px;
  background: rgba(255, 215, 0, 0.25);
  border: 2px solid rgba(255, 215, 0, 0.65);
  border-radius: 4px 4px 2px 2px;
}

/* ─── Spinner ────────────────────────────────────────────────── */
.spinner {
  border-top-color: var(--racing-accent);
}

/* ─── Lobby panel ────────────────────────────────────────────── */
.racing-lobby-panel {
  width: min(92vw, 520px);
  max-height: 90dvh;
  overflow-y: auto;
}

.racing-score-panel {
  width: min(96vw, 740px);
  max-height: 90dvh;
  overflow-y: auto;
}

/* ─── Name input ─────────────────────────────────────────────── */
.name-input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 2px solid var(--racing-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--racing-text);
  font: inherit;
}

.name-input:focus,
.settings-select:focus,
.racing-chat-input:focus {
  outline: none;
  border-color: var(--racing-accent);
}

/* ─── Car selector ──────────────────────────────────────────── */
.car-select-label {
  margin-bottom: 8px !important;
}

.car-selector {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.car-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border: 2px solid rgba(255, 107, 53, 0.2);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}

.car-option:hover {
  border-color: rgba(255, 107, 53, 0.5);
  background: rgba(255, 107, 53, 0.08);
}

.car-option.selected {
  border-color: var(--racing-accent);
  background: rgba(255, 107, 53, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 0 12px rgba(255, 107, 53, 0.3);
}

.car-option img {
  width: 32px;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 4px rgba(255, 107, 53, 0.4));
}

.car-option span {
  font-size: 0.68rem;
  color: var(--racing-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.car-option.selected span {
  color: var(--racing-accent);
}

/* Player car icon in lobby list */
.player-car-icon {
  width: 18px;
  height: auto;
  flex-shrink: 0;
  image-rendering: pixelated;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  padding: 12px 28px;
  background: var(--racing-accent);
  color: #0a0506;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 10px;
}

.btn-primary:hover {
  background: #ff8c55;
  transform: translateY(-1px);
}

.btn-secondary {
  display: inline-block;
  padding: 10px 22px;
  background: transparent;
  color: var(--racing-text);
  border: 2px solid var(--racing-border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  margin-top: 10px;
}

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

/* ─── Player list ────────────────────────────────────────────── */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.player-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 107, 53, 0.2);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
}

.player-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
  flex-shrink: 0;
}

.player-name {
  flex: 1;
  text-align: left;
  color: var(--racing-text);
}

.host-badge {
  color: var(--racing-accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* ─── Settings ───────────────────────────────────────────────── */
.lobby-settings {
  margin-bottom: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 107, 53, 0.1);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-label {
  color: var(--racing-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.settings-select {
  min-width: 120px;
  padding: 8px 12px;
  border: 2px solid var(--racing-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--racing-text);
  font: inherit;
}

/* ─── Chat area ──────────────────────────────────────────────── */
.racing-chat-area {
  margin-top: 16px;
  border: 1px solid rgba(255, 107, 53, 0.18);
  border-radius: 10px;
  overflow: hidden;
}

.racing-chat-messages {
  height: 90px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.4);
  text-align: left;
  font-size: 0.82rem;
  color: var(--racing-muted);
}

.racing-chat-input-row {
  display: flex;
  border-top: 1px solid rgba(255, 107, 53, 0.15);
}

.racing-chat-input {
  flex: 1;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: var(--racing-text);
  font: inherit;
  font-size: 0.85rem;
}

/* ─── Back link ──────────────────────────────────────────────── */
.racing-back-link {
  display: block;
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--racing-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.racing-back-link:hover {
  color: var(--racing-accent);
}

/* ─── Waiting text ───────────────────────────────────────────── */
.waiting-text {
  margin-top: 12px;
  color: var(--racing-muted);
  font-size: 0.9rem;
}

/* ─── Game area ──────────────────────────────────────────────── */
#gameArea {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #1a1a0a;
}

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

/* ─── Minimap ────────────────────────────────────────────────── */
#minimapCanvas {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 200px;
  height: 150px;
  border: 2px solid rgba(255, 107, 53, 0.45);
  border-radius: 8px;
  background: rgba(10, 10, 20, 0.78);
  z-index: 20;
}

/* ─── HUD ────────────────────────────────────────────────────── */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

#position {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 52px;
  font-weight: 900;
  color: var(--racing-text);
  text-shadow:
    0 0 16px rgba(255, 107, 53, 0.7),
    0 2px 4px rgba(0, 0, 0, 0.9);
  letter-spacing: 0.02em;
}

#lapCounter {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 22px;
  font-weight: 700;
  color: var(--racing-text);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  background: rgba(10, 10, 20, 0.65);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 107, 53, 0.28);
}

#lapTimes {
  position: absolute;
  top: 20px;
  right: 20px;
  font-size: 16px;
  text-align: right;
  color: var(--racing-text);
  background: rgba(10, 10, 20, 0.65);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 107, 53, 0.28);
  line-height: 1.6;
}

#currentLapTime {
  font-size: 18px;
  font-weight: 700;
  color: var(--racing-accent2);
}

#bestLapTime {
  font-size: 13px;
  color: var(--racing-muted);
}

#speedIndicator {
  position: absolute;
  bottom: 20px;
  right: 240px;
  font-size: 18px;
  font-weight: 700;
  color: var(--racing-text);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  background: rgba(10, 10, 20, 0.65);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 107, 53, 0.28);
}

/* ─── Boost indicator ────────────────────────────────────────── */
.racing-boost-indicator {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  font-weight: 900;
  color: var(--racing-boost-color);
  text-shadow:
    0 0 20px rgba(0, 207, 255, 0.9),
    0 0 40px rgba(0, 207, 255, 0.5);
  letter-spacing: 0.12em;
  animation: boostPulse 0.4s ease-in-out infinite alternate;
}

@keyframes boostPulse {
  from { opacity: 0.85; transform: translateX(-50%) scale(1); }
  to   { opacity: 1;    transform: translateX(-50%) scale(1.07); }
}

/* ─── Countdown overlay ──────────────────────────────────────── */
.racing-countdown {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(100px, 18vw, 180px);
  font-weight: 900;
  color: var(--racing-accent2);
  text-shadow:
    0 0 24px rgba(255, 215, 0, 0.85),
    0 0 48px rgba(255, 215, 0, 0.45);
  z-index: 200;
  animation: racingCountdownPulse 0.9s ease-in-out infinite;
  pointer-events: none;
}

@keyframes racingCountdownPulse {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  50%       { opacity: 0.8; transform: translate(-50%, -50%) scale(1.1); }
}

/* ─── Spectator bar ──────────────────────────────────────────── */
.racing-spectator-bar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: rgba(10, 10, 20, 0.82);
  border: 1px solid rgba(255, 107, 53, 0.3);
  border-top: none;
  border-radius: 0 0 12px 12px;
  color: var(--racing-text);
  font-size: 0.9rem;
  pointer-events: auto;
}

.racing-spectator-label {
  font-weight: 700;
  color: var(--racing-accent);
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

.racing-spectator-btn {
  padding: 4px 10px;
  background: rgba(255, 107, 53, 0.2);
  border: 1px solid rgba(255, 107, 53, 0.4);
  border-radius: 6px;
  color: var(--racing-text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.racing-spectator-btn:hover {
  background: rgba(255, 107, 53, 0.38);
}

.racing-spectator-target {
  min-width: 80px;
  text-align: center;
  font-weight: 600;
  color: var(--racing-accent2);
}

/* ─── Results screen ─────────────────────────────────────────── */
.racing-table-wrap {
  width: 100%;
  max-width: 100%;
  max-height: min(44dvh, 340px);
  overflow: auto;
  border: 1px solid rgba(255, 107, 53, 0.2);
  border-radius: 10px;
  margin-bottom: 16px;
}

.rankings-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
}

.rankings-table th,
.rankings-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 107, 53, 0.14);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--racing-text);
  font-size: 0.9rem;
}

.rankings-table th {
  color: var(--racing-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: rgba(0, 0, 0, 0.3);
}

.rankings-table tbody tr:nth-child(odd) {
  background: rgba(255, 107, 53, 0.04);
}

.rankings-table tbody tr:first-child td {
  color: var(--racing-accent2);
  font-weight: 700;
}

/* ─── Awards list ────────────────────────────────────────────── */
.racing-awards-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.racing-award-item {
  padding: 10px 14px;
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.22);
  border-radius: 10px;
  text-align: left;
}

.racing-award-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--racing-accent);
  margin-bottom: 4px;
}

.racing-award-name {
  font-weight: 700;
  color: var(--racing-text);
}

/* ─── Rankings empty ─────────────────────────────────────────── */
.rankings-empty {
  padding: 24px;
  text-align: center;
}

.rankings-empty h2 {
  color: var(--racing-muted);
  margin-bottom: 8px;
}

.rankings-empty p {
  color: var(--racing-muted);
  font-size: 0.9rem;
}

/* ─── Audio controls ─────────────────────────────────────────── */
.audio-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 160;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.audio-controls button {
  padding: 6px 10px;
  background: rgba(10, 10, 20, 0.88);
  border: 1px solid rgba(255, 107, 53, 0.3);
  border-radius: 8px;
  color: var(--racing-text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.audio-controls button:hover {
  border-color: var(--racing-accent);
}

.volume-slider {
  width: 72px;
  height: 18px;
  accent-color: var(--racing-accent);
  cursor: pointer;
}

/* ─── Mobile controls ────────────────────────────────────────── */
.racing-mobile-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  height: 150px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  pointer-events: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.racing-steer-zone {
  flex: 0 0 25%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 20, 0.75);
  border-top: 2px solid rgba(255, 107, 53, 0.3);
  color: var(--racing-text);
  font-size: 2rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: pointer;
  transition: background 0.1s;
}

.racing-steer-zone:active,
.racing-steer-zone.pressed {
  background: rgba(255, 107, 53, 0.28);
}

.racing-throttle-brake {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.racing-mobile-btn {
  flex: 1;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.1s;
}

.racing-mobile-btn:active {
  opacity: 0.8;
}

.racing-throttle-btn {
  background: rgba(0, 180, 80, 0.75);
  color: #fff;
  border-top: 2px solid rgba(0, 220, 100, 0.4);
}

.racing-brake-btn {
  background: rgba(220, 40, 40, 0.72);
  color: #fff;
  border-top: 2px solid rgba(255, 70, 70, 0.35);
}

/* Show mobile controls only on touch devices */
@media (pointer: coarse) {
  .racing-mobile-controls {
    display: flex;
  }

  .audio-controls {
    top: auto;
    right: 12px;
    bottom: calc(158px + env(safe-area-inset-bottom));
    max-width: min(300px, calc(100vw - 24px));
  }
}

/* ─── Drift indicator class (applied by JS) ──────────────────── */
.drift-indicator {
  box-shadow:
    inset 0 0 0 3px rgba(255, 215, 0, 0.55),
    0 0 18px rgba(255, 215, 0, 0.3);
}

/* ─── Sub text ───────────────────────────────────────────────── */
.sub {
  color: var(--racing-muted);
  font-size: 0.95rem;
  margin-bottom: 18px;
}

/* ─── host-only / non-host-only visibility ───────────────────── */
.host-only {
  display: none;
}

.host-only.visible,
.host-only.show {
  display: block;
}

.non-host-only {
  display: block;
}

.non-host-only.hidden-for-host {
  display: none;
}

/* ─── Responsive adjustments ─────────────────────────────────── */
@media (max-width: 640px) {
  .racing-score-panel,
  .racing-lobby-panel {
    padding: 20px 14px;
  }

  .rankings-table {
    min-width: 380px;
  }

  #minimapCanvas {
    width: 140px;
    height: 105px;
  }

  #position {
    font-size: 36px;
  }

  #lapCounter {
    font-size: 16px;
  }
}

@media (max-height: 700px) {
  .racing-lobby-panel {
    padding: 16px 14px;
  }

  .racing-logo {
    display: none;
  }
}
