/* Reading themes. Keep the archive's original paper palette as the default. */
:root{
  color-scheme:light;
  --theme-control-bg:#fffefa;
  --theme-control-text:#25362f;
  --theme-control-line:#cbd3c3;
  --theme-control-hover:#e9eee5;
  --theme-control-shadow:0 4px 20px #25362f14;
  --theme-focus:#678a56;
}

.theme-toggle{
  position:fixed;
  z-index:20;
  right:max(24px,env(safe-area-inset-right));
  bottom:calc(22px + env(safe-area-inset-bottom));
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:44px;
  min-width:44px;
  padding:11px 15px;
  border:1px solid var(--theme-control-line);
  border-radius:24px;
  background:var(--theme-control-bg);
  color:var(--theme-control-text);
  box-shadow:var(--theme-control-shadow);
  font-size:12px;
  line-height:1.5;
  white-space:nowrap;
  transition:background-color .15s,border-color .15s,box-shadow .15s;
}
.theme-toggle:hover{background:var(--theme-control-hover)}
.theme-toggle:focus-visible{outline:2px solid var(--theme-focus);outline-offset:4px}
.theme-toggle svg{width:17px;height:17px;flex-shrink:0;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
/* Leave room for the fixed control when the reader reaches the footer. */
.bottom-bar{padding-bottom:88px}

html[data-theme="dark"]{
  color-scheme:dark;
  --paper:#141c18;
  --white:#1b251f;
  --ink:#e4e7dc;
  --muted:#a7b1a3;
  --line:#38463a;
  --green:#b5cba5;
  --soft-green:#293a2d;
  --gold:#c8b882;
  --red:#e5a594;
  --night-surface:#202d24;
  --night-raised:#293a2d;
  --night-hover:#25352a;
  --night-selected:#2c4130;
  --night-selected-line:#708967;
  --night-soft-text:#b4beab;
  --night-dim-text:#9caa93;
  --night-accent:#c0d5af;
  --night-accent-solid:#b5cba5;
  --night-accent-ink:#1b2b1c;
  --night-focus:#d5dfab;
  --night-gain:#b7d5a5;
  --night-gain-bg:#25382a;
  --night-gain-line:#81a576;
  --night-loss:#efb09e;
  --night-loss-bg:#382b26;
  --night-loss-line:#b58270;
  --night-neutral:#c4c6ae;
  --night-neutral-bg:#2c3228;
  --night-neutral-line:#899176;
  --theme-control-bg:#26382b;
  --theme-control-text:#e2e8d8;
  --theme-control-line:#63765a;
  --theme-control-hover:#314735;
  --theme-control-shadow:0 4px 24px #0005;
  --theme-focus:var(--night-focus);
}
html[data-theme="dark"] ::selection{background:#516348;color:#fffef2}
html[data-theme="dark"] :is(button,a,input,select):focus-visible{outline-color:var(--night-focus)}
html[data-theme="dark"] .search-box:focus-within{outline:2px solid var(--night-focus);outline-offset:3px}
html[data-theme="dark"] .text-button:hover{color:#d4e4bd}
html[data-theme="dark"] .serif-accent{color:var(--night-accent)}
html[data-theme="dark"] .hero-description{color:var(--night-soft-text)}
html[data-theme="dark"] .primary-button{background:var(--night-accent-solid);color:var(--night-accent-ink)}
html[data-theme="dark"] .primary-button:hover{background:#caddb9}
html[data-theme="dark"] .secondary-button{color:var(--night-accent)}
html[data-theme="dark"] .hero-note{color:var(--night-dim-text)}
html[data-theme="dark"] .tiny-dot{background:var(--night-dim-text)}
html[data-theme="dark"] .ledger-art{
  background:#253429;
  border-color:#4b6046;
  box-shadow:9px 11px 0 #1d2920;
  color:#b6cba7;
}
html[data-theme="dark"] :is(.ledger-head,.ledger-footer){border-color:#53664a}
html[data-theme="dark"] .ledger-title{color:#d0dfbd}
html[data-theme="dark"] :is(.ledger-lines em,.art-curve span){color:#b1c09f}
html[data-theme="dark"] .stats strong span{color:var(--night-soft-text)}
html[data-theme="dark"] .download-button{border-color:#56664c}
html[data-theme="dark"] .scope-note{background:var(--night-surface);border-color:var(--line);color:var(--night-soft-text)}
html[data-theme="dark"] .scope-note b{color:var(--night-accent)}
html[data-theme="dark"] .info-icon{border-color:#8c9f7a;color:var(--night-accent)}
html[data-theme="dark"] :is(.era-tab>span,.era-tab>span b,.era-tab small){color:var(--night-dim-text)}
html[data-theme="dark"] :is(.era-tab.active>span,.era-tab.active>span b){color:var(--night-accent)}
html[data-theme="dark"] .timeline-panel{background:var(--night-surface)}
html[data-theme="dark"] :is(.timeline-caption small,.timeline-key,.timeline-years){color:var(--night-dim-text)}
html[data-theme="dark"] .timeline{
  border-color:#53634a;
  background:repeating-linear-gradient(90deg,transparent 0,transparent calc(20% - 1px),#3b4b38 calc(20% - 1px),#3b4b38 20%);
}
html[data-theme="dark"] .timeline-dot{background:#8fa880;border-color:var(--night-surface)}
html[data-theme="dark"] .timeline-dot.loss{background:var(--night-loss)}
html[data-theme="dark"] :is(.timeline-dot:hover,.timeline-dot.selected){background:var(--night-accent);box-shadow:0 0 0 2px #6e875f}
html[data-theme="dark"] :is(.timeline-dot.loss:hover,.timeline-dot.loss.selected){background:var(--night-loss);box-shadow:0 0 0 2px #ac7c68}
html[data-theme="dark"] .search-box svg{stroke:var(--night-soft-text)}
html[data-theme="dark"] .search-box input::placeholder{color:var(--night-dim-text)}
html[data-theme="dark"] .search-box kbd{color:var(--night-soft-text);background:var(--night-surface);border-color:var(--line)}
html[data-theme="dark"] .select-wrap select{color:var(--night-soft-text)}
html[data-theme="dark"] :is(.results-heading,.results-hint){color:var(--night-dim-text)}
html[data-theme="dark"] .record-list{scrollbar-color:#64785b transparent}
html[data-theme="dark"] .record:hover{background:var(--night-hover)}
html[data-theme="dark"] .record.selected{background:var(--night-selected);border-color:var(--night-selected-line);box-shadow:inset 3px 0 0 var(--night-accent)}
html[data-theme="dark"] :is(.record-top,.record-top time,.record .en,.record-arrow,.record-summary){color:var(--night-soft-text)}
html[data-theme="dark"] .monogram{background:#27382a;color:#c0d1af;border-color:#53664b}
html[data-theme="dark"] .record:nth-child(4n+2) .monogram{background:#37372a;color:#d1c69e}
html[data-theme="dark"] .record:nth-child(4n+3) .monogram{background:#3b302a;color:#d4b5a3}
html[data-theme="dark"] .tag{border-color:#5b6c4e;color:#bdcda9}
html[data-theme="dark"] .metric{color:var(--night-gain)}
html[data-theme="dark"] .metric.loss{color:var(--night-loss)}
html[data-theme="dark"] :is(.metric.unknown,.metric.mixed,.metric.holding){color:var(--night-neutral)}
html[data-theme="dark"] .detail-panel{border-color:#4d6044}
html[data-theme="dark"] :is(.detail-top,.detail-en,.summary-label){color:var(--night-dim-text)}
html[data-theme="dark"] .summary-value{color:var(--night-accent)}
html[data-theme="dark"] .reason-num{color:#b7c7a6;border-color:#718765}
html[data-theme="dark"] .reason-block p{color:var(--night-soft-text)}
html[data-theme="dark"] .result-box{background:var(--night-gain-bg);border-color:var(--night-gain-line)}
html[data-theme="dark"] .result-box.loss{background:var(--night-loss-bg);border-color:var(--night-loss-line)}
html[data-theme="dark"] :is(.result-box.mixed,.result-box.unknown,.result-box.holding){background:var(--night-neutral-bg);border-color:var(--night-neutral-line)}
html[data-theme="dark"] .result-label{color:var(--night-soft-text)}
html[data-theme="dark"] .result-label strong{color:var(--night-gain)}
html[data-theme="dark"] .result-box.loss .result-label strong{color:var(--night-loss)}
html[data-theme="dark"] :is(.result-box.mixed,.result-box.unknown,.result-box.holding) .result-label strong{color:var(--night-neutral)}
html[data-theme="dark"] .result-box p{color:var(--night-soft-text)}
html[data-theme="dark"] .metric-note{color:var(--night-dim-text)!important}
html[data-theme="dark"] .lesson{border-color:#4a5b41;color:var(--night-accent)}
html[data-theme="dark"] :is(.lesson span,.detail-note,.sources-header){color:var(--night-dim-text)}
html[data-theme="dark"] .source-link{background:var(--night-surface);border-color:#42533a;color:var(--night-accent)}
html[data-theme="dark"] .source-link:hover{background:var(--night-raised)}
html[data-theme="dark"] .detail-pager button{color:var(--night-accent)}
html[data-theme="dark"] .detail-pager button:disabled{color:#6f7a67}
html[data-theme="dark"] .empty-state{color:var(--night-soft-text)}
html[data-theme="dark"] .components-box th{color:var(--night-dim-text)}
html[data-theme="dark"] .components-box td{border-color:#33422f;color:var(--night-soft-text)}
html[data-theme="dark"] .components-box td b{color:var(--night-accent)}
html[data-theme="dark"] :is(.components-box td small,.components-box>p){color:var(--night-dim-text)}
html[data-theme="dark"] :is(.section-aside,.chapter-number span){color:var(--night-dim-text)}
html[data-theme="dark"] .evolution-grid article{border-color:#667e57}
html[data-theme="dark"] .chapter-number{color:var(--night-accent)}
html[data-theme="dark"] .evolution-grid p{color:var(--night-soft-text)}
html[data-theme="dark"] :is(.evolution-grid button,.research-footer button){color:var(--night-accent)}
html[data-theme="dark"] .research-footer>div>p:not(.eyebrow){color:var(--night-soft-text)}
html[data-theme="dark"] .research-footer .succession{color:var(--night-dim-text)!important}
html[data-theme="dark"] .bottom-bar{color:var(--night-dim-text)}
html[data-theme="dark"] :is(.footer-brand,.footer-brand b,.bottom-bar a){color:var(--night-accent)}
html[data-theme="dark"] dialog{border-color:#627954;box-shadow:0 15px 70px #0008}
html[data-theme="dark"] dialog::backdrop{background:#050d09c9}
html[data-theme="dark"] .close-button{color:var(--night-accent)}
html[data-theme="dark"] .method-body{color:var(--night-soft-text)}
html[data-theme="dark"] :is(.method-body h3,.method-body a){color:var(--night-accent)}
html[data-theme="dark"] .skip-link:focus{background:var(--night-accent-solid);color:var(--night-accent-ink)}
html[data-theme="dark"] .timeline-scroll{scrollbar-color:#64785b transparent}

@media(max-width:760px){
  .theme-toggle{right:max(16px,env(safe-area-inset-right));bottom:calc(16px + env(safe-area-inset-bottom));padding:11px 13px;font-size:11px}
  .bottom-bar{padding-bottom:calc(80px + env(safe-area-inset-bottom))}
}
@media(prefers-reduced-motion:reduce){.theme-toggle{transition:none}}
