:root {
  --bg: #0f1117;
  --bg-elev: #171a23;
  --panel: #1e222e;
  --text: #e6e9f0;
  --muted: #9aa3b2;
  --accent: #4ade80;
  --accent-2: #38bdf8;
  --snake-body: #3fbf6f;
  --obstacle: #7c8696;
  --danger: #f87171;
  --border: #2a2f3d;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --maxw: 960px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* Visually hidden but exposed to assistive tech (screen readers). */
.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;
}

/* Game shell */
.game { max-width: 560px; margin: 0 auto; padding: 24px 16px 56px; }
.game__header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 8px;
}
.game__header h1 { margin: 0; font-size: 1.5rem; flex: 1; }
.back { font-size: 0.9rem; }
.hud {
  display: flex; align-items: center; flex: 1 1 100%; min-width: 0;
  flex-wrap: wrap; gap: 8px 14px; font-size: 0.9rem; color: var(--muted);
}
.hud b { color: var(--text); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 4px 0 16px; }

/* Next-milestone indicator: one explicit, color-independent line telling the
   player the immediate goal (eat N more, clear N bricks, score N points). */
.milestone {
  margin: 0 0 14px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}
.milestone b { color: var(--accent-2); }

/* Goal progress bar: a color-independent, accessible (role=progressbar)
   visualization of progress toward the next milestone, sitting under the
   milestone text line so the player sees both the goal and how close they are. */
.goalbar {
  position: relative;
  height: 8px;
  margin: -6px 0 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.goalbar__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.18s ease;
}
@media (prefers-reduced-motion: reduce) {
  .goalbar__fill { transition: none; }
}

/* New-best celebration badge: shown the first time a run beats the record
   loaded at start, so progress is felt as well as seen. It is color-independent
   (text + border, no hue reliance) and respects reduced-motion. */
.bestbadge {
  display: inline-block;
  margin: 2px 0 16px;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  animation: bestpop 0.35s ease-out;
}
.bestbadge[hidden] { display: none; }
@keyframes bestpop {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .bestbadge { animation: none; }
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn--primary { background: var(--accent); color: #06210f; border-color: var(--accent); font-weight: 600; }
.btn--ghost { background: transparent; padding: 8px 10px; }

/* Help dialog — keyboard-operable, modal, accessible across every game. */
.help-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 10, 16, 0.82);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.help-overlay[hidden] { display: none; }
.help-overlay__card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 420px; width: 100%;
  max-height: 86vh; overflow-y: auto;
  padding: 24px;
}
.help-overlay__card h2 { margin: 0 0 12px; font-size: 1.4rem; }
.help-overlay__card h3 { margin: 18px 0 6px; font-size: 1rem; color: var(--text); }
.help-overlay__card p { margin: 0 0 10px; color: var(--muted); line-height: 1.5; }
.help-overlay__card ul { margin: 0 0 12px; padding-left: 18px; color: var(--muted); line-height: 1.6; }
.help-overlay__card li { margin-bottom: 2px; }
.help-overlay__card kbd {
  display: inline-block; min-width: 20px; text-align: center;
  padding: 1px 6px; margin: 0 2px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.85rem;
}
.help-overlay__card .btn--primary { margin-top: 12px; }

/* A solid, theme-aware surface keeps pause text readable over any canvas.
   The bounded inner scroll region also keeps actions reachable on small boards. */
.game .overlay { padding: 12px; }
.game .overlay__card {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 4vw, 24px);
}
.help-overlay__card {
  max-height: min(86vh, calc(100dvh - 40px));
  overscroll-behavior: contain;
  padding: clamp(16px, 4vw, 24px);
}
.help-overlay__card #help-close {
  position: sticky;
  bottom: 0;
  width: 100%;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-elev: #ffffff;
    --panel: #ffffff;
    --text: #14181f;
    --muted: #5b6472;
    --obstacle: #9aa3b2;
    --border: #d7dce5;
    --shadow: 0 8px 30px rgba(20, 24, 31, 0.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Portfolio polish: consistent density, native focus, and comfortable targets. */
:root { --maxw: 1120px; }
body { line-height: 1.5; }
.skip-link { position: absolute; left: 16px; top: -80px; z-index: 50; padding: 12px 18px; background: var(--panel); border: 2px solid var(--accent); border-radius: 10px; }
.skip-link:focus { top: 12px; }
a:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 4px; }
.btn { min-height: 44px; font-weight: 600; touch-action: manipulation; }
.game { padding-top: 24px; }
.game__header { margin-bottom: 16px; }
.back { display: inline-flex; align-items: center; min-height: 44px; }
.hud { gap: 10px 12px; padding: 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev); font-size: .82rem; }
.hud > span { font-variant-numeric: tabular-nums; }
.game .stage { max-width: 100%; }
.game canvas { max-width: 100%; }
.hint { line-height: 1.55; }
@media (max-width: 420px) {
  .hud { padding: 10px; gap: 8px 10px; }
}
@media (prefers-color-scheme: light) {
  :root { --accent: #15803d; --accent-2: #0369a1; }
  .btn--primary { color: #fff; }
}
#reset-status:empty { display: none; }
