/* The original paper palette remains the light appearance. */
:root {
  color-scheme: light;
  --surface: #fff;
  --surface-raised: #fff;
  --surface-soft: #eef0ec;
  --field: #fff;
  --control-border: #bdc9c5;
  --focus: #af637b;
  --on-accent: #fff;
  --toggle-track: #e9ece7;
  --toggle-thumb: #fff;
  --toggle-active: #76552e;
}

/* A warm, quiet reading palette with distinct canvas, card, and input surfaces. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151b1d;
  --white: #20292c;
  --surface: #20292c;
  --surface-raised: #293337;
  --surface-soft: #273234;
  --field: #182124;
  --ink: #f0eee8;
  --muted: #b3bfbd;
  --line: #3b494b;
  --control-border: #637674;
  --accent: #e6adbf;
  --accent-dark: #f3c6d4;
  --on-accent: #2c1921;
  --pale: #3b2b34;
  --green: #a4cbb7;
  --blue: #a7c7df;
  --gold: #d8bf93;
  --focus: #f0c591;
  --shadow: 0 18px 50px #00000026;
  --canvas: #172023;
  --canvas-dot: #324346;
  --lineage-surface: #352a33;
  --context-line: #809a91;
  --partner-line: #79d3d6;
  --toggle-track: #11191c;
  --toggle-thumb: #354349;
  --toggle-active: #f0cf9e;
}

.theme-toggle {
  position: relative;
  display: inline-grid;
  grid-template-columns: 34px 34px;
  align-items: center;
  justify-items: center;
  flex: 0 0 auto;
  width: 78px;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--control-border);
  border-radius: 24px;
  background: var(--toggle-track);
  color: var(--muted);
  isolation: isolate;
}
.theme-toggle::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: 4px;
  left: 4px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--toggle-thumb);
  box-shadow: 0 1px 5px #00000018;
  transition: transform 180ms ease;
}
.theme-toggle .icon {width: 19px;height: 19px;stroke-width: 1.8}
.theme-toggle:hover {border-color: var(--accent)}
.theme-toggle .theme-sun {color: var(--toggle-active)}
[data-theme="dark"] .theme-toggle::before {transform: translateX(34px)}
[data-theme="dark"] .theme-toggle .theme-sun {color: var(--muted)}
[data-theme="dark"] .theme-toggle .theme-moon {color: var(--toggle-active)}
:is(a,button,input,textarea,select,summary):focus-visible {outline-color: var(--focus)}
::selection {background: var(--accent);color: var(--on-accent)}

/* Pages, navigation, stories, and profile reading surfaces. */
[data-theme="dark"] .site-header {background: #1b2326}
[data-theme="dark"] :is(.brand-mark,.footer-bottom,.tree-workspace,.chip,.step-label) {border-color: var(--line)}
[data-theme="dark"] :is(.lineage-card,.story-card,.home-story-feature,.filter-bar,.tree-workspace,.facts-panel,.paper-form,.review-card,.person-results,.tree-profile-panel,.explorer-controls,.chip,dialog) {background: var(--surface)}
[data-theme="dark"] .site-footer {background: #11191b}
[data-theme="dark"] :is(.button,.focus-node .node-role) {color: var(--on-accent)}
[data-theme="dark"] .button.secondary {color: var(--ink);border-color: var(--control-border);background: transparent}
[data-theme="dark"] :is(.button.secondary:hover,.icon-button:hover) {background: var(--surface-raised)}
[data-theme="dark"] .button.light {background: #dce9e2;color: #20372e}
[data-theme="dark"] .button.light:hover {background: #f0f6f2}
[data-theme="dark"] .button.danger-button {background: #edb0ac;color: #391e20}
[data-theme="dark"] .button.danger-button:hover {background: #f4c7c3}
[data-theme="dark"] .danger {color: #f3b4b4}
[data-theme="dark"] .eyebrow span {color: var(--muted)}
[data-theme="dark"] :is(.skip-link,.pagination .current) {background: var(--accent);color: var(--on-accent)}
[data-theme="dark"] .hero-tree {background: #203b36;border: 1px solid #49645a;box-shadow: var(--shadow)}
[data-theme="dark"] .card-image {background: #263832}
[data-theme="dark"] .card-image.is-story {background: #362f2c}
[data-theme="dark"] .art-symbol {color: #b8cfbf;border-color: #738e7f}
[data-theme="dark"] .art-label {color: #c0d2c5}
[data-theme="dark"] .contribution-banner {background: #302730;border-color: #57424e}
[data-theme="dark"] .contribution-banner p {color: #d5bdc6}
[data-theme="dark"] :is(.count,.initials) {background: #304139;color: #c9ded1}
[data-theme="dark"] .portrait {background: var(--surface-soft)}
[data-theme="dark"] .portrait .icon {color: #abc6b4}
[data-theme="dark"] .source-evidence blockquote {background: #302730}
[data-theme="dark"] .life-timeline {border-color: #a67a8a}

/* The diagram keeps family context subdued and the selected lineage prominent. */
[data-theme="dark"] .tree-canvas {background-color: var(--canvas);background-image: radial-gradient(var(--canvas-dot) 1px,transparent 1px)}
[data-theme="dark"] .person-node {background: #243034;border-color: #5d726c;box-shadow: 0 5px 18px #00000024}
[data-theme="dark"] .person-node.lineage-node {background: var(--lineage-surface);border-color: var(--accent);box-shadow: 0 4px 18px #00000029}
[data-theme="dark"] .person-node.focus-node {box-shadow: 0 0 0 3px #e6adbf35,0 5px 22px #00000038}
[data-theme="dark"] :is(.node-body:hover,.node-action:hover,.directory-person:hover,.directory-person.active,.saved-person:hover) {background: var(--pale)}
[data-theme="dark"] .node-action {background: #1d282c;border-top-color: var(--line)}
[data-theme="dark"] .node-action:hover {background: #40303b}
[data-theme="dark"] .connection-lines path {stroke: var(--context-line)}
[data-theme="dark"] .connection-lines path.partner {stroke: var(--partner-line)}
[data-theme="dark"] .connection-lines path.lineage-connection {stroke: var(--accent)}
[data-theme="dark"] .connection-lines path.partner.lineage-connection {stroke: var(--partner-line)}
[data-theme="dark"] .legend-context {border-color: var(--context-line)}
[data-theme="dark"] :is(.view-switch,.dialog-footer) {background: #182124}
[data-theme="dark"] :is(.view-switch .selected,.tree-zoom-controls button) {background: var(--surface-raised);box-shadow: 0 1px 4px #00000026}
[data-theme="dark"] .tree-zoom-controls button:hover:not(:disabled) {background: var(--pale)}
[data-theme="dark"] .tree-list .relative-row {background: var(--surface)}
[data-theme="dark"] .tree-profile-panel {box-shadow: -8px 0 32px #00000030}
[data-theme="dark"] .tree-notice {background: #3a3020;color: #efd5a3}

/* Native controls, uploads, dialogs, and feedback use the same appearance. */
[data-theme="dark"] :is(input:not([type=checkbox]):not([type=radio]),select,textarea) {color: var(--ink);background: var(--field);border-color: var(--control-border)}
[data-theme="dark"] :is(input,textarea)::placeholder {color: #a9b6b2}
[data-theme="dark"] :is(input,textarea)[readonly] {background: var(--surface-soft)}
[data-theme="dark"] input::file-selector-button {background: var(--surface-raised);color: var(--ink);border: 1px solid var(--control-border);border-radius: 4px;padding: 6px 10px}
[data-theme="dark"] :is(.type-choices label:has(:checked),#relative-fields) {background: var(--pale)}
[data-theme="dark"] .file-drop {background: #1b2725;border-color: #76948a}
[data-theme="dark"] .form-message:not(:empty) {background: #402c2f;color: #f5bebe}
[data-theme="dark"] .form-message.success {background: #263f33;color: #bce4c8}
[data-theme="dark"] :is(.success-panel,.editor-note) {background: #253830;border-color: #597465}
[data-theme="dark"] dialog {box-shadow: 0 25px 100px #00000070}
[data-theme="dark"] dialog::backdrop {background: #060b0dd9}
[data-theme="dark"] #fa-toast {background: #d5e8dd;color: #193329;box-shadow: 0 6px 32px #00000040}
[data-theme="dark"] #fa-toast button {background: #244638;color: #f2f7f4}
[data-theme="dark"] {scrollbar-color: #697d78 #182124}

@media (max-width:1100px) {.header-actions>.button {display:none}}
@media (max-width:500px) {
  .header-inner .brand {gap:8px}
  .header-inner .brand-mark {width:32px;height:32px}
  .header-inner .brand-text {font-size:18px}
  .header-inner .brand-text small {font-size:8px;letter-spacing:.15em}
  .header-actions {gap:4px}
}
@media (prefers-reduced-motion:reduce) {.theme-toggle::before {transition:none}}
