/* Load after app.css and every page-specific stylesheet. Artwork is never filtered. */
html[data-theme="dark"] {
    color-scheme: dark;
    --theme-control-border: var(--border);
}

html[data-theme="dark"] .theme-error {
    color: var(--danger);
    background: #ff98980c;
    border: 1px solid #ff989840;
}

html[data-theme="dark"] .fund-donut {
    background: conic-gradient(#b6edf7 0 42.857%, #b4f38b 42.857% 71.429%, #f1cc59 71.429% 85.714%, #9ee33f 85.714% 100%);
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #f3f8f4;
    --sidebar: #edf4ef;
    --panel: #ffffff;
    --panel-raised: #e8f1eb;
    --theme-soft: #f0f7f2;
    --theme-hover: #def2e4;
    --border: #b8cdc0;
    --theme-control-border: #5d7d69;
    --muted: #496253;
    --text: #132a1c;
    --theme-inverse: #ffffff;
    --theme-accent: #086b35;
    --theme-accent-hover: #054b29;
    --theme-accent-bright: #31e85f;
    --theme-action: linear-gradient(135deg, #064026, #08773b 55%, #05532d);
    --theme-chrome: linear-gradient(135deg, #fcfffd, #e2ece5 48%, #f8fcf9 72%, #d8e6dc);
    --theme-action-shadow: inset 0 1px 0 #ffffff40, 0 3px 8px #0640261a;
    --theme-track: #cfdfd4;
    --theme-shadow: 0 8px 26px #06402612;
    --theme-overlay: #062b1a80;
    --theme-grid: #086b3519;
    --theme-fund-1: #075c31;
    --theme-fund-2: #0f8b45;
    --theme-fund-3: #63c982;
    --theme-fund-4: #b4c9bd;
}

html[data-theme="light"] {
    --lime: var(--theme-accent);
    --cyan: #086958;
    --warning: #805600;
    --danger: #b42336;
    background: var(--bg);
    color: var(--text);
    accent-color: var(--theme-accent);
    scrollbar-color: var(--theme-control-border) var(--bg);
}

html[data-theme="light"] body { background: var(--bg); color: var(--text); }
html[data-theme="light"] ::selection { background: var(--theme-accent); color: var(--theme-inverse); }
html[data-theme="light"] :focus-visible { outline-color: var(--theme-accent); }

html[data-theme="light"] :is(.sidebar, .topbar) {
    background: var(--theme-chrome);
    border-color: var(--border);
}

html[data-theme="light"] :is(
    .panel, .network-panel, .stat-card, .stat-card:first-child,
    .hero, .hero.dashboard-hero, .ranking-intro, .metric-banner,
    .rank-showcase, .prize-card, .prize-card-crown,
    .network-summary-item, .network-member, .network-member-inactive,
    .network-member-origin, .auth-story, .auth-form-side,
    .error-page, .tree-list
) {
    background: var(--panel);
    border-color: var(--border);
    box-shadow: var(--theme-shadow);
}

html[data-theme="light"] :is(
    .hero, .hero.dashboard-hero, .ranking-intro, .metric-banner,
    .network-summary-item, .auth-story
) { background: linear-gradient(125deg, var(--panel), var(--theme-hover)); }

html[data-theme="light"] :is(
    .sidebar-status, .constellation-node, .tree-node-card,
    .tree-node-inactive .tree-node-card, .rank-step, .rank-stage-7,
    .rank-step.is-current, .fund-cell, .settings-status > div,
    .available-card, .approval-form, .rejection-form,
    .network-modes, .network-zoom, .network-card-top .avatar,
    .dashboard-goals > article, .dashboard-goals > .dashboard-rank,
    .dashboard-goals > .dashboard-prize, .dashboard-rank-metrics > div,
    .dashboard-prize-requirements > span, .prize-fine-print, .prize-art,
    .simulation-editor, .simulation-equations > div,
    .simulation-equations > div:nth-child(3), .simulation-reconciliation,
    .simulation-reconciliation > div, .auth-bottom, .filters,
    .copy-field, .balance-available, .quick-link, .fund-breakdown > div
) {
    background: var(--theme-soft);
    border-color: var(--border);
    box-shadow: none;
}

html[data-theme="light"] :is(
    .avatar, .tree-node-inactive .avatar, .network-member-inactive .avatar,
    .icon-tile, .icon-tile-cyan, .transaction-icon, .transaction-icon.outgoing,
    .badge, .badge-success, .badge-warning, .badge-danger, .badge-cyan,
    .position, .position-top, .stat-icon, .stat-card:nth-child(2) .stat-icon,
    .stat-card:nth-child(3) .stat-icon, .stat-card:nth-child(4) .stat-icon,
    .empty-state > .icon, .dashboard-rank-stop, .dashboard-rank-stop.is-reached,
    .dashboard-rank-stop.is-next, .dashboard-rank-level, .prize-level,
    .hero-visual > .badge
) {
    color: var(--theme-accent);
    background: var(--panel-raised);
    border-color: var(--theme-control-border);
    box-shadow: none;
}

html[data-theme="light"] :is(
    .sidebar-subtitle, .nav-section-label, .nav-link, .field label, .field-label,
    .check-label, .stat-top, .stat-hint, .hero .eyebrow, .hero p,
    .hero-badges, .hero-actions .text-link, .hero-visual-label, .auth-proof span,
    .auth-story-content > p, .auth-story-footer, .auth-lock, .auth-lock .icon,
    .page-footer, .footer-divider, .constellation-node small, .node-control,
    .rank-step-number, .prize-cap > span, .prize-requirements dt, .prize-once,
    .fund-donut small, .simulation-rules > span, .dashboard-month,
    .dashboard-goal-label, .dashboard-current-rank, .network-status,
    .dashboard-prize-requirements > span
) { color: var(--muted); }

html[data-theme="light"] :is(
    .brand-version, .brand-mark, .rank-step strong, .prize-fine-print strong,
    .prize-card-crown .prize-cap strong, .prize-card-crown .prize-level,
    .dashboard-prize-cap strong,
    .stat-top .icon, .stat-card:nth-child(3) .icon,
    .dashboard-rank-metrics dt .icon, .network-member-origin .network-member-kind,
    .dashboard-prize-status
) { color: var(--text); text-shadow: none; }

html[data-theme="light"] .text-lime { color: var(--lime); }
html[data-theme="light"] .text-cyan { color: var(--cyan); }
html[data-theme="light"] .text-warning { color: var(--warning); }
html[data-theme="light"] .brand-version { border-color: var(--theme-control-border); }
html[data-theme="light"] .nav-link:hover {
    color: var(--text);
    background: var(--theme-hover);
}
html[data-theme="light"] :is(.tab, .network-modes a, .competition-program) {
    color: var(--theme-accent);
    background: var(--theme-chrome);
    border-color: var(--theme-accent);
    box-shadow: none;
}
html[data-theme="light"] :is(.nav-link.is-active, .tab.is-active, .network-modes a[aria-current], .competition-program.is-selected) {
    color: var(--theme-inverse);
    background: var(--theme-action);
    border-color: var(--theme-accent);
    box-shadow: var(--theme-action-shadow);
    font-weight: 700;
}
html[data-theme="light"] :is(.rank-step.is-current, .network-member-origin, .dashboard-rank-stop.is-next) {
    border-color: var(--theme-accent);
    box-shadow: 0 0 0 1px var(--theme-accent);
}
html[data-theme="light"] :is(.network-member:hover, .prize-card:hover, .prize-card-crown:hover, .tree-node-card:hover, .sidebar-status:hover) {
    border-color: var(--theme-accent);
    box-shadow: var(--theme-shadow);
}
html[data-theme="light"] :is(.status-dot, .constellation-point, .constellation-point:last-child) {
    background: var(--theme-accent-bright);
    box-shadow: 0 0 0 3px #086b3514;
}
html[data-theme="light"] :is(.legend-dot.inactive, .network-legend i.inactive, .network-member-inactive .network-status i) {
    background: var(--muted);
}
html[data-theme="light"] .sidebar-overlay { background: var(--theme-overlay); }

html[data-theme="light"] .button {
    color: var(--theme-inverse);
    background: var(--theme-action);
    border-color: var(--theme-accent);
    box-shadow: var(--theme-action-shadow);
}
html[data-theme="light"] .button:hover {
    color: var(--theme-inverse);
    background: var(--theme-accent-hover);
    border-color: var(--theme-accent-hover);
}
html[data-theme="light"] .button-primary {
    color: var(--theme-inverse);
    background: var(--theme-action);
    border-color: var(--theme-accent);
}
html[data-theme="light"] .button-primary:hover {
    color: var(--theme-inverse);
    background: var(--theme-accent-hover);
    border-color: var(--theme-accent-hover);
}
html[data-theme="light"] .button-secondary {
    color: var(--theme-accent);
    background: var(--theme-chrome);
    border-color: var(--theme-control-border);
}
html[data-theme="light"] .button-secondary:hover {
    color: var(--theme-inverse);
    background: var(--theme-accent-hover);
    border-color: var(--theme-accent-hover);
}
html[data-theme="light"] .button-danger {
    color: var(--theme-inverse);
    background: var(--danger);
    border: 3px double var(--theme-inverse);
    box-shadow: 0 0 0 1px var(--danger);
}
html[data-theme="light"] .button-danger:hover { color: var(--theme-inverse); background: #8d1b2b; border-color: var(--theme-inverse); }
html[data-theme="light"] :is(.button:disabled, .button.disabled, .icon-button:disabled) {
    opacity: .6;
}
html[data-theme="light"] .text-link:hover { text-decoration: underline; }

/* Keep semantic colors and border patterns in addition to the logo palette. */
html[data-theme="light"] :is(.notice, .notice-success, .notice-warning, .notice-error, .notice-info, .theme-error) {
    color: var(--text);
    background: #e7f4ed;
    border-color: var(--theme-control-border);
}
html[data-theme="light"] :is(.notice-info, .badge-cyan) { color: var(--cyan); background: #e7f4ef; border-color: var(--cyan); }
html[data-theme="light"] :is(.notice-success, .badge-success) { color: var(--lime); background: #e4f4e9; border-color: var(--lime); }
html[data-theme="light"] :is(.notice-warning, .badge-warning) { color: var(--warning); background: #fff4d8; border-color: var(--warning); border-style: dashed; }
html[data-theme="light"] :is(.notice-error, .badge-danger, .theme-error) { color: var(--danger); background: #fff0f2; border-color: var(--danger); border-style: double; border-width: 3px; }
html[data-theme="light"] .notice-success { border-left: 4px solid var(--lime); }
html[data-theme="light"] .transaction-icon.outgoing { color: var(--danger); background: #fff0f2; border-color: var(--danger); }
html[data-theme="light"] :is(.notice .icon, .notice p, .notice strong, .notice a) { color: inherit; }
html[data-theme="light"] .notice a { text-decoration: underline; }
html[data-theme="light"] :is(.credentials, .rule-number) { border-color: var(--theme-control-border); }
html[data-theme="light"] .toast {
    color: var(--theme-inverse);
    background: var(--theme-action);
    box-shadow: var(--theme-shadow);
}

html[data-theme="light"] :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    color: var(--text);
    background: var(--panel);
    border-color: var(--theme-control-border);
    caret-color: var(--text);
}
html[data-theme="light"] :is(input:hover, select:hover, textarea:hover, input:focus, select:focus, textarea:focus) {
    border-color: var(--theme-accent);
}
html[data-theme="light"] :is(input::placeholder, textarea::placeholder) { color: var(--muted); opacity: 1; }
html[data-theme="light"] input[readonly] { background: var(--panel-raised) !important; color: var(--muted); }
html[data-theme="light"] :is(input:disabled, select:disabled, textarea:disabled) { color: var(--muted); }
html[data-theme="light"] :is(select option, select optgroup) { background: var(--panel); color: var(--text); }
html[data-theme="light"] :is(input[type="checkbox"], input[type="radio"], progress) { accent-color: var(--theme-accent); }
html[data-theme="light"] :is(input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"]) {
    border: 2px dashed var(--danger);
}
html[data-theme="light"] input:-webkit-autofill {
    -webkit-text-fill-color: var(--text);
    box-shadow: 0 0 0 1000px var(--panel-raised) inset;
    caret-color: var(--text);
}

html[data-theme="light"] th { background: var(--theme-chrome); color: var(--theme-accent); }
html[data-theme="light"] td { border-color: var(--border); }
html[data-theme="light"] tbody tr:hover { background: var(--theme-hover); }
html[data-theme="light"] .table-wrap { scrollbar-color: var(--theme-control-border) var(--bg); }
html[data-theme="light"] :is(.chart-grid-line, .chart-baseline) { stroke: var(--theme-control-border); }
html[data-theme="light"] :is(.chart-bar, .chart-bar:hover) { fill: var(--theme-accent); }
html[data-theme="light"] .chart-bar:hover { opacity: .75; }
html[data-theme="light"] :is(.progress-track, .dashboard-rank .progress-track) { background: var(--theme-track); }
html[data-theme="light"] :is(.progress-track, .dashboard-rank .progress-track)::-webkit-progress-bar { background: var(--theme-track); }
html[data-theme="light"] :is(.progress-track, .dashboard-rank .progress-track)::-webkit-progress-value { background: var(--theme-action); }
html[data-theme="light"] :is(.progress-track, .dashboard-rank .progress-track)::-moz-progress-bar { background: var(--theme-action); }

html[data-theme="light"] :is(
    .orbit, .orbit:nth-child(2), .auth-art-ring, .auth-art-ring:nth-child(2),
    .auth-art-ring:nth-child(3), .constellation-ring, .constellation-ring:nth-child(2),
    .hero-emblem, .constellation-core, .auth-art-core, .dashboard-rank-emblem,
    .prize-requirements, .network-card-footer,
    .network-viewport
) { border-color: var(--border); box-shadow: none; }
html[data-theme="light"] .dashboard-rank-emblem::before { border-color: var(--border); }
html[data-theme="light"] :is(.hero-emblem, .dashboard-rank-emblem) { background: var(--panel-raised); }
/* Logos retain their original dark image backing in either mode. */
html[data-theme="light"] :is(.constellation-core, .auth-art-core) { background: #000000; }
html[data-theme="light"] .auth-story::after {
    background-image: linear-gradient(var(--theme-grid) 1px, transparent 1px), linear-gradient(90deg, var(--theme-grid) 1px, transparent 1px);
}
html[data-theme="light"] .dashboard-hero::before { background: var(--theme-accent-bright); }
html[data-theme="light"] .dashboard-prize::after {
    background: linear-gradient(90deg, var(--theme-soft) 10%, transparent 90%);
}
html[data-theme="light"] .prize-art::after { background: none; }
html[data-theme="light"] :is(.icon-button, a.quick-link, a.sidebar-status, a.text-link, .dashboard-prize a.dashboard-prize-link, details > summary) {
    color: var(--theme-inverse);
    background: var(--theme-action);
    border-color: var(--theme-accent);
    box-shadow: var(--theme-action-shadow);
}
html[data-theme="light"] :is(a.text-link, details > summary) {
    padding: 10px 14px;
    border: 1px solid var(--theme-accent);
    border-radius: 9px;
}
html[data-theme="light"] a.text-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}
html[data-theme="light"] :is(.icon-button, a.quick-link, a.sidebar-status, a.text-link, .dashboard-prize a.dashboard-prize-link, .tab, .network-modes a, .competition-program, details > summary):hover {
    color: var(--theme-inverse);
    background: var(--theme-accent-hover);
    border-color: var(--theme-accent-hover);
}
html[data-theme="light"] details[open] > summary { background: var(--theme-accent-hover); }
html[data-theme="light"] :is(
    .icon-button, a.quick-link, a.sidebar-status, a.text-link,
    .nav-link.is-active, .tab.is-active, .network-modes a[aria-current],
    .competition-program, details > summary
) :is(.icon, .icon-tile, strong, small, h2, h3, .competition-program-copy, .competition-program-rates, .competition-program-icon) {
    color: inherit;
}
html[data-theme="light"] :is(
    a.quick-link, a.sidebar-status, a.text-link, .competition-program,
    .network-modes a[aria-current], details > summary
) :is(.icon-tile, .competition-program-icon) {
    background: transparent;
    border-color: currentColor;
}
html[data-theme="light"] .dashboard-rank-stop + .dashboard-rank-stop::before { background: var(--border); }
html[data-theme="light"] .tree-node::before { border-color: var(--theme-control-border); }
html[data-theme="light"] .network-viewport {
    background: radial-gradient(var(--theme-grid) .8px, transparent .8px) var(--bg);
    background-size: 22px 22px;
}
html[data-theme="light"] [data-network-view="chart"][data-chart-ready] .network-viewport {
    scrollbar-color: var(--theme-control-border) var(--bg);
}
html[data-theme="light"] .network-connections path { stroke: var(--theme-control-border); }
html[data-theme="light"] .network-connections path.inactive { stroke: var(--muted); }
html[data-theme="light"] .network-member.is-context { opacity: .8; }
html[data-theme="light"] .network-member-inactive .network-status i { border: 1px solid var(--muted); background: transparent; }

html[data-theme="light"] .fund-donut {
    background: conic-gradient(var(--theme-fund-1) 0 42.857%, var(--theme-fund-2) 42.857% 71.429%, var(--theme-fund-3) 71.429% 85.714%, var(--theme-fund-4) 85.714% 100%);
    outline-color: var(--theme-control-border);
    box-shadow: none;
}
html[data-theme="light"] .fund-donut > div { background: var(--panel); border-color: var(--panel); box-shadow: none; }
html[data-theme="light"] .fund-breakdown > div { --fund-color: var(--theme-accent); border-left-color: var(--theme-fund-1); }
html[data-theme="light"] .fund-breakdown > .fund-double { border-left-color: var(--theme-fund-2); }
html[data-theme="light"] .fund-breakdown > .fund-crown { border-left-color: var(--theme-fund-3); }
html[data-theme="light"] .fund-breakdown > .fund-prizes { border-left-color: var(--theme-fund-4); }

html[data-theme] :is(.avatar img, img.avatar) { object-fit: cover; object-position: center; }
html[data-theme] .avatar:has(img) { overflow: hidden; }
html[data-theme] .avatar img { display: block; width: 100%; height: 100%; border-radius: inherit; }

.theme-selector { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; min-width: 0; }
.theme-selector select { width: auto; min-width: 76px; max-width: 130px; min-height: 34px; padding: 7px 22px 7px 9px; border: 1px solid var(--theme-control-border); border-radius: 8px; font-size: 12px; }
.theme-selector .button { flex-shrink: 0; }
.theme-error { flex: 0 0 100%; margin: 0; max-width: 320px; padding: 8px 10px; border-radius: 6px; font-size: 12px; line-height: 1.5; text-align: start; overflow-wrap: anywhere; }
.auth-form-container > .theme-selector { margin-bottom: 28px; }
.auth-form-container > .language-selector:has(+ .theme-selector) { margin-bottom: 12px; }
.error-page > .theme-selector { margin: 18px 0; }
html[data-theme] .topbar { height: auto; min-height: 79px; flex-wrap: wrap; }
html[data-theme] .topbar-right { flex-wrap: wrap; gap: 12px; min-width: 0; }

@media (max-width: 1050px) {
    html[data-theme] .topbar-date { display: none; }
}
@media (max-width: 760px) {
    html[data-theme] .topbar { gap: 10px; padding-top: 12px; padding-bottom: 12px; }
    html[data-theme] .topbar .breadcrumb { display: none; }
    html[data-theme] .topbar-right { flex: 1; gap: 10px; }
    html[data-theme] .topbar :is(.environment-badge, .topbar-profile) { display: none; }
    html[data-theme] .topbar :is(.language-selector, .theme-selector) { gap: 5px; }
    html[data-theme] .topbar :is(.language-selector > .icon, .theme-symbol) { display: none; }
    html[data-theme] .topbar :is(.language-selector select, .theme-selector select) { max-width: 112px; min-width: 0; }
    html[data-theme] .topbar :is(.language-selector .button, .theme-selector .button) { padding: 7px 8px; }
}
@media (max-width: 460px) {
    html[data-theme] .topbar { align-items: flex-start; }
    html[data-theme] .topbar .menu-button { margin-top: 2px; }
    html[data-theme] .topbar-right { flex-basis: calc(100% - 45px); gap: 8px; }
    html[data-theme] .topbar :is(.language-selector, .theme-selector) { flex: 0 1 100%; }
    html[data-theme] .topbar :is(.language-selector select, .theme-selector select) { max-width: 155px; flex: 1; }
    html[data-theme] .topbar :is(.language-selector .button, .theme-selector .button) { min-width: 65px; }
    .theme-error { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    html[data-theme] :is(.button, .nav-link, .prize-card, .prize-art img) { transition: none; }
}
@media print {
    html[data-theme] { color-scheme: light; --bg: #ffffff; --sidebar: #ffffff; --panel: #ffffff; --panel-raised: #ffffff; --theme-soft: #ffffff; --text: #111111; --muted: #333333; --border: #cccccc; --theme-control-border: #777777; --theme-inverse: #ffffff; --theme-accent: #111111; --theme-accent-hover: #333333; --theme-accent-bright: #111111; --theme-action: #111111; --theme-chrome: #ffffff; --theme-action-shadow: none; --lime: #111111; --cyan: #111111; --warning: #111111; --danger: #111111; }
    html[data-theme="light"] :is(.notice, .badge, .theme-error, .transaction-icon.outgoing) { background: var(--panel); color: var(--text); }
    .theme-selector, .language-selector { display: none !important; }
}
