/*
 * Nine's Table — the shared theme layer for Nine's Lives.
 * Both modes use the same paper-card and paired-pip grammar;
 * Mint Table by day, neutral charcoal and ash after dark.
 */

:root {
  --theme-font-body: "Aptos", "Segoe UI Variable Text", "Segoe UI", sans-serif;
  --theme-font-display: "Arial Rounded MT Bold", "Trebuchet MS", "Leelawadee UI", sans-serif;
  --theme-font-display-light: var(--theme-font-display);
  --theme-font-display-dark: var(--theme-font-display);
  --theme-font-utility: "Cascadia Code", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --theme-card-radius: 18px;
  --theme-button-radius: 12px;
  --theme-focus-width: 3px;
  --theme-focus-offset: 3px;
}

html:root[data-theme="light"] {
  color-scheme: light;
  --theme-bg: #bdf7ea;
  --theme-bg-deep: #86ead8;
  --theme-surface: #fbfffd;
  --theme-surface-soft: #f3faf7;
  --theme-surface-muted: #e9f7f2;
  --theme-ink: #172128;
  --theme-muted: #607078;
  --theme-quiet: #657772;
  --theme-line: #dcebe6;
  --theme-border: rgba(23, 33, 40, 0.14);
  --theme-accent: #0b7f73;
  --theme-accent-strong: #075f56;
  --theme-accent-soft: rgba(11, 127, 115, 0.13);
  --theme-coral: #ff704d;
  --theme-saffron: #ffc857;
  --theme-blue: #4d7cfe;
  --theme-success: #07856e;
  --theme-danger: #bd3b32;
  --theme-danger-soft: rgba(189, 59, 50, 0.12);
  --theme-topbar: rgba(251, 255, 253, 0.94);
  --theme-shadow-color: rgba(30, 93, 80, 0.14);
  --theme-card-shadow: 0 18px 50px rgba(30, 93, 80, 0.14);
  --theme-button-text: #ffffff;
  --theme-dot-a: rgba(255, 255, 255, 0.72);
  --theme-dot-b: rgba(255, 255, 255, 0.5);
  --theme-focus-color: #075f56;
  --theme-focus-halo: rgba(7, 95, 86, 0.2);
  --theme-display: var(--theme-font-display);
}

html:root[data-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #1C1C1E;
  --theme-bg-deep: #242426;
  --theme-surface: #2A2A2D;
  --theme-surface-soft: #232325;
  --theme-surface-muted: #333336;
  --theme-ink: #F0F0EE;
  --theme-muted: #B9B9BD;
  --theme-quiet: #A3A3A8;
  --theme-line: rgba(240, 240, 238, 0.16);
  --theme-border: rgba(240, 240, 238, 0.16);
  --theme-accent: #C6C6CD;
  --theme-accent-strong: #E2E2E5;
  --theme-accent-soft: rgba(198, 198, 205, 0.14);
  --theme-coral: #FF8A70;
  --theme-saffron: #F4C95D;
  --theme-blue: #79A5FF;
  --theme-success: #72D9B8;
  --theme-danger: #FF9C93;
  --theme-danger-soft: rgba(255, 156, 147, 0.14);
  --theme-topbar: rgba(28, 28, 30, 0.94);
  --theme-shadow-color: rgba(0, 0, 0, 0.48);
  --theme-card-shadow: 0 1px 0 rgba(240, 240, 238, 0.05), 0 20px 48px rgba(0, 0, 0, 0.42);
  --theme-button-text: #1c1c1e;
  --theme-dot-a: rgba(240, 240, 238, 0.045);
  --theme-dot-b: rgba(240, 240, 238, 0.025);
  --theme-focus-color: #F4C95D;
  --theme-focus-halo: rgba(244, 201, 93, 0.2);
  --theme-display: var(--theme-font-display);
}

/* Canonical tokens plus adapters for legacy project naming systems. */
html:root[data-theme] {
  background: var(--theme-bg);
  color: var(--theme-ink);
  font-family: var(--theme-font-body);
  --accent: var(--theme-accent);
  --accent-2: var(--theme-saffron);
  --accent-3: var(--theme-coral);
  --accent-soft: var(--theme-accent-soft);
  --accent-strong: var(--theme-accent-strong);
  --amber: var(--theme-saffron);
  --ambient-dot-a: var(--theme-dot-a);
  --ambient-dot-b: var(--theme-dot-b);
  --bg: var(--theme-bg);
  --bg-strong: var(--theme-surface-soft);
  --border: var(--theme-border);
  --button-text: var(--theme-button-text);
  --card: color-mix(in srgb, var(--theme-surface) 86%, transparent);
  --card-border: color-mix(in srgb, var(--theme-surface) 86%, var(--theme-border));
  --card-strong: var(--theme-surface);
  --coral: var(--theme-coral);
  --cyan: var(--theme-accent);
  --danger: var(--theme-danger);
  --danger-soft: var(--theme-danger-soft);
  --dim: var(--theme-quiet);
  --emerald: var(--theme-success);
  --gold: var(--theme-saffron);
  --highlight-color: var(--theme-accent);
  --ink: var(--theme-ink);
  --line: var(--theme-line);
  --line-strong: color-mix(in srgb, var(--theme-ink) 26%, transparent);
  --muted: var(--theme-muted);
  --panel: color-mix(in srgb, var(--theme-surface) 88%, transparent);
  --panel-3: var(--theme-surface-muted);
  --panel2: var(--theme-surface-soft);
  --panel-shadow: var(--theme-shadow-color);
  --panel-soft: var(--theme-surface-soft);
  --panel-strong: var(--theme-surface);
  --paper: var(--theme-surface);
  --pool: var(--theme-bg);
  --pool-deep: var(--theme-bg-deep);
  --positive: var(--theme-success);
  --project-accent: var(--theme-accent);
  --project-accent-2: var(--theme-saffron);
  --quiet-text: var(--theme-quiet);
  --rose: var(--theme-coral);
  --saffron: var(--theme-saffron);
  --shadow: var(--theme-card-shadow);
  --shadow-card: var(--theme-card-shadow);
  --signal: var(--theme-saffron);
  --success: var(--theme-success);
  --success-soft: color-mix(in srgb, var(--theme-success) 13%, transparent);
  --text: var(--theme-ink);
  --topbar: var(--theme-topbar);
  --violet: color-mix(in srgb, var(--theme-blue) 62%, var(--theme-coral));

  --focus-color: var(--theme-focus-color);
  --focus-halo: var(--theme-focus-halo);
  --focus-offset: var(--theme-focus-offset);
  --focus-width: var(--theme-focus-width);

  --bench-body: var(--theme-font-body);
  --bench-display: var(--theme-display);
  --bench-mono: var(--theme-font-utility);
  --font-body: var(--theme-font-body);
  --font-display: var(--theme-display);
  --font-stack: var(--theme-font-body);
  --font-timer: var(--theme-font-utility);
  --font-utility: var(--theme-font-utility);

  --action-shadow: #000000;
  --action-surface: var(--theme-ink);
  --action-text: var(--theme-button-text);
  --computed-surface: color-mix(in srgb, var(--theme-saffron) 32%, var(--theme-surface));
  --divider: color-mix(in srgb, var(--theme-ink) 10%, transparent);
  --edit-hover: var(--theme-surface-muted);
  --empty-text: var(--theme-quiet);
  --fuse-border: color-mix(in srgb, var(--theme-saffron) 52%, var(--theme-line));
  --fuse-core: color-mix(in srgb, var(--theme-saffron) 7%, var(--theme-surface));
  --fuse-surface: color-mix(in srgb, var(--theme-saffron) 18%, var(--theme-surface));
  --fuse-track: color-mix(in srgb, var(--theme-saffron) 34%, var(--theme-surface));
  --focus-bg: var(--theme-bg);
  --focus-shell: var(--theme-surface);
  --focus-panel: var(--theme-surface-soft);
  --focus-line: var(--theme-line);
  --focus-green: var(--theme-accent);
  --focus-ink: var(--theme-ink);
  --focus-muted: var(--theme-muted);
  --glass-border: color-mix(in srgb, var(--theme-surface) 72%, var(--theme-border));
  --glass-soft: color-mix(in srgb, var(--theme-surface) 68%, transparent);
  --glass-soft-border: color-mix(in srgb, var(--theme-surface) 62%, var(--theme-border));
  --glass-surface: color-mix(in srgb, var(--theme-surface) 76%, transparent);
  --inline-field: var(--theme-surface);
  --input-surface: var(--theme-surface-soft);
  --operator-shadow: color-mix(in srgb, var(--theme-coral) 70%, #000000);
  --operator-surface: var(--theme-surface-muted);
  --score-panel: var(--theme-surface-soft);
  --secondary-surface: var(--theme-surface-muted);
  --subtle-surface: var(--theme-surface-muted);
  --team-rule-base: var(--theme-surface);
  --trail-surface: var(--theme-surface-muted);

  --ledger-bg: var(--theme-bg);
  --ledger-sheet: var(--theme-surface);
  --ledger-ink: var(--theme-ink);
  --ledger-muted: var(--theme-muted);
  --ledger-line: var(--theme-line);
  --ledger-green: var(--theme-accent);
  --ledger-green-dark: var(--theme-accent-strong);
  --ledger-gold: var(--theme-saffron);
  --ledger-danger: var(--theme-danger);
  --ledger-blue: var(--theme-blue);
  --ledger-shadow: var(--theme-card-shadow);

  --sleep-ink: var(--theme-ink);
  --sleep-paper: var(--theme-bg);
  --sleep-panel: var(--theme-surface);
  --sleep-panel-soft: var(--theme-surface-soft);
  --sleep-line: var(--theme-line);
  --sleep-muted: var(--theme-muted);
  --sleep-green: var(--theme-accent);
  --sleep-mauve: var(--theme-coral);
  --sleep-amber: var(--theme-saffron);
  --sleep-red: var(--theme-danger);
  --sleep-shadow: var(--theme-card-shadow);

  --reply-frost: var(--theme-bg);
  --reply-ink: var(--theme-ink);
  --reply-mint: var(--theme-bg-deep);
  --reply-teal: var(--theme-accent);
  --reply-coral: var(--theme-coral);
  --reply-fog: var(--theme-surface-muted);
  --reply-paper: var(--theme-surface);
  --reply-muted: var(--theme-muted);
  --reply-line: var(--theme-line);
  --reply-soft-mint: color-mix(in srgb, var(--theme-accent) 12%, var(--theme-surface));
  --reply-soft-coral: color-mix(in srgb, var(--theme-coral) 10%, var(--theme-surface));
  --reply-shadow: var(--theme-card-shadow);
}

/* Body-level aliases beat project-local body tokens without touching layout. */
html:root[data-theme] body.project-page.project-page {
  --accent: var(--project-accent, var(--theme-accent));
  --accent-2: var(--project-accent-2, var(--theme-saffron));
  --accent-3: var(--theme-coral);
  --accent-soft: color-mix(in srgb, var(--project-accent, var(--theme-accent)) 14%, transparent);
  --accent-strong: color-mix(in srgb, var(--project-accent, var(--theme-accent)) 78%, var(--theme-ink));
  --bg: var(--theme-bg);
  --bg-strong: var(--theme-surface-soft);
  --border: var(--theme-border);
  --button-text: var(--theme-button-text);
  --card: color-mix(in srgb, var(--theme-surface) 88%, transparent);
  --card-strong: var(--theme-surface);
  --ink: var(--theme-ink);
  --line: var(--theme-line);
  --muted: var(--theme-muted);
  --panel: color-mix(in srgb, var(--theme-surface) 90%, transparent);
  --panel-strong: var(--theme-surface);
  --panel-shadow: var(--theme-shadow-color);
  --text: var(--theme-ink);
  --topbar: var(--theme-topbar);
  color: var(--theme-ink);
  font-family: var(--theme-font-body);
}

html:root[data-theme] body.project-page.project-page:not(.project-24-game) {
  --shadow: var(--theme-shadow-color);
}

/* The paired, staggered pips are the signature in both rooms. */
html:root[data-theme] body:not(.project-page),
html:root[data-theme] body.project-page.project-page {
  background:
    radial-gradient(circle at 18% 12%, var(--theme-dot-a) 0 4px, transparent 5px) 0 0 / 64px 64px,
    radial-gradient(circle at 82% 88%, var(--theme-dot-b) 0 3px, transparent 4px) 0 0 / 82px 82px,
    var(--theme-bg);
  background-attachment: fixed;
  color: var(--theme-ink);
}

html:root[data-theme] body:not(.project-page) :is(h1, h2, h3),
html:root[data-theme] body.project-page.project-page:not(.project-family-money) :is(h1, h2, h3, .brand-title) {
  font-family: var(--theme-font-display);
  font-stretch: normal;
  letter-spacing: -0.035em;
}

html:root[data-theme] .global-topnav__brand {
  font-family: var(--theme-font-display);
}

html:root[data-theme] body:not(.project-page) :is(.project-card, .project-search-panel, .status-panel, .split),
html:root[data-theme] body.project-page.project-page :is(
  .card,
  .comp-card,
  .hero-card,
  .panel,
  .metric,
  .solver-form-panel,
  .solver-results-panel,
  .settings-card,
  .practice-card,
  .date-card,
  .macro-form,
  .macro-panel,
  .chart-card,
  .upload-panel,
  .folder-path,
  .file-row,
  .board-panel,
  .result-card,
  .format-container,
  .setup-panel,
  .results-panel,
  .login-card,
  .month-board
) {
  border-radius: var(--theme-card-radius);
  box-shadow: var(--theme-card-shadow);
}

html:root[data-theme] body :is(
  .button,
  .cta-button,
  .back-link,
  .download-link,
  .ghost-button,
  .primary-action,
  .directory-link
):not(.theme-toggle) {
  border-radius: var(--theme-button-radius);
}

html:root[data-theme] body :is(input, select, textarea) {
  border-radius: var(--theme-button-radius);
}

html:root[data-theme] body :is(a, button, input, select, textarea):focus-visible {
  box-shadow: 0 0 0 5px var(--theme-focus-halo);
  outline: var(--theme-focus-width) solid var(--theme-focus-color);
  outline-offset: var(--theme-focus-offset);
}

/* TFT shipped as dark-only. These adapters give it a true light mode. */
html:root[data-theme="light"] body.project-tft.project-tft {
  --ink: var(--theme-ink);
  --panel: var(--theme-surface);
  --panel2: var(--theme-surface-soft);
  --panel-3: var(--theme-surface-muted);
  --gold: var(--theme-saffron);
  --cyan: var(--theme-accent);
  --violet: #7657c9;
  --rose: var(--theme-coral);
  --emerald: var(--theme-success);
  --text: var(--theme-ink);
  --muted: var(--theme-muted);
  --dim: var(--theme-quiet);
  --line: var(--theme-line);
  --line-strong: var(--theme-border);
  --shadow-card: var(--theme-card-shadow);
}

html:root[data-theme="light"] body.project-tft.project-tft :is(.card, .comp-card) {
  background: color-mix(in srgb, var(--theme-surface) 90%, transparent);
}

html:root[data-theme="light"] body.project-tft.project-tft :is(
  .metric,
  .icon-btn,
  .level-btn,
  .board-slot,
  .trait-pill,
  .filter-btn,
  .cost-label,
  .emblem-pill,
  .comp-level-tab,
  .comp-trait-chip,
  .load-more-btn
) {
  background: var(--theme-surface-soft);
  color: var(--theme-ink);
}

html:root[data-theme="light"] body.project-tft.project-tft :is(.board-grid, .search-box, .calc-select) {
  background: color-mix(in srgb, var(--theme-bg-deep) 20%, var(--theme-surface));
  color: var(--theme-ink);
}

html:root[data-theme="light"] body.project-tft.project-tft :is(
  h1,
  h2,
  h3,
  .brand-title,
  .metric strong,
  .search-box input,
  .comp-trait-count
) {
  color: var(--theme-ink);
}

html:root[data-theme="light"] body.project-tft.project-tft :is(
  .level-btn.active,
  .trait-pill.active,
  .comp-level-tab.active
) {
  background: var(--theme-accent-soft);
  color: var(--theme-accent-strong);
}

html:root[data-theme="light"] body.project-cryptid.project-cryptid :is(.board-wrap, .piece-board, .map-shell) {
  background: color-mix(in srgb, var(--theme-surface) 92%, transparent);
}

/* Wordont had a second independent dark toggle and inline body colors. */
html:root[data-theme] body.project-wordont.project-wordont {
  background:
    radial-gradient(circle at 18% 12%, var(--theme-dot-a) 0 4px, transparent 5px) 0 0 / 64px 64px,
    radial-gradient(circle at 82% 88%, var(--theme-dot-b) 0 3px, transparent 4px) 0 0 / 82px 82px,
    var(--theme-bg) !important;
  background-attachment: fixed !important;
}

html:root[data-theme="light"] body.project-wordont.project-wordont #game.theme-dark,
html:root[data-theme="dark"] body.project-wordont.project-wordont #game,
html:root[data-theme="dark"] body.project-wordont.project-wordont #game.theme-dark {
  --accent: var(--theme-accent);
  --accent-soft: var(--theme-accent-soft);
  --bg: var(--theme-bg);
  --border: var(--theme-border);
  --button-text: var(--theme-button-text);
  --card: color-mix(in srgb, var(--theme-surface) 86%, transparent);
  --card-strong: var(--theme-surface);
  --muted: var(--theme-muted);
  --panel-shadow: var(--theme-shadow-color);
  --text: var(--theme-ink);
  --topbar: var(--theme-topbar);
}

body.project-wordont .darkMode {
  display: none !important;
}

/* Generated converter styles use OS preference; document theme wins here. */
html:root[data-theme] body.project-converter.project-converter {
  --accent-soft: var(--theme-accent-soft);
  --bg: var(--theme-bg);
  --border: var(--theme-border);
  --button-text: var(--theme-button-text);
  --card: color-mix(in srgb, var(--theme-surface) 88%, transparent);
  --card-strong: var(--theme-surface);
  --highlight-color: var(--theme-accent);
  --muted: var(--theme-muted);
  --panel-shadow: var(--theme-shadow-color);
  --text: var(--theme-ink);
  --topbar: var(--theme-topbar);
}

html:root[data-theme="light"] body.project-converter.project-converter #file-area {
  background:
    radial-gradient(circle at 18% 14%, color-mix(in srgb, var(--theme-coral) 17%, transparent), transparent 28%),
    radial-gradient(circle at 84% 18%, color-mix(in srgb, var(--theme-saffron) 24%, transparent), transparent 30%),
    linear-gradient(135deg, color-mix(in srgb, var(--theme-bg-deep) 30%, var(--theme-surface)), var(--theme-surface));
  border-bottom: 1px solid var(--theme-border);
  color: var(--theme-ink);
}

html:root[data-theme="light"] body.project-converter.project-converter #file-area :is(.step-label, #drop-hint-text, #privacy-note) {
  color: var(--theme-muted);
}

html:root[data-theme="light"] body.project-converter.project-converter :is(#commit-id, #side-panel button) {
  color: var(--theme-accent-strong);
}

html:root[data-theme="light"] body.project-converter.project-converter #mode-help {
  background: var(--theme-ink);
  color: var(--theme-surface);
}

html:root[data-theme="dark"] body.project-converter.project-converter #file-area {
  background:
    linear-gradient(115deg, color-mix(in srgb, var(--theme-accent) 17%, transparent), transparent 48%),
    repeating-linear-gradient(135deg, color-mix(in srgb, var(--theme-accent) 5%, transparent) 0 1px, transparent 1px 18px),
    linear-gradient(135deg, var(--theme-bg-deep), var(--theme-surface));
  color: var(--theme-ink);
}

/* Bundled converter controls must pair the shared accent with its own ink. */
html:root[data-theme] body.project-converter.project-converter :is(#convert-button, #popup button, .format-list button.selected) {
  background: var(--theme-accent);
  color: var(--theme-button-text);
}

html:root[data-theme] body.project-converter.project-converter #side-panel button {
  background: var(--theme-surface);
  color: var(--theme-accent-strong);
  border: 1px solid var(--theme-border);
  box-shadow: var(--theme-card-shadow);
}

html:root[data-theme] body.project-converter.project-converter #mode-help {
  background: var(--theme-surface-soft);
  color: var(--theme-muted);
  border: 1px solid var(--theme-border);
}

html:root[data-theme] body.project-converter.project-converter #file-area:is(:focus-visible, .drag-active) {
  box-shadow: inset 0 0 0 var(--theme-focus-width) var(--theme-focus-color);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
