* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #10131a;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: #fff;
  user-select: none;
}

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

#stage {
  position: relative;
  line-height: 0;
}

#game {
  display: block;
  width: min(100vw, 160vh);
  height: min(100vh, 62.5vw);
  background: #2c2c34;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  line-height: 1.3;
}

.hud-top-left,
.hud-top-right,
.hud-bottom-right {
  position: absolute;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  backdrop-filter: blur(2px);
}

.hud-top-left {
  top: 12px;
  left: 12px;
  min-width: 130px;
}

.hud-top-right {
  top: 12px;
  right: 12px;
  text-align: right;
}

.hud-bottom-right {
  bottom: 12px;
  right: 12px;
  text-align: right;
  min-width: 120px;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: #9aa3b5;
  margin-top: 6px;
}

.hud-label:first-child {
  margin-top: 0;
}

.hud-value {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 18px;
  font-weight: 600;
}

#minimap {
  margin-top: 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

#speed {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
}

.kmh {
  font-size: 12px;
  letter-spacing: 2px;
  color: #9aa3b5;
}

#speedTrack {
  margin-top: 6px;
  width: 130px;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  margin-left: auto;
}

#speedBar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, #37c871, #ffd23e 70%, #ff5040);
  transition: width 0.08s linear;
}

/* ---------- countdown ---------- */

#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 800;
  font-family: "Consolas", "Menlo", monospace;
  color: #ffd23e;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(0.96); opacity: 0.85; }
  to   { transform: scale(1.06); opacity: 1; }
}

/* ---------- overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.66);
  line-height: 1.4;
}

.panel {
  background: rgba(16, 19, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 34px 46px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  max-width: 90%;
}

.panel h1 {
  font-size: 34px;
  letter-spacing: 4px;
  margin-bottom: 6px;
}

.subtitle {
  color: #9aa3b5;
  font-size: 14px;
  margin-bottom: 18px;
}

.controls {
  display: inline-block;
  text-align: left;
  font-size: 14px;
  color: #cfd6e4;
  margin-bottom: 14px;
}

.controls div {
  margin: 5px 0;
}

.key {
  display: inline-block;
  min-width: 26px;
  padding: 1px 7px;
  margin-right: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12px;
  text-align: center;
}

.hint {
  color: #7f8798;
  font-size: 12px;
  margin-top: 12px;
}

button {
  margin-top: 18px;
  padding: 12px 34px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #10131a;
  background: #ffd23e;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease;
}

button:hover {
  background: #ffe070;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

/* ---------- results ---------- */

.record {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #ffd23e;
  min-height: 28px;
  animation: pulse 0.6s ease-in-out infinite alternate;
}

.res-grid {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin: 16px 0 6px;
}

.res-cell {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 22px;
  min-width: 150px;
}

.res-value {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 26px;
  font-weight: 700;
}

.res-laps {
  margin: 10px 0 4px;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 14px;
  color: #cfd6e4;
}

.lap-row {
  margin: 3px 0;
}

/* ---------- multiplayer ---------- */

.button-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.button-row button {
  margin-top: 18px;
}

.btn-secondary {
  background: #3a4152;
  color: #fff;
}

.btn-secondary:hover {
  background: #46506a;
}

.multi-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 8px;
}

.multi-form label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: #cfd6e4;
}

.multi-form input {
  width: 240px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13px;
}

.player-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 12px 0;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
}

.player-slot.empty {
  color: #7f8798;
}

.player-slot.me {
  border-color: rgba(255, 210, 62, 0.55);
}

.player-slot.host::after {
  content: "HOST";
  margin-left: auto;
  font-size: 10px;
  letter-spacing: 1px;
  color: #ffd23e;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.hud-standings {
  position: absolute;
  left: 12px;
  bottom: 12px;
  min-width: 150px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
}

.standings-row.me {
  color: #ffd23e;
  font-weight: 700;
}

.lap-row.me {
  color: #ffd23e;
  font-weight: 700;
}

.hidden {
  display: none !important;
}
