/* Practice-only, opt-in night study. Keep every dark declaration screen-only:
   print then uses the original cascade verbatim, including its hidden widgets.
   Freeze inherited studio dark tokens on html before the daylight band remaps
   them. Descendants reuse that palette rather than introducing a second one. */
@media screen {
  #gym-dark-mode { min-width: 44px; min-height: 44px; border-color: var(--ink-2); }
  html:root[data-practice-theme="dark"] {
    color-scheme: dark;
    --practice-paper: var(--paper);
    --practice-surface: var(--surface);
    --practice-surface-2: var(--surface-2);
    --practice-recessed: var(--recessed);
    --practice-ink: var(--ink);
    --practice-ink-2: var(--ink-2);
    --practice-muted: var(--muted);
    --practice-accent: var(--accent);
    --practice-accent-bright: var(--accent-bright);
    --practice-accent-tint: var(--accent-tint);
    --practice-c-alg1: var(--c-alg1);
    --practice-c-geo: var(--c-geo);
    --practice-c-alg2: var(--c-alg2);
    --practice-c-sci: var(--c-sci);
    --practice-c-precalc: var(--c-precalc);
    --practice-c-calc: var(--c-calc);
    --practice-c-phys: var(--c-phys);
    --practice-c-apphys: var(--c-apphys);
    --practice-c-ess: var(--c-ess);
    --practice-c-alg1-tint: var(--c-alg1-tint);
    --practice-c-geo-tint: var(--c-geo-tint);
    --practice-c-alg2-tint: var(--c-alg2-tint);
    --practice-c-sci-tint: var(--c-sci-tint);
    --practice-c-precalc-tint: var(--c-precalc-tint);
    --practice-c-calc-tint: var(--c-calc-tint);
    --practice-c-phys-tint: var(--c-phys-tint);
    --practice-c-apphys-tint: var(--c-apphys-tint);
    --practice-c-ess-tint: var(--c-ess-tint);
    --practice-neon-green: var(--neon-green);
    --practice-neon-red: var(--neon-red);
    --practice-ah-text-on-accent: var(--ah-text-on-accent);
  }
  html:root[data-practice-theme="dark"] body { background: var(--paper); }
  html:root[data-practice-theme="dark"] :is(.gym-v3, .light-band, #pe-hub-mount, .gym-config-dialog, .gym-intro, .course-ref-dialog) {
    --paper: var(--practice-paper);
    --surface: var(--practice-surface);
    --surface-2: var(--practice-surface-2);
    --recessed: var(--practice-recessed);
    --ink: var(--practice-ink);
    --ink-2: var(--practice-ink-2);
    --muted: var(--practice-muted);
    --accent: var(--practice-accent);
    --accent-bright: var(--practice-accent-bright);
    --accent-tint: var(--practice-accent-tint);
    --c-alg1: var(--practice-c-alg1);
    --c-geo: var(--practice-c-geo);
    --c-alg2: var(--practice-c-alg2);
    --c-sci: var(--practice-c-sci);
    --c-precalc: var(--practice-c-precalc);
    --c-calc: var(--practice-c-calc);
    --c-phys: var(--practice-c-phys);
    --c-apphys: var(--practice-c-apphys);
    --c-ess: var(--practice-c-ess);
    --c-alg1-tint: var(--practice-c-alg1-tint);
    --c-geo-tint: var(--practice-c-geo-tint);
    --c-alg2-tint: var(--practice-c-alg2-tint);
    --c-sci-tint: var(--practice-c-sci-tint);
    --c-precalc-tint: var(--practice-c-precalc-tint);
    --c-calc-tint: var(--practice-c-calc-tint);
    --c-phys-tint: var(--practice-c-phys-tint);
    --c-apphys-tint: var(--practice-c-apphys-tint);
    --c-ess-tint: var(--practice-c-ess-tint);
    --neon-green: var(--practice-neon-green);
    --neon-red: var(--practice-neon-red);
    --ah-text-on-accent: var(--practice-ah-text-on-accent);
    /* Studio's muted ink gives control edges >=3:1 on every night surface. */
    --line: var(--practice-muted);
    --line-strong: var(--practice-muted);
    --gym-paper: var(--practice-paper);
    --gym-selected: var(--practice-accent) !important;
    --gym-wash: var(--practice-surface-2);
    --gym-edge: var(--practice-muted);
    --gym-numeral: var(--practice-surface-2);
    --portal-surface: var(--practice-surface);
    --portal-text: var(--practice-ink);
    --portal-accent: var(--practice-accent);
    --portal-border-strong: var(--practice-muted);
    color: var(--ink);
  }
  html:root[data-practice-theme="dark"] .gym-v3 > .light-band--page {
    background: var(--paper);
  }
  /* Atlas plates and calm view contain literal daylight fills/foregrounds. */
  html:root[data-practice-theme="dark"] :is(#gym-subjects, #gym-modules, #gym-topic-step, #gym-lessons,
    .gym-modbtn, .gym-topic-choices button, .gym-topic, .gym-toggle, .gym-breadcrumbs,
    .gym-tools, .gym-deskbar, .gym-config-dialog, .gym-intro, .gym-v3[data-calm=true] .gym-welcome,
    .gym-v3[data-calm=true] .gym-course) {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
  }
  html:root[data-practice-theme="dark"] :is(.gym-modbtn .num, .gym-lesson-quick,
    .gym-lesson:has(input:checked), .gym-modbtn.active, .gym-modbtn:hover,
    .gym-topic-choices button:hover, .gym-flow-status:not(:empty)) {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--accent);
  }
  html:root[data-practice-theme="dark"] :is(.gym-section-title, .gym-topic-head, .gym-explore summary,
    .gym-button--quiet, #gym-start-module, .gym-config-dialog h2, .gym-config-dialog p,
    .gym-config-dialog .eyebrow, .gym-intro h2, .gym-intro p,
    .gym-v3[data-calm=true] .gym-welcome h1, .gym-v3[data-calm=true] .gym-welcome h1 em,
    .gym-v3[data-calm=true] .gym-welcome .eyebrow, .gym-v3[data-calm=true] .gym-welcome-copy>p,
    .gym-v3[data-calm=true] .gym-course .nm, .gym-v3[data-calm=true] .gym-course .mc,
    .gym-v3[data-calm=true] .gym-course .glyph) { color: var(--ink); }
  html:root[data-practice-theme="dark"] :is(.gym-topic-choices button span, .gym-settings-note,
    .gym-flow-status, .gym-breadcrumbs button:disabled, .gym-topic-choices button:disabled) {
    color: var(--ink-2); opacity: 1;
  }
  html:root[data-practice-theme="dark"] :is(.gym-breadcrumbs button, .gym-modbtn.active .num) {
    color: var(--ink); background: var(--surface-2);
  }
  html:root[data-practice-theme="dark"] :is(.gym-breadcrumbs button[aria-current=step],
    .gym-toggle:has(input:checked), .gym-button--primary, #gym-sticky-start,
    #gym-flow-return, .gym-step-label, .gym-calc-use:not([aria-disabled=true]),
    .gym-tool-buttons .gym-button[aria-expanded=true], #gym-dark-mode[aria-pressed=true]) {
    color: var(--ah-text-on-accent); background: var(--accent); border-color: var(--accent);
  }
  html:root[data-practice-theme="dark"] .gym-breadcrumbs button::before {
    color: var(--ink); background: var(--surface); border-color: var(--line-strong);
  }
  html:root[data-practice-theme="dark"] :is(.gym-tool-buttons .gym-button:not([aria-expanded=true]),
    .gym-welcome .gym-button--quiet, .gym-intro .gym-button--quiet,
    #gym-sticky-clear, #gym-sticky-start:disabled) {
    color: var(--ink); background: var(--surface); border-color: var(--line-strong); opacity: 1;
  }
  html:root[data-practice-theme="dark"] :is(.gym-sticky, .gym-tool-head, #gym-calculator .gym-tool-head) {
    background: var(--surface); border-color: var(--line-strong);
  }
  html:root[data-practice-theme="dark"] :is(.light-band select, .light-band option, .gym-config-dialog select, .course-ref-dialog button,
    .course-ref-dialog select, .course-ref-trigger) {
    background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
  }
  html:root[data-practice-theme="dark"] :is(input, textarea, select) { accent-color: var(--accent); color-scheme: dark; }
  html:root[data-practice-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
  html:root[data-practice-theme="dark"] :is(.gym-v3, .gym-config-dialog, .course-ref-dialog) :is(button:disabled, [aria-disabled=true]) {
    opacity: 1; background: var(--surface); color: var(--ink-2);
    border-color: var(--line-strong); border-style: dashed;
  }
  html:root[data-practice-theme="dark"] :is(button, a, input, textarea, select, [tabindex]):focus-visible {
    outline: 3px solid var(--practice-accent-bright); outline-offset: 3px;
  }
  html:root[data-practice-theme="dark"] .pe-progress { border: 1px solid var(--line-strong); }
  html:root[data-practice-theme="dark"] .pe-lv { background: transparent; border: 1px solid var(--line-strong); }
  html:root[data-practice-theme="dark"] .pe-lv.on { background: var(--accent); border-color: var(--accent); }
  html:root[data-practice-theme="dark"] .pe-lv.cap { opacity: 1; border-style: dashed; }
  /* Ghost actions can sit on a tinted toolbar and add another hover wash. */
  html:root[data-practice-theme="dark"] .pe-btn.pe-ghost { color: var(--accent-bright); }
  html:root[data-practice-theme="dark"] .pe-progress-bar.done { background: var(--accent); }
  html:root[data-practice-theme="dark"] .notes-search-panel mark {
    color: var(--ink); background: var(--accent-tint);
  }
}
/* No token reset needed: none of the dark rules participates in print. */
@media print { #gym-dark-mode { display: none !important; } }
