/* A restrained ink-and-paper night palette; default light styling stays untouched. */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.theme-toggle:hover { background: #f1ebdd; }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { display: block; }

@media (max-width: 700px) {
  .header-actions { flex-direction: row-reverse; }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #211f1c;
  --ink: #e8e1d5;
  --muted: #b7ad9d;
  --accent: #e1a078;
  --accent-dark: #f0b08a;
  --card: #2b2824;
  --line: #494239;
}

html[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3 { color: #eee7db; }
html[data-theme="dark"] a { color: var(--accent); }
html[data-theme="dark"] a:hover { color: #f2c2a1; }
html[data-theme="dark"] .announce { background: #171614; color: #eee7db; }
html[data-theme="dark"] .announce a { color: #f3c49f; }
html[data-theme="dark"] .announce code { background: rgba(255,255,255,.12); }
html[data-theme="dark"] .site-header,
html[data-theme="dark"] .site-footer,
html[data-theme="dark"] .main-nav { background: var(--card); }
html[data-theme="dark"] .brand,
html[data-theme="dark"] .main-nav a,
html[data-theme="dark"] .nav-toggle,
html[data-theme="dark"] .theme-toggle { color: var(--ink); }
html[data-theme="dark"] .main-nav a:hover,
html[data-theme="dark"] .theme-toggle:hover { background: #39342e; color: #f0b08a; }
html[data-theme="dark"] blockquote { color: var(--muted); }
html[data-theme="dark"] code { color: var(--ink); background: #39342e; }
html[data-theme="dark"] .btn:disabled { background: #625c51; color: #e1d9cc !important; }
html[data-theme="dark"] .btn:not(:disabled) { background: #814321; }
html[data-theme="dark"] .btn:not(:disabled):hover { background: #96542d; }
html[data-theme="dark"] form input,
html[data-theme="dark"] form textarea,
html[data-theme="dark"] select {
  color: var(--ink);
  border-color: var(--line);
  background: #24221f;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #a99f90; }
html[data-theme="dark"] .notice,
html[data-theme="dark"] .flash {
  color: #efe1c7;
  border-color: #766343;
  background: #393126;
}
html[data-theme="dark"] .pill:has(input:checked) { background: #3b3028; }
html[data-theme="dark"] .site-footer { color: var(--muted); }
html[data-theme="dark"] .footer-nav a,
html[data-theme="dark"] .support-line,
html[data-theme="dark"] .support-line a { color: var(--muted); }
html[data-theme="dark"] .home-door { background: var(--card); }
html[data-theme="dark"] .home-book { background: var(--bg); }

/* Reader, editorial tools, and turn surfaces use paper-colored local tokens. */
html[data-theme="dark"] .book-reader,
html[data-theme="dark"] .book-editor,
html[data-theme="dark"] .book-admin,
html[data-theme="dark"] .book-history {
  --book-paper: #302d28;
  --book-paper-edge: #514a40;
  --book-ink: #e8e1d5;
  --book-muted: #b7ad9d;
  --book-accent: #e1a078;
  --book-wash: #3b362f;
  color: var(--book-ink);
}
html[data-theme="dark"] .book-page-heading h1,
html[data-theme="dark"] .book-cover h1,
html[data-theme="dark"] .book-end h1,
html[data-theme="dark"] .book-essay-heading .book-essay-title,
html[data-theme="dark"] .book-essay-body h2,
html[data-theme="dark"] .book-essay-body h3,
html[data-theme="dark"] .book-editor-header h1,
html[data-theme="dark"] .book-admin-header h1,
html[data-theme="dark"] .book-admin-essay h2,
html[data-theme="dark"] .book-history-header h1,
html[data-theme="dark"] .book-history-differences > h2,
html[data-theme="dark"] .book-history-version-header h2,
html[data-theme="dark"] .book-history-select legend {
  color: #eee7db;
}
html[data-theme="dark"] .book-cover .book-subtitle,
html[data-theme="dark"] .book-preface,
html[data-theme="dark"] .book-contents-part h2,
html[data-theme="dark"] .book-skip-note,
html[data-theme="dark"] .book-essay-body,
html[data-theme="dark"] .book-essay-body blockquote,
html[data-theme="dark"] .book-preview p:last-child,
html[data-theme="dark"] .book-history-confirm,
html[data-theme="dark"] .book-history-warning,
html[data-theme="dark"] .book-history-warning h2,
html[data-theme="dark"] .book-history-diff pre,
html[data-theme="dark"] .book-history-source pre {
  color: #d8cebf;
}
html[data-theme="dark"] .book-paper,
html[data-theme="dark"] .book-draft-recovery,
html[data-theme="dark"] .book-history-version,
html[data-theme="dark"] .book-history-select,
html[data-theme="dark"] .book-contents-dialog,
html[data-theme="dark"] .book-essay-card,
html[data-theme="dark"] .book-history-source pre {
  background-color: var(--book-paper, #302d28);
  color: var(--book-ink, #e8e1d5);
}
html[data-theme="dark"] .book-essay-card:hover { border-color: #766858; background: #39342e; }
html[data-theme="dark"] .book-index-chapter[aria-current="page"] { background: #47392f; color: #f0b08a; }
html[data-theme="dark"] .book-index-dot { background: #a5b28f; }
html[data-theme="dark"] .book-index-chapter.is-in-progress .book-index-dot { background: #847a6b; }
html[data-theme="dark"] .book-skip-note,
html[data-theme="dark"] .book-editor-error,
html[data-theme="dark"] .book-history-warning { background: #3a3028; }
html[data-theme="dark"] .book-badge { background: #394236; color: #cfdfbf; }
html[data-theme="dark"] .book-badge.is-pending { background: #403a31; color: #d1c4ad; }
html[data-theme="dark"] .book-editor-form input,
html[data-theme="dark"] .book-editor-form textarea,
html[data-theme="dark"] .book-history-select select,
html[data-theme="dark"] .book-history-diff,
html[data-theme="dark"] .book-admin-empty,
html[data-theme="dark"] .book-preview,
html[data-theme="dark"] .book-history-source pre {
  border-color: var(--book-paper-edge);
  background: #292622;
  color: var(--book-ink);
}
html[data-theme="dark"] .book-admin-status-value { color: #b9d0a4; }
html[data-theme="dark"] .book-admin-status-value.is-pending { color: var(--book-accent); }
html[data-theme="dark"] .book-editor-error { color: #f0c6ae; }
html[data-theme="dark"] .book-editor-save,
html[data-theme="dark"] .book-admin-actions button,
html[data-theme="dark"] .book-history-select button,
html[data-theme="dark"] .book-history-restore button,
html[data-theme="dark"] .book-section-restore button {
  border-color: #814321;
  background: #814321;
  color: #fff4e8;
}
html[data-theme="dark"] .book-editor-save:hover,
html[data-theme="dark"] .book-admin-actions button:hover,
html[data-theme="dark"] .book-history-select button:hover,
html[data-theme="dark"] .book-history-restore button:hover,
html[data-theme="dark"] .book-section-restore button:hover {
  border-color: #96542d;
  background: #96542d;
}
html[data-theme="dark"] .book-editor-form input:focus,
html[data-theme="dark"] .book-editor-form textarea:focus,
html[data-theme="dark"] .book-history-select select:focus,
html[data-theme="dark"] .book-history-select button:focus-visible,
html[data-theme="dark"] .book-history-restore button:focus-visible,
html[data-theme="dark"] .book-history-confirm input:focus-visible { outline-color: #d5a47f; }
html[data-theme="dark"] .book-turn-flat,
html[data-theme="dark"] .book-turn-backface,
html[data-theme="dark"] .book-turn-destination-page,
html[data-theme="dark"] .book-turn-layer .book-turn-destination-page,
html[data-theme="dark"] .book-turn-sheet::after {
  background: var(--book-paper, #302d28);
  border-color: var(--book-paper-edge, #514a40);
}
html[data-theme="dark"] .book-section-admin-index a,
html[data-theme="dark"] .book-section-form,
html[data-theme="dark"] .book-section-version,
html[data-theme="dark"] .book-section-version-value pre {
  border-color: var(--book-paper-edge, #514a40);
  background: var(--book-paper, #302d28);
  color: var(--book-ink, #e8e1d5);
}
html[data-theme="dark"] .book-section-admin-index a:hover { background: #39342e; }
html[data-theme="dark"] .book-section-admin-heading h2,
html[data-theme="dark"] .book-section-history-header h1 { color: #eee7db; }
html[data-theme="dark"] .book-section-form label,
html[data-theme="dark"] .book-section-version-header h2,
html[data-theme="dark"] .book-section-version-value pre { color: var(--book-ink, #e8e1d5); }
html[data-theme="dark"] .book-section-form input:not([type="hidden"]),
html[data-theme="dark"] .book-section-form select,
html[data-theme="dark"] .book-section-form textarea {
  border-color: var(--book-paper-edge, #514a40);
  background: #292622;
  color: var(--book-ink, #e8e1d5);
}
html[data-theme="dark"] .book-section-admin-index,
html[data-theme="dark"] .book-section-admin-heading,
html[data-theme="dark"] .book-section-history-header,
html[data-theme="dark"] .book-section-version { border-color: var(--book-paper-edge, #514a40); }
html[data-theme="dark"] .book-section-history-warning { background: #3a3028; color: #d8cebf; }
html[data-theme="dark"] .book-section-history-warning h2 { color: #eee0d0; }
html[data-theme="dark"] .book-section-field-help,
html[data-theme="dark"] .book-section-version-meta { color: var(--book-muted, #b7ad9d); }
html[data-theme="dark"] .book-section-version-values { border-color: var(--book-paper-edge, #514a40); }

@media (max-width: 700px) {
  html[data-theme="dark"] .main-nav { border-color: var(--line); }
  html[data-theme="dark"] .main-nav a { border-color: var(--line); }
}
