:root {
  --bg: #07161c;
  --panel: rgba(8, 30, 38, 0.95);
  --panel-2: rgba(14, 46, 56, 0.96);
  --line: #1f4b57;
  --text: #effdfb;
  --muted: #a9cfd0;
  --accent: #34e0c0;
  --accent-2: #ffd347;
  --hot: #ff6b4a;
  --good: #8cf08a;
  --radius: 14px;
  --header-h: 48px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-2); }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.4em;
  border: 1px solid rgba(239, 253, 251, 0.35);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 700 0.82em/1.5 system-ui, sans-serif;
  text-align: center;
  background: rgba(255, 255, 255, 0.08);
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.site-header nav a { color: var(--muted); text-decoration: none; font-size: 14px; }

.page { padding: 8px 8px 40px; }

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 1280px;
  height: calc(100vh - var(--header-h) - 16px);
  height: calc(100dvh - var(--header-h) - 16px);
  max-height: 820px;
  min-height: 300px;
  background: #051015;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
.game-root:fullscreen { max-width: none; max-height: none; height: 100vh; height: 100dvh; border: 0; border-radius: 0; }
.stage { position: absolute; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(8px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
  z-index: 3;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5), 0 0 8px rgba(0, 0, 0, 0.35);
}
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 4px; }
.hud-right { flex-direction: row; align-items: center; gap: 10px; }
.hud-dist { font-weight: 900; font-size: clamp(22px, 4.4vmin, 36px); letter-spacing: 0.5px; }
.hud-dist small { font-size: 0.55em; margin-left: 2px; color: var(--muted); }
.hud-best { font-weight: 700; font-size: clamp(11px, 2vmin, 14px); color: var(--muted); min-height: 1em; }
.hud-meter {
  position: relative;
  width: clamp(90px, 20vmin, 160px);
  height: 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.25);
  overflow: hidden;
}
.hud-meter i {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, #34e0c0, #9cfff0);
  transition: width 0.15s linear;
}
.hud-meter.full i { background: linear-gradient(90deg, #ffd347, #ff8a3d, #ff4fa0); animation: meterglow 0.4s linear infinite alternate; }
.hud-meter b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; font-weight: 900; letter-spacing: 2px; color: #fff; text-shadow: 0 0 3px rgba(0, 0, 0, 0.95), 0 1px 1px rgba(0, 0, 0, 0.9); }
@keyframes meterglow { from { filter: brightness(1); } to { filter: brightness(1.35); } }
.hud-caps {
  display: flex; align-items: center; gap: 6px;
  font-weight: 900; font-size: clamp(18px, 3.4vmin, 26px);
  padding: 3px 12px 3px 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.35);
}
.ico-cap {
  display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.12em;
  background: radial-gradient(circle at 45% 38%, #fffbe0 0 16%, #ffe066 24% 52%, #f0a818 70% 100%);
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 58%, 80% 94%, 50% 73%, 20% 94%, 31% 58%, 2% 37%, 38% 36%);
}
.icon-btn {
  pointer-events: auto; width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.35); color: var(--text); cursor: pointer; fill: currentColor;
}
.icon-btn:focus-visible, .btn:focus-visible, .tab:focus-visible, .card:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

/* ---------- Toasts and teaching ---------- */
.toasts {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 4; width: min(92%, 460px);
}
.toast {
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 12px;
  padding: 7px 14px; font-weight: 800; font-size: 14px; text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); animation: toastin 0.25s ease-out;
}
.toast.gold { border-color: var(--accent-2); color: #fff2c0; }
.toast small { display: block; font-weight: 600; color: var(--muted); }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.teach {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  z-index: 4; pointer-events: none; background: var(--panel); border: 2px solid var(--accent);
  border-radius: 16px; padding: 10px 18px; font-weight: 800; font-size: clamp(15px, 3vmin, 20px);
  text-align: center; animation: bob 1s ease-in-out infinite alternate; max-width: 90%;
}
@keyframes bob { from { transform: translate(-50%, 0); } to { transform: translate(-50%, -6px); } }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  padding: 12px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen:empty { display: none; }
.screen.dim { background: rgba(3, 12, 16, 0.62); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: clamp(12px, 2.4vmin, 22px); width: min(100%, 760px); max-height: 100%;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.panel.narrow { width: min(100%, 440px); }
.panel h2 { margin: 0; font-size: clamp(20px, 3.8vmin, 28px); }
.panel h3 { margin: 4px 0 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.panel p { margin: 0; color: var(--muted); line-height: 1.45; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-body { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.wallet { display: inline-flex; align-items: center; gap: 6px; font-weight: 900; font-variant-numeric: tabular-nums; }

.title-wrap { display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 2vmin, 16px); text-align: center; width: min(100%, 720px); }
.logo {
  margin: 0; font-size: clamp(40px, 11vmin, 92px); font-weight: 900; letter-spacing: 1px; line-height: 1;
  background: linear-gradient(180deg, #ffffff 10%, #9cfff0 45%, #20b89f 80%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #063b35) drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}
.subtitle { margin: 0; color: #d9fbf6; font-weight: 700; font-size: clamp(13px, 2.6vmin, 18px); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
.rank-line { font-weight: 800; color: var(--accent-2); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); font-size: clamp(13px, 2.4vmin, 16px); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.btn {
  min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--panel-2); font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.primary {
  background: linear-gradient(180deg, #52f0d2, #16a58c); color: #032a24; border-color: #9cfff0;
  font-size: clamp(18px, 3.6vmin, 24px); padding: 10px 34px; box-shadow: 0 5px 0 #0a5c4f, 0 10px 24px rgba(0, 0, 0, 0.4);
}
.btn.gold { background: linear-gradient(180deg, #ffe07a, #e6a519); color: #3a2402; border-color: #fff0b5; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.btn .badge { background: var(--hot); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; font-weight: 700; cursor: pointer; font-size: 14px;
}
.tab[aria-selected='true'] { background: var(--accent); color: #032a24; border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.03);
  padding: 8px; cursor: pointer; min-height: 44px;
}
.card canvas { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; background: rgba(0, 0, 0, 0.3); }
.card b { font-size: 14px; }
.card span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.card .price { font-weight: 900; color: var(--accent-2); display: flex; align-items: center; gap: 4px; font-size: 13px; }
.card.locked { opacity: 0.75; }
.card.locked canvas { filter: grayscale(0.9) brightness(0.5); }
.card.equipped { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.card:disabled { cursor: default; }
.card[aria-pressed='true'] .ride-choice { color: var(--accent); font-weight: 900; }
.card .tagline { position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: 900; background: var(--accent); color: #032a24; border-radius: 6px; padding: 1px 6px; }

.missions { display: flex; flex-direction: column; gap: 8px; }
.mission { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.mission .tick { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; font-weight: 900; }
.mission.done .tick { background: var(--good); border-color: var(--good); color: #053a1a; }
.mission.done .text { color: var(--good); }
.mission .bar { height: 6px; border-radius: 999px; background: rgba(0, 0, 0, 0.4); overflow: hidden; margin-top: 4px; }
.mission .bar i { display: block; height: 100%; background: var(--accent); }
.mission .text { font-weight: 700; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.stat { background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 6px 10px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.results-big { font-size: clamp(40px, 10vmin, 76px); font-weight: 900; line-height: 1; text-align: center; }
.results-big small { font-size: 0.4em; color: var(--muted); }
.new-best { color: var(--accent-2); font-weight: 900; text-align: center; letter-spacing: 2px; animation: pulse 0.7s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
.lines { display: flex; flex-direction: column; gap: 4px; }
.line { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; font-size: 14px; padding: 4px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.line b { font-variant-numeric: tabular-nums; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.setting input[type='range'] { width: min(52%, 220px); accent-color: var(--accent); }
.setting input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--accent); }

.help-list { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.5; font-size: 14px; }
.help-list b { color: var(--text); }

.pc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.pc { border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); }
.pc canvas { width: 100%; aspect-ratio: 3 / 2; display: block; }
.pc span { display: block; font-size: 12px; padding: 4px 6px; color: var(--muted); }

.about { max-width: 820px; margin: 24px auto 0; padding: 0 8px; line-height: 1.55; color: #d7eeee; }
.about h1 { font-size: 28px; margin: 0 0 8px; }
.about h2 { font-size: 19px; margin: 22px 0 6px; }

.no-kbd kbd { display: none; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
  .btn.primary { padding: 10px 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .teach, .new-best, .hud-meter.full i, .toast { animation: none; }
}

/* Workshop, records and results details */
.pips { display: flex; gap: 4px; margin: 2px 0; }
.pip { width: 16px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); }
.pip.on { background: var(--accent); box-shadow: 0 0 6px rgba(52, 224, 192, 0.55); }
.ach { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); opacity: 0.62; }
.ach.got { opacity: 1; border-color: rgba(255, 211, 71, 0.7); background: rgba(255, 211, 71, 0.08); }
.ach b { font-size: 13px; }
.ach span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.center { text-align: center; }
.mprog { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mission.now { box-shadow: inset 0 0 0 2px var(--good); animation: fz-pop 0.45s ease-out; }
.rankup { margin: 12px auto; padding: 10px 16px; max-width: 320px; border-radius: 12px; text-align: center; font-weight: 900; color: #1d1400; background: linear-gradient(135deg, #ffd347, #ff9f43); box-shadow: 0 6px 24px rgba(255, 180, 60, 0.35); animation: fz-pop 0.5s ease-out; }
.rankup small { display: block; margin-top: 3px; font-size: 12px; font-weight: 700; }
.revive-count { margin: 6px 0 10px; font-size: 64px; line-height: 1; font-weight: 900; text-align: center; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.pc.done canvas { box-shadow: 0 0 0 2px var(--accent-2), 0 0 18px rgba(255, 211, 71, 0.35); }
@keyframes fz-pop { 0% { transform: scale(0.92); opacity: 0.4; } 60% { transform: scale(1.03); opacity: 1; } 100% { transform: scale(1); } }
/* Mission and rank results keep their brief animation in calm mode. */
