.theme-setting { margin:12px 0 22px; }
.theme-control { display:inline-flex; align-items:center; padding:2px; border:1px solid var(--line); border-radius:999px; background:var(--paper-2); color:var(--muted); }
.theme-icon { position:relative; display:grid; place-items:center; width:44px; height:40px; min-height:40px; padding:0; border:0; border-radius:999px; background:transparent; color:inherit; cursor:pointer; -webkit-tap-highlight-color:transparent; }
.theme-icon::before { content:""; position:absolute; inset:3px 5px; border-radius:50%; background:transparent; }
.theme-icon svg { position:relative; pointer-events:none; }
.theme-icon[aria-pressed="true"] { color:var(--moss-dark); }
.theme-icon[aria-pressed="true"]::before { background:var(--surface); box-shadow:0 1px 5px #00000012; }
.theme-icon:hover { color:var(--ink); }
.theme-icon:focus-visible { outline:2px solid var(--clay); outline-offset:2px; }
.theme-notice { margin:6px 0 0; color:var(--muted); font-size:12px; line-height:1.5; }
.theme-notice:empty { display:none; }
.auth__controls { display:flex; flex-wrap:wrap; align-items:center; gap:16px; }
.auth__controls .theme-setting { margin:0; }
@media (max-width:500px) {
  .auth__controls { width:100%; justify-content:space-between; gap:10px; }
}

:root[data-theme="dark"] {
  color-scheme:dark;
  --paper:#17231e; --paper-2:#2c3a31; --surface:#223229;
  --ink:#eee9da; --muted:#b4bdaa; --moss:#b3cbb0; --moss-dark:#c4d6ba;
  --clay:#d9b27f; --fact:#bfd7b9; --fact-bg:#2a4033; --story:#e5c19a; --story-bg:#44372b;
  --image:#d5c3eb; --image-bg:#383044; --difficult:#efb6a7; --difficult-bg:#40302c; --danger:#f0afa2;
  --line:rgba(212,222,202,.23); --shadow:0 18px 50px #050a0755; --cream:#29372c;
}
/* Text, controls and surfaces have their own palette; photographs are untouched. */
:root[data-theme="dark"] :is(.auth,.ai-action-button__icon,.topbar__brand span:first-child,.ancestor-card--self,.ancestor-card__mark--audio,.person-hero,.material--image,.today-card,.toast,.walk-guide__wingbeat,.reader-bar,.author-card__mark) { background:#304639; color:var(--ink); }
:root[data-theme="dark"] :is(.topbar,.modal__head,.desktop-person-pane .topbar) { background:#17231ef5; }
:root[data-theme="dark"] .bottom-nav { background:#17231efa; }
:root[data-theme="dark"] .bottom-nav button { color:var(--muted); }
:root[data-theme="dark"] .bottom-nav button.active { color:var(--ink); background:var(--paper-2); }
:root[data-theme="dark"] .bottom-nav::before { color:var(--ink); }
:root[data-theme="dark"] .button { background:#c4d6ba; border-color:#c4d6ba; color:#18261c; }
:root[data-theme="dark"] .button:hover { background:#d3e4c9; }
:root[data-theme="dark"] .button--secondary { background:transparent; border-color:var(--line); color:var(--ink); }
:root[data-theme="dark"] .button--secondary:hover { background:var(--paper-2); }
:root[data-theme="dark"] .button--danger { color:var(--danger); border-color:#b7786866; background:transparent; }
:root[data-theme="dark"] ::placeholder { color:var(--muted); opacity:.9; }
:root[data-theme="dark"] .auth__mark { color:#27372f; }
:root[data-theme="dark"] .layer-tag--audio { color:#eee9da; background:#344c3c; }
:root[data-theme="dark"] :is(.toast--error,.dictation__button[aria-pressed="true"]) { background:#793d31; color:#fff2e9; }
:root[data-theme="dark"] :is(.auth__vision,.home-hero__image,.walk-guide__art) { background:var(--paper); }
:root[data-theme="dark"] .home-hero__image .read-aloud--icon { background:#223229ec; }
:root[data-theme="dark"] :is(.ai-action-button,.journey-invitation) { background:linear-gradient(135deg,#2b3c2e,#223229); color:var(--ink); border-color:var(--line); }
:root[data-theme="dark"] :is(.entry,.fact-cell,.walk-guide li,.export-group,.research-note,.overview-detail) { background:var(--surface); }
:root[data-theme="dark"] :is(.sync-progress,.ai-access-request--pending,.bone-offering,.bone-reflection,.bone-invitation,.atlas-coverage,.atlas-evidence article,.atlas-path,.atlas-map-time,.atlas-map-candidates button,.atlas-map-chosen) { background:var(--paper-2); }
:root[data-theme="dark"] .atlas-hero { background:radial-gradient(ellipse at 90% 15%,#354535,transparent 60%),var(--surface); }
:root[data-theme="dark"] .atlas-map-candidates button[aria-pressed="true"] { background:var(--fact-bg); }
:root[data-theme="dark"] :is(.atlas-view-tabs button[aria-pressed="true"],.research-tabs [aria-pressed="true"]) { background:var(--paper-2); color:var(--ink); }
:root[data-theme="dark"] :is(.atlas-map-canvas,.leaflet-container) { background:var(--paper-2); }
:root[data-theme="dark"] :is(.leaflet-popup-content-wrapper,.leaflet-popup-tip,.leaflet-bar a) { background:var(--surface); color:var(--ink); }
:root[data-theme="dark"] .leaflet-control-attribution { background:#223229ed; color:var(--muted); }
:root[data-theme="dark"] .leaflet-control-attribution a { color:var(--moss); }
:root[data-theme="dark"] :is(.ai-access-panel [data-ai-access-error],[data-exchange-error],.sync-panel [data-sync-error],.research-warning) { color:var(--danger); }
:root[data-theme="dark"] .research-kind { color:var(--clay); }
:root[data-theme="dark"] .research-dialog textarea { background:var(--surface); color:var(--ink); }
:root[data-theme="dark"] .fan::before { background:radial-gradient(ellipse at 50% 0,#80956c18,transparent 38%),linear-gradient(180deg,transparent,#17231e); }
:root[data-theme="dark"] .fan-scroll { background:linear-gradient(180deg,#22322933,#17231eb8); }
:root[data-theme="dark"] .ancestor-card--empty { background:#22322988; }
:root[data-theme="dark"] .ancestor-card--current { background:#423e2b; }
:root[data-theme="dark"] .ancestor-card__current { background:#765334; color:#fff8e9; }
:root[data-theme="dark"] .ancestor-card--male .ancestor-card__photo { background:#34483b; color:#bed5bd; }
:root[data-theme="dark"] .ancestor-card--female .ancestor-card__photo { background:#493c31; color:#ddc3a8; }
:root[data-theme="dark"] .ancestor-card--self .ancestor-card__photo { background:#d4c8ac; color:#27372f; }
:root[data-theme="dark"] .ancestor-card__candle { background:#50442c; }
:root[data-theme="dark"] :is(.person-photo,.today-card__image) { background:#465343; }
:root[data-theme="dark"] .button.person-walk { background:#d5c199; color:#233024; }
:root[data-theme="dark"] .person-walk__copy small { color:#3a493b; }
:root[data-theme="dark"] .difficult-section { background:linear-gradient(145deg,#40302c,#28362b); }
:root[data-theme="dark"] .difficult-entry { background:#302d26; }
:root[data-theme="dark"] .material__delete { background:#18261ced; }
:root[data-theme="dark"] :is(.journey-companion,.journey-entry-companion,.journey-question,.journey-encounters button) { background:#2c3b2d; color:var(--ink); border-color:var(--line); }
:root[data-theme="dark"] :is(.journey-page .text-link,.journal-page > .text-link,.journey-summary details) { color:var(--moss); }
:root[data-theme="dark"] :is(.journey-list__item small,.journey-encounters small) { color:var(--muted); }
:root[data-theme="dark"] :is(.journey-timeline,.journey-writing,.journey-return,.journey-summary,.journey-transcript,#journeyForm fieldset) { border-color:var(--line); }
:root[data-theme="dark"] .journal-card.dream-card { background:linear-gradient(120deg,#393247,#282f2b); }
:root[data-theme="dark"] :is(.dream-empty,.dream-original,.modal:has(.dream-heading),.dream-interpretation) { background:#302b3a; color:var(--ink); }
:root[data-theme="dark"] :is(.dream-badge,.dream-heading .dream-moon,.dream-extras > summary) { color:var(--image); }
:root[data-theme="dark"] .dream-interpretation [data-dream-evidence] { color:var(--clay); }
:root[data-theme="dark"] :is(.letter-invitation,.letter-invitation:hover,.letter-phrase:hover) { background:#333c2e; border-color:var(--line); }
:root[data-theme="dark"] :is(.letter-invitation > span:first-child,.letter-recipient > span:first-child,.letter-phrase > span:last-child) { color:var(--clay); }
:root[data-theme="dark"] .letter-dialog .letter-paper { background:linear-gradient(135deg,#30392b,#283427); border-color:#667050; box-shadow:0 12px 30px #07100b33; }
:root[data-theme="dark"] .letter-dialog .letter-paper textarea { background:transparent; color:#ede5cf; }
:root[data-theme="dark"] .letter-paper > span { color:var(--clay); }
:root[data-theme="dark"] .overview-stage { background:radial-gradient(ellipse,#2b3b2f,#19261e); }
:root[data-theme="dark"] .overview-node text { fill:var(--ink); stroke:var(--paper); }
:root[data-theme="dark"] .overview-edges path { stroke:#8da58b; }
:root[data-theme="dark"] .overview-edges .is-path { stroke:#e4c792; }
:root[data-theme="dark"] .overview-edges .is-partner { stroke:#d2a0c6; }
:root[data-theme="dark"] .overview-halo { stroke:#c2d7b2; }
:root[data-theme="dark"] :is(.overview-node.is-selected .overview-halo,.overview-node:focus circle) { stroke:#f0d29c; }
:root[data-theme="dark"] :is(.overview-navigation button,.overview-selected,.tree-overview.is-expanded) { background:var(--surface); color:var(--ink); }
:root[data-theme="dark"] :is([data-overview-results] button,.overview-detail details button) { color:var(--moss); }
:root[data-theme="dark"] :is(.language-switch,.letter-source) { border-color:var(--line); }
:root[data-theme="dark"] .language-switch button { color:var(--muted); }
:root[data-theme="dark"] .language-switch button[aria-pressed="true"] { background:#c4d6ba; color:#18261c; }
:root[data-theme="dark"] .language-note { color:var(--muted); }
:root[data-theme="dark"] .app-footer a { text-decoration-color:#b3cbb066; }
:root[data-theme="dark"] .altar-space { background:radial-gradient(ellipse at 50% 35%,#35432e,#223126 65%,#1c2a21); color:var(--ink); }
:root[data-theme="dark"] .altar-space[data-lit="true"] { background:radial-gradient(ellipse at 50% 85%,#665436,#2d3929 45%,#1c2a21); }
:root[data-theme="dark"] .altar-portrait { background:#48503b; color:#e1d1a6; border-color:#727558; }
:root[data-theme="dark"] .altar-centre > .altar-portrait { box-shadow:0 0 64px 14px #e0b9650c; }
:root[data-theme="dark"] :is(.altar-centre .eyebrow,.altar-companion .link-button) { color:#d1c6a2; }
:root[data-theme="dark"] .altar-empty { background:var(--surface); }
/* Camera output and spatial overlay retain their own legible colors. */
:root[data-theme="dark"] .altar-camera-view .button { background:#f1e5c9; color:#25382c; border-color:#f1e5c9; }
:root[data-theme="dark"] .altar-camera-view .button--secondary { background:#273d32; color:#fff8e9; border-color:#abbba9; }
:root[data-theme="dark"] .altar-camera-scene .altar-space { background:radial-gradient(ellipse,#27382b55,transparent 70%); color:#fff8e9; }
@media print { .theme-setting { display:none; } }
