:root {
  --bg: #070a14;
  --panel: rgba(13, 19, 40, 0.88);
  --line: rgba(140, 160, 220, 0.22);
  --text: #e8ecf8;
  --dim: #98a1bd;
  --accent: #7df9ff;
  --gold: #ffd166;
  --violet: #b892ff;
  --danger: #ff5d73;
  --laser: #7dff9a;
  --shield: #6ea8ff;
  --font: ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(7, 10, 20, 0.35), rgba(7, 10, 20, 0.8));
  animation: fade 0.25s ease-out;
}
.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  margin: auto; /* centers, but scrolls instead of clipping on short screens */
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px 22px;
  text-align: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.panel.small { width: min(320px, 100%); }

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
}

h1 {
  margin: 4px 0 10px;
  font-size: clamp(40px, 11vw, 64px);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-shadow: 0 0 28px rgba(125, 249, 255, 0.45);
}
h2 { margin: 6px 0 14px; font-size: 28px; }

.lede { margin: 0 0 18px; line-height: 1.5; color: var(--text); font-size: 15px; }
.gold { color: var(--gold); font-weight: 600; }
.green { color: var(--laser); font-weight: 600; }
.blue { color: var(--shield); font-weight: 600; }
.violet { color: var(--violet); font-weight: 600; }

.controls {
  list-style: none;
  margin: 0 0 20px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  color: var(--dim);
  display: grid;
  gap: 8px;
}
.controls li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.controls li:last-child { justify-content: center; }

kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.primary {
  min-width: 180px;
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #04121a;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 0 24px rgba(125, 249, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 0 34px rgba(125, 249, 255, 0.55); }
.primary:active { transform: translateY(1px); }

.secondary {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-weight: 600;
}
.secondary:hover { border-color: var(--accent); }

.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row .primary { min-width: 0; }

.best { margin: 14px 0 0; color: var(--dim); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.best strong { color: var(--text); font-family: var(--mono); margin-left: 6px; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--dim); }

.score-big {
  font-family: var(--mono);
  font-size: clamp(44px, 12vw, 64px);
  font-weight: 700;
  margin: 4px 0 6px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.new-best {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.14);
  color: var(--gold);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.new-best[hidden] { display: none; }
.stats { margin: 0 0 16px; color: var(--dim); font-size: 14px; line-height: 1.5; }

/* ---------- Leaderboard ---------- */
.menu-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.menu-actions .secondary { min-width: 180px; }

.score-form { display: flex; gap: 8px; margin: 0 0 6px; }
.score-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
  user-select: text;
  -webkit-user-select: text;
}
.score-form input::placeholder { color: var(--dim); }
.score-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.score-form .secondary { min-height: 44px; white-space: nowrap; }
.score-form .secondary:disabled { opacity: 0.5; cursor: default; }

.submit-msg { min-height: 1.4em; margin: 0 0 10px; font-size: 13px; line-height: 1.4; color: var(--dim); }
.submit-msg.ok { color: var(--laser); }
.submit-msg.err { color: var(--danger); }

.board {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  text-align: left;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.board li { display: grid; grid-template-columns: 2.4em 1fr auto; gap: 8px; padding: 6px 12px; }
.board li:nth-child(even) { background: rgba(255, 255, 255, 0.03); }
.board .rk { color: var(--dim); font-family: var(--mono); }
.board .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sc { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.board li.mine { background: rgba(125, 249, 255, 0.12); color: var(--accent); font-weight: 600; }
.board li.note { display: block; text-align: center; color: var(--dim); }
.board li.gap { display: block; text-align: center; color: var(--dim); padding: 0 12px; line-height: 1.2; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- HUD buttons ---------- */
.hud-buttons {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 2;
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(13, 19, 40, 0.6);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; fill: var(--text); }
.icon-btn svg .stroke { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
#muteBtn .ico-off { display: none; }
#muteBtn[aria-pressed="true"] .ico-on { display: none; }
#muteBtn[aria-pressed="true"] .ico-off { display: block; }
body:not(.playing) #pauseBtn { visibility: hidden; }

/* ---------- Touch dash button ---------- */
.dash-btn {
  --cd: 1;
  display: none;
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 0;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: var(--text);
  background:
    radial-gradient(circle, rgba(13, 19, 40, 0.92) 62%, transparent 63%),
    conic-gradient(var(--accent) calc(var(--cd) * 360deg), rgba(140, 160, 220, 0.2) 0);
  z-index: 2;
  touch-action: none;
}
.dash-btn.ready { box-shadow: 0 0 22px rgba(125, 249, 255, 0.45); }

/* ---------- Touch laser / force-field buttons ---------- */
.ability-btn {
  display: none;
  position: fixed;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: rgba(13, 19, 40, 0.88);
  font-weight: 800;
  font-size: 10px;
  letter-spacing: 0.08em;
  z-index: 2;
  touch-action: none;
}
.ability-btn.laser {
  color: var(--laser);
  right: calc(max(20px, env(safe-area-inset-right)) + 96px);
  bottom: calc(34px + env(safe-area-inset-bottom));
}
.ability-btn.shield {
  color: var(--shield);
  right: calc(max(20px, env(safe-area-inset-right)) + 10px);
  bottom: calc(124px + env(safe-area-inset-bottom));
}
.ability-btn .count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--badge);
  color: #04121a;
  font-size: 12px;
  line-height: 22px;
  text-align: center;
}
.ability-btn.laser { --badge: var(--laser); }
.ability-btn.shield { --badge: var(--shield); }
.ability-btn.empty { opacity: 0.35; }
.ability-btn.active { background: rgba(110, 168, 255, 0.25); box-shadow: 0 0 22px rgba(110, 168, 255, 0.6); }

.touch-only { display: none !important; }
@media (pointer: coarse) {
  .touch-only { display: flex !important; }
  .mouse-only { display: none !important; }
  body.playing .dash-btn,
  body.playing .ability-btn { display: block; }
}

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