/* Turbo Type — dark neon racing theme */

:root {
  --bg: #070b1c;
  --bg2: #0d1330;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e2e8f0;
  --dim: rgba(226, 232, 240, 0.55);
  --cyan: #22d3ee;
  --magenta: #e879f9;
  --lime: #a3e635;
  --red: #f43f5e;
  --gold: #facc15;
  --mono: "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(34, 211, 238, 0.08), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(232, 121, 249, 0.07), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

#app { max-width: 1060px; margin: 0 auto; padding: 22px 24px 48px; }

.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 0.8rem; }

.screen { animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- logo & header ---------- */

.logo {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  font-style: italic;
  color: var(--text);
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.55);
}
.logo span { color: var(--cyan); }
.small-logo { font-size: 1.3rem; }

.garage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.head-right { display: flex; gap: 10px; align-items: center; }

.streak {
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(250, 204, 21, 0.1);
  border: 1px solid rgba(250, 204, 21, 0.3);
}

.icon-btn {
  font-size: 1.05rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  width: 40px; height: 40px;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(4px);
}
.panel-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim); margin-bottom: 12px; }

/* ---------- garage ---------- */

.garage-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  margin-bottom: 18px;
}
@media (max-width: 760px) { .garage-grid { grid-template-columns: 1fr; } }

.player-card { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#garage-car { filter: drop-shadow(0 6px 18px rgba(34, 211, 238, 0.25)); }

.league-badge {
  font-weight: 800;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid;
  letter-spacing: 0.04em;
}

.level-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.level-chip {
  background: rgba(34, 211, 238, 0.12);
  border: 1px solid rgba(34, 211, 238, 0.4);
  color: var(--cyan);
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
.xp-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#xp-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--lime));
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.7);
  transition: width 0.4s ease;
}
.xp-label { font-size: 0.75rem; color: var(--dim); }

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.swatch {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); }
.swatch.locked { opacity: 0.45; }

.mode-buttons { display: flex; flex-direction: column; gap: 12px; }

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px 18px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
  flex: 1;
}
.mode-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 6px 24px rgba(34, 211, 238, 0.15);
}
.mode-btn.primary {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.16), rgba(163, 230, 53, 0.1));
  border-color: rgba(34, 211, 238, 0.45);
}
.mode-btn.slim { flex-direction: row; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; }
.mode-icon { font-size: 1.5rem; }
.mode-name { font-weight: 800; font-size: 1.1rem; letter-spacing: 0.03em; }
.mode-desc { font-size: 0.8rem; color: var(--dim); }

.trophy-shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.trophy {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  opacity: 0.42;
  font-size: 0.8rem;
}
.trophy.earned {
  opacity: 1;
  border-color: rgba(250, 204, 21, 0.35);
  background: rgba(250, 204, 21, 0.07);
}
.t-icon { font-size: 1.1rem; width: 22px; text-align: center; }
.t-name { font-weight: 600; }

/* ---------- race screen ---------- */

.race-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 12px;
}
.race-title { font-weight: 700; font-size: 1.05rem; padding-top: 6px; }

#race-canvas {
  width: 100%;
  height: 340px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  display: block;
}

.hud {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 12px 0;
}
#speedo { flex-shrink: 0; }

.hud-mid { flex: 1; }
.combo-bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
#combo-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  transition: width 0.15s ease;
}
#combo-fill.nitro {
  background: linear-gradient(90deg, var(--gold), var(--red));
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.8);
  animation: nitropulse 0.5s infinite alternate;
}
@keyframes nitropulse { from { filter: brightness(1); } to { filter: brightness(1.5); } }
.combo-label { font-size: 0.8rem; color: var(--dim); margin-top: 4px; font-weight: 700; }

.hud-right { display: flex; gap: 16px; }
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.hud-stat-label { font-size: 0.65rem; letter-spacing: 0.12em; color: var(--dim); }
.hud-stat span:last-child { font-size: 1.25rem; font-weight: 800; }

/* ---------- passage ---------- */

.passage {
  font-family: var(--mono);
  font-size: 1.35rem;
  line-height: 2.1rem;
  letter-spacing: 0.02em;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px 22px;
  max-height: 11rem;
  overflow-y: auto;
  user-select: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.passage.tall { max-height: 13rem; }

.passage span { color: rgba(226, 232, 240, 0.45); border-radius: 3px; }
.passage span.done { color: var(--lime); }
.passage span.cur {
  background: rgba(34, 211, 238, 0.35);
  color: #fff;
  box-shadow: 0 2px 0 var(--cyan);
  animation: caretblink 1s steps(1) infinite;
}
@keyframes caretblink { 50% { background: rgba(34, 211, 238, 0.15); } }
.passage span.cur.err, .passage span.err {
  background: rgba(244, 63, 94, 0.55);
  box-shadow: 0 2px 0 var(--red);
}

.passage.shake { animation: shake 0.18s ease; }
@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.hint { margin-top: 8px; text-align: center; }

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

.countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7rem;
  font-weight: 900;
  font-style: italic;
  color: var(--cyan);
  text-shadow: 0 0 40px rgba(34, 211, 238, 0.9);
  pointer-events: none;
  z-index: 50;
}
.countdown.pop { animation: pop 0.7s ease; }
@keyframes pop {
  0% { transform: scale(1.7); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.92); opacity: 0.9; }
}

/* ---------- pit stop ---------- */

.pit-keys { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.key-chip {
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 0.78rem;
}
.key-chip b { color: var(--red); font-family: var(--mono); font-size: 0.9rem; }

.pit-hud { display: flex; align-items: center; gap: 14px; margin: 14px 0; }
.timer-bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
#pit-timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--lime), var(--gold));
}
.timer-label { font-weight: 800; font-family: var(--mono); min-width: 42px; }

/* ---------- stats ---------- */

#stats-summary { margin: 4px 0 16px; }

.chart { width: 100%; height: 240px; display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
  margin-top: 18px;
}
@media (max-width: 760px) { .stats-grid { grid-template-columns: 1fr; } }

.heatmap { display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 8px 0; }
.kb-row { display: flex; gap: 6px; }
.kb-row-1 { margin-left: 14px; }
.kb-row-2 { margin-left: 34px; }
.kb-key {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  cursor: default;
}
.kb-key.nodata { color: rgba(226, 232, 240, 0.3); }
.kb-errdot {
  position: absolute;
  top: 4px; right: 4px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.weak-list { display: flex; flex-direction: column; gap: 8px; }
.weak-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(244, 63, 94, 0.06);
  border: 1px solid rgba(244, 63, 94, 0.25);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
}
.weak-key {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--red);
  background: rgba(244, 63, 94, 0.15);
  border-radius: 8px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
}

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

#screen-results { display: flex; justify-content: center; padding-top: 5vh; }
.results-card {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 28px;
}
.res-title { font-size: 1.8rem; font-weight: 900; font-style: italic; letter-spacing: 0.04em; }

.res-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.res-badge {
  font-weight: 800;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}
.res-badge.pb { background: rgba(250, 204, 21, 0.15); border: 1px solid var(--gold); color: var(--gold); animation: nitropulse 0.6s infinite alternate; }
.res-badge.ghost { background: rgba(34, 211, 238, 0.12); border: 1px solid var(--cyan); color: var(--cyan); }
.res-badge.ghost-lost { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--panel-border); color: var(--dim); }
.res-badge.level { background: rgba(163, 230, 53, 0.12); border: 1px solid var(--lime); color: var(--lime); }

.res-grid { display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; }
.res-stat { display: flex; flex-direction: column; }
.res-num { font-size: 2rem; font-weight: 900; color: var(--cyan); }
.res-label { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }

.res-xp {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--lime);
  text-shadow: 0 0 12px rgba(163, 230, 53, 0.5);
}

.res-achlist { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--gold); }

.res-buttons { display: flex; gap: 12px; width: 100%; }

/* ---------- toasts & confetti ---------- */

.toasts {
  position: fixed;
  top: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 100;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  background: rgba(13, 19, 48, 0.95);
  border: 1px solid rgba(250, 204, 21, 0.5);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.85rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: slidein 0.3s ease;
  max-width: 300px;
}
.toast.out { animation: slideout 0.5s ease forwards; }
.toast-icon { font-size: 1.5rem; }
@keyframes slidein { from { transform: translateX(120%); } to { transform: none; } }
@keyframes slideout { to { transform: translateX(120%); opacity: 0; } }

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

/* ---------- mobile capture field ---------- */
/* Invisible but focusable — summons the soft keyboard on touch devices.
   Must not be display:none / visibility:hidden (either suppresses the keyboard).
   font-size:16px prevents focus-zoom on iOS. Focused programmatically only. */
.mobile-capture {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  font-size: 16px;
  opacity: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  pointer-events: none;
}
