/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/*
 * ── Design tokens ─────────────────────────────────────────────
 *
 * Canonical tokens (colors, font, type scale, spacing, radii) come from the CDN:
 *   https://cdn.neorgon.org/v1.0.0/styles/base.css   (linked in index.html)
 * Do NOT redeclare them here — a local copy is how the fleet drifted. The block
 * below holds only what base.css does not define, plus the per-site accent.
 *
 * Motion: base.css still ships --ease-snap (bounce) for legacy sites, but it is
 * deprecated for new work (impeccable law: ease-out exponential, no bounce).
 * Use --ease-out below.
 */

:root {
  /* Per-site identity — set to this site's hub card accent (PROJECTS.md section 4) */
  --accent: #a855f7;
  --accent-bright: #c084fc;
  /* Set per game module by render.js, so each game tints its own surfaces. */
  --game-accent: #a855f7;

  /* Site extras base.css does not define */
  --surface-toast: #1a1730;
  --danger: #e11d48;
  --danger-hover: #f43f5e;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --control-height: 44px;
  --control-height-sm: 36px;
  --shadow-card: 0 12px 28px rgba(15, 23, 42, 0.5);
  --shadow-modal: 0 24px 48px rgba(2, 6, 23, 0.58);
  --z-sticky-header: 200;
  --z-modal: 400;
  --z-toast: 500;
}

/* Author display values (e.g. .section/.stack flex) would otherwise defeat the
   hidden attribute — restore its authority once, globally. */
[hidden] { display: none !important; }

html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100%;
  color: var(--text-primary);
  display: flex; flex-direction: column;
}

body.modal-open {
  overflow: hidden;
}

main#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

/* ── Layout ────────────────────────────────────────────────── */
/*
 * GOTCHA: body { display:flex; flex-direction:column } + margin: 0 auto
 * on a child collapses its width — always pair with width: 100%.
 *
 * GOTCHA: External images (YouTube ggpht, Gravatar, etc.) may block loading
 * when the Referer header points to localhost or an unknown origin. Fix:
 * 1. Add <meta name="referrer" content="no-referrer"> in <head> (global)
 * 2. Or add referrerpolicy="no-referrer" on each <img> tag
 */
.container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6);
  flex: 1;
}

/* Vertical rhythm: use inside .container or nested regions */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.stack--tight { gap: var(--space-4); }
/* 32px between major sections read as "no space at all" once the sections had
   headings of their own. Separate them the way a page break would. */
.stack--loose { gap: 56px; }

/* Page section: title row + body (replaces “card everything” for grouping) */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
}
.section__titles {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
.section__title {
  font-size: var(--text-xl);
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}
.section__lead {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 64ch;
}
.section__lead code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  color: var(--text-secondary);
}
.stack > .card { margin-bottom: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ── Header ────────────────────────────────────────────────────
 * Owned by the Neorgon Header Kit (css/neorgon-header.css — canonical
 * source: packages/neorgon-ui/header/). Do NOT style .header-bar,
 * .header-logo*, .header-title-link, .header-subtitle, .header-right,
 * .header-actions, or .header-home here. Auth styles (.auth-*) stay
 * site-owned below.
 */
nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ── Buttons (canonical) ─────────────────────────────────────
 * Use .btn + a variant. Aliases: .nav-link = toolbar ghost; .auth-* map below.
 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  transition:
    background-color var(--dur),
    color var(--dur),
    border-color var(--dur),
    box-shadow var(--dur),
    transform var(--dur-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn--sm {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn--block { width: 100%; }
.btn--icon {
  min-width: var(--control-height);
  padding: 0;
}
.btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.btn--primary:hover { background: var(--accent-bright); }
.btn--secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}
.btn--ghost {
  background: transparent;
  color: rgba(255,255,255,0.92);
  border-color: rgba(255,255,255,0.18);
}
.btn--ghost:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}
.btn--danger:hover { background: var(--danger-hover); }

/* Toolbar ghost (header nav) — same as .btn.btn--ghost.btn--sm */
.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255,255,255,0.92);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.nav-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.auth-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: 0;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255,255,255,0.92);
  cursor: pointer;
  font-family: inherit;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-toggle:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.auth-toggle svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
}
.auth-toggle.logged-in { color: var(--accent); }
.auth-toggle.logged-in svg circle:nth-of-type(2) {
  fill: currentColor;
  stroke: none;
}

/* ── Sheet (inline panel under header) — not a modal ─────────
 * Use for auth, filters, compact forms. No backdrop; page scrolls.
 * For blocking overlays use .modal below.
 */
.auth-panel {
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border-subtle);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}
.auth-panel.open { max-height: 300px; }
.auth-panel-inner {
  padding: var(--space-6);
  max-width: 400px;
  margin: 0 auto;
}
.auth-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.auth-tab {
  flex: 1;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-tab.active {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.auth-form input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
}
.auth-submit {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background-color var(--dur);
}
.auth-submit:hover { background: var(--accent-bright); }
#authUser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.auth-username {
  color: var(--text-primary);
  font-weight: 600;
}
.auth-logout {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-logout:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.auth-divider {
  height: 1px;
  background: var(--border-subtle);
}

/* ── Modal (blocking overlay) ──────────────────────────────── */
.modal[hidden] {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 12, 0.85);
  -webkit-backdrop-filter: blur(10px); /* Safari still needs the prefix */
  backdrop-filter: blur(10px);
}
.modal__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  max-height: min(90vh, 680px);
  overflow: hidden;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
}
/* For modals holding option grids or editors — narrow dialogs cramp them */
.modal__dialog--wide {
  width: min(100%, 760px);
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.modal__header h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}
.modal__body {
  padding: var(--space-6);
  overflow: auto;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.55;
}
.modal__body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  color: var(--text-primary);
}
.modal__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
}

/* ── Card ──────────────────────────────────────────────────── */
/*
 * GOTCHA: backdrop-filter creates a stacking context — dropdowns inside
 * a card can be clipped by a later card's stacking context. Fix by adding
 * position: relative; z-index: 10 to the card that owns the open dropdown.
 *
 * Default: static surface (no hover lift — avoids generic “dashboard demo”).
 * Use .card--interactive for raised hover + entrance motion.
 *
 * GOTCHA: a <button> or <a> used AS a card does not inherit body text color —
 * buttons default to canvas text (near-black), rendering invisible on the dark
 * bg. When a card is an interactive element, set color: var(--text-primary)
 * and font-family: var(--font) explicitly on it.
 */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  backdrop-filter: blur(10px);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.45);
}
.card--interactive {
  transition:
    transform var(--dur) ease-out,
    box-shadow var(--dur) ease-out,
    border-color var(--dur);
  animation: fadeIn 0.35s ease-out both;
}
.card--interactive:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
  border-color: var(--border-strong);
}
.card--enter {
  animation: fadeIn 0.35s ease-out both;
}
.card--flat:hover {
  box-shadow: none;
}
/* Card with an action row, in an equal-height grid: pin the toolbar to the
   bottom so buttons align across cards whose text wraps differently. */
.card--actions {
  display: flex;
  flex-direction: column;
}
.card--actions > .toolbar:last-child {
  margin-top: auto;
}

/* ── Button press feedback ─────────────────────────────────── */
button:active,
.btn:active,
.nav-link:active,
.auth-toggle:active,
.auth-tab:active,
.auth-submit:active,
.auth-logout:active {
  transform: scale(0.98);
  transition-duration: var(--dur-fast);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Skeleton loading ──────────────────────────────────────── */
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  max-width: min(360px, calc(100vw - var(--space-8)));
  background: var(--surface-toast);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  pointer-events: none;
  transform: translateY(8px);
  opacity: 0;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Footer ────────────────────────────────────────────────────
   Owned by the Neorgon Footer Kit (css/neorgon-footer.css).
   Don't add .neo-footer rules here — edit packages/neorgon-ui/footer/
   and re-run sync-footer.sh. */

/* ── Focus styles ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* ── Skip link ─────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent-bright);
  color: #000;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--dur);
}
.skip-link:focus { top: 0; }

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .card--interactive:hover { transform: none; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .container { padding: var(--space-4); }
  .toast {
    left: var(--space-4);
    right: var(--space-4);
    max-width: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Gamme app
   ═══════════════════════════════════════════════════════════════ */

.app-shell {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
  align-content: start;
}
.app-shell > * { min-width: 0; }

/* Desktop moves the section nav into the left gutter that was empty anyway,
   which also narrows the reading column toward a comfortable measure instead
   of stretching every paragraph across the full window. */
@media (min-width: 940px) {
  .app-shell {
    grid-template-columns: 208px minmax(0, 1fr);
    gap: var(--space-8);
    padding: var(--space-8) var(--space-8) 80px;
  }
}

/* ── Header skin: cosy wood ────────────────────────────────────
 * The one sanctioned exception to "no site-local header CSS": a site-authored
 * `custom` skin, tokens only. The selector below is copied exactly from
 * packages/neorgon-ui/header/README.md, because the scoping IS the contract:
 *
 *   html:not([data-theme])  collapses the skin the moment a visitor picks a
 *                           theme with ?theme= , so visitor choice still wins.
 *   [data-header-skin]      lands at (0,3,1): above the kit default, below an
 *                           armed season, which is the precedence the fleet uses.
 *
 * Warm walnut into a dark table edge, so the bar reads like the side of a
 * boardgame box rather than a product header.
 */
html:not([data-theme]) .header-bar[data-header-skin="custom"] {
  --header-bg-start: #6b3f23;
  --header-bg-mid:   #4a2b17;
  --header-bg-end:   #24150b;
  --header-accent:   #e8b979;

  /* The grain. Still tokens only: the kit composes --header-bg ON .header-bar
     precisely so a skin can replace it, and its own comment says so. Three
     layers over the base ramp, all of them low alpha so the header text keeps
     its contrast: fine grain, a slower cathedral figure, then two plank seams.
     No image, no request, and it re-skins with the season like any other value. */
  --header-bg:
    repeating-linear-gradient(94deg,
      rgba(0, 0, 0, .10) 0px, rgba(0, 0, 0, .10) 1px,
      rgba(255, 214, 160, .035) 1px, rgba(255, 214, 160, .035) 3px,
      transparent 3px, transparent 7px),
    repeating-linear-gradient(87deg,
      rgba(0, 0, 0, .07) 0px, rgba(0, 0, 0, .07) 2px,
      transparent 2px, transparent 29px),
    linear-gradient(to bottom,
      rgba(255, 226, 183, .05) 0 1px,
      transparent 1px calc(100% - 1px),
      rgba(0, 0, 0, .22) calc(100% - 1px) 100%),
    linear-gradient(in oklch 135deg,
      var(--header-bg-start) 0%, var(--header-bg-mid) 52%, var(--header-bg-end) 100%);

  /* Warm the bottom ramp to match, instead of the cool default hairline. */
  --header-edge-from: rgba(255, 205, 145, .12);
  --header-edge-to:   rgba(255, 205, 145, .30);
}

/* ── Section nav: a row on mobile, a rail on desktop ───────── */
.viewnav {
  display: flex;
  gap: var(--space-1);
  padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  scrollbar-width: none;
}
.viewnav::-webkit-scrollbar { display: none; }

.viewtab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur), color var(--dur);
}
.viewtab:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.05); }
.viewtab.is-active {
  background: color-mix(in srgb, var(--game-accent) 20%, transparent);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--game-accent) 45%, transparent);
}

@media (min-width: 940px) {
  .viewnav {
    position: sticky;
    top: 76px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: var(--space-2);
    overflow: visible;
    align-self: start;
  }
  .viewtab {
    min-height: 44px;
    text-align: left;
    padding: 0 var(--space-3);
    display: flex;
    align-items: center;
  }
  /* An accent spine reads as "you are here" without shouting. */
  .viewtab.is-active {
    background: color-mix(in srgb, var(--game-accent) 14%, transparent);
    box-shadow: inset 3px 0 0 var(--game-accent);
  }
}

/* ── Game switcher menu ────────────────────────────────────────
 * The panel is the Header Kit's .header-menu: it owns the box, the shadow,
 * the open animation and the a11y. The kit's stylesheet loads after this one,
 * so a site-local .header-menu rule loses anyway. Only the row contents here.
 */
.menudot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.menutext { display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left; }
.menutext small { line-height: 1.4; }
/* Without a cap the taglines make a 450px dropdown out of a 180px control. */
.header-menu__item { max-width: 320px; }
.menutext small { color: var(--text-muted); font-size: var(--text-xs); font-weight: 400; }
.header-menu__item { display: flex; align-items: center; gap: var(--space-3); width: 100%; }
.header-menu__item.is-active .menutext strong { color: var(--game-accent); }

/* ── The core rule banner ──────────────────────────────────── */
.corerule {
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--game-accent) 40%, transparent);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--game-accent) 14%, transparent),
      transparent 65%),
    var(--surface-1);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.corerule__kicker {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--game-accent);
}
.corerule__title { font-size: var(--text-xl); font-weight: 650; }
.corerule__body { color: var(--text-secondary); line-height: 1.7; max-width: 62ch; }
.corerule__formula {
  align-self: flex-start;
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

/* ── Pattern cards ─────────────────────────────────────────── */
.patterngrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-6);
}
.pcard {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.pcard:hover {
  border-color: color-mix(in srgb, var(--game-accent) 45%, var(--border));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}
.pcard__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.pcard__name { font-size: var(--text-base); font-weight: 650; }
.pcard__acc {
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pcard__acc.is-untested { color: var(--text-muted); }
.pcard__acc.is-good { color: #4ade80; border-color: rgba(74, 222, 128, 0.4); }
.pcard__acc.is-mid  { color: #fbbf24; border-color: rgba(251, 191, 36, 0.4); }
.pcard__acc.is-bad  { color: #fb7185; border-color: rgba(251, 113, 133, 0.4); }
.pcard__diagram { display: flex; justify-content: center; }
.pcard__rows { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--space-3); margin: 0; }
.pcard__rows dt {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--game-accent);
  padding-top: 2px;
}
.pcard__rows dd { margin: 0; font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.5; }
.pcard__why summary {
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
}
.pcard__why summary::-webkit-details-marker { display: none; }
.pcard__why summary::before { content: '+ '; color: var(--game-accent); }
.pcard__why[open] summary::before { content: '- '; }
.pcard__why p {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}
.pcard__tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Diagrams ──────────────────────────────────────────────── */
.diagram { margin: 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.diagram figcaption {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
  max-width: 34ch;
  line-height: 1.45;
}
.msmini {
  display: grid;
  grid-template-columns: repeat(var(--cols), 30px);
  gap: 2px;
}
.msmini__c {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.msmini__c.is-open { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.09); }
.msmini__c.is-void { background: transparent; border: 1px dashed rgba(255, 255, 255, 0.14); }
.msmini__c.is-safe {
  background: rgba(74, 222, 128, 0.18);
  border-color: rgba(74, 222, 128, 0.5);
  color: #4ade80;
}
.msmini__c.is-minemark {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.5);
  color: #fb7185;
}
.algebra {
  display: flex; flex-direction: column; gap: 4px;
  padding: var(--space-3) var(--space-4);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.algebra code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-secondary); }
.algebra__result {
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--game-accent) !important;
  font-weight: 700;
}

/* ── The Minesweeper board ─────────────────────────────────── */
.boardwrap { display: flex; justify-content: center; width: 100%; overflow-x: auto; padding-bottom: 4px; }
.msboard {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell, 30px));
  gap: 2px;
  padding: var(--space-3);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: max-content;
}
.mscell {
  width: var(--cell, 30px);
  height: var(--cell, 30px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-top-color: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  background: #2b2545;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: calc(var(--cell, 30px) * 0.52);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  position: relative;
  transition: background-color 0.12s var(--ease-out), transform 0.1s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mscell:hover:not(.is-open) { background: #3a3159; }
.mscell.is-open {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
  border-top-color: rgba(255, 255, 255, 0.05);
  cursor: default;
}
.mscell.is-flag { color: #fbbf24; }
.mscell.is-wrongflag { background: rgba(244, 63, 94, 0.2); }
.mscell.is-mine { background: rgba(244, 63, 94, 0.18); color: #fb7185; }
.mscell.is-boom { background: #f43f5e; color: #fff; }
.mscell.mark-safe { background: rgba(74, 222, 128, 0.24); color: #4ade80; border-color: rgba(74, 222, 128, 0.5); }
.mscell.mark-mine { background: rgba(244, 63, 94, 0.24); color: #fb7185; border-color: rgba(244, 63, 94, 0.5); }

/* Classic number hues, lifted for a dark background. */
.mscell.n1, .msmini__c.n1 { color: #60a5fa; }
.mscell.n2, .msmini__c.n2 { color: #4ade80; }
.mscell.n3, .msmini__c.n3 { color: #fb7185; }
.mscell.n4, .msmini__c.n4 { color: #c084fc; }
.mscell.n5, .msmini__c.n5 { color: #fbbf24; }
.mscell.n6, .msmini__c.n6 { color: #2dd4bf; }
.mscell.n7, .msmini__c.n7 { color: #e2e8f0; }
.mscell.n8, .msmini__c.n8 { color: #94a3b8; }

/* Overlays painted by hints and by drill grading. */
.mscell.ov-safe   { box-shadow: inset 0 0 0 2px #4ade80; }
.mscell.ov-mine   { box-shadow: inset 0 0 0 2px #fb7185; }
.mscell.ov-source { box-shadow: inset 0 0 0 2px var(--game-accent); }
.mscell.ov-hint   { box-shadow: inset 0 0 0 2px #fbbf24; animation: pulseHint 1.2s ease-out infinite; }
.mscell.ov-wrong  { box-shadow: inset 0 0 0 2px #f43f5e; background: rgba(244, 63, 94, 0.3); }
@keyframes pulseHint { 50% { box-shadow: inset 0 0 0 2px rgba(251, 191, 36, 0.35); } }

.mscell.has-odds::after {
  content: attr(data-odds);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell, 30px) * 0.36);
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 3px;
}

/* ── Generic board, used by chess and 2048 ─────────────────── */
.gboard {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), var(--cell, 44px));
  gap: var(--gap, 2px);
  padding: var(--space-2);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: max-content;
  margin: 0 auto;
}
.gcell {
  width: var(--cell, 44px);
  height: var(--cell, 44px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: calc(var(--cell, 44px) * 0.62);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.gcell.is-light { background: #cbd5e1; color: #0f172a; }
.gcell.is-dark  { background: #64748b; color: #0f172a; }
.gcell.is-target { box-shadow: inset 0 0 0 3px var(--game-accent); }
.gcell.is-right  { box-shadow: inset 0 0 0 3px #4ade80; }
.gcell.is-wrong  { box-shadow: inset 0 0 0 3px #f43f5e; }
.gcell.is-hint   { box-shadow: inset 0 0 0 3px #fbbf24; }

/* ── Stats strip ───────────────────────────────────────────── */
.statbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-2) var(--space-4);
  min-width: 92px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat__label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.stat__value { font-size: var(--text-sm); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ── Drills ────────────────────────────────────────────────── */
.drillbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}
.drillbar__pos { font-weight: 700; }
.drillbar__score { color: var(--text-muted); font-size: var(--text-sm); }
.drillbar__clock { margin-left: auto; color: var(--game-accent); font-weight: 700; }
.drillprompt {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.4;
  max-width: 60ch;
}
.drillstage { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); }

.levelgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-3);
}
.levelcard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-4);
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--dur), background-color var(--dur);
}
.levelcard:hover { border-color: var(--border-strong); }
.levelcard.is-active {
  border-color: var(--game-accent);
  background: color-mix(in srgb, var(--game-accent) 12%, var(--surface-1));
}
.levelcard__n { font-size: 10px; font-weight: 800; letter-spacing: 0.1em; color: var(--game-accent); }
.levelcard__name { font-weight: 650; }
.levelcard__blurb { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.45; }

.choicegrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-2);
  width: 100%;
  max-width: 560px;
}
.choice {
  min-height: 46px;
  padding: 0 var(--space-4);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur), border-color var(--dur);
}
.choice:hover { background: var(--surface-2); border-color: var(--game-accent); }
.choice.is-picked { border-color: var(--game-accent); background: color-mix(in srgb, var(--game-accent) 18%, var(--surface-1)); }
.choice.is-right { border-color: #4ade80; background: rgba(74, 222, 128, 0.16); }
.choice.is-wrong { border-color: #f43f5e; background: rgba(244, 63, 94, 0.16); }

.feedback {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  animation: fadeIn 0.25s var(--ease-out) both;
}
.feedback.is-right { border-color: rgba(74, 222, 128, 0.45); background: rgba(74, 222, 128, 0.08); }
.feedback.is-wrong { border-color: rgba(244, 63, 94, 0.45); background: rgba(244, 63, 94, 0.08); }
.feedback__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.feedback__head strong { font-size: var(--text-lg); }
.feedback.is-right .feedback__head strong { color: #4ade80; }
.feedback.is-wrong .feedback__head strong { color: #fb7185; }
.feedback__time { font-size: var(--text-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.feedback__detail { color: var(--text-secondary); line-height: 1.65; max-width: 68ch; }

/* ── Scoreboard ────────────────────────────────────────────── */
.scoretable { display: flex; flex-direction: column; gap: 6px; }
.scorerow {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 140px 62px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.scorerow__tier { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.scorerow__name { font-size: var(--text-sm); font-weight: 600; }
.scorerow__pct { font-size: var(--text-xs); color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.meter { display: block; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter__fill { display: block; height: 100%; border-radius: 999px; transition: width 0.4s var(--ease-out); }
.meter__fill.is-good { background: #4ade80; }
.meter__fill.is-mid  { background: #fbbf24; }
.meter__fill.is-bad  { background: #fb7185; }
.meter__fill.is-empty { background: transparent; }

/* ── Rules tab ─────────────────────────────────────────────── */
.ruletable { display: flex; flex-direction: column; gap: var(--space-3); }
.rulerow {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
  padding: var(--space-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.rulerow__name { display: flex; flex-direction: column; gap: var(--space-2); }
.rulerow__body { font-size: var(--text-sm); color: var(--text-secondary); line-height: 1.65; max-width: 68ch; }
.ruleswitch { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); cursor: pointer; }
.ruleswitch input { width: 18px; height: 18px; accent-color: var(--game-accent); cursor: pointer; }

.select {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.presetrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); }
.preset {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-4);
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--dur), background-color var(--dur);
}
.preset:hover { border-color: var(--game-accent); background: var(--surface-2); }
.preset small { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.45; }

.measure { margin-top: var(--space-3); }
.measure__note { margin-top: var(--space-3); font-size: var(--text-xs); color: var(--text-muted); line-height: 1.55; max-width: 70ch; }

/* ── Notices and callouts ──────────────────────────────────── */
.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.55;
}
.notice--warn { border-color: rgba(251, 191, 36, 0.45); background: rgba(251, 191, 36, 0.08); }
.notice--good { border-color: rgba(74, 222, 128, 0.45); background: rgba(74, 222, 128, 0.08); }
.notice__sub { margin-top: var(--space-2); color: var(--text-muted); }
.callout {
  padding: var(--space-4);
  border-left: 3px solid var(--game-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-1);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}
.callout--warn { border-left-color: #fbbf24; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px var(--space-4); margin: 0; }
.kv__k { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.kv__v { font-size: var(--text-sm); color: var(--text-secondary); }

/* ── Tables ────────────────────────────────────────────────── */
.progblock { margin-bottom: var(--space-6); }
.progblock__title { font-size: var(--text-base); font-weight: 650; margin-bottom: var(--space-2); }
.progtable { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.progtable th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.progtable td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.progtable tr.is-untested td { color: var(--text-muted); }
.progtable td.is-bad { color: #fb7185; font-weight: 700; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 860px) {
  .rulerow { grid-template-columns: 1fr; gap: var(--space-2); }
  .scorerow { grid-template-columns: minmax(0, 1fr) 100px 52px; }
  .scorerow__tier { display: none; }
}
@media (max-width: 700px) {
  .app-shell { padding: var(--space-4) var(--space-4) var(--space-8); gap: var(--space-4); }
  .msboard { --cell: 26px; padding: var(--space-2); }
  .gboard, .chess-frame { --cell: 38px; }
  .drillprompt { font-size: var(--text-base); }
  .patterngrid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .msboard { --cell: 22px; }
  .gboard, .chess-frame { --cell: 34px; }
  .msmini { grid-template-columns: repeat(var(--cols), 26px); }
  .msmini__c { width: 26px; height: 26px; font-size: 12px; }
}

/* ── Chess ─────────────────────────────────────────────────── */
.chess-frame { display: flex; gap: 4px; justify-content: center; align-items: stretch; max-width: 100%; overflow-x: auto; }
.chess-ranks {
  display: grid;
  grid-template-rows: repeat(8, var(--cell, 44px));
  align-items: center;
  padding-top: var(--space-2);
}
.chess-ranks span, .chess-files span {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.chess-mid { display: flex; flex-direction: column; }
.chess-files {
  display: grid;
  grid-template-columns: repeat(8, var(--cell, 44px));
  padding: 0 var(--space-2);
}
.chess-board .gcell { font-size: calc(var(--cell, 44px) * 0.72); }
.chess-board .chess-white { color: #f8fafc; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
.chess-board .chess-black { color: #0b1020; }
.chess-frame--mini { --cell: 26px; }
.chess-frame--mini .chess-ranks, .chess-frame--mini .chess-files { display: none; }
.chess-hint { font-size: var(--text-xs); color: var(--text-muted); text-align: center; }
