:root {
  --bg1: #0f172a;
  --bg2: #1e293b;
  --ink: #f8fafc;
  --muted: #a5b4c8;
  --card: rgba(255, 255, 255, .07);
  --line: rgba(255, 255, 255, .15);
  --good: #4ade80;
  --bad: #f87171;
  --gold: #fde047;
  --orange: #fb923c;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.025) 0 18px, transparent 18px 36px),
    radial-gradient(ellipse at 50% 0%, #334155 0%, var(--bg2) 40%, var(--bg1) 100%) fixed;
  color: var(--ink);
  font-family: "Nunito", "Segoe UI Rounded", "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px; line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.hidden { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: rgba(15, 23, 42, .8); border-bottom: 3px solid transparent;
  border-image: repeating-linear-gradient(90deg, #fff 0 12px, #111 12px 24px) 3;
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px); height: 58px;
}
.logo { font-weight: 900; font-size: 24px; white-space: nowrap; font-style: italic; }
.top-actions { display: flex; gap: 8px; }
.top-btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px; font-size: 16px; font-weight: 700; white-space: nowrap; }
.top-btn:hover { background: rgba(255, 255, 255, .16); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- circuits ---------- */
.intro { text-align: center; margin: 4px 0 16px; }
.intro h1 { margin: 0 0 6px; font-size: 32px; }
.intro p { margin: 0; color: var(--muted); }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.lvl {
  position: relative; text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 4px; min-height: 150px; transition: transform .12s, border-color .12s;
}
.lvl:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--orange); }
.lvl:disabled { opacity: .45; cursor: not-allowed; }
.lvl .num { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--orange); }
.lvl .name { font-size: 20px; font-weight: 900; line-height: 1.15; }
.lvl .ex { font-size: 14px; color: var(--muted); font-weight: 700; flex: 1; }
.lvl .group { font-size: 12px; color: var(--muted); font-weight: 700; }
.lvl .res { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 15px; }
.lvl .stars { font-size: 18px; letter-spacing: 1px; }
.lvl .stars .off { opacity: .2; filter: grayscale(1); }
.lvl .lock { position: absolute; top: 10px; right: 12px; font-size: 20px; }
.lvl.next { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(251, 146, 60, .25); }

.speed-row { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin: 18px 0; font-weight: 800; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: rgba(255, 255, 255, .08); border: 2px solid var(--line); border-radius: 14px;
  padding: 9px 14px; font-weight: 800; font-size: 17px; transition: background .15s, border-color .15s;
}
.chip:hover { border-color: rgba(255, 255, 255, .4); }
.chip.on { background: rgba(251, 146, 60, .2); border-color: var(--orange); }

.big-btn {
  background: linear-gradient(180deg, #fb923c, #ea580c); color: #fff;
  font-size: 22px; font-weight: 900; padding: 12px 28px; border-radius: 16px;
  box-shadow: 0 5px 0 #9a3412; transition: transform .1s;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #9a3412; }
.big-btn.ghost { background: rgba(255, 255, 255, .14); box-shadow: 0 5px 0 rgba(0, 0, 0, .3); }
.howto { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.howto h2 { margin: 0 0 10px; font-size: 20px; }
.howto-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.howto-grid div { display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.howto-grid span { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; margin: 14px 0 0; }

/* ---------- race ---------- */
.game-wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; height: calc(100vh - 58px - 32px); height: calc(100dvh - 58px - 32px); min-height: 500px; }
.hud { display: grid; grid-template-columns: 74px 1fr 84px; align-items: center; gap: 8px; }
.hud-left { text-align: center; }
.hud-right { display: flex; justify-content: flex-end; }
.hud-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 800; }
.hud-val { font-size: 26px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-err { font-size: 13px; color: var(--muted); font-weight: 800; margin-top: 3px; }
.hud-task {
  text-align: center; background: #fff; color: #0f172a; border-radius: 16px; padding: 6px 10px;
  min-height: 84px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
}
.task-lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; font-weight: 900; color: #ea580c; }
.task-txt { font-size: 30px; font-weight: 900; line-height: 1.1; }
.task-txt.digi { font-family: "DSEG7 Classic", ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: #0f172a; color: #4ade80; padding: 2px 12px; border-radius: 8px; letter-spacing: 2px; }
.task-txt.long { font-size: 20px; }
.task-clock { width: 72px; height: 72px; }
.hud-task.flash-good { animation: fg .5s; }
.hud-task.flash-bad { animation: fb .5s; }
@keyframes fg { 30% { background: #bbf7d0; } }
@keyframes fb { 30% { background: #fecaca; } }
#miniMap { width: 80px; height: 80px; }
.canvas-box { position: relative; flex: 1; min-height: 0; border-radius: 20px; overflow: hidden; border: 1px solid var(--line); background: #3f8f3a; touch-action: none; }
canvas#cv { display: block; width: 100%; height: 100%; }
.toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 3;
  background: rgba(15, 23, 42, .92); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px;
  font-weight: 800; font-size: 18px; text-align: center; width: max-content; max-width: 92%; pointer-events: none;
  display: flex; align-items: center; gap: 12px;
}
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); text-align: left; }
.toast canvas { width: 76px; height: 76px; flex: none; }
.toast small { display: block; color: var(--muted); font-weight: 700; font-size: 15px; margin-top: 2px; }
.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; overflow: auto;
  background: rgba(15, 23, 42, .8); text-align: center; padding: 20px;
}
.ov-title { font-size: 36px; font-weight: 900; margin: 0 0 6px; }
.ov-text { font-size: 18px; margin: 6px 0 12px; color: var(--muted); }
.ov-stars { font-size: 52px; letter-spacing: 6px; }
.ov-stars .off { opacity: .2; filter: grayscale(1); }
.ov-count { font-size: 110px; font-weight: 900; color: var(--gold); line-height: 1; }
.lights { display: inline-flex; gap: 10px; background: #111; padding: 10px 14px; border-radius: 16px; margin-bottom: 10px; }
.lights i { width: 34px; height: 34px; border-radius: 50%; background: #333; }
.lights i.red { background: #ef4444; box-shadow: 0 0 16px #ef4444; }
.lights i.green { background: #22c55e; box-shadow: 0 0 16px #22c55e; }
.ov-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.ov-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0; max-width: 420px; }
.ov-list span { background: rgba(255, 255, 255, .1); border-radius: 10px; padding: 4px 10px; font-weight: 800; font-size: 15px; }
.ov-stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.ov-stats div { background: rgba(255, 255, 255, .08); border-radius: 12px; padding: 6px 12px; font-size: 15px; color: var(--muted); }
.ov-stats b { display: block; font-size: 26px; color: var(--ink); }
.ov-new { color: var(--gold); font-weight: 900; }
.touch { display: none; grid-template-columns: 1fr 1fr; gap: 12px; }
.t-btn {
  background: rgba(255, 255, 255, .14); border-radius: 18px; font-size: 32px; font-weight: 900; height: 66px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .35); user-select: none; -webkit-user-select: none; touch-action: none;
}
.t-btn.down { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
body.touchy .touch { display: grid; }

@media (max-width: 960px) {
  .levels { grid-template-columns: repeat(2, 1fr); }
  .howto-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  main { padding: 10px; }
  .logo { font-size: 20px; }
  .top { padding: 8px 10px; }
  .top-btn { padding: 6px 10px; font-size: 16px; }
  .bt { display: none; }
  .intro h1 { font-size: 24px; }
  .levels { gap: 10px; }
  .lvl { min-height: 130px; padding: 10px; }
  .lvl .name { font-size: 17px; }
  .howto-grid { grid-template-columns: 1fr; }
  .game-wrap { height: calc(100dvh - 58px - 20px); }
  .hud { grid-template-columns: 58px 1fr 64px; gap: 6px; }
  .hud-val { font-size: 20px; }
  .task-txt { font-size: 22px; }
  .task-txt.long { font-size: 16px; }
  #miniMap { width: 62px; height: 62px; }
  .t-btn { height: 58px; }
  .ov-title { font-size: 28px; }
}
