/* Shared controls keep their placement in both themes, including narrow screens. */
.chapter-heading-tools{display:flex;align-items:start;justify-content:space-between;gap:12px;margin-bottom:6px}
.chapter-heading-tools .chapter-parent{margin-bottom:0}
.theme-toggle{flex:none;min-height:36px;padding:6px 10px;border:1px solid var(--line);border-radius:7px;background:var(--surface);color:var(--ink);font-size:12px;cursor:pointer}
.theme-toggle:hover{border-color:var(--muted)}

:root[data-theme=dark]{color-scheme:dark;--ink:#e0e9e2;--muted:#a6b8ac;--paper:#161e1b;--surface:#202b25;--line:#415247;--deep:#a3d6b7;--mint:#304b3a;--gold:#f5df93}

/* :where keeps theme state from adding specificity to component overrides. */
/* Component colors not inherited from the reader palette. Images retain their
   original colors and white paper so chemical labels remain legible. */
:root:where([data-theme=dark]) .sidebar{background:#1c2821}
:root:where([data-theme=dark]) :is(.player,#pi-chat,#pi-chat-compose,#orbital-explainer,.uk-btn.pi-chat-trigger,.figure-expand-icon,.photo-actions textarea,.photo-actions .attachment-choice:not([hidden]),.attachment-selected:not([hidden]),.attachment-remove){background:var(--surface)}
:root:where([data-theme=dark]) :is(#pi-chat input,#pi-chat textarea,#pi-chat-history article){background:var(--paper)}
:root:where([data-theme=dark]) :is(#chapter-index a:hover,.chapter-pager:hover,.uk-btn-ghost:hover,.uk-btn.pi-chat-trigger:hover){background:#304538}
:root:where([data-theme=dark]) #chapter-index a[aria-current]{background:#304b3a;border-color:#557562}
:root:where([data-theme=dark]) :is(.chapter-subsections,#lesson-contents li){border-color:var(--line)}
:root:where([data-theme=dark]) :is(.chapter-passage .text-reference,.reference-link,figcaption a,.beat-play,.beat-number){color:var(--deep)}
:root:where([data-theme=dark]) :is(.guidance dl,.practice-question details[open],#pi-chat-status,#pi-chat-history article[data-role=user],.pi-chat-markdown code,.pi-chat-markdown pre,#pi-chat-pair code,.pi-chat-markdown th,.explainer-stage,.audio-symbol){background:#293c30}
:root:where([data-theme=dark]) .pi-chat-markdown pre code{background:transparent}
:root:where([data-theme=dark]) :is(.prediction,.confused-band){background:#3a3221;color:#efddb0}
:root:where([data-theme=dark]) .confused-band:hover{background:#4b4028}
:root:where([data-theme=dark]) .uk-btn-primary{background:#a3d6b7;color:#162b1e}
:root:where([data-theme=dark]) .uk-btn-primary:hover:not(:disabled){background:#bce8cd}
:root:where([data-theme=dark]) .brand-symbol{background:#304b3a;color:#e0e9e2}
:root:where([data-theme=dark]) .attachment-choice:hover{background:#304538 !important}
:root:where([data-theme=dark]) .photo-error:not(:empty){color:#ffa89f}
:root:where([data-theme=dark]) #term-card{background:#293c30;border-color:#557562}
:root:where([data-theme=dark]) .term.uk-btn{background:#304b3a;color:var(--deep)}
:root:where([data-theme=dark]) .term:is(:hover,[data-open]){background:#3f604a}
:root:where([data-theme=dark]) :focus-visible{outline-color:#a3d6b7}
/* The expand button sits on an intentionally white image. */
:root:where([data-theme=dark]) .figure-expand-icon{color:var(--ink)}
