/* =========================================================
   Dark mode (theme.js sets <html data-mode="dark">).
   The whole page takes the builder's charcoal panel palette
   (see "Dark panels" in styles.css): the room goes near-black,
   cards and tiles are warm charcoal, and the near-black accents
   (main buttons, selected states, hover outlines) flip to cream.
   Loaded after every other stylesheet, so these win.
   ========================================================= */
:root[data-mode="dark"] {
  color-scheme: dark;
  --felt: #100f0e;
  --felt-deep: #0b0a0a;
  --felt-edge: #24221f;
  --paper: #1f1e1c;
  --paper-2: #2a2826;
  --control: #262422;
  --line: #3a3835;
  --line-strong: #4d4a45;
  --ink: #f1ece3;
  --ink-soft: #a9a195;
  --solid: #f1ece3;
  --on-solid: #161514;
  --gold: #d8d1c4;
  --gold-deep: #8f877b;
  --focus: #f1ece3;
  --ok: #7cc496;
  --bad: #f0897a;
  --page-bg: linear-gradient(180deg, #121110 0%, #0d0c0b 100%);
}
:root[data-mode="dark"] body { color: var(--ink); }
:root[data-mode="dark"] ::selection { background: rgba(240, 190, 80, 0.45); color: #fff; }
:root[data-mode="dark"] * { scrollbar-color: rgba(241, 236, 227, 0.4) transparent; }

/* the black header and dark bands sit on a near-black page: a hairline keeps their edge */
:root[data-mode="dark"] .bar, :root[data-mode="dark"] .masthead, :root[data-mode="dark"] .deckhead { box-shadow: 0 1px 0 rgba(241, 236, 227, 0.08); }
:root[data-mode="dark"] .panel, :root[data-mode="dark"] .zone, :root[data-mode="dark"] .stats, :root[data-mode="dark"] dialog {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px rgba(0, 0, 0, 0.45);
}
:root[data-mode="dark"] dialog::backdrop { background: rgba(0, 0, 0, 0.62); }

/* main buttons and selected states: cream on charcoal, like inside the builder's panels */
:root[data-mode="dark"] :is(.btn.primary, .zone .btn.primary, .chip[aria-pressed="true"], .br-btn[aria-pressed="true"],
  .seg button[aria-pressed="true"], .ex-fmt[aria-pressed="true"], .im-pill, .btag.gc, .sg-tab, .md-fchip[aria-pressed="true"],
  .ds-tag.on, .cx-bar.on, .pl-chip) {
  background: var(--solid); color: var(--on-solid); border-color: var(--solid); box-shadow: none;
}
:root[data-mode="dark"] :is(.btn.primary, .sg-tab):hover { background: #fff; border-color: #fff; }
:root[data-mode="dark"] .sg-spark, :root[data-mode="dark"] .sg-tab .sg-spark { color: var(--on-solid); }
:root[data-mode="dark"] .sg-count { background: var(--on-solid); color: var(--solid); }
:root[data-mode="dark"] .cx-bar.on .cx-bar-fill { background: var(--on-solid); }

/* everything else that was a light surface or a near-black line */
:root[data-mode="dark"] :is(.btn, .bar .btn, .zone .btn):not(.primary) { border-color: var(--line-strong); }
:root[data-mode="dark"] :is(.btn, .chip, .md-fchip, .dash-tile, .feature, .ds-tile > a, .md-cont, .md-tile, .pr-art, .brackets .br-btn):not(.primary):not([aria-pressed="true"]):hover { border-color: var(--ink); }
:root[data-mode="dark"] :is(.search, .lb-filter input, .subpick select, .field input, .field textarea, .field select, .im-row select, .role-pick select,
  .chip:not([aria-pressed="true"]), .seg button:not([aria-pressed="true"]), .step, .x, .more, .qty-in, .dlg-x, .sg-x, .ex-fmt:not([aria-pressed="true"]),
  .zone .btn:not(.primary), .theme, .brackets .br-btn:not([aria-pressed="true"]), .dash-tile, .cx-input, .cx-select select, .cx-deck, .sg-drawer) {
  background-color: var(--control); color: var(--ink); border-color: var(--line-strong);
}
:root[data-mode="dark"] :is(.search, .lb-filter input, .field input, .field textarea, .cx-input)::placeholder { color: #857d72; }
:root[data-mode="dark"] :is(.search, .qty-in, .cx-input):focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(241, 236, 227, 0.12); }
:root[data-mode="dark"] :is(.row:hover, .result:hover, .frame.empty, .empty-list, .lstat, .dash-panel, .syn, .note, .pr-opt[aria-pressed="true"],
  #import-text.drop, .step-list li, .support-band) {
  background: var(--paper-2);
}
:root[data-mode="dark"] :is(.frame.empty, .empty-list) { border-color: var(--line-strong); }
:root[data-mode="dark"] :is(.cat-blurb, .note, .im-preview, .theme) { border-left-color: var(--ink); }
:root[data-mode="dark"] :is(.lstat::before, .finder::before, dialog::before, .dt-bars span, .dt-split span, .cx-bar-fill, .cx-progress span, .role-row.low .fill) { background: var(--ink); }
:root[data-mode="dark"] .dt-split, :root[data-mode="dark"] .rbar { background: rgba(241, 236, 227, 0.1); }
:root[data-mode="dark"] .rbar .band { background: rgba(241, 236, 227, 0.14); }
:root[data-mode="dark"] .curve .bar-fill { background: linear-gradient(0deg, #d9d2c5, #8f887c); }
:root[data-mode="dark"] .dash-tile.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
:root[data-mode="dark"] .dash-tile.on::after { border-color: var(--ink); }
:root[data-mode="dark"] .vcard.on-theme { box-shadow: 0 0 0 2px var(--ink), 0 6px 16px rgba(0, 0, 0, 0.35); }
:root[data-mode="dark"] :is(.pr-sw, .pr-bd)[aria-pressed="true"], :root[data-mode="dark"] .adm-pick:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); }
:root[data-mode="dark"] :is(.adm-bd[aria-pressed="true"], .pr-opt[aria-pressed="true"], .cx-pip[aria-pressed="true"]) { border-color: var(--ink); }
:root[data-mode="dark"] .pg-card .btn.danger { color: #161514; }
/* Playtest on Moxgate: the light theme's deep purple text is too dark on charcoal; a soft lavender reads calmer */
:root[data-mode="dark"] #btn-moxgate { color: #c4b2ff; background: rgba(124, 77, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(160, 130, 255, 0.24); }
:root[data-mode="dark"] #btn-moxgate:hover { color: #ddd2ff; background: rgba(124, 77, 255, 0.18); box-shadow: inset 0 0 0 1px rgba(160, 130, 255, 0.42), 0 0 12px rgba(124, 77, 255, 0.2); }
:root[data-mode="dark"] #btn-moxgate:focus-visible { outline-color: #b39bff; }
:root[data-mode="dark"] .toast { background: #2a2826; border: 1px solid var(--line-strong); }

/* the color wheel and mana symbols outside the dark panels */
:root[data-mode="dark"] .wheel .link { stroke: rgba(241, 236, 227, 0.22); }
:root[data-mode="dark"] .wheel .w-off circle { stroke: rgba(241, 236, 227, 0.4); }
:root[data-mode="dark"] :is(.pip-W, .pip-n) { color: #161514; }

/* landing page: the feature icons and numbered steps */
:root[data-mode="dark"] .feature-ic { background: color-mix(in srgb, var(--ic-bg) 22%, var(--paper-2)); color: color-mix(in srgb, var(--ic) 45%, #f1ece3); }
:root[data-mode="dark"] .step-n { background: var(--solid); color: var(--on-solid); }

/* commander trims: the lighter mixes the panels use, so the hue still shows on charcoal */
:root[data-mode="dark"][data-themed] {
  --trim-line: color-mix(in srgb, var(--trim-1) 40%, var(--line));
  --trim-soft: color-mix(in srgb, var(--trim-1) 9%, var(--paper));
}
:root[data-mode="dark"][data-themed] :is(.dt-bars span, .dt-split span) { background: color-mix(in srgb, var(--trim-1) 65%, #f1ece3); }

/* the sun/moon switch in the header */
.mode-btn {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: #fbf5eb; border: 1px solid rgba(247, 245, 240, 0.32);
  transition: background-color 0.15s, border-color 0.15s;
}
.mode-btn:hover { background: rgba(247, 245, 240, 0.1); border-color: rgba(247, 245, 240, 0.7); }
.mode-btn:focus-visible { outline: 2px solid #fbf5eb; outline-offset: 2px; }
.mode-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bar > .mode-btn { order: 3; } /* the builder's header reorders on phones: keep it after the account menu */
@media (max-width: 600px) { .mode-btn { width: 30px; height: 30px; } }
