:root {
  --bg-1: #0b0f1e;
  --bg-2: #141b2e;
  --accent: #ffd24d;
  --accent-2: #4da6ff;
  --green: #4dff88;
  --red: #ff4d4d;
  --text: #eef1fb;
  --muted: #8d94b5;
  --card-bg: rgba(20, 27, 46, 0.92);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Segoe UI', 'Trebuchet MS', system-ui, sans-serif;
  background: radial-gradient(circle at 50% 0%, #1b2442 0%, var(--bg-1) 60%);
  color: var(--text);
  overflow-x: hidden;
}

#app { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; animation: fadeIn 0.25s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* HOME */
.home-wrap { text-align: center; max-width: 520px; }
.all-games-link { position: fixed; top: 16px; left: 16px; z-index: 5; color: var(--muted); text-decoration: none; font-weight: 600; padding: 8px; }
.all-games-link:hover { color: var(--text); }
.logo { font-size: 3rem; margin: 0 0 4px; letter-spacing: 1px; text-shadow: 0 0 24px rgba(255, 210, 77, 0.4); }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin-bottom: 36px; font-size: 1.05rem; }
.home-menu { display: flex; flex-direction: column; gap: 14px; }
.home-footer { margin-top: 28px; color: var(--muted); font-size: 0.85rem; }

/* BUTTONS */
.btn {
  border: none; border-radius: 10px; padding: 12px 20px; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: transform 0.12s ease, box-shadow 0.12s ease; color: var(--text);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-lg { padding: 16px 24px; font-size: 1.1rem; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #ff9d4d); color: #1a1200; box-shadow: 0 6px 18px rgba(255, 180, 60, 0.3); }
.btn-secondary { background: #212a46; border: 1px solid #39456c; }
.btn-back { align-self: flex-start; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.95rem; margin-bottom: 8px; }
.btn-back:hover { color: var(--text); }
.btn-copy { background: #212a46; border: 1px solid #39456c; color: var(--text); border-radius: 8px; padding: 4px 10px; font-size: 0.8rem; cursor: pointer; margin-left: 10px; }

/* PANEL CARD */
.panel-card {
  background: var(--card-bg); border: 1px solid #28335a; border-radius: var(--radius);
  padding: 28px; width: 100%; max-width: 540px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.panel-card h2 { margin: 0 0 6px; }
.panel-card label { font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.panel-card input, .panel-card select {
  background: #0f1527; border: 1px solid #2b3658; color: var(--text); border-radius: 8px;
  padding: 10px 12px; font-size: 1rem; margin-top: 4px;
}
.name-field { display: flex; flex-direction: column; margin-bottom: 8px; }

.mp-options { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.mp-option { flex: 1 1 200px; display: flex; flex-direction: column; background: #0f1527; border-radius: 10px; padding: 14px; border: 1px solid #22304f; }
.mp-option h3 { margin: 0 0 6px; font-size: 1rem; }
.mp-option button { margin-top: 12px; }
.mp-divider { align-self: center; color: var(--muted); font-weight: 700; }
.error-text { color: var(--red); font-size: 0.9rem; min-height: 1.2em; }

/* LOBBY */
.lobby-settings { display: flex; gap: 16px; color: var(--muted); font-size: 0.9rem; }
.lobby-players { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.lobby-player { display: flex; align-items: center; gap: 10px; background: #0f1527; border-radius: 8px; padding: 10px 12px; border: 1px solid #22304f; }
.lobby-player .dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.lobby-player .name { flex: 1; font-weight: 600; }
.lobby-player .tag { font-size: 0.75rem; color: var(--muted); }
.lobby-player .ready-badge { font-size: 0.8rem; padding: 2px 8px; border-radius: 6px; background: #223; color: var(--muted); }
.lobby-player .ready-badge.ready { background: rgba(77,255,136,0.18); color: var(--green); }
.lobby-actions { display: flex; gap: 10px; }
.lobby-hint { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

/* RACE SCREEN */
.race-wrap { width: 100%; max-width: 960px; display: flex; flex-direction: column; gap: 10px; }
.race-hud {
  display: flex; justify-content: space-between; background: var(--card-bg); border: 1px solid #28335a;
  border-radius: 10px; padding: 10px 16px; flex-wrap: wrap; gap: 8px;
}
.hud-item { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.hud-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.hud-value { font-size: 1.2rem; font-weight: 700; color: var(--accent); }

#track-canvas {
  width: 100%; max-width: 900px; height: auto; aspect-ratio: 900 / 420; align-self: center;
  background: #1a6b3a; border-radius: 16px; border: 4px solid #0f3f21;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.countdown-overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: 8rem; font-weight: 900; color: var(--accent); text-shadow: 0 0 40px rgba(255,210,77,0.6);
  background: rgba(5,8,18,0.55); z-index: 50; pointer-events: none;
}
.countdown-overlay.show { display: flex; }

.standings { display: flex; flex-wrap: wrap; gap: 8px; }
.standing-chip {
  display: flex; align-items: center; gap: 6px; background: var(--card-bg); border: 1px solid #28335a;
  border-radius: 20px; padding: 4px 12px; font-size: 0.85rem;
}
.standing-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.standing-chip .rank { font-weight: 700; color: var(--accent); }
.standing-chip.me { outline: 2px solid var(--accent); }

.typing-panel { background: var(--card-bg); border: 1px solid #28335a; border-radius: 12px; padding: 16px; }
.typing-text { font-size: 1.3rem; line-height: 1.7; font-family: 'Consolas', 'Courier New', monospace; letter-spacing: 0.5px; margin-bottom: 12px; user-select: none; }
.typing-text .correct { color: var(--green); }
.typing-text .incorrect { color: var(--red); background: rgba(255,77,77,0.18); border-radius: 2px; }
.typing-text .current { border-bottom: 2px solid var(--accent); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { border-color: transparent; } }
.typing-text .pending { color: var(--muted); }
#typing-input {
  width: 100%; padding: 14px; font-size: 1.15rem; border-radius: 8px; border: 1px solid #2b3658;
  background: #0f1527; color: var(--text); font-family: 'Consolas', 'Courier New', monospace;
}
#typing-input:disabled { opacity: 0.5; }
#typing-input:focus { outline: 2px solid var(--accent-2); }

/* RESULTS */
.results-card { max-width: 600px; }
.results-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.result-row { display: flex; align-items: center; gap: 10px; background: #0f1527; border-radius: 8px; padding: 10px 14px; border: 1px solid #22304f; }
.result-row .rank-badge { font-weight: 900; font-size: 1.1rem; width: 32px; text-align: center; }
.result-row.rank-1 .rank-badge { color: #ffd24d; }
.result-row.rank-2 .rank-badge { color: #cfd6ea; }
.result-row.rank-3 .rank-badge { color: #d9924a; }
.result-row .dot { width: 12px; height: 12px; border-radius: 50%; }
.result-row .name { flex: 1; font-weight: 600; }
.result-row .stat { color: var(--muted); font-size: 0.85rem; min-width: 70px; text-align: right; }
.results-stats { color: var(--muted); font-size: 0.9rem; margin-top: 6px; }
.results-actions { display: flex; gap: 10px; margin-top: 14px; }

@media (max-width: 640px) {
  .logo { font-size: 2.2rem; }
  .race-hud { justify-content: space-around; }
  .typing-text { font-size: 1.05rem; }
  .countdown-overlay { font-size: 5rem; }
}
