/* Shared theme control stays visible on every page and at mobile widths. */
.theme-toggle {
    position: fixed;
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 100;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 18px;
    border: 1px solid #e0bb64;
    border-radius: 999px;
    background: #241d12;
    color: #f5d78e;
    box-shadow: 0 6px 24px #0005;
    font: 700 13px/1.3 Arial, sans-serif;
    cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { background: #3c2e16; }
.theme-toggle[aria-pressed="true"] { background: #e2bd6b; color: #21190d; }
.theme-toggle-icon { font-size: 23px; line-height: 1; }
.theme-toggle:focus-visible { outline: 3px solid #b68225; outline-offset: 4px; }
.footer { padding-bottom: 90px; }
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] {
    color-scheme: dark;
    --ink: #f0e6cf; --ink-soft: #dbceb4; --muted: #b9ae98;
    --moss: #d9b766; --moss-2: #e3c681; --moss-3: #b99245;
    --leaf: #c6a458; --leaf-light: #e4cd93;
    --paper: #181713; --paper-2: #23211b; --paper-3: #302b21;
    --wood: #201c15; --wood-2: #30271a; --stone: #b6a88e;
    --gold: #d7b46b; --gold-light: #f0d99c; --line: #514532;
    --cream: #24211a; --success: #a2cc85; --danger: #f0a195;
    --purple: #c8a7e5; --blue: #a0c8e5;
    --shadow: 0 18px 48px #0006; --soft-shadow: 0 10px 26px #0004;
}
html[data-theme="dark"] body {
    background: radial-gradient(ellipse at 50% 0, #302719, transparent 60%), #14130f;
    color: var(--ink);
}
html[data-theme="dark"] body::before { background: none; }
html[data-theme="dark"] body :is(h1,h2,h3,h4,strong,b,dd) { color: var(--ink); text-shadow: none; }
html[data-theme="dark"] body :is(p,li,td,label,code) { color: var(--ink-soft); }
html[data-theme="dark"] body :is(small,span,dt,th,time,figcaption) { color: var(--muted); }
html[data-theme="dark"] body :is(a,.kicker,.crumb,.eyebrow,.mini,.step) { color: var(--gold-light); }
html[data-theme="dark"] body :is(.rank,.value,.player,.wiki-report-link) { color: var(--gold-light) !important; }
html[data-theme="dark"] body :is(.home-rank-empty,.admin-log-empty,.auth-check) { color: var(--muted) !important; }
html[data-theme="dark"] body :is(.site-header .brand-name,.site-header .brand-name small) { color: var(--gold-light) !important; text-shadow: none; }
html[data-theme="dark"] body :is(.hero,.page-hero) {
    background-image: linear-gradient(90deg, #17150ff5 0%, #1c190ed9 40%, #1b190d8c 100%), url('assets/yggdrasil-hero.png') !important;
}
html[data-theme="dark"] body :is(.hero-note,.terms,.character-job,.character-class,.character-appearance-caption,.ranking-leader-class,.ranking-leader-sub,.ranking-number,.status-security-note,.fame-final-note,.download-warning,.wiki-item-description-line,.wiki-result-count,.wiki-detail-note) { color: var(--muted); }
html[data-theme="dark"] body :is(.rune-card,.auth-step-number,.ranking-crown,.ranking-leader-place,.fame-seal,.fame-first-decoration,.fame-first-player,.fame-historic-title,.fame-entry-index,.fame-about-icon) { color: var(--gold-light); }
html[data-theme="dark"] body :is(.ranking-class,.ranking-level,.ranking-primary,.ranking-number) { color: var(--ink-soft) !important; }
html[data-theme="dark"] body :is(.hero h1,.page-hero h1) { color: #f4deb0; text-shadow: 0 2px 12px #0006; }
html[data-theme="dark"] body :is(.nav,.panel,.status-card,.auth-shell,.form,.feed-item,.filters,.stat-box,.rune-card,
    .character-card,.character-card-v2,.character-appearance-stage,.account-chart-card,.security-account-box,.registration-result,
    .ranking-tabs,.ranking-leader,.fame-first,.admin-log-tabs,.admin-log-filters,.admin-log-summary article,.admin-log-table-wrap,.vending-selected,
    .wiki-directory,.wiki-title-list,.wiki-npc-list,.wiki-family,.wiki-portal-card,.wiki-title-card,.wiki-search-results,.wiki-search-entry,
    .wiki-class-detail-head,.wiki-build-grid,.wiki-data-table,.wiki-search-group,.wiki-link-list,.wiki-walkthrough,.wiki-spawn-row,
    .wiki-correction-list article,.wiki-quest-reference-list > div) {
    background: linear-gradient(145deg, #29251c, #1d1b16);
    border-color: var(--line);
    box-shadow: var(--soft-shadow);
}
html[data-theme="dark"] body :is(.wiki-main,.wiki-section) { background: #181713; }
html[data-theme="dark"] body :is(.footer,.cta-block,.auth-art,.legend-card) { background: linear-gradient(125deg,#292217,#171510); border-color: var(--line); }
html[data-theme="dark"] body :is(.wiki-detail-bonus,.wiki-copy-command,.wiki-build-loadout a,.wiki-media-cell,.wiki-map-thumb,
    .wiki-rebirth,.wiki-path,.wiki-location-list span,.wiki-correction-list blockquote,.vending-warp code,.download-hash,
    .wiki-list-head,.wiki-data-head,.admin-log-table th,.admin-log-badge,.class-pill,.medal,.feed-icon,.tag,.wiki-rarity,.wiki-correction-status) {
    background: #342d20;
    color: var(--ink-soft);
    border-color: var(--line);
}
html[data-theme="dark"] body :is(.calc-selection,.calc-range span) { background: #342d20; border-color: var(--line); }
html[data-theme="dark"] body :is(input,select,textarea,.input) {
    background: #15140f;
    color: var(--ink);
    border-color: #766344;
}
html[data-theme="dark"] body ::placeholder { color: #afa38b; opacity: 1; }
html[data-theme="dark"] body :is(input,select,textarea):focus { border-color: var(--gold); box-shadow: 0 0 0 3px #d7b46b30; }
html[data-theme="dark"] body :is(a,button,input,select,textarea):focus-visible { outline: 2px solid var(--gold-light); outline-offset: 3px; }
html[data-theme="dark"] body :is(.btn,.tab,.filter,.page,.admin-log-tabs a) {
    background: linear-gradient(#393020,#292318);
    border-color: #8b7043;
    color: var(--gold-light);
    box-shadow: 0 4px 12px #0004;
}
html[data-theme="dark"] body :is(.btn.primary,.tab.active,.filter.active,.page.active,.wiki-filter-bar button,.wiki-copy-command button,.admin-log-tabs a.active) {
    background: linear-gradient(#e0bd70,#b58a3b);
    border-color: #e5c683;
    color: #21190d;
    text-shadow: none;
}
html[data-theme="dark"] body :is(.nav a.active,.nav .nav-launcher,.ranking-tab.active,.wiki-subnav a.active,
    .wiki-data-row:hover,.wiki-title-row:hover,.wiki-npc-row:hover,.wiki-link-list > a:hover,.wiki-search-entry:hover,.wiki-search-group a:hover,
    .ranking-table tbody tr:hover,.admin-log-table tbody tr:hover,.vending-catalog-table tr.is-selected) { background: #d7b46b1c; color: var(--gold-light); }
html[data-theme="dark"] body :is(.table th,.table td,.metric,.tabs,.pod,.title-stats,.wiki-subnav,.wiki-directory,
    .wiki-directory-head,.wiki-directory-section,.wiki-directory-section a,.wiki-data-row,.wiki-link-list > *,
    .wiki-walkthrough li,.wiki-title-row,.wiki-npc-row,.wiki-search-group h2,.wiki-search-group a,.wiki-build-grid article,
    .wiki-detail-side dl div,.ranking-table th,.ranking-table td,.admin-log-table th,.admin-log-table td) { border-color: var(--line); }
html[data-theme="dark"] body :is(.feature-icon,.crest,.wiki-leaf,.wiki-family-mark,.wiki-portal-mark,.wiki-npc-mark,.wiki-legend b) {
    background: linear-gradient(145deg,#66502a,#312717); color: var(--gold-light); border-color: #967740;
}
/* Keep status and rarity meanings distinct from the gold navigation accents. */
html[data-theme="dark"] body :is(.is-online,.character-online,.account-state-online,.ranking-online,.status-badge-online,.auth-success,.wiki-correction-success,.download-ready-text) { color: var(--success) !important; }
html[data-theme="dark"] body :is(.is-offline,.account-state-blocked,.status-badge-offline,.auth-error,.admin-log-error,.wiki-correction-errors) { color: var(--danger); }
html[data-theme="dark"] body :is(.wiki-correction-success,.wiki-correction-errors) { background: #25231c; }
html[data-theme="dark"] body :is(.rarity-uncommon .wiki-rarity,.rarity-1,.wiki-correction-status.fixed) { color: var(--success); }
html[data-theme="dark"] body :is(.rarity-rare .wiki-rarity,.rarity-2,.tag.purple,.admin-log-badge.rare) { color: var(--purple); }
html[data-theme="dark"] body :is(.rarity-epic .wiki-rarity,.rarity-3,.wiki-correction-status.new,.download-wait-text) { color: var(--gold-light) !important; }
html[data-theme="dark"] body :is(.rarity-historic .wiki-rarity,.rarity-4,.wiki-correction-status.rejected,.admin-log-badge.danger) { color: var(--danger); }
html[data-theme="dark"] body :is(.tag.blue,.admin-log-badge.info,.wiki-correction-status.review) { color: var(--blue); background: #253039; }
html[data-theme="dark"] body :is(.hero,.page-hero,.panel,.status-card,.auth-shell,.cta-block,.footer,.nav)::after,
html[data-theme="dark"] body .footer::before { filter: sepia(.65) brightness(.65); }
html[data-theme="dark"] body .theme-toggle { color: #21190d; }
html[data-theme="dark"] body .theme-toggle span { color: inherit; }
@media (max-width: 980px) {
    html[data-theme="dark"] .site-header { background: #211d15; }
}
@media (max-width: 580px) {
    .theme-toggle { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); min-height: 46px; padding: 10px 14px; }
}
