:root {
  color-scheme: dark;
  --bg: #151515;
  --ink: #f6f1e8;
  --muted: #b9b0a2;
  --road: #282828;
  --line: #f0c24b;
  --panel: rgba(20, 20, 20, 0.88);
  --accent: #33c6a6;
  --danger: #ee5c4d;
  --blue: #5aa7ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #37332b 0%, var(--bg) 46%, #0b0b0b 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

button, input {
  font: inherit;
}

button {
  border: 1px solid rgba(255,255,255,0.18);
  background: #f2efe6;
  color: #151515;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 800;
}

button:active { transform: translateY(1px); }

.shell {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

#game {
  width: min(100vw, 520px);
  height: 100dvh;
  max-height: 960px;
  display: block;
  background: var(--road);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 24px 80px rgba(0,0,0,0.45);
}

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  width: min(calc(100vw - 20px), 500px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 6px;
  align-items: stretch;
  pointer-events: none;
}

.hud div, .hud button {
  pointer-events: auto;
  min-width: 0;
  border-radius: 8px;
}

.hud div {
  background: rgba(12,12,12,0.72);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 7px 8px;
  display: grid;
  gap: 1px;
}

.label {
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  font-weight: 700;
}

.hud strong {
  font-size: clamp(15px, 4vw, 22px);
  line-height: 1;
}

#pauseButton {
  min-height: 0;
  padding: 0 10px;
  background: rgba(242,239,230,0.92);
}

.panel {
  position: fixed;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: min(calc(100vw - 32px), 380px);
  transform: translate(-50%, -50%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
}

.panel.hidden { display: none; }
.panel h1, .panel h2, .leaderboard h2 {
  margin: 0;
  letter-spacing: 0;
}
.panel h1 { font-size: 34px; }
.panel h2, .leaderboard h2 { font-size: 18px; }
.panel p { margin: 0; color: var(--muted); line-height: 1.4; }
.panel label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
.panel input {
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  padding: 0 12px;
  text-transform: uppercase;
}

.leaderboard {
  position: fixed;
  z-index: 3;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(calc(100vw - 20px), 260px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(12,12,12,0.72);
  padding: 12px;
}

.boardHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

#clearBoardButton {
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink);
}

.leaderboard ol {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.leaderboard li span {
  color: var(--ink);
  font-weight: 800;
}

@media (max-width: 720px) {
  .leaderboard {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-height: 118px;
    overflow: hidden;
  }

  .leaderboard ol {
    grid-template-columns: 1fr 1fr;
    column-gap: 18px;
  }
}

@media (max-width: 360px) {
  .hud { grid-template-columns: repeat(3, 1fr); }
  #pauseButton { grid-column: 1 / -1; min-height: 34px; }
  .leaderboard { display: none; }
}
