:root {
  --bg: #070a12;
  --panel: rgba(14, 20, 34, 0.86);
  --border: rgba(148, 163, 184, 0.2);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

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

body {
  font-family: var(--font-sans);
  background: radial-gradient(circle at 50% 0%, #131c33 0%, #070a12 65%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.mono { font-family: var(--font-mono); }
.accent { color: var(--accent); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.hidden { display: none !important; }

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #ef4444);
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
}
.brand h1 { font-size: 1.15rem; line-height: 1.15; letter-spacing: -0.02em; }
.sub { font-size: 0.76rem; color: var(--muted); }

.top-btns { display: flex; gap: 8px; align-items: center; }

.pill-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(24, 34, 54, 0.8);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.16s ease;
}
.pill-btn:hover { border-color: var(--accent); background: rgba(56, 189, 248, 0.18); }

/* Stage Frame */
.stage-wrap { display: flex; flex-direction: column; gap: 10px; }

.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(56, 189, 248, 0.28);
  background: #04070e;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.65);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* In-Game HUD */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 18px;
}

.hud-top {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-width: 720px;
}

.hud-box {
  background: rgba(8, 13, 24, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
}

.timer-box { border-color: rgba(56, 189, 248, 0.5); }
.timer-box.low { border-color: rgba(248, 113, 113, 0.85); animation: pulseWarn 0.45s infinite alternate; }
@keyframes pulseWarn { from { background: rgba(127, 29, 29, 0.55); } to { background: rgba(220, 38, 38, 0.45); } }

.hud-lbl { font-size: 0.65rem; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.hud-box strong { font-size: 1.15rem; line-height: 1.2; }

.banner-msg {
  align-self: center;
  padding: 7px 20px;
  border-radius: 999px;
  background: rgba(8, 13, 24, 0.85);
  border: 1px solid var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.45);
  transform: translateY(-10px);
}

.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
}

.nitro-panel {
  width: 245px;
  background: rgba(8, 13, 24, 0.78);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  padding: 9px 12px;
}

.nitro-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: #bae6fd;
  margin-bottom: 6px;
}

.nitro-track {
  height: 9px;
  border-radius: 999px;
  background: rgba(30, 41, 59, 0.9);
  overflow: hidden;
}

.nitro-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0284c7, #38bdf8, #a78bfa);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.7);
  transition: width 0.06s linear;
}

.combo-badge {
  margin-top: 7px;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.55);
  padding: 2px 9px;
  border-radius: 999px;
}

/* Digital Superbike Dash Cluster */
.dash-cluster {
  width: 290px;
  background: rgba(8, 13, 24, 0.84);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 14px;
  padding: 10px 14px;
}

.rpm-strip {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}

.rpm-seg {
  height: 8px;
  border-radius: 2px;
  background: rgba(51, 65, 85, 0.65);
}
.rpm-seg.on.g { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.rpm-seg.on.y { background: #facc15; box-shadow: 0 0 6px #facc15; }
.rpm-seg.on.r { background: #ef4444; box-shadow: 0 0 8px #ef4444; }

.dash-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.gear-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 8px;
  padding: 3px 10px;
}
.gear-box strong { font-size: 1.55rem; color: #7dd3fc; line-height: 1.1; }

.speed-box { display: flex; align-items: baseline; gap: 4px; }
.speed-box strong { font-size: 2.35rem; font-weight: 900; line-height: 1; color: #fff; }
.speed-box span { font-size: 0.78rem; color: var(--muted); font-weight: 700; }

.rpm-num { display: flex; flex-direction: column; align-items: flex-end; }
.rpm-num strong { font-size: 0.92rem; color: #cbd5e1; }

/* Overlays & Modals */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 16, 0.78);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}

.modal {
  width: 100%;
  max-width: 680px;
  background: rgba(14, 21, 36, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 18px;
  padding: 24px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal.compact { max-width: 480px; }

.modal-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #7dd3fc;
  background: rgba(14, 165, 233, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 3px 11px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.modal-badge.warn { color: #fde68a; border-color: rgba(251, 191, 36, 0.5); background: rgba(245, 158, 11, 0.16); }

.modal h2 { font-size: 1.75rem; margin-bottom: 8px; }
.modal-desc { font-size: 0.88rem; color: var(--muted); margin-bottom: 18px; line-height: 1.55; }

.track-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.track-card {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(22, 32, 52, 0.75);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.16s ease;
}
.track-card:hover { border-color: rgba(148, 163, 184, 0.5); transform: translateY(-2px); }
.track-card.active {
  border-color: var(--accent);
  background: rgba(14, 165, 233, 0.2);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.25);
}
.track-icon { font-size: 1.6rem; }
.track-card strong { font-size: 0.88rem; }
.track-card span { font-size: 0.72rem; color: var(--muted); }

.controls-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 18px;
}

kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #fff;
}

.btn-primary {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 12px 28px;
  font-size: 0.98rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #0284c7, #ef4444);
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(239, 68, 68, 0.35);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 28px rgba(56, 189, 248, 0.45); }

.btn-secondary {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(30, 41, 59, 0.8);
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--accent); }

.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.result-grid div {
  background: rgba(22, 32, 52, 0.8);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-grid span { font-size: 0.74rem; color: var(--muted); }
.result-grid strong { font-size: 1.25rem; }

.record-tip { font-size: 0.86rem; font-weight: 700; color: var(--amber); margin-bottom: 10px; }

/* Mobile Touch Controls */
.touch-pad {
  display: none;
  justify-content: space-between;
  gap: 10px;
}
.touch-left, .touch-right { display: flex; gap: 8px; }
.touch-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(22, 32, 52, 0.9);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 14px 16px;
  border-radius: 12px;
  touch-action: none;
}
.touch-btn.gas { background: linear-gradient(135deg, #059669, #0284c7); border-color: transparent; }
.touch-btn.nitro { background: linear-gradient(135deg, #6366f1, #38bdf8); border-color: transparent; }
.touch-btn.brake { background: rgba(220, 38, 38, 0.45); border-color: rgba(248, 113, 113, 0.6); }

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 4px;
}
.footer a { color: var(--accent); text-decoration: none; }

@media (max-width: 820px) {
  .touch-pad { display: flex; }
  .track-grid { grid-template-columns: 1fr; }
  .hud-top { grid-template-columns: repeat(2, 1fr); }
  .dash-cluster { width: 220px; padding: 7px 10px; }
  .speed-box strong { font-size: 1.6rem; }
  .nitro-panel { width: 175px; }
}
