/* ============================================================================
 * Plyvona — Base Styles & Components
 * ----------------------------------------------------------------------------
 * Depends on: tokens.css (must be loaded first)
 *
 * Provides:
 *   - CSS reset
 *   - Typography defaults mapped to tokens
 *   - Reusable component patterns (.eyebrow, .btn, .surface, .stat, .tabs,
 *     .instr-bar, .kbd, .result-overlay, .theme-toggle)
 *
 * Game-specific styles (canvas layout, peg drawing, etc.) stay inline
 * in each game's HTML — base.css is for SHARED patterns only.
 * ========================================================================= */

/* ── 1. RESET ──────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
  transition: background-color var(--t-slow) var(--ease),
              color var(--t-slow) var(--ease);
}

img, svg, video, canvas { display: block; max-width: 100%; }

/* The `hidden` attribute must win over component display rules (e.g. flex). */
[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--accent); opacity: 0.8; }

::selection { background: var(--accent-soft); color: var(--ink); }

/* ── 2. HEADINGS ───────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400; /* DM Serif Display ships a single weight (400) */
  color: var(--ink);
}

h1 { font-size: var(--fs-h1); line-height: var(--lh-h1); letter-spacing: var(--ls-h1); }
h2 { font-size: var(--fs-h2); line-height: var(--lh-h2); letter-spacing: var(--ls-h2); }
h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); letter-spacing: var(--ls-h3); }
h4 { font-size: var(--fs-h4); line-height: var(--lh-h4); letter-spacing: var(--ls-h4); }

.display {
  font-family: var(--font-display);
  font-size: var(--fs-display);
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
  font-weight: 400;
}

.lead {
  font-size: var(--fs-lead);
  line-height: var(--lh-lead);
  color: var(--ink-2);
  font-weight: 400;
}

.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }

/* DM Serif Display italic (restrained use) */
em, .italic {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
}

/* ── 3. EYEBROW (uppercase small label) ────────────────────────────────── */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-body);
  font-size: var(--fs-eyebrow);
  font-weight: 500;
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
  line-height: 1;
}

.eyebrow--accent { color: var(--accent); }

.eyebrow::before {
  /* Leading rule/dash removed site-wide per Brian 2026-05-31. */
  display: none;
}

.eyebrow--no-rule::before { display: none; }

/* ── 4. CAPTION (small body text) ──────────────────────────────────────── */
.caption {
  font-size: var(--fs-caption);
  line-height: var(--lh-ui);
  color: var(--ink-muted);
}

/* ── 5. NUMERIC DISPLAY ────────────────────────────────────────────────── */
/* For HUD numbers that tick (timers, scores) — keep digit widths stable */
.num-tabular {
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-variant-numeric: tabular-nums lining-nums;
}

/* For magazine-moment numbers (end-game results, big stats) */
.num-display {
  font-family: var(--font-display);
  font-weight: 400;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: var(--ls-display);
}

/* ── 6. SURFACES ───────────────────────────────────────────────────────── */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.surface-2 {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.surface--interactive {
  transition: border-color var(--t-base) var(--ease),
              transform var(--t-base) var(--ease),
              box-shadow var(--t-base) var(--ease);
}
.surface--interactive:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ── 7. BUTTONS ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--fs-ui-sm);
  font-weight: 600;
  letter-spacing: var(--ls-button);
  line-height: 1;
  padding: 12px 20px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: all var(--t-base) var(--ease);
  text-decoration: none;
  user-select: none;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-on-accent);
}
.btn--primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-on-accent);
  filter: brightness(1.08);
  box-shadow: 0 8px 20px var(--accent-soft);
}

.btn--brand {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--ink-on-brand);
}
.btn--brand:hover {
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: var(--ink-on-brand);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
}
.btn--ghost:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.btn--soft {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.btn--soft:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  filter: brightness(1.05);
}

.btn--sm { font-size: var(--fs-caption); padding: 8px 14px; }
.btn--lg { font-size: var(--fs-body); padding: 14px 24px; }

/* ── 8. STAT BLOCK (number above small label) ──────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  text-align: center;
}
.stat__label {
  font-family: var(--font-body);
  font-size: var(--fs-eyebrow);
  font-weight: 500;
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
  line-height: 1;
}
.stat__value {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--fs-h3);
  line-height: 1;
  color: var(--ink);
  font-feature-settings: "tnum" 1, "lnum" 1;
}
.stat__value--accent { color: var(--accent); }
.stat__value--bump { animation: stat-bump 0.35s var(--ease); }
@keyframes stat-bump {
  0%, 100% { transform: scale(1); color: var(--ink); }
  50%      { transform: scale(1.20); color: var(--accent); }
}
.stat__value--accent.stat__value--bump {
  animation-name: stat-bump-accent;
}
@keyframes stat-bump-accent {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.20); filter: brightness(1.2); }
}

/* Card discipline (v2.1): stats are non-interactive — no card chrome.
   Inline grouping via spacing + dividers only. */
.stats-row {
  display: flex;
  justify-content: center;
  gap: var(--space-8);
  padding: var(--space-4) var(--space-6);
}

@media (max-width: 480px) {
  .stats-row { gap: var(--space-5); padding: var(--space-3) var(--space-4); }
}

/* ── 9. TABS ───────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--space-2);
  width: 100%;
}
.tab {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  font-family: var(--font-body);
  font-size: var(--fs-eyebrow);
  font-weight: 600;
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-base) var(--ease);
  line-height: 1;
}
.tab:hover {
  border-color: var(--accent);
  color: var(--ink);
}
.tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.tab__sub {
  display: block;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
  margin-top: 4px;
  opacity: 0.75;
}

/* ── 10. INSTRUCTION / MESSAGE BAR ─────────────────────────────────────── */
/* Card discipline (v2.1): the instruction bar is a non-interactive message —
   no card chrome. Inline, with the state-coloured icon carrying emphasis. */
.instr-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  font-size: var(--fs-body);
  line-height: var(--lh-ui);
  min-height: 44px;
}
.instr-bar__icon { font-size: 20px; flex-shrink: 0; line-height: 1; }
.instr-bar__msg  { flex: 1; }
.instr-bar__msg .hi  { color: var(--accent); font-weight: 600; }
.instr-bar__msg .ok  { color: var(--success); font-weight: 600; }
.instr-bar__msg .err { color: var(--danger); font-weight: 600; }

/* ── 11. KEYBOARD KEY ──────────────────────────────────────────────────── */
.kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: var(--ls-kbd);
  color: var(--ink-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  line-height: 1.2;
  vertical-align: middle;
}

/* ── 12. RESULT OVERLAY (end-of-game) ──────────────────────────────────── */
.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-slow) var(--ease);
  text-align: center;
}
.result-overlay.is-shown {
  opacity: 1;
  pointer-events: auto;
}
.result-overlay__title {
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 400;
  line-height: var(--lh-display);
  letter-spacing: var(--ls-display);
  color: var(--accent);
}
.result-overlay__scores {
  display: flex;
  gap: var(--space-7);
  padding: var(--space-3) var(--space-7);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: var(--space-3) 0;
}
.result-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border: 1px solid var(--success);
  color: var(--success);
  border-radius: var(--r-pill);
  font-size: var(--fs-caption);
  font-weight: 600;
}

@media (max-width: 480px) {
  .result-overlay__scores { gap: var(--space-4); padding: var(--space-3); }
}

/* ── 13. THEME TOGGLE (sun/moon icon button) ───────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  cursor: pointer;
  transition: all var(--t-base) var(--ease);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── 14. PAGE / CONTAINER ──────────────────────────────────────────────── */
.page {
  width: 100%;
  max-width: var(--container-base);
  margin: 0 auto;
  padding: 0 var(--space-5);
}
.page--narrow { max-width: var(--container-narrow); }
.page--wide   { max-width: var(--container-wide); }

/* ── 15. HEADER BLOCK (eyebrow + title + optional theme toggle row) ────── */
.header-block {
  padding: var(--space-7) 0 var(--space-3);
}
.header-block__row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}
.header-block__title {
  font-size: var(--fs-h1);
  line-height: var(--lh-h1);
  letter-spacing: var(--ls-h1);
  margin-top: var(--space-2);
}
.header-block__tagline {
  font-size: var(--fs-body);
  color: var(--ink-muted);
  margin-top: var(--space-2);
  max-width: 540px;
  line-height: var(--lh-lead);
}

/* ── 15b. TOP BAR (v2.1 — shared chrome across dashboard + all 12 games) ── */
/* Composition: wordmark · back arrow (games only) · glyph+name (games only) ·
   progress (games only) · spacer · theme toggle. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar__wordmark {
  font-family: var(--font-display);
  font-size: 24px;
  line-height: 1;
  letter-spacing: var(--ls-display);
  color: var(--brand);
  text-decoration: none;
}
.topbar__wordmark:hover { opacity: 0.85; color: var(--brand); }
.topbar__game {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--accent); /* glyph inherits the game tint via currentColor */
}
.topbar__glyph { width: 20px; height: 20px; flex-shrink: 0; }
.topbar__glyph svg {
  width: 100%; height: 100%;
  fill: none; stroke: currentColor;
  stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round;
}
.topbar__name {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-ui-sm);
  color: var(--ink);
}
.topbar__progress {
  font-family: var(--font-body);
  font-size: var(--fs-caption);
  color: var(--brand);
}
.topbar__spacer { flex: 1; }
/* Top bar is wordmark + theme toggle only (2026-05-31) — the page header below
   carries the game name + number, so the glyph / name / progress are all hidden
   here to keep the bar identical across the whole site. */
.topbar__game, .topbar__progress { display: none; }
@media (max-width: 560px) {
  .topbar { gap: var(--space-3); padding: var(--space-3) var(--space-4); }
  .topbar__name { display: none; }
}

/* ── 15c. RESULT-SCREEN ILLUSTRATION (per-game glyph as the result "moment") ── */
.result-illustration {
  width: 76px;
  height: 76px;
  color: var(--accent); /* inherits the game tint */
  margin: 0 auto var(--space-2); /* centre uniformly across all 12 games (3.9a) */
}
.result-illustration svg { width: 100%; height: 100%; }
.result-illustration .halo { color: var(--accent-soft); }

/* ── 16. UTILITY ───────────────────────────────────────────────────────── */
.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;
}

.center { text-align: center; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
