/* Appearance controls live outside the re-rendered game area. */
.header-tools { display:flex; align-items:center; gap:14px; flex-shrink:0; }
.color-mode-toggle {
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  min-height:36px; padding:6px 10px; border:1px solid #b2b6be80;
  border-radius:7px; background:#ffffff08; color:#e7ebf3;
  font:600 11px/1.5 var(--sans); white-space:nowrap; cursor:pointer;
}
.color-mode-toggle[aria-pressed="true"] { background:#d1b77520; border-color:#c3a86d; color:#f1d99d; }
.color-mode-toggle:focus-visible { outline:2px solid #f1d99d; outline-offset:3px; }
@media(max-width:1100px) { .header-tools {flex-direction:column;gap:5px;} }
@media(max-width:800px) {
  .header-tools {margin-left:auto;}
  .header .header-tools .help-btn {margin:0;}
  .color-mode-toggle {min-height:30px;padding:4px 8px;font-size:10px;}
}

:root[data-color-mode="dark"] {
  color-scheme:dark;
  --paper:#181c24 !important; --light:#252931 !important;
  --ink:#e8ecf4 !important; --muted:#b3b7bf !important;
  --line:#4e525a !important;
  --red:#dfac91 !important;
  --surface:#252931; --surface-raised:#31353d; --surface-inset:#1e222a;
}
:root[data-color-mode="dark"] body {
  --ink:#e8ecf4; --muted:#b3b7bf; --gold:#d5b97a; --green:#c0c4cc;
  background:#12161e !important; color:var(--ink);
}
:root[data-color-mode="dark"] .site-wrap {
  background:linear-gradient(115deg,#1b1f27,#22262e 52%,#1a1e26);
  border-color:#494d55; box-shadow:0 0 70px #0008;
}

/* Reading surfaces. No filters or inversion are applied to artwork/maps. */
:root[data-color-mode="dark"] :is(
  .birth-panel,.home-scenes,.path-card,.archive-card,.hall-card,.hall-intro,
  .honor-summary,.ending,.conquest-sidebar,.character-panel,.secondary,
  .experience-grid article,.policy-panel,.policy-option,.campaign-method,
  .unification-panel,.trait-card,.birth-innate,.ability-radar,.support-panel,
  .faction-court,.court-grid .court-person,.province-panel,.province-item,
  .personnel-review,.personnel-review-role,.recruitment-review,.recruitment-review-candidate,
  .career-transfer,.career-transfer-candidate,.promotion-all,.promotion-check,
  .conquest-card,.conquest-detail,.conquest-city-directory,.conquest-position,
  .chronology-year,.elder-choice-group,.history-choice-group,.atlas-region-summary
) {
  background:linear-gradient(135deg,#2c3038,#23272f);
  color:var(--ink); border-color:var(--line);
  box-shadow:0 5px 18px #0002;
}
:root[data-color-mode="dark"] :is(
  .setup-randomize,.portrait-setup,.portrait-option,.art-gallery figure,
  .birth-customization,.home-scene-card,.annual-action-slot,.personal-choice-group,
  .life-progress-card,.story-choice-group,.personal-story-promise,.story-actual-rewards,
  .world-strip,.world-strip>div,.historical-context,.talent-badge,.income-panel,
  .campaign-requirements,.campaign-readiness,.conquest-pressure,.allegiance-reputation,
  .career-management,.personal-story-panel,.personal-story-result,.life-result,
  .mastery-entry,.hall-readonly,.choice-experience,.routine-choice-detail,
  .experience-mastery,.policy-rules,.campaign-route-explanation,.unification-summary,
  .growth-outcome,.world-result-entry,.world-detail .world-effect,.world-metrics>div,
  .biography-judgment,.birth-family,.birth-table thead,.honor-badge,.patronage-strip,
  .historical-choice-reward,.historical-result-reward,.historical-duty-info,
  .promotion-status,.personnel-review-result,.recruitment-review-warning.is-notice,
  .expedition-match,.city-grade-card,.conquest-region-controls,.conquest-choice-link,
  .conquest-placement-note,.campaign-phase-table thead,.chronology-entry-heading small,
  .chronology-entry .chronology-divergence,.policy-benefit,.policy-current,
  .story-choice-memory,.atlas-heading,.atlas-legend,.atlas-note,.atlas-controls,
  .atlas-pan-hint,.conquest-map-controls,.conquest-drag-hint
) { background:var(--surface-inset); color:var(--ink); border-color:var(--line); }
:root[data-color-mode="dark"] :is(.result-box,.annual-actions,.choice-category-tabs) {
  background:linear-gradient(120deg,#2a2e36,#1e222a) !important; color:var(--ink);
}
:root[data-color-mode="dark"] :is(.choices .choice[data-choice],.choices .routine-choice-card,
  .choice-jump-nav .choice-jump-button,.conquest-region-controls button,
  .conquest-city-directory button,.conquest-connections button,.province-item button) {
  background:var(--surface-raised); color:var(--ink); border-color:#5f636b;
  box-shadow:0 2px 5px #0003;
}
:root[data-color-mode="dark"] :is(.choices .choice[data-choice]:disabled,.choice.disabled,
  .routine-choice-card:has(>.choice:disabled),.policy-option>button:disabled) {
  background:#22262e; color:#a1a5ad; border-color:#444850;
}
:root[data-color-mode="dark"] :is(.action-slot-badge,.choice-jump-count) {
  background:#40444c !important; color:#dbdfe7 !important; border-color:#6a6e76 !important;
}
:root[data-color-mode="dark"] .annual-action-slot.is-used {background:#343840 !important;}
:root[data-color-mode="dark"] .routine-success-rate {
  background:#3d4149; color:#d9dde5; border-color:#80848c; box-shadow:none;
}
:root[data-color-mode="dark"] :is(.campaign-method-missing,.recruitment-review-warning,
  .career-transfer-warning,.allegiance-warning,.policy-tradeoff) {
  background:#3c2d25 !important; color:#f1ba9f !important;
}
:root[data-color-mode="dark"] :is(.campaign-method-heading strong,.campaign-method.is-ready .campaign-method-heading strong) {
  background:#3d4149; color:#d1d5dd;
}

/* Legacy components contain fixed ink colors; adapt the text as well as the card. */
:root[data-color-mode="dark"] :is(.birth-panel,.home-scenes,.character-panel,
  .choice,.routine-choice-detail,.policy-panel,.policy-option,.promotion-readable,
  .recruitment-review,.career-guide,.conquest-panel,.conquest-detail,.conquest-position,
  .province-panel,.faction-court,.hall-card,.hall-intro,.honor-summary,.support-panel,
  .modal-copy,.historical-context,.chronology-year,.history-choice-group,
  .campaign-requirements,.campaign-readiness,.story-choice-group,.personal-story-panel,
  .life-progress-card,.trait-card,.world-detail,.ending,.result-box) :is(p,small,label,li,td,th) {
  color:var(--muted);
}
:root[data-color-mode="dark"] :is(.event-description,.biography-body,.biography-judgment p,.char-title,
  .choice-description,.modal-copy,.origin-reveal p,.birth-separation p,.birth-upbringing p,
  .birth-rule,.policy-intro,.policy-note,.policy-current p,.campaign-role-note,
  .campaign-readiness strong,.campaign-readiness b,.trait-choice-note>b,
  .home-scenes-title,.setup-randomize-note,.portrait-setup strong,.portrait-setup span,
  .honor-fields-note,.atlas-heading,.atlas-note,.conquest-placement-note) {color:var(--ink) !important;}
:root[data-color-mode="dark"] :is(.text-button,.event-eyebrow,.char-label,.char-name,
  .report-label,.eyebrow,.historical-context>span,.historical-context a,.source-list a,
  .talent-badge strong,.honor-score strong,.home-scene-card strong,.log-entry strong,
  .fate-cell strong,.birth-identity strong,.path-card h3,.ending .epithet,
  .policy-panel-top span,.choice-experience strong) {color:#e1c78e;}
:root[data-color-mode="dark"] :is(.forecast-gain b,.political-chance) {color:#c5c9d1;}
:root[data-color-mode="dark"] :is(.danger-note,.choice-requirement,.choice.disabled .choice-requirement) {color:#edb499;}
:root[data-color-mode="dark"] :is(.choice.disabled .choice-title,.forecast-gain small,
  .name-field label,.name-field input::placeholder,.setup-select-row label,.fate-cell span) {color:var(--muted);}
:root[data-color-mode="dark"] .promotion-readable {
  --promotion-ink:#e8ecf4; --promotion-muted:#b3b7bf;
  --promotion-good:#c9cdd5; --promotion-bad:#edb499;
}
:root[data-color-mode="dark"] .recruitment-review-candidate[data-recruitment-colors] {
  background:linear-gradient(135deg,color-mix(in srgb,var(--recruitment-banner) 45%,#252931),#23272f);
  --recruitment-ink:#e8ecf4; --recruitment-muted:#c0c4cc;
}
:root[data-color-mode="dark"] :is(.primary,.map-layer-switch .active,.region-chip.active,
  .alternate-stage-current .alternate-stage-number,.portrait-filter button[aria-pressed="true"]) {color:#fff2d6;}
:root[data-color-mode="dark"] :is(.bgm-player button,.bgm-player select,input,select,textarea) {
  color:var(--ink); border-color:#5c6068;
}
:root[data-color-mode="dark"] input::placeholder {color:#a5a9b1;}
:root[data-color-mode="dark"] :is(.atlas-controls button,.conquest-map-controls button) {color:#e8ecf4;}
:root[data-color-mode="dark"] .stat-track {background:#4a4e56;}
:root[data-color-mode="dark"] .stat-fill {filter:brightness(1.5);}
:root[data-color-mode="dark"] :is(.radar-label,.radar-number) {fill:#e1d1a8;}
:root[data-color-mode="dark"] .radar-value {fill:#b99a5b55;stroke:#e1c382;}
:root[data-color-mode="dark"] .radar-grid {stroke:#7b7f87;}
:root[data-color-mode="dark"] .radar-axis {stroke:#71757d;}
:root[data-color-mode="dark"] .growth-outcome.grown {background:#2e323a;}
:root[data-color-mode="dark"] .growth-outcome.grown.is-critical {background:linear-gradient(135deg,#554423,#302a1d);}
:root[data-color-mode="dark"] .specialty-badges>.rare-specialty-badge {color:#f0d598; background:#715a243d;}
:root[data-color-mode="dark"] .footer {color:var(--muted);border-color:#5a5e66;}
:root[data-color-mode="dark"] dialog {background:#252931;border-color:#7a7e86;box-shadow:0 20px 80px #0008;}
:root[data-color-mode="dark"] #toast {background:#dfcc98;color:#22262e;}
:root[data-color-mode="dark"] ::selection {background:#6b6f77;color:#fff;}
:root[data-color-mode="dark"] :focus-visible {outline-color:#e1c78e;}
:root[data-color-mode="dark"] :is(.bgm-label,.feature-symbol,.rare-slot-title,
  .ability-radar figcaption,.ability-radar figcaption strong,.home-court span,
  .chronology-heading h3,.chronology-entry-heading h4,.chronology-entry-heading>span,
  .chronology-sources a,.chronology-year summary,.chronology-era summary,
  .history-choice-group summary,.routine-choice-detail>summary,.choice-jump-heading,
  .char-stamp) {color:#e1c78e;}
:root[data-color-mode="dark"] :is(.choice-jump-heading>span,.home-life-line,
  .ability-radar>p,.footer b,.chronology-guide,.chronology-note) {color:var(--muted);}
:root[data-color-mode="dark"] .routine-choice-effects {color:#c5c9d1;}
:root[data-color-mode="dark"] :is(.routine-choice-effects .is-cost,.routine-choice-risk,
  .forecast-fixed.is-cost,.is-drawback) {color:#edb499;}
:root[data-color-mode="dark"] :is(.map-layer-switch .active,.region-chip.active,
  .alternate-stage-current .alternate-stage-number) {background:var(--faction-banner,#3b3f47);}
:root[data-color-mode="dark"] :is(h2,h3,h4,h5) {color:var(--ink);}
:root[data-color-mode="dark"] :is(summary,.home-lord-grid figcaption,.court-heading,
  .court-person strong,.court-officers>summary,.choice-person b) {color:#e1c78e;}
:root[data-color-mode="dark"] :is(.court-person small,.choice-person small,.court-notice) {color:var(--muted);}
:root[data-color-mode="dark"] :is(.chronology-details,.court-person,.world-detail,.modal-copy) a {color:#e1c78e;}
:root[data-color-mode="dark"] .choice-jump-nav {background:#2a2e36;}
:root[data-color-mode="dark"] :is(.choice-jump-arrow,.personnel-review-state,
  .historical-duty-heading>span,.historical-reward-heading,.historical-duty-info strong,
  .historical-choice-reward b,.recruitment-review-candidate-heading>strong) {color:#e1c78e;}
:root[data-color-mode="dark"] .routine-choice-participation {color:var(--muted);}
:root[data-color-mode="dark"] .career-transfer-ineligible {color:#edb499;}
:root[data-color-mode="dark"] .recruitment-review-candidate [data-recruitment-faction] {
  background:var(--recruitment-accent); color:#fff2d6;
}
:root[data-color-mode="dark"] :is(.conquest-position,.conquest-detail,.conquest-city-directory,
  .province-item,.province-heading,.city-grade-card) :is(strong,b) {color:#e1c78e;}
:root[data-color-mode="dark"] :is(.conquest-position,.conquest-detail,.conquest-city-directory,
  .conquest-region-controls,.conquest-map-controls,.province-item,.conquest-map-legend) :is(span,small),
:root[data-color-mode="dark"] :is(.conquest-status,.conquest-detail-copy,.conquest-map-note) {color:var(--muted);}
:root[data-color-mode="dark"] :is(.city-grade-card,.conquest-map-note) a {color:#e1c78e;}
:root[data-color-mode="dark"] .conquest-detail .conquest-detail-flag {color:#fff2d6;}
/* Reading contrast: override faction-specific ink only on dark reading surfaces. */
:root[data-color-mode="dark"] :is(.char-stamp,.age-number,.year-scene-kicker,
 .ability-radar figcaption span,.experience-grid strong,.experience-grid strong small,
 .career-transfer-candidate-heading>strong,.promotion-arrow,.policy-seal,.policy-rules b) {
 color:#ead19c !important;
}
:root[data-color-mode="dark"] :is(.ability-radar>p,.career-management-guide,
 .promotion-divider,.policy-panel-bottom>span,.fate-cell>span) {color:#c9cdd5 !important;}
:root[data-color-mode="dark"] .char-stamp {border-color:#9ca0a8 !important;}
:root[data-color-mode="dark"] .fate-row {background:#242830 !important;border-color:#61656d;}
:root[data-color-mode="dark"] .fate-cell strong {color:#ead19c !important;}
:root[data-color-mode="dark"] .choices .choice-arrow {
 background:#43474f !important;color:#f3dfb7 !important;border-color:#9599a1 !important;
}
:root[data-color-mode="dark"] .experience-grid article {background:#272b33 !important;}
:root[data-color-mode="dark"] .path-character {color:#baa77599;}
:root[data-color-mode="dark"] :is(.atlas-eyebrow,.atlas-note a,.conquest-position a,
 .conquest-detail a,.city-grade-card a) {color:#ead19c !important;}
:root[data-color-mode="dark"] :is(.atlas-heading-note,.atlas-zoom,.conquest-detail dd,
 .conquest-position dd) {color:#c9cdd5 !important;}
:root[data-color-mode="dark"] .conquest-detail .conquest-detail-flag {color:#fff !important;}

:root[data-color-mode="dark"] .character-mobile-summary strong{color:#ead19c!important}
/* Full reading-state audit: populated archives and expanded detail panels. */
:root[data-color-mode="dark"] {
  --reading-main:#edf1f9; --reading-muted:#c4c8d0; --reading-accent:#ead19c;
  --reading-good:#d3d7df; --reading-warning:#f0b99f;
}
:root[data-color-mode="dark"] .hall-stat-panel {border-color:#70747c;}
:root[data-color-mode="dark"] .hall-stat-panel>span {color:var(--reading-accent);}
:root[data-color-mode="dark"] .hall-stat-row {color:var(--reading-muted);}
:root[data-color-mode="dark"] .hall-stat-row dd {color:var(--reading-main);}
:root[data-color-mode="dark"] .hall-stat-fame dd {color:var(--reading-warning);}
:root[data-color-mode="dark"] .hall-stat-panel>small {color:var(--reading-muted);}
:root[data-color-mode="dark"] .hall-stat-row i {background:#4d5159;}
:root[data-color-mode="dark"] .hall-stat-row i b {background:#d8be83;}
:root[data-color-mode="dark"] .hall-stat-fame i b {background:#e5a68e;}
:root[data-color-mode="dark"] .honor-badge>b {color:var(--reading-accent);border-color:#9e8960;}
:root[data-color-mode="dark"] .honor-badge.locked {opacity:1;filter:none;background:#242830;border-style:dashed;}
:root[data-color-mode="dark"] .honor-badge.locked :is(b,span,small) {color:var(--reading-muted);}
:root[data-color-mode="dark"] .honor-badge small {color:var(--reading-muted);}
:root[data-color-mode="dark"] :is(.trait-study-progress,.trait-legacy,.trait-rare-progress,
 .rare-opportunity,.rare-specialty-result) {background:#2e323a;border-color:#817952;}
:root[data-color-mode="dark"] :is(.rare-section-title>span,.trait-rare-progress-heading>b,
 .trait-rare-progress-heading>span,.rare-specialty-card .trait-card-top>span,
 .rare-specialty-card .trait-card-top small,.rare-specialty-badge>small,
 .rare-opportunity-seal,.rare-specialty-result>span) {color:var(--reading-accent);}
:root[data-color-mode="dark"] :is(.trait-study-progress,.trait-legacy,.trait-rare-progress,.rare-opportunity) p {color:var(--reading-muted);}
:root[data-color-mode="dark"] .campaign-method-stats .is-met {color:var(--reading-good);}
:root[data-color-mode="dark"] .campaign-method-stats .is-missing {color:var(--reading-warning);}
:root[data-color-mode="dark"] .campaign-method-stats>div {border-color:#5e626a;}
:root[data-color-mode="dark"] :is(.policy-source,.policy-option-heading>span,.policy-option-heading>strong) {color:var(--reading-accent);}
:root[data-color-mode="dark"] .policy-footnote {color:var(--reading-muted);}
:root[data-color-mode="dark"] .policy-benefit b {color:var(--reading-good);}
:root[data-color-mode="dark"] .policy-tradeoff b {color:var(--reading-warning);}
:root[data-color-mode="dark"] .growth-outcome.grown strong {color:color-mix(in srgb,var(--stat-color) 45%,white);text-shadow:none;}
:root[data-color-mode="dark"] .growth-outcome.grown.is-critical strong {color:#ffe29c;}
:root[data-color-mode="dark"] :is(.frontier-alert,.frontier-result,.frontier-map-note) {background:#302b24;color:var(--reading-main);border-color:#a57760;}
:root[data-color-mode="dark"] .frontier-result.is-held {background:#2f333b;border-color:#8d9199;}
:root[data-color-mode="dark"] .frontier-odds>div {background:#23272f;border-color:#6b6f77;}
:root[data-color-mode="dark"] :is(.frontier-alert-heading>b,.frontier-seal,.frontier-stakes b) {color:var(--reading-warning);}
:root[data-color-mode="dark"] .frontier-odds strong {color:var(--reading-accent);}
:root[data-color-mode="dark"] :is(.frontier-odds span,.frontier-odds small,.frontier-alert p,.frontier-result p) {color:var(--reading-muted);}
:root[data-color-mode="dark"] .frontier-stakes {border-color:#826c55;}
:root[data-color-mode="dark"] .chronology-entry p {color:var(--reading-muted);}
:root[data-color-mode="dark"] {--choice-ready-bg:#373b43;--choice-ready-border:#9a9ea6;--choice-ready-ink:#e6eaf2;--choice-ready-chip:#4a4e56;--choice-locked-bg:#282c34;--choice-locked-border:#71757d;--choice-locked-ink:#c6cad2;--choice-locked-chip:#393d45;}
:root[data-color-mode="dark"] .choices .routine-choice-card:has(>.choice:not(:disabled)),
:root[data-color-mode="dark"] .choices .choice[data-choice]:not(:disabled){background:var(--choice-ready-bg);border-color:var(--choice-ready-border);}
:root[data-color-mode="dark"] .choices .routine-choice-card:has(>.choice:disabled),
:root[data-color-mode="dark"] .choices .choice[data-choice]:disabled{background:var(--choice-locked-bg);border-color:var(--choice-locked-border);}
:root[data-color-mode="dark"] .choices .choice[data-choice]:disabled :is(.choice-num,.choice-arrow){background:#393d45!important;color:var(--choice-locked-ink)!important;border-color:var(--choice-locked-border)!important;}
:root[data-color-mode="dark"] .choices .choice[data-choice]:not(:disabled) .choice-arrow{background:#4a4e56!important;color:#e6eaf2!important;border-color:#9a9ea6!important;}

:root[data-color-mode="dark"] :is(.story-person-label,.personal-choice-context,.historical-duty-info>b){color:var(--reading-accent);}
:root[data-color-mode="dark"] :is(.personal-choice-group>summary b,.personal-choice-group>p,.story-actual-rewards>small){color:var(--reading-muted);}
:root[data-color-mode="dark"] .growth-stat-values :is(span,b){color:var(--reading-main);}
:root[data-color-mode="dark"] .growth-critical-label{color:#ffe29c;}
:root[data-color-mode="dark"] .choices .choice-state-label{color:var(--choice-ready-ink)!important;}
:root[data-color-mode="dark"] .choices .choice-state-label.is-locked{color:var(--choice-locked-ink)!important;}
