/* Theme selection is independent of game state and defaults to dark in App.razor. */
:root { color-scheme: light; }
.theme-toggle { display:grid;place-items:center;flex:0 0 34px;width:34px;height:34px;padding:7px;border:1px solid var(--line);border-radius:8px;background:var(--card);color:var(--green);cursor:pointer; }
.theme-toggle svg { width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round; }
.theme-icon-light { display:none; }
:root[data-theme="dark"] .theme-icon-light { display:block; }
:root[data-theme="dark"] .theme-icon-dark { display:none; }
@media(max-width:600px) {
    .theme-toggle { flex-basis:30px;width:30px;height:30px;padding:6px; }
    .theme-toggle svg { width:16px;height:16px; }
}

/* Plum, antique gold and ivory. Semantic status colors keep their own meaning. */
:root[data-theme="dark"] {
    color-scheme:dark;
    --paper:#19141f;
    --card:#292130;
    --ink:#f0e8da;
    --muted:#b6a99b;
    --gold:#c8aa70;
    --green:var(--gold);
    --green2:#3c3040;
    --line:#514456;
    --surface-soft:#241d2b;
    --surface-raised:#322a3b;
    --surface-input:#201a26;
    --on-accent:#201922;
    --accent-border:#80694c;
    --positive:#85c69c;
    --negative:#f19a91;
    --warning:#d8b36c;
    --info:#a8bce7;
    --positive-surface:#20332b;
    --negative-surface:#3d252e;
    --warning-surface:#372c24;
    --info-surface:#272c40;
    --positive-border:#416550;
    --negative-border:#81505b;
    --warning-border:#796343;
    --disabled:#39313f;
    --portrait:#40344c;
    --portrait-figure:#8b7897;
    --chrome:rgba(25,20,31,.97);
    --overlay:rgba(12,8,17,.78);
}

:root[data-theme="dark"] body { background:var(--paper); }
:root[data-theme="dark"] :is(.topbar,.profile-header,.mobile-bottom-nav,.mobile-game-tabs) { background:var(--chrome);border-color:var(--line);box-shadow:none; }
:root[data-theme="dark"] :is(.language,.zoom-controls) { background:var(--surface-raised); }
:root[data-theme="dark"] :is(.language button,.mobile-bottom-nav button) { color:var(--muted); }
:root[data-theme="dark"] :is(.language .active,.mobile-bottom-nav button.active,.mobile-game-tabs button.active) { background:var(--green2);color:var(--gold);box-shadow:none; }
:root[data-theme="dark"] :is(.brand .brand-label,.brand,.mobile-sheet h2,.mobile-section-heading h2,.mobile-page-heading h2,.mobile-energy-heading strong) { color:var(--ink); }
:root[data-theme="dark"] :is(.brand .brand-dot,.brand>span,.eyebrow) { color:var(--gold); }

/* Base cards, nested details and neutral controls. These groups also cover archives. */
:root[data-theme="dark"] :is(.creator-panel,.step,.profile-grid,.turn-panel,.school-card,.active-game-card,.leaderboard-row,.run-metric,.run-record-card,.run-tree-card,.replay-card,.archive-state,.person-energy-history,.partner-modal,.family-popup,.mobile-sheet,.mobile-plan-card,.mobile-energy-card,.mobile-family-card,.mobile-children-card,.mobile-family-event,.mobile-empty-family,.mobile-chronicle-view .person-turn-history) { border-color:var(--line);background:var(--card);box-shadow:none; }
:root[data-theme="dark"] :is(.stat-group,.traits-group,.parameters-group,.partner-panel,.occupation-control,.school-control,.school-fixed-preview,.university-preview,.current-compatibility,.candidate-requirements,.candidate-wealth,.person-main-occupation,.candidate-indicators span,.candidate-indicators details,.candidate-axis,.activities-total,.person-turn-entry,.replay-frame,.archive-shell .person-history-modal>.partner-metrics .metric) { background:var(--surface-soft);border-color:var(--line); }
:root[data-theme="dark"] :is(.change-sources,.efficiency-sources,.energy-source div,.energy-source-details,.pregnancy-chance small,.school-card>div span,.worldview-list .metric,.partner-axes .metric,.children-list>span,.person-turn-decisions span,.energy-exhaustion-tile.stable,.mobile-year-summary,.mobile-year-summary>div,.replay-frame>header) { background:var(--surface-raised);border-color:var(--line); }
:root[data-theme="dark"] :is(.player-statistics .development-stats .metric,.player-statistics .mini-stats .metric,.score-pair article) { background:var(--surface-soft);border-color:var(--line); }
:root[data-theme="dark"] :is(.player-statistics .development-stats .metric strong,.player-statistics .mini-stats .metric strong) { color:var(--ink); }
:root[data-theme="dark"] :is(.event,.active-save-status,.active-save-transfer-message,.archive-import-message,.death-estate-summary,.gift-balance,.mobile-family-setting,.mobile-pregnancy-chance,.menopause-note) { background:var(--surface-raised);border-color:var(--line); }
:root[data-theme="dark"] :is(.fields input,.intimacy-choice select,.mobile-intimacy-choice select,.gift-amount input,.gift-amount button,.gift-recipient,.family-popup input,.profile-output,.descendant-time-modal input,.portrait-upload input,.choice,.preset,.activity,.activity-slider,.mobile-choice-list>button) { background:var(--surface-input);color:var(--ink);border-color:var(--line); }
:root[data-theme="dark"] :is(input,select,textarea) { color:var(--ink);accent-color:var(--gold); }
:root[data-theme="dark"] :is(input,textarea)::placeholder { color:var(--muted);opacity:.8; }
:root[data-theme="dark"] :is(.budget,.activity-toggle) { background:var(--surface-raised); }
:root[data-theme="dark"] :is(.choice.selected,.preset.selected,.activity.selected,.activity-toggle.selected,.activity-choice.selected,.mobile-choice-list>button.selected,.living-standard-options button.selected) { background:var(--green2);border-color:var(--accent-border); }
:root[data-theme="dark"] :is(.activity-choice,.mobile-person-row,.mobile-plan-row,.mobile-plan-list,.mobile-family-actions,.mobile-card-title,.school-card>div,.energy-breakdown,.children-panel,.candidate-requirements>div,.person-turn-entry>div,.replay-state-grid,.replay-state-grid>span) { border-color:var(--line); }

/* Gold is reserved for actions, selection and headings rather than every statistic. */
:root[data-theme="dark"] :is(.primary,.candidate-attempt,.mobile-next-year-primary,.mobile-game-tabs .mobile-next-year,.run-metric.featured) { background:var(--gold);color:var(--on-accent);box-shadow:0 5px 18px #0003; }
:root[data-theme="dark"] .portrait-upload input[type=file]::file-selector-button { background:var(--gold);color:var(--on-accent); }
:root[data-theme="dark"] .run-metric.featured small { color:var(--on-accent); }
:root[data-theme="dark"] :is(.primary:disabled,.candidate-attempt.unavailable,.mobile-year-view .year-next-cta:disabled,.mobile-next-year-primary:disabled,.mobile-game-tabs .mobile-next-year:disabled,.finder-launch:disabled,.replay-controls button:disabled) { background:var(--disabled);color:var(--muted);border-color:var(--line);box-shadow:none; }
:root[data-theme="dark"] :is(.finder-launch:disabled b,.living-standard-options button:disabled) { color:var(--muted); }
:root[data-theme="dark"] .living-standard-options button:disabled { background:var(--surface-raised); }
:root[data-theme="dark"] :is(.secondary-link,.search-action,.tree-open,.profile-history-open,.turn-replay-open,.profile-switch,.replay-controls button,.activity-summary,.mobile-family-actions button) { background:var(--surface-soft);color:var(--gold);border-color:var(--accent-border); }
:root[data-theme="dark"] :is(.secondary-link:hover,.living-standard-options button:not(:disabled):hover) { background:var(--green2); }
:root[data-theme="dark"] :is(.randomize,.gift-open,.living-standard,.descendant-time-preview-summary) { background:var(--warning-surface);color:var(--ink);border-color:var(--warning-border); }
:root[data-theme="dark"] .living-standard-options { border-color:var(--warning-border); }
:root[data-theme="dark"] :is(.living-standard-current strong,.living-standard-cost b,.living-standard-options strong,.living-standard-options b) { color:var(--ink); }
:root[data-theme="dark"] :is(.activity-choice-mark,.mobile-choice-list>button>i) { border-color:var(--accent-border);color:var(--on-accent); }

/* Outcomes retain green/red semantics and sufficient contrast on tinted surfaces. */
:root[data-theme="dark"] .positive { color:var(--positive)!important; }
:root[data-theme="dark"] .negative { color:var(--negative)!important; }
:root[data-theme="dark"] .metric.stress-metric :is(summary,.metric-summary) strong { color:var(--negative)!important; }
:root[data-theme="dark"] :is(.player-status-stress,.player-status-health svg,.activity-energy,.school-card .job-energy,.school-card .job-energy b,.search-action b,.activity-summary>b,.activities-total>strong,.breakup-effects,.living-standard-lock,.childcare-details small,.tree-person b,.genealogy em,.mobile-plan-row>b,.mobile-obligations-link>b,.mobile-obligation-list b,.mobile-energy-heading em.danger,.candidate-requirements p.unmet,.person-turn-changes .negative,.school-card.unavailable em,.school-card.unavailable .job-requirement,.university-quit-card h2,.university-quit-card em) { color:var(--negative); }
:root[data-theme="dark"] .activity-energy { color:var(--negative)!important; }
:root[data-theme="dark"] :is(.danger-action,.validation,.plan-error,.school-card.unavailable,.budget.over,.death-risk-explanation,.active-save-warning,.active-game-card.invalid,.active-save-transfer-message.error,.active-storage-error,.archive-import-message.error,.archive-recovery,.negative-event-effects,.archive-error,.bereavement-effects,.death-cause-prominent,.university-quit-card,.person-death-entry,.candidate-stat.negative,.energy-balance-tile.fatigue,.energy-exhaustion-tile.rising) { background:var(--negative-surface);color:var(--negative);border-color:var(--negative-border); }
:root[data-theme="dark"] :is(.active-game-recovery-status,.person-death-entry span,.mobile-empty-family .plan-error) { color:var(--negative); }
:root[data-theme="dark"] :is(.pregnancy-badge,.mobile-family-status.pregnant) { background:var(--negative-surface);color:#edb3ca;border-color:var(--negative-border); }
:root[data-theme="dark"] :is(.energy-recovery,.energy-balance-tile.rest,.energy-exhaustion-tile.falling,.candidate-stat.positive,.verified-badge,.forecast-limit) { background:var(--positive-surface);color:var(--positive);border-color:var(--positive-border); }
:root[data-theme="dark"] :is(.finder-decision small,.mobile-energy-heading em) { color:var(--positive); }
:root[data-theme="dark"] :is(.energy-warning,.risk-details div,.mobile-risk-details,.fixed-care,.childcare-inline,.childcare-summary,.candidate-stat.medium) { background:var(--warning-surface);color:var(--warning);border-color:var(--warning-border); }
:root[data-theme="dark"] :is(.childcare-details span,.player-status-finances svg,.mobile-empty-family>span,.mobile-year-summary summary small,.mobile-section-heading p,.mobile-page-heading p,.mobile-family-event small) { color:var(--gold); }
:root[data-theme="dark"] :is(.partner-deceased,.mobile-family-status.deceased) { background:var(--surface-raised);color:var(--muted); }
:root[data-theme="dark"] .descendant-time-effect.worldview { color:var(--info)!important; }
:root[data-theme="dark"] .efficiency-stats .efficiency-metric { background:hsl(var(--efficiency-hue) 25% 18%);border-color:hsl(var(--efficiency-hue) 35% 40%); }
:root[data-theme="dark"] .efficiency-stats :is(summary,.metric-summary) strong { color:hsl(var(--efficiency-hue) 55% 72%); }

/* Portraits, genealogy, meters and supporting copy. Image assets keep their colors. */
:root[data-theme="dark"] :is(.portrait-card,.profile-silhouette,.candidate-silhouette,.partner-mini-silhouette,.finder-portrait,.portrait-option,.mobile-person-avatar,.player-status-portrait) { background:var(--portrait);border-color:var(--line); }
:root[data-theme="dark"] :is(.silhouette .head,.silhouette .body) { background:var(--portrait-figure); }
:root[data-theme="dark"] .mobile-person-avatar.child { background:var(--warning-surface); }
:root[data-theme="dark"] :is(.finder-portrait>span,.creator-portrait-change>.creator-portrait-caption) { background:var(--overlay);color:var(--ink); }
:root[data-theme="dark"] .dynasty-preview { border-color:var(--line); }
:root[data-theme="dark"] :is(.tree-person,.tree-collapse) { background:var(--surface-raised);border-color:var(--line); }
:root[data-theme="dark"] .tree-person.founder { background:var(--warning-surface);border-color:var(--accent-border); }
:root[data-theme="dark"] .tree-person.dynasty-partner { background:var(--info-surface);border-color:#59657f; }
:root[data-theme="dark"] :is(.tree-couple>i,.mobile-sheet-handle) { background:var(--line); }
:root[data-theme="dark"] .tree-children::before,
:root[data-theme="dark"] .tree-branch,
:root[data-theme="dark"] .tree-branch::before { border-color:var(--line); }
:root[data-theme="dark"] :is(.battery,.compatibility-bar,.axis-meter,.mobile-energy-meter,.mobile-stability>div) { background:var(--line); }
:root[data-theme="dark"] :is(.battery .high,.mobile-stability>div i) { background:var(--positive); }
:root[data-theme="dark"] .battery .medium { background:var(--warning); }
:root[data-theme="dark"] :is(.battery .low,.mobile-energy-meter.over-budget i) { background:var(--negative); }
:root[data-theme="dark"] .mobile-energy-meter i { background:var(--positive); }
:root[data-theme="dark"] .axis-input { background:linear-gradient(to right,transparent var(--axis-start),var(--gold) var(--axis-start),var(--gold) calc(var(--axis-start) + var(--axis-width)),transparent calc(var(--axis-start) + var(--axis-width))),var(--line); }
:root[data-theme="dark"] .axis-meter u,
:root[data-theme="dark"] .axis-meter::after { background:var(--gold); }
:root[data-theme="dark"] .axis-input::-webkit-slider-thumb { border-color:var(--card); }
:root[data-theme="dark"] .axis-input::-moz-range-thumb { border-color:var(--card); }
:root[data-theme="dark"] :is(.step-number,.mobile-choice-list small,.mobile-obligation-list small,.mobile-obligation-list>p,.mobile-intimacy-choice,.mobile-pregnancy-chance small,.mobile-pregnancy-chance p,.mobile-energy-caption,.activity-choice small,.mobile-year-summary>div p,.mobile-year-summary>div span small,.mobile-section-heading>span,.mobile-plan-row small,.mobile-energy-heading small,.mobile-exhaustion small,.mobile-person-row small,.mobile-person-row em,.mobile-stability>span,.mobile-family-setting small,.mobile-empty-family p,.mobile-empty-copy,.mobile-plan-row>i,.mobile-obligations-link>i,.mobile-family-setting>i,.mobile-person-row>i,.deceased-child) { color:var(--muted); }
:root[data-theme="dark"] .mobile-card-title span { background:var(--green2); }
:root[data-theme="dark"] .mobile-row-icon.work { background:var(--info-surface);color:var(--info); }
:root[data-theme="dark"] .mobile-row-icon.home { background:var(--warning-surface);color:var(--gold); }
:root[data-theme="dark"] .mobile-row-icon.activity { background:var(--positive-surface);color:var(--positive); }
:root[data-theme="dark"] .mobile-row-icon.family { background:var(--negative-surface);color:var(--negative); }
:root[data-theme="dark"] .finder-modal { background:var(--card); }
:root[data-theme="dark"] :is(.finder-header span,.finder-empty>span) { color:#edb3ca; }
:root[data-theme="dark"] .finder-decision.no button { background:var(--negative);color:var(--on-accent); }
:root[data-theme="dark"] .finder-decision.yes button { background:var(--positive);color:var(--on-accent); }
:root[data-theme="dark"] .modal-backdrop { background:var(--overlay); }
:root[data-theme="dark"] :focus-visible { outline:2px solid var(--gold);outline-offset:3px; }
@media(max-width:850px) {
    :root[data-theme="dark"] :is(.profile-grid,.turn-panel,.mobile-profile-view,.mobile-profile-view .worldview-list .metric) { background:transparent; }
}

/* The next-year action keeps its green identity in both themes. */
:root .primary.year-next-cta{background:#1f684b;color:#fff;border-color:#1f684b}
:root .primary.year-next-cta:hover:not(:disabled){background:#19563e;border-color:#19563e}
:root[data-theme="dark"] .primary.year-next-cta{background:#286348;color:#fff;border-color:#43805c}
:root[data-theme="dark"] .primary.year-next-cta:hover:not(:disabled){background:#307653;border-color:#5c9b73}
:root .primary.year-next-cta:disabled{background:#53665a;color:#f3f5f3;border-color:#53665a;box-shadow:none}
:root[data-theme="dark"] .primary.year-next-cta:disabled{background:#334b3f;color:#adb9b1;border-color:#435c4d;box-shadow:none}

@media(max-width:850px){
    :root[data-theme="dark"] .creator-layout-single .creator-portrait-change>.creator-portrait-caption{background:transparent;color:var(--ink)}
}
