:root {
  --turquoise: #2FD9C4;
  --sea-blue: #0e3b4d;
  --sun-yellow: #FFD93D;
  --coral: #FF6B5B;
  --sand: #F3E9D2;
  --dark-blue: #123145;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--sea-blue), var(--dark-blue));
  color: var(--sand);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.screen { min-height: 100vh; padding: 22px 18px; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* START */
#screen-start { align-items: stretch; justify-content: center; gap: 14px; max-width: 420px; margin: 0 auto; }
#screen-start h1, #screen-results h1 { font-size: 26px; letter-spacing: 1px; text-align: center; margin: 0; color: var(--turquoise); }
.subtitle { text-align: center; margin: 0 0 16px; opacity: 0.8; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field input {
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  font-size: 18px;
  background: rgba(255,255,255,0.92);
  color: var(--dark-blue);
}

.btn {
  padding: 16px;
  border: none;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--coral); color: white; }
.btn-secondary { background: var(--turquoise); color: var(--dark-blue); }
.btn-ghost { background: rgba(255,255,255,0.08); color: var(--sand); font-size: 14px; padding: 12px; }
.btn:disabled { opacity: 0.4; }

.divider { text-align: center; opacity: 0.6; margin: 4px 0; }
.error { color: var(--coral); min-height: 20px; text-align: center; }
.hint { text-align: center; opacity: 0.75; font-size: 13px; min-height: 18px; }

/* LOBBY */
#screen-lobby { gap: 14px; max-width: 480px; margin: 0 auto; width: 100%; }
.lobby-header { display: flex; align-items: center; justify-content: space-between; }
.room-code { font-size: 26px; font-weight: 700; letter-spacing: 3px; color: var(--turquoise); }

.vehicle-picker { display: flex; gap: 10px; }
.vehicle-card {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 12px;
  color: var(--sand);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.vehicle-card.selected { border-color: var(--turquoise); background: rgba(47,217,196,0.15); }
.vehicle-svg { width: 100%; max-width: 130px; color: var(--turquoise); }
.vehicle-card span { font-weight: 600; font-size: 13px; text-align: center; }
.vehicle-card small { opacity: 0.7; font-size: 11px; text-align: center; }

.roster-list { display: flex; flex-direction: column; gap: 8px; max-height: 32vh; overflow-y: auto; }
.roster-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
}
.roster-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.roster-name { flex: 1; }
.roster-tag { font-size: 11px; opacity: 0.7; }
.roster-ready { font-size: 16px; }
.roster-remove {
  background: none; border: none; color: var(--coral);
  font-size: 16px; padding: 2px 6px; cursor: pointer; opacity: 0.8;
}
.roster-row.offline { opacity: 0.4; }

/* RENNEN */
#screen-race { padding: 10px; gap: 8px; position: relative; }
.hud { display: flex; align-items: flex-start; justify-content: space-between; font-weight: 600; }

.hud-panel {
  background: rgba(11, 37, 49, 0.55);
  backdrop-filter: blur(3px);
  border-radius: 14px;
  padding: 8px 12px;
}
.hud-top-left { font-size: 16px; }
.hud-timer { font-size: 12px; font-weight: 400; opacity: 0.8; }
.hud-sep { opacity: 0.5; margin: 0 3px; }

.hud-standings {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  max-height: 160px;
  overflow-y: auto;
}
.standing-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  opacity: 0.85;
  white-space: nowrap;
}
.standing-row.self { font-weight: 700; opacity: 1; }
.standing-rank { width: 14px; text-align: right; opacity: 0.75; }
.standing-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.standing-name { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
.standing-status { font-size: 10px; opacity: 0.8; }

.hud-top-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.minimap {
  width: 90px; height: 90px;
  border-radius: 12px;
  background: rgba(11, 37, 49, 0.55);
  backdrop-filter: blur(3px);
}
.hud-status-panel {
  display: flex; align-items: center; gap: 5px;
  font-weight: 400; font-size: 12px; padding: 6px 8px;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-good { background: #2ECC71; }
.status-weak { background: var(--sun-yellow); }
.status-bad { background: var(--coral); }
.btn-icon { background: none; border: none; color: var(--sand); font-size: 16px; cursor: pointer; opacity: 0.7; padding: 0 0 0 4px; }

/* min-height/min-width: 0 sind hier Pflicht, nicht kosmetisch: Ein <canvas>
   hat als "replaced element" eine intrinsische Größe (seine width/height
   Attribute), die Flexbox sonst als Schrumpf-Untergrenze behandelt - ohne
   das kann der Canvas beim Verkleinern des Fensters nicht mitschrumpfen und
   sprengt den Container. */
#arena { width: 100%; flex: 1; min-height: 0; min-width: 0; border-radius: 16px; background: #8fd3f4; display: block; touch-action: none; }

.name-labels { position: absolute; inset: 0; pointer-events: none; }
.name-label {
  position: absolute;
  transform: translate(-50%, -100%);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  white-space: nowrap;
}

.fps-counter {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  opacity: 0.55;
  pointer-events: none;
}

.countdown-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#countdownNumber {
  font-size: 90px; font-weight: 800; color: var(--sun-yellow);
  text-shadow: 0 4px 18px rgba(0,0,0,0.5);
}

.controls { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.ctrl-row { display: flex; gap: 18px; }
.ctrl {
  width: 72px; height: 72px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: var(--sand);
  font-size: 28px;
}
.ctrl:active { background: var(--turquoise); color: var(--dark-blue); }
.ctrl-turbo { width: 60px; height: 60px; font-size: 26px; border-radius: 50%; background: rgba(255,107,91,0.35); }

.controls-right { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hud-speed { font-size: 12px; font-weight: 600; padding: 5px 10px; white-space: nowrap; }

.debug-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(10, 30, 40, 0.97);
  padding: 16px 20px 24px;
  border-radius: 20px 20px 0 0;
  font-size: 13px;
  z-index: 10;
}
.debug-panel h3 { margin: 0 0 10px; font-size: 15px; }
.debug-panel label { display: block; margin-bottom: 10px; }
.debug-stats { display: flex; gap: 16px; margin-top: 10px; opacity: 0.8; }

/* ERGEBNIS */
#screen-results { max-width: 480px; margin: 0 auto; gap: 14px; width: 100%; }
.results-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.results-table th { text-align: left; opacity: 0.6; font-weight: 500; font-size: 12px; padding: 6px 8px; }
.results-table td { padding: 10px 8px; background: rgba(255,255,255,0.05); }
.results-table tr:first-child td { background: rgba(255,217,61,0.18); font-weight: 700; }
.results-table td:first-child { border-radius: 10px 0 0 10px; }
.results-table td:last-child { border-radius: 0 10px 10px 0; }

@media (orientation: landscape) {
  #screen-race { flex-direction: row; flex-wrap: wrap; }
  #arena { order: 1; flex-basis: 100%; }
}
