/* Theme primitives come only from the validated local palette catalogue. */
:root[data-theme]{
 --ink:var(--theme-ink,#203e34);--muted:var(--theme-muted,#62766b);--line:var(--theme-border,#d5dfd0);
 --green:var(--theme-primary,#2c5943);--green-dark:var(--theme-primary,#2c5943);--paper:var(--theme-surface,#fffefa);
 --warm:var(--theme-soft,#edf2e7);--surface:var(--paper);--surface-alt:var(--warm);--border:var(--line);
 --reading-surface:var(--paper);--reading-ink:var(--ink);--reading-muted:var(--muted);--reading-line:var(--line);
 --theme-focus:var(--green);--theme-selected:color-mix(in srgb,var(--green) 12%,var(--paper));
}
html[data-theme],html[data-theme] body{background:var(--theme-bg,#f6f7f2);color:var(--ink)}
:root[data-theme] .sidebar{background:var(--theme-rail,#203e33);border-color:color-mix(in srgb,var(--theme-rail,#203e33) 85%,white);scrollbar-color:#ffffff44 transparent}
:root[data-theme] .brand-mark{background:var(--theme-accent,#d1b47b);color:var(--theme-rail,#203e33)}
:root[data-theme] .nav-item.active::before{background:var(--theme-accent,#d1b47b)}:root[data-theme] .nav-item.active .nav-icon{color:var(--theme-accent,#d1b47b)}
:root[data-theme] .sidebar .avatar{color:var(--theme-accent,#d1b47b)}
:root[data-theme] :is(.sidebar .family-switcher p,.sidebar .family-switcher label,.sidebar-note p,.sidebar .user-card span){color:#d1ddd4}
:root[data-theme] .topbar{background:color-mix(in srgb,var(--paper) 94%,transparent);border-color:var(--line)}
:root[data-theme] :is(.account-bar,.panel,.auth-card,.modal,.modal-head,.modal-actions,.search-box,.button-secondary,.tree-wrap.expanded,.platform-metrics>div){background:var(--paper);border-color:var(--line)}
:root[data-theme] :is(#save-status,.role-badge,.detail-facts,.tree-households,.directory-head,.story-timeline li,.archive-list li,.merge-candidates li,.merge-preview,.auth-notice,.auth-status,.notification-item.is-unread,.security-setup,.story-source){background:var(--theme-soft,#edf2e7);border-color:var(--line);color:var(--ink)}
:root[data-theme] .overview-heading{background:var(--theme-soft,#edf2e7);border-color:var(--line)}
:root[data-theme] .overview-heading::before{border-color:color-mix(in srgb,var(--green) 15%,transparent);box-shadow:0 0 0 38px var(--theme-soft,#edf2e7),0 0 0 39px color-mix(in srgb,var(--green) 12%,transparent),0 0 0 77px var(--theme-soft,#edf2e7),0 0 0 78px color-mix(in srgb,var(--green) 8%,transparent)}
:root[data-theme] :is(.page-heading h1,.person-hero h2,.auth-story h1,.auth-brand,.crumb strong){color:var(--ink)}
:root[data-theme] :is(.subheading,.overview-heading .subheading,.overview-heading .eyebrow,.overview-heading .eyebrow span,.overview-heading .updated,.eyebrow,.panel-heading .eyebrow,.detail-panel .person-bio,.member-main small,.member-branch,.member-date,.form-hint,.tree-foot,.tree-legend,.tree-relationship-legend,.directory-count,.directory-sort,.person-location,.scope-description,.account-tools label,.stat-top,.stat-card small,.auth-intro-note,.auth-story p,.auth-card header p,.auth-footnote,.auth-hint){color:var(--muted)}
:root[data-theme] .page-heading:not(.overview-heading){border-left-color:var(--theme-accent,#d1b47b)}
:root[data-theme] .stat-card{background:var(--paper);border-color:var(--line)}:root[data-theme] :is(.stat-card>strong,.platform-metrics strong,.row-arrow,.text-button,.button-secondary){color:var(--green)}
:root[data-theme] .stat-card::after{background:var(--theme-accent,#d1b47b)}:root[data-theme] .stat-card:first-child{background:var(--theme-rail,#203e33);border-color:var(--theme-rail,#203e33)}
:root[data-theme] .stat-card:first-child>strong{color:#fffefa}:root[data-theme] .stat-card:first-child :is(.stat-top,small){color:#e0e9df}
:root[data-theme] .stat-icon{background:var(--theme-soft,#edf2e7);color:var(--green)}:root[data-theme] .stat-card:first-child .stat-icon{background:#ffffff15;color:#f0eadc}
:root[data-theme] .button-primary,:root[data-theme] .auth-brand-mark{background:var(--green);border-color:var(--green);color:white}
:root[data-theme] :is(.member-row.selected,.tree-card.current,.tree-card.household-highlight,.tree-household-option[aria-pressed=true],.merge-rows label:has(input:checked)){background:var(--theme-selected);border-color:var(--green)}
:root[data-theme] :is(.avatar,.status.verified,.admin-chip){background:var(--theme-soft,#edf2e7);color:var(--green)}
:root[data-theme] .tree-viewport{background:radial-gradient(circle,var(--line) 1px,transparent 1px) 4px 4px/20px 20px,var(--paper)}
:root[data-theme] .tree-canvas .tree-card{background:var(--paper);border-color:var(--line)}:root[data-theme] .tree-canvas .tree-card.current{background:var(--theme-selected);border-color:var(--green);box-shadow:0 0 0 1px var(--green)}
:root[data-theme] :is(.tree-canvas .tree-card small,.tree-canvas .tree-card .tree-dates){color:var(--muted)}
:root[data-theme] .tree-links .parent-link{stroke:var(--green)}:root[data-theme] .tree-links .tree-arrow{fill:var(--green)}:root[data-theme] .tree-links .spouse-link{stroke:var(--muted)}
:root[data-theme] :is(.account-tools select,.preference-grid select,.language-switcher select,.theme-switcher select,.auth-password){background:var(--paper);border-color:var(--line);color:var(--ink)}
:root[data-theme] :where(.page-content,.modal,.auth-page) :is(input:not([type]),input[type=text],input[type=search],input[type=email],input[type=password],input[type=url],input[type=number],input[type=date],input[type=datetime-local],select,textarea){background:var(--paper);color:var(--ink);border-color:var(--line)}
:root[data-theme] :is(.story-source,.deduplication-page pre,.archives-page pre){background:var(--theme-soft,#edf2e7);color:var(--ink)}
:root[data-theme] :is(.notification-todos,.story-timeline,.story-timeline li,.archive-list li,.merge-preview,.merge-rows fieldset,.notification-item){border-color:var(--line)}:root[data-theme] .notification-todos{border-left-color:var(--theme-accent,#d1b47b)}
:root[data-theme] .story-timeline li::before{background:var(--green);border-color:var(--paper);box-shadow:0 0 0 1px var(--line)}
:root[data-theme] .story-detail blockquote{border-left-color:var(--theme-accent,#d1b47b)}
:root[data-theme] .auth-page{background:radial-gradient(ellipse at 0% 0%,var(--theme-soft,#edf2e7),transparent 65%),var(--theme-bg,#f6f7f2)}
:root[data-theme] :is(.auth-tabs a,.auth-card a,.auth-password button){color:var(--green)}:root[data-theme] .auth-tabs a[aria-current]{border-color:var(--green)}
:root[data-theme] .auth-art span{background:var(--paper);border-color:var(--line);color:var(--green)}:root[data-theme] .auth-art i{background:var(--line)}
:root[data-theme] input[type=checkbox],:root[data-theme] input[type=radio]{accent-color:var(--green)}
:root[data-theme] :where(button,a,input,select,textarea,summary):focus-visible{outline-color:var(--theme-focus)}:root[data-theme] .sidebar :is(button,select):focus-visible{outline-color:var(--theme-accent,#d1b47b)}
:root[data-theme] ::selection{background:var(--theme-selected);color:var(--ink)}
/* Palette choices are real buttons with text and persistent selected state. */
.interface-controls{display:flex;gap:8px;align-items:center;min-width:0;flex-wrap:wrap}
.theme-switcher label{display:flex;align-items:center;gap:8px;color:var(--ink);font-size:14px;white-space:nowrap}
.theme-switcher select{font:inherit;min-height:44px;padding:8px 10px;max-width:100%;border:1px solid var(--line);border-radius:10px;background:var(--paper);color:var(--ink)}
.topbar .theme-switcher label>span{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.auth-page>.interface-controls{justify-content:flex-end;width:100%;max-width:1120px;margin-bottom:20px}.auth-page>.interface-controls .language-switcher{width:auto;max-width:none;margin:0}
.theme-settings{margin:28px 0;padding:24px;border:1px solid var(--line);border-radius:14px;background:var(--paper)}
.theme-heading{display:flex;gap:16px;align-items:center;justify-content:space-between;flex-wrap:wrap}.theme-heading h3{margin:0;font-family:"Songti TC","Songti SC",serif;font-size:1.5rem}.theme-heading .eyebrow{margin:0 0 6px}.theme-heading>a{color:var(--green);font-size:.9rem;text-underline-offset:4px;min-height:44px;display:inline-flex;align-items:center}
.theme-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px;margin:20px 0 16px}
.theme-card{display:flex;flex-direction:column;align-items:stretch;text-align:left;min-width:0;padding:12px;border:1px solid var(--line);border-radius:12px;background:var(--paper);color:var(--ink);gap:10px;transition:border-color 160ms,box-shadow 160ms}
.theme-card[aria-pressed=true]{border-color:var(--green);box-shadow:0 0 0 1px var(--green);background:var(--theme-selected)}
.theme-swatches{display:flex;height:40px;border-radius:7px;overflow:hidden;border:1px solid #0000000a}.theme-swatches i{flex:1}.theme-swatches i:first-child{flex:1.5}
.theme-card-title{display:flex;gap:8px;align-items:center;justify-content:space-between;font-size:1rem;font-weight:650}.theme-selected{visibility:hidden;display:grid;place-items:center;width:22px;height:22px;background:var(--green);color:#fff;border-radius:50%;font-size:.85rem}.theme-card[aria-pressed=true] .theme-selected{visibility:visible}
.theme-description{font-size:.875rem;color:var(--muted);line-height:1.7}.theme-harmony{font-size:.8rem;color:var(--green)}.theme-settings [data-theme-status]{min-height:24px;margin-bottom:0}
@media(hover:hover) and (pointer:fine){:root[data-theme] .button-primary:hover:enabled{background:color-mix(in srgb,var(--green) 85%,black);border-color:var(--green)}:root[data-theme] :is(.button-secondary,.tree-control,.member-row,.tree-household-option):hover:enabled{background:var(--theme-selected);border-color:var(--line)}:root[data-theme] .nav-item:hover{background:#ffffff14;color:#fff}.theme-card:hover{border-color:var(--green);box-shadow:0 4px 14px #00000008}}
@media(max-width:1279px){.save-state{display:none}.theme-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.topbar{flex-wrap:wrap}.top-actions{max-width:100%;flex-wrap:wrap}}
@media(max-width:767px){.topbar{flex-wrap:wrap}.topbar .top-actions{justify-content:flex-end;gap:8px;width:100%}.interface-controls{gap:6px}.theme-switcher select{font-size:14px;padding-inline:8px;max-width:116px}.topbar .language-switcher select{max-width:106px;padding-inline:8px}.top-actions .notification-bell{padding-inline:8px}.top-actions>[data-action=open-add]{margin-left:auto}.theme-settings{padding:16px;margin-inline:-2px}.theme-grid{gap:12px;grid-template-columns:repeat(2,minmax(0,1fr))}.theme-card{padding:10px;gap:8px}.theme-description{font-size:.85714rem}.theme-swatches{height:32px}.theme-heading{gap:8px}.auth-page>.interface-controls{max-width:480px;margin-bottom:8px;justify-content:flex-end}.auth-page>.interface-controls label>span{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}}
@media(max-width:390px){.topbar .top-actions{justify-content:flex-start}.topbar .interface-controls{margin-left:auto}.top-actions>[data-action=open-add]{width:100%;margin:0}.top-actions>[data-view=access]{width:100%}}
:root[data-contrast=high]{--ink:#102219;--muted:#24392b;--line:#536553;--green:#214b30;--green-dark:#123820;--paper:#fff;--theme-bg:#fff!important;--theme-soft:#f0f5eb!important;--theme-selected:#dce8d2;--theme-focus:#123820;--theme-rail:#f0f5eb!important;--theme-accent:#214b30!important}
:root[data-contrast=high] .sidebar{background:#f0f5eb;border-color:#536553}:root[data-contrast=high] .stat-card:first-child{background:#fff;border-color:#536553}:root[data-contrast=high] .stat-card:first-child>strong{color:#102219}:root[data-contrast=high] .theme-card[aria-pressed=true]{outline:2px solid #123820;outline-offset:2px}:root[data-contrast=high] .theme-card .theme-selected{background:#123820;color:#fff!important}:root[data-contrast=high] .brand-mark{background:#123820;color:#fff!important}
@media(prefers-reduced-motion:reduce){.theme-card{transition:none}}
@media print{:root[data-theme]{--paper:#fff;--theme-bg:#fff!important;--theme-soft:#fff!important;--ink:#000;--muted:#333}.theme-settings,.theme-switcher{display:none}}
