:root {
  --bg: #0b0f19;
  --panel: #121a2b;
  --panel-2: #172238;
  --line: #22304d;
  --text: #e6ebf5;
  --muted: #8b97b0;
  --accent: #4ade80;
  --accent-2: #22c55e;
  --apple: #f43f5e;
  --gold: #fbbf24;
  --rock: #64748b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #15213a 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px max(16px, env(safe-area-inset-left));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: .2px;
  text-decoration: none;
}

.brand span { color: var(--accent); }

.nav { display: flex; gap: 18px; }

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.nav a:hover { color: var(--text); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 320px);
  justify-content: center;
  gap: 24px;
  padding: 8px 16px 32px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

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

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
}

.label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.value.bump { animation: bump .25s ease; }

@keyframes bump {
  50% { transform: scale(1.18); color: var(--accent); }
}

.icon-btn {
  width: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.icon-btn:hover { background: var(--panel-2); }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  touch-action: none;
  user-select: none;
}

.board canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(11, 15, 25, .78);
  backdrop-filter: blur(4px);
  transition: opacity .2s ease;
}

.overlay.hidden { opacity: 0; pointer-events: none; }

.overlay-title { margin: 0; font-size: clamp(28px, 6vw, 40px); }

.overlay-text { margin: 0; color: var(--muted); max-width: 320px; }

.overlay-text .best { color: var(--gold); font-weight: 700; }

.modes {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
}

.mode {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.mode[aria-checked="true"] { background: var(--accent); color: #062312; }

.primary {
  display: inline-block;
  border: 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #062312;
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  padding: 12px 36px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(34, 197, 94, .35);
}

.primary:hover { filter: brightness(1.06); }

.hint { margin: 0; font-size: 12px; color: var(--muted); }

.pad {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  justify-content: center;
}

.pad button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  font-size: 18px;
  touch-action: manipulation;
}

.pad button:active { background: var(--panel-2); }

.pad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.pad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.pad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.pad [data-dir="right"] { grid-column: 3; grid-row: 2; }

@media (pointer: coarse) {
  .pad { display: grid; }
  .hint { display: none; }
}

.side { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card h2 { margin: 0 0 10px; font-size: 16px; }

.leaderboard { margin: 0; padding: 0; list-style: none; counter-reset: rank; }

.leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.leaderboard li:last-child { border-bottom: 0; }

.leaderboard li::before { content: counter(rank); color: var(--muted); }

.leaderboard .meta { color: var(--muted); font-size: 13px; }

.empty { margin: 0; color: var(--muted); font-size: 14px; }

.empty.hidden { display: none; }

.rules { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; color: var(--muted); }

.rules strong { color: var(--text); }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.dot.red { background: var(--apple); }
.dot.gold { background: var(--gold); }
.dot.rock { background: var(--rock); border-radius: 3px; }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.notfound { align-items: center; justify-content: center; }

.notfound-box { text-align: center; padding: 16px; }

.notfound-box h1 { font-size: 80px; margin: 0; color: var(--accent); }

.notfound-box p { color: var(--muted); margin: 0 0 24px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 560px); }
}

@media (max-width: 480px) {
  .nav { display: none; }
  .value { font-size: 19px; }
  .hud { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .value.bump { animation: none; }
  .overlay { transition: none; }
}
