/* Ten coordinated palettes. Existing theme IDs keep saved preferences valid. */
@media screen {
    html[data-theme="classic"][data-theme-mode="light"] {
        --bg: #f5f3ee; --panel: #fffefa; --text: #242725; --muted: #5d625d;
        --line: #cbc9be; --primary: #303e39; --primary-dark: #1c2924;
        --primary-on: #fffefa; --accent: #9a772f; --theme-soft: #e8e8dd;
        --success: #216c49; --danger: #ae2842; --theme-art-image: url("theme-art/classic.webp");
    }
    html[data-theme="sand"][data-theme-mode="light"] {
        --bg: #faf1e4; --panel: #fffaf3; --text: #37271d; --muted: #75614e;
        --line: #d8bea1; --primary: #993e14; --primary-dark: #76300f;
        --primary-on: #fffaf3; --accent: #b56c2c; --theme-soft: #f2dfc7;
        --success: #2e6e43; --danger: #ab2440; --theme-art-image: url("theme-art/sand.webp");
    }
    html[data-theme="arctic"][data-theme-mode="light"] {
        --bg: #eef4ff; --panel: #fbfdff; --text: #182d51; --muted: #536580;
        --line: #b8c9e6; --primary: #2452c6; --primary-dark: #153c9e;
        --primary-on: #fff; --accent: #397ca3; --theme-soft: #dfe9ff;
        --success: #176a4d; --danger: #b42448; --theme-art-image: url("theme-art/arctic.webp");
    }
    html[data-theme="sage"][data-theme-mode="light"] {
        --bg: #eef5ec; --panel: #fbfdf7; --text: #233b2b; --muted: #526850;
        --line: #b9cdb4; --primary: #176546; --primary-dark: #0d4b32;
        --primary-on: #fff; --accent: #7c7027; --theme-soft: #dae9d5;
        --success: #176546; --danger: #a92c43; --theme-art-image: url("theme-art/sage.webp");
    }
    html[data-theme="rose"][data-theme-mode="light"] {
        --bg: #fcf0f4; --panel: #fffafd; --text: #482537; --muted: #7c5369;
        --line: #dcb8c8; --primary: #9c2859; --primary-dark: #791b43;
        --primary-on: #fff; --accent: #8a617e; --theme-soft: #f2dae5;
        --success: #196951; --danger: #a42429; --theme-art-image: url("theme-art/rose.webp");
    }
    html[data-theme="midnight"][data-theme-mode="dark"] {
        --bg: #0b1425; --panel: #152238; --text: #f6f4ed; --muted: #bac6db;
        --line: #435672; --primary: #f0c568; --primary-dark: #ffdc8d;
        --primary-on: #1e1a0e; --accent: #90b9ec; --theme-soft: #26354c;
        --success: #86e3b6; --danger: #ffa6b8; --theme-art-image: url("theme-art/midnight.webp");
    }
    html[data-theme="ocean"][data-theme-mode="dark"] {
        --bg: #071e21; --panel: #103035; --text: #e9fff7; --muted: #a7cec8;
        --line: #3c696b; --primary: #79e1b6; --primary-dark: #a4f3cf;
        --primary-on: #092b22; --accent: #74c8eb; --theme-soft: #19474a;
        --success: #9ce9b1; --danger: #ffb0ba; --theme-art-image: url("theme-art/ocean.webp");
    }
    html[data-theme="lavender"][data-theme-mode="dark"] {
        --bg: #190f29; --panel: #2a1a40; --text: #f9eeff; --muted: #cfb9df;
        --line: #705587; --primary: #d7a4ff; --primary-dark: #e9c9ff;
        --primary-on: #241132; --accent: #f2accc; --theme-soft: #412950;
        --success: #9ae0bc; --danger: #ffabb2; --theme-art-image: url("theme-art/lavender.webp");
    }
    html[data-theme="burgundy"][data-theme-mode="dark"] {
        --bg: #250f1b; --panel: #391d2d; --text: #fff0f3; --muted: #dfb9c8;
        --line: #86576d; --primary: #f2cf9c; --primary-dark: #ffe0b5;
        --primary-on: #34200d; --accent: #e99ab7; --theme-soft: #532b40;
        --success: #a3e3c0; --danger: #ffb2b7; --theme-art-image: url("theme-art/burgundy.webp");
    }
    html[data-theme="graphite"][data-theme-mode="dark"] {
        --bg: #12110f; --panel: #211d19; --text: #fff5e9; --muted: #c9bdb0;
        --line: #6b5543; --primary: #ffa24c; --primary-dark: #ffbd7b;
        --primary-on: #25160a; --accent: #e0c4a5; --theme-soft: #382a20;
        --success: #9ae4ae; --danger: #ffabb9; --theme-art-image: url("theme-art/graphite.webp");
    }
    html[data-theme][data-theme-mode] {
        --theme-on-accent: var(--primary-on);
        --theme-art-opacity: .38;
    }
    /* Override older per-exam hard-coded palettes with the shared colors. */
    html[data-theme][data-theme-mode] body.ui-page {
        --exam-bg: var(--bg); --exam-card: var(--panel); --exam-ink: var(--text);
        --exam-muted: var(--muted); --exam-border: var(--line);
        --exam-primary: var(--primary); --exam-primary-soft: var(--theme-soft);
        --exam-success: var(--success); --exam-danger: var(--danger);
        --exam-success-soft: color-mix(in srgb, var(--success) 12%, var(--panel));
        --exam-danger-soft: color-mix(in srgb, var(--danger) 12%, var(--panel));
        isolation: isolate; background: var(--bg); color: var(--text);
    }
    /* One still image, painted behind the page. The center stays quiet. */
    html[data-theme][data-theme-mode]:not([data-theme-art="off"]) body.ui-page::before {
        content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
        background-image: linear-gradient(90deg, transparent, var(--bg) 30%, var(--bg) 70%, transparent), var(--theme-art-image);
        background-size: cover; background-position: center; background-repeat: no-repeat;
        opacity: var(--theme-art-opacity);
    }
    html[data-theme][data-theme-mode][data-theme-art="off"] body.ui-page::before { content: none; }
    html[data-theme][data-theme-mode] .ui-page :is(.btn.primary, .admin-tabs a.active, .brand-badge, .exam-icon-large) {
        background: var(--primary); color: var(--primary-on); border-color: var(--primary);
    }
    html[data-theme][data-theme-mode] .ui-page .btn.primary:is(:hover, :focus-visible) {
        background: var(--primary-dark); color: var(--primary-on); border-color: var(--primary-dark);
    }
    html[data-theme][data-theme-mode] .ui-page :is(input, textarea, select) {
        caret-color: var(--primary);
    }
    html[data-theme][data-theme-mode] .ui-page :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
    html[data-theme][data-theme-mode] .ui-page :is(select option, .practice-dialog, .recovery-dialog, .entry-card) {
        background: var(--panel); color: var(--text);
    }
    /* Opaque typing surfaces keep artwork away from letter feedback. */
    html[data-theme][data-theme-mode] .ui-page :is(#passageViewport, .fight-guide) {
        background: var(--bg); color: var(--muted);
    }
    html[data-theme][data-theme-mode] .ui-page :is(#passageTrack, .fight-guide-track) { color: var(--muted); }
    html[data-theme][data-theme-mode] .ui-page :is(#typingInput, #fightInput) { color: var(--text); }
    html[data-theme][data-theme-mode] .ui-page .typing-guide-caret { background: var(--primary); }
    html[data-theme][data-theme-mode] .ui-page :is(.legend-current, .exam-progress-bar) { background: var(--primary); }
    html[data-theme][data-theme-mode] .ui-page .legend-wrong { background: var(--danger); }
    html[data-theme][data-theme-mode] .ui-page .guide-char.is-wrong {
        color: var(--danger); background: var(--exam-danger-soft); text-decoration-color: var(--danger);
    }
    html[data-theme][data-theme-mode] .ui-page :is(.typing-zone:focus-within, .practice-dialog input:focus) {
        border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary);
    }
    html[data-theme][data-theme-mode] .ui-page :is(.practice-nav [data-open-dialog="loginDialog"], .focus-view-toggle[aria-pressed="true"]) {
        background: var(--theme-soft); color: var(--primary);
    }
    html[data-theme][data-theme-mode] .ui-page.practice-home .site-theme-slot .theme-select {
        width: 172px; max-width: 172px;
    }
    html[data-theme][data-theme-mode] .ui-page .exam-metrics .metric strong { color: var(--text); }
    html[data-theme][data-theme-mode] .ui-page .exam-metrics :is(.metric-time, .metric-net) strong { color: var(--primary); }
    html[data-theme][data-theme-mode] .ui-page .theme-art-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        flex: 0 0 32px; width: 32px; height: 36px; min-height: 36px;
        padding: 0; margin: 0; border: 1px solid var(--line); border-radius: 8px;
        background: var(--panel); color: var(--primary); font-size: 16px; line-height: 1; font-family: inherit;
        cursor: pointer;
    }
    html[data-theme][data-theme-mode] .ui-page .theme-art-toggle[aria-pressed="false"] { color: var(--muted); }
    html[data-theme][data-theme-mode] .ui-page .theme-art-toggle:hover { border-color: var(--primary); }
    html[data-theme][data-theme-mode] .ui-page .theme-art-toggle svg { width: 17px; height: 17px; }
    @media (prefers-reduced-data: reduce) {
        html[data-theme][data-theme-mode] body.ui-page::before { content: none !important; }
    }
}
