:root { color-scheme: light; }
.theme-toggle { flex: none; white-space: nowrap; }
.theme-mode-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; min-width: 0; }
:root[data-theme-mode] .button,
:root[data-theme-mode] .proof-row { transition: none; }

/* Only the active dark palette overrides saved light colours. Inline UI
   settings stay intact, so removing the mode restores them immediately. */
:root[data-theme-mode="dark"] {
  color-scheme: dark;
  --paper: #171619 !important;
  --white: #242125 !important;
  --ink: #eee6db !important;
  --muted: #b8ada2 !important;
  --line: #584c49 !important;
  --red: #e0a2b1 !important;
  --red-dark: #351a25 !important;
  --red-pale: #40242e !important;
  --gold: #d3ba85 !important;
  --gold-pale: #342e23 !important;
  --sage: #bdcda5 !important;
  --sage-pale: #28342b !important;
  --shadow: 0 18px 55px #00000070 !important;
  --mode-action: #823b4d;
  --mode-action-hover: #94475b;
  --mode-info-bg: #26323e;
  --mode-info-text: #b9cee4;
  --mode-info-line: #50657c;
  --mode-warning-bg: #352d21;
  --mode-warning-text: #e2c992;
  --mode-warning-line: #806947;
  --mode-error-bg: #40242d;
  --mode-error-text: #f0bcc7;
  --mode-error-line: #945665;
}

:root[data-theme-mode="dark"] body { background-image: none; }
:root[data-theme-mode="dark"] .sidebar { background-color: var(--red-dark); color: var(--ink); border-right-color: var(--line); }
:root[data-theme-mode="dark"] .sidebar .brand strong,
:root[data-theme-mode="dark"] .sidebar .nav-item,
:root[data-theme-mode="dark"] .sidebar .sidebar-note strong,
:root[data-theme-mode="dark"] .sidebar .text-button,
:root[data-theme-mode="dark"] .sidebar .note-seal { color: var(--ink); }
:root[data-theme-mode="dark"] .sidebar .brand small,
:root[data-theme-mode="dark"] .sidebar .nav-caption,
:root[data-theme-mode="dark"] .sidebar .sidebar-note p,
:root[data-theme-mode="dark"] .sidebar .sidebar-bottom { color: var(--muted); }
:root[data-theme-mode="dark"] .sidebar .nav-item.active { background: var(--mode-action); color: var(--ink); }
:root[data-theme-mode="dark"] .sidebar .nav-count { background: #ffffff18; color: var(--ink); }
:root[data-theme-mode="dark"] .brand-mark { color: var(--ink); background: var(--mode-action); }
:root[data-theme-mode="dark"] .sidebar-rule,
:root[data-theme-mode="dark"] .sidebar .sidebar-note,
:root[data-theme-mode="dark"] .sidebar-bottom { border-color: var(--line); }
:root[data-theme-mode="dark"] .sidebar-rule { background: var(--line); }
:root[data-theme-mode="dark"] .button-primary,
:root[data-theme-mode="dark"] .reader-modes [aria-pressed="true"] { background: var(--mode-action); border-color: var(--mode-action); color: var(--ink); }
:root[data-theme-mode="dark"] .button-primary:hover { background: var(--mode-action-hover); border-color: var(--mode-action-hover); }
:root[data-theme-mode="dark"] .button-secondary,
:root[data-theme-mode="dark"] .reader-modes [aria-pressed="false"] { background: var(--white); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] .button-secondary:hover,
:root[data-theme-mode="dark"] .button-quiet:hover { background: var(--gold-pale); }
:root[data-theme-mode="dark"] input,
:root[data-theme-mode="dark"] textarea,
:root[data-theme-mode="dark"] select { background-color: var(--white); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] input[type="checkbox"],
:root[data-theme-mode="dark"] input[type="radio"],
:root[data-theme-mode="dark"] input[type="range"] { accent-color: var(--red); }
:root[data-theme-mode="dark"] .search-field input { background: transparent; border: 0; }
:root[data-theme-mode="dark"] input::placeholder,
:root[data-theme-mode="dark"] textarea::placeholder,
:root[data-theme-mode="dark"] .search-field > span { color: var(--muted); }
:root[data-theme-mode="dark"] :focus-visible { outline-color: var(--gold); }
:root[data-theme-mode="dark"] .project-cover,
:root[data-theme-mode="dark"] .project-cover.tone-red { background: #542b37; color: var(--ink); }
:root[data-theme-mode="dark"] .project-cover.tone-olive { background: #374235; color: var(--ink); }
:root[data-theme-mode="dark"] .project-cover.tone-sand { background: #4e4133; color: var(--ink); }
:root[data-theme-mode="dark"] .status-pill.pending { background: var(--gold-pale); color: var(--gold); }
:root[data-theme-mode="dark"] .status-pill.translating,
:root[data-theme-mode="dark"] .status-pill.proposed { background: var(--mode-info-bg); color: var(--mode-info-text); }
:root[data-theme-mode="dark"] .file-icon { background: var(--red-pale); border-color: var(--mode-error-line); color: var(--red); }
:root[data-theme-mode="dark"] .file-icon.docx,
:root[data-theme-mode="dark"] .file-icon.doc { background: var(--mode-info-bg); border-color: var(--mode-info-line); color: var(--mode-info-text); }
:root[data-theme-mode="dark"] .file-icon.csv { background: var(--sage-pale); border-color: #53664d; color: var(--sage); }
:root[data-theme-mode="dark"] .term-origin,
:root[data-theme-mode="dark"] .term-book,
:root[data-theme-mode="dark"] .term-date,
:root[data-theme-mode="dark"] .help-list { color: var(--muted); }
:root[data-theme-mode="dark"] .empty-state { border-color: var(--line); }
:root[data-theme-mode="dark"] .empty-symbol { color: var(--gold); }
:root[data-theme-mode="dark"] .task-text,
:root[data-theme-mode="dark"] .history-diff,
:root[data-theme-mode="dark"] .term-context-excerpt,
:root[data-theme-mode="dark"] .term-context-quote,
:root[data-theme-mode="dark"] .context-editor-row { background: var(--paper); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] .history-diff .old { color: var(--mode-warning-text); }
:root[data-theme-mode="dark"] .history-diff .new { color: var(--sage); }
:root[data-theme-mode="dark"] .term-context-quote mark,
:root[data-theme-mode="dark"] .term-context-excerpt mark { background: var(--gold-pale); color: var(--ink); }
:root[data-theme-mode="dark"] .upload-file-list > div { color: var(--muted); border-color: var(--line); }
:root[data-theme-mode="dark"] .pdf-frame { background: var(--paper); }
:root[data-theme-mode="dark"] .toast { background: var(--white); color: var(--ink); border: 1px solid var(--line); }
:root[data-theme-mode="dark"] .toast.error,
:root[data-theme-mode="dark"] .form-error,
:root[data-theme-mode="dark"] .conflict-box { background: var(--mode-error-bg); color: var(--mode-error-text); border-color: var(--mode-error-line); }
:root[data-theme-mode="dark"] .proof-term-contexts summary,
:root[data-theme-mode="dark"] .proof-page-link,
:root[data-theme-mode="dark"] .proof-status.has-drafts,
:root[data-theme-mode="dark"] .proof-status.has-error { color: var(--red); }
:root[data-theme-mode="dark"] .proof-badge.manual { background: var(--sage-pale); color: var(--sage); border-color: #53664d; }
:root[data-theme-mode="dark"] .proof-badge.reviewed { background: #253835; color: #b7d2c9; border-color: #4a6e65; }
:root[data-theme-mode="dark"] .proof-badge.anchored,
:root[data-theme-mode="dark"] .proof-sequence-auto { background: var(--mode-info-bg); color: var(--mode-info-text); border-color: var(--mode-info-line); }
:root[data-theme-mode="dark"] .proof-badge.suggested,
:root[data-theme-mode="dark"] .proof-sequence-special,
:root[data-theme-mode="dark"] .proof-term-warning,
:root[data-theme-mode="dark"] .proof-sequence-warning,
:root[data-theme-mode="dark"] .proof-image-notice,
:root[data-theme-mode="dark"] .proof-conflict,
:root[data-theme-mode="dark"] .proof-orphan-draft { background: var(--mode-warning-bg); color: var(--mode-warning-text); border-color: var(--mode-warning-line); }
:root[data-theme-mode="dark"] .proof-badge.unlinked { background: var(--paper); color: var(--muted); border-color: var(--line); }
:root[data-theme-mode="dark"] .proof-warnings { color: var(--mode-warning-text); }
:root[data-theme-mode="dark"] .proof-edit-text,
:root[data-theme-mode="dark"] .proof-conflict .proof-latest-text { background: var(--white); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] .proof-row.is-active { background: var(--red-pale); border-color: var(--red); }
:root[data-theme-mode="dark"] .proof-row.is-corresponding { background: var(--gold-pale); border-color: var(--gold); }
:root[data-theme-mode="dark"] .proof-row.is-selected { background: var(--paper); border-color: var(--gold); }
:root[data-theme-mode="dark"] #ui-editor-panel { background: var(--white); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-search input,
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-search select,
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-section textarea { background: var(--white); color: var(--ink); border-color: var(--line); }
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-control input[type="range"] { accent-color: var(--red); background: transparent; }
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-conflict { background: var(--mode-warning-bg); color: var(--mode-warning-text); border-color: var(--mode-warning-line); }
:root[data-theme-mode="dark"] #ui-editor-panel .ui-editor-label.is-active { background: var(--red-pale); border-left-color: var(--red); }
:root[data-theme-mode="dark"] .ui-text-picking .ui-text-selected { background: var(--red-pale); outline-color: var(--red); }

@media (max-width: 640px) {
  .theme-toggle { min-height: 44px; }
  .about-header { flex-wrap: wrap; }
  .theme-mode-actions { gap: 8px; }
}
