/* ===== Color themes (issue #2936) =====
   One token block per theme in ColorThemeCatalog. The shared layout renders the account's
   theme as <html data-qm-theme="slug" data-bs-theme="light|dark">; settings swatches reuse the
   same attribute to preview a theme. Every hex token is checked for WCAG 2.1 AA contrast by
   ColorThemeStylesheetTests, and every decorative effect lives only inside the
   prefers-reduced-motion: no-preference block at the end of this file.

   --qm-banner-wash-opacity (issue #3314) is set only where a quiz banner needs a stronger wash
   than the 0.9 default in QuizBannerStylesheet for page text to stay AA readable.

   Light keeps the existing look: its block repeats the site.css :root defaults, and the
   Bootstrap mapping below skips it. */

/* ----- Theme tokens ----- */
[data-qm-theme="light"] {
    --qm-bg: #ffffff;
    --qm-surface: #ffffff;
    --qm-surface-subtle: #f8f9fa;
    --qm-surface-accent: #f0f4ff;
    --qm-surface-muted: #e9ecef;
    --qm-border: #dee2e6;
    --qm-text: #1a1a2e;
    --qm-text-muted: #495057;
    --qm-accent: #4361ee;
    --qm-accent-strong: #3a0ca3;
    --qm-on-accent: #ffffff;
    --qm-link: #304bc4;
    --qm-focus: #0d6efd;
    --qm-success: #146c43;
    --qm-danger: #b02a37;
    --qm-bg-rgb: 255, 255, 255;
    --qm-text-rgb: 26, 26, 46;
    --qm-accent-rgb: 67, 97, 238;
    --qm-link-rgb: 48, 75, 196;
}

[data-qm-theme="dark"] {
    --qm-bg: #121826;
    --qm-surface: #1a2233;
    --qm-surface-subtle: #1f2940;
    --qm-surface-accent: #232f4d;
    --qm-surface-muted: #2a3550;
    --qm-border: #34405c;
    --qm-text: #e6e9f2;
    --qm-text-muted: #aab3c5;
    --qm-accent: #7b93ff;
    --qm-accent-strong: #9aabff;
    --qm-on-accent: #0b1020;
    --qm-link: #9aabff;
    --qm-focus: #9aabff;
    --qm-success: #5fd39a;
    --qm-danger: #ff8a95;
    --qm-bg-rgb: 18, 24, 38;
    --qm-text-rgb: 230, 233, 242;
    --qm-accent-rgb: 123, 147, 255;
    --qm-link-rgb: 154, 171, 255;
}

[data-qm-theme="green-phosphor"] {
    --qm-bg: #030a03;
    --qm-surface: #061206;
    --qm-surface-subtle: #0a1a0a;
    --qm-surface-accent: #0c220c;
    --qm-surface-muted: #102a10;
    --qm-border: #1f5a1f;
    --qm-text: #33ff66;
    --qm-text-muted: #22c74c;
    --qm-accent: #33ff66;
    --qm-accent-strong: #7dff9e;
    --qm-on-accent: #021202;
    --qm-link: #7dff9e;
    --qm-focus: #33ff66;
    --qm-success: #c8ffd6;
    --qm-danger: #ff7070;
    --qm-bg-rgb: 3, 10, 3;
    --qm-text-rgb: 51, 255, 102;
    --qm-accent-rgb: 51, 255, 102;
    --qm-link-rgb: 125, 255, 158;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="orange-phosphor"] {
    --qm-bg: #0d0700;
    --qm-surface: #140b00;
    --qm-surface-subtle: #1c1000;
    --qm-surface-accent: #241500;
    --qm-surface-muted: #2b1a00;
    --qm-border: #6b4000;
    --qm-text: #ffb000;
    --qm-text-muted: #d98f00;
    --qm-accent: #ffb000;
    --qm-accent-strong: #ffcc55;
    --qm-on-accent: #1a0d00;
    --qm-link: #ffcc55;
    --qm-focus: #ffb000;
    --qm-success: #b8f09a;
    --qm-danger: #ff7a6b;
    --qm-bg-rgb: 13, 7, 0;
    --qm-text-rgb: 255, 176, 0;
    --qm-accent-rgb: 255, 176, 0;
    --qm-link-rgb: 255, 204, 85;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="red-phosphor"] {
    --qm-bg: #0d0202;
    --qm-surface: #160404;
    --qm-surface-subtle: #1e0606;
    --qm-surface-accent: #260808;
    --qm-surface-muted: #2e0a0a;
    --qm-border: #6e1a1a;
    --qm-text: #ff5c5c;
    --qm-text-muted: #e84a4a;
    --qm-accent: #ff5c5c;
    --qm-accent-strong: #ff9a9a;
    --qm-on-accent: #1a0000;
    --qm-link: #ff9a9a;
    --qm-focus: #ff5c5c;
    --qm-success: #a6f0a0;
    --qm-danger: #ffd0d0;
    --qm-bg-rgb: 13, 2, 2;
    --qm-text-rgb: 255, 92, 92;
    --qm-accent-rgb: 255, 92, 92;
    --qm-link-rgb: 255, 154, 154;
    --qm-banner-wash-opacity: 0.92;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="blue-phosphor"] {
    --qm-bg: #01060f;
    --qm-surface: #030b19;
    --qm-surface-subtle: #061223;
    --qm-surface-accent: #08182e;
    --qm-surface-muted: #0b1d38;
    --qm-border: #1d4a80;
    --qm-text: #4da6ff;
    --qm-text-muted: #3a8ee6;
    --qm-accent: #4da6ff;
    --qm-accent-strong: #8cc8ff;
    --qm-on-accent: #001029;
    --qm-link: #8cc8ff;
    --qm-focus: #4da6ff;
    --qm-success: #7de39a;
    --qm-danger: #ff8a8a;
    --qm-bg-rgb: 1, 6, 15;
    --qm-text-rgb: 77, 166, 255;
    --qm-accent-rgb: 77, 166, 255;
    --qm-link-rgb: 140, 200, 255;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="white-phosphor"] {
    --qm-bg: #0a0a0a;
    --qm-surface: #111111;
    --qm-surface-subtle: #181818;
    --qm-surface-accent: #1e1e1e;
    --qm-surface-muted: #242424;
    --qm-border: #555555;
    --qm-text: #f2f2f2;
    --qm-text-muted: #bdbdbd;
    --qm-accent: #ffffff;
    --qm-accent-strong: #d9d9d9;
    --qm-on-accent: #0a0a0a;
    --qm-link: #ffffff;
    --qm-focus: #ffffff;
    --qm-success: #9be59b;
    --qm-danger: #ff8f8f;
    --qm-bg-rgb: 10, 10, 10;
    --qm-text-rgb: 242, 242, 242;
    --qm-accent-rgb: 255, 255, 255;
    --qm-link-rgb: 255, 255, 255;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="darkly"] {
    --qm-bg: #212337;
    --qm-surface: #1e2132;
    --qm-surface-subtle: #191a2a;
    --qm-surface-accent: #262a42;
    --qm-surface-muted: #383e5c;
    --qm-border: #4e5579;
    --qm-text: #aab3e5;
    --qm-text-muted: #a0a8d6;
    --qm-accent: #65bcff;
    --qm-accent-strong: #86e1fc;
    --qm-on-accent: #191a2a;
    --qm-link: #34d3fb;
    --qm-focus: #65bcff;
    --qm-success: #c3e88d;
    --qm-danger: #ff757f;
    --qm-bg-rgb: 33, 35, 55;
    --qm-text-rgb: 170, 179, 229;
    --qm-accent-rgb: 101, 188, 255;
    --qm-link-rgb: 52, 211, 251;
    --qm-banner-wash-opacity: 0.91;
}

[data-qm-theme="ayu-light"] {
    --qm-bg: #f8f9fa;
    --qm-surface: #fcfcfc;
    --qm-surface-subtle: #f3f4f5;
    --qm-surface-accent: #fff4e0;
    --qm-surface-muted: #e7e8e9;
    --qm-border: #d8d9da;
    --qm-text: #5c6166;
    --qm-text-muted: #5f646a;
    --qm-accent: #ffaa33;
    --qm-accent-strong: #fa8d3e;
    --qm-on-accent: #1a1a1a;
    --qm-link: #1f6fb8;
    --qm-focus: #b86200;
    --qm-success: #4d6b00;
    --qm-danger: #c03b3b;
    --qm-bg-rgb: 248, 249, 250;
    --qm-text-rgb: 92, 97, 102;
    --qm-accent-rgb: 255, 170, 51;
    --qm-link-rgb: 31, 111, 184;
    --qm-banner-wash-opacity: 0.96;
}

[data-qm-theme="ayu-mirage"] {
    --qm-bg: #1f2430;
    --qm-surface: #242936;
    --qm-surface-subtle: #1a1f29;
    --qm-surface-accent: #2a3040;
    --qm-surface-muted: #333a4a;
    --qm-border: #3a4152;
    --qm-text: #cccac2;
    --qm-text-muted: #a3a8b2;
    --qm-accent: #ffcc66;
    --qm-accent-strong: #ffd173;
    --qm-on-accent: #1f2430;
    --qm-link: #73d0ff;
    --qm-focus: #ffcc66;
    --qm-success: #d5ff80;
    --qm-danger: #f28779;
    --qm-bg-rgb: 31, 36, 48;
    --qm-text-rgb: 204, 202, 194;
    --qm-accent-rgb: 255, 204, 102;
    --qm-link-rgb: 115, 208, 255;
}

[data-qm-theme="ayu-dark"] {
    --qm-bg: #0d1017;
    --qm-surface: #10141c;
    --qm-surface-subtle: #0b0e14;
    --qm-surface-accent: #151a23;
    --qm-surface-muted: #1c222c;
    --qm-border: #2a303a;
    --qm-text: #bfbdb6;
    --qm-text-muted: #8f949e;
    --qm-accent: #e6b450;
    --qm-accent-strong: #ffb454;
    --qm-on-accent: #0d1017;
    --qm-link: #59c2ff;
    --qm-focus: #e6b450;
    --qm-success: #aad94c;
    --qm-danger: #f07178;
    --qm-bg-rgb: 13, 16, 23;
    --qm-text-rgb: 191, 189, 182;
    --qm-accent-rgb: 230, 180, 80;
    --qm-link-rgb: 89, 194, 255;
}

[data-qm-theme="arcade-neon"] {
    --qm-bg: #050008;
    --qm-surface: #0d0612;
    --qm-surface-subtle: #120a1a;
    --qm-surface-accent: #1a0d24;
    --qm-surface-muted: #1f1029;
    --qm-border: #7a1f6e;
    --qm-text: #f4f0ff;
    --qm-text-muted: #c9b8e6;
    --qm-accent: #ff2bd6;
    --qm-accent-strong: #00f0ff;
    --qm-on-accent: #050008;
    --qm-link: #00f0ff;
    --qm-focus: #00f0ff;
    --qm-success: #39ff88;
    --qm-danger: #ff5577;
    --qm-bg-rgb: 5, 0, 8;
    --qm-text-rgb: 244, 240, 255;
    --qm-accent-rgb: 255, 43, 214;
    --qm-link-rgb: 0, 240, 255;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: .25rem;
}

[data-qm-theme="handheld"] {
    --qm-bg: #9bbc0f;
    --qm-surface: #a9c832;
    --qm-surface-subtle: #8bac0f;
    --qm-surface-accent: #b7d24f;
    --qm-surface-muted: #8bac0f;
    --qm-border: #306230;
    --qm-text: #0f380f;
    --qm-text-muted: #153a15;
    --qm-accent: #306230;
    --qm-accent-strong: #0f380f;
    --qm-on-accent: #e8f5b8;
    --qm-link: #0f380f;
    --qm-focus: #0f380f;
    --qm-success: #0f380f;
    --qm-danger: #5a0f0f;
    --qm-bg-rgb: 155, 188, 15;
    --qm-text-rgb: 15, 56, 15;
    --qm-accent-rgb: 48, 98, 48;
    --qm-link-rgb: 15, 56, 15;
    --qm-font-body: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: 0;
}

[data-qm-theme="blueprint"] {
    --qm-bg: #0b2a5b;
    --qm-surface: #0e3268;
    --qm-surface-subtle: #123a75;
    --qm-surface-accent: #164283;
    --qm-surface-muted: #1a4a8f;
    --qm-border: #5b84c4;
    --qm-text: #ffffff;
    --qm-text-muted: #c7d7f2;
    --qm-accent: #ffffff;
    --qm-accent-strong: #dbe8ff;
    --qm-on-accent: #0b2a5b;
    --qm-link: #9fd0ff;
    --qm-focus: #ffffff;
    --qm-success: #8ef0b0;
    --qm-danger: #ffb0b0;
    --qm-bg-rgb: 11, 42, 91;
    --qm-text-rgb: 255, 255, 255;
    --qm-accent-rgb: 255, 255, 255;
    --qm-link-rgb: 159, 208, 255;
    --qm-font-heading: "Cascadia Mono", Consolas, "Courier New", monospace;
    --qm-radius: .125rem;
}

[data-qm-theme="paper-and-ink"] {
    --qm-bg: #fbf6e9;
    --qm-surface: #fffaf0;
    --qm-surface-subtle: #f4eedc;
    --qm-surface-accent: #efe6cc;
    --qm-surface-muted: #e8dfc4;
    --qm-border: #b5a985;
    --qm-text: #1b1b1b;
    --qm-text-muted: #4e4a40;
    --qm-accent: #1b1b1b;
    --qm-accent-strong: #3a3a3a;
    --qm-on-accent: #fbf6e9;
    --qm-link: #1d3f8a;
    --qm-focus: #1d3f8a;
    --qm-success: #2f6b2f;
    --qm-danger: #a3271f;
    --qm-bg-rgb: 251, 246, 233;
    --qm-text-rgb: 27, 27, 27;
    --qm-accent-rgb: 27, 27, 27;
    --qm-link-rgb: 29, 63, 138;
    --qm-font-body: Georgia, "Times New Roman", serif;
    --qm-font-heading: Georgia, "Times New Roman", serif;
}

[data-qm-theme="space-console"] {
    --qm-bg: #0a1226;
    --qm-surface: #0f1a33;
    --qm-surface-subtle: #13203d;
    --qm-surface-accent: #172748;
    --qm-surface-muted: #1b2d52;
    --qm-border: #2f4f7f;
    --qm-text: #e3f2ff;
    --qm-text-muted: #9fc3e6;
    --qm-accent: #7fdbff;
    --qm-accent-strong: #b3ecff;
    --qm-on-accent: #0a1226;
    --qm-link: #7fdbff;
    --qm-focus: #7fdbff;
    --qm-success: #7ef0b5;
    --qm-danger: #ff8f9a;
    --qm-bg-rgb: 10, 18, 38;
    --qm-text-rgb: 227, 242, 255;
    --qm-accent-rgb: 127, 219, 255;
    --qm-link-rgb: 127, 219, 255;
    --qm-font-heading: Bahnschrift, "Segoe UI", system-ui, sans-serif;
}

[data-qm-theme="vaporwave"] {
    --qm-bg: #2b1240;
    --qm-surface: #34174d;
    --qm-surface-subtle: #3d1c59;
    --qm-surface-accent: #462066;
    --qm-surface-muted: #4e2570;
    --qm-border: #8a4fb5;
    --qm-text: #ffe9f5;
    --qm-text-muted: #f2bfd8;
    --qm-accent: #ff9e7a;
    --qm-accent-strong: #ff71ce;
    --qm-on-accent: #2b1240;
    --qm-link: #ffb38f;
    --qm-focus: #ffb38f;
    --qm-success: #9effd8;
    --qm-danger: #ff9fb0;
    --qm-bg-rgb: 43, 18, 64;
    --qm-text-rgb: 255, 233, 245;
    --qm-accent-rgb: 255, 158, 122;
    --qm-link-rgb: 255, 179, 143;
}

[data-qm-theme="quiz-show"] {
    --qm-bg: #0b1e6b;
    --qm-surface: #10267f;
    --qm-surface-subtle: #142d8f;
    --qm-surface-accent: #18349e;
    --qm-surface-muted: #1c3aa8;
    --qm-border: #3b5bd1;
    --qm-text: #ffffff;
    --qm-text-muted: #ccd6ff;
    --qm-accent: #f5c518;
    --qm-accent-strong: #ffd84d;
    --qm-on-accent: #0b1e6b;
    --qm-link: #ffd84d;
    --qm-focus: #f5c518;
    --qm-success: #8cf0a6;
    --qm-danger: #ffb0b0;
    --qm-bg-rgb: 11, 30, 107;
    --qm-text-rgb: 255, 255, 255;
    --qm-accent-rgb: 245, 197, 24;
    --qm-link-rgb: 255, 216, 77;
    --qm-font-heading: "Arial Black", "Segoe UI", system-ui, sans-serif;
}

[data-qm-theme="minimal-light"] {
    --qm-bg: #ffffff;
    --qm-surface: #ffffff;
    --qm-surface-subtle: #fafafa;
    --qm-surface-accent: #fff1ec;
    --qm-surface-muted: #f2f2f2;
    --qm-border: #e5e5e5;
    --qm-text: #111111;
    --qm-text-muted: #555555;
    --qm-accent: #ff5a1f;
    --qm-accent-strong: #e64a12;
    --qm-on-accent: #111111;
    --qm-link: #c2410c;
    --qm-focus: #e64a12;
    --qm-success: #1e7a3c;
    --qm-danger: #c0262d;
    --qm-bg-rgb: 255, 255, 255;
    --qm-text-rgb: 17, 17, 17;
    --qm-accent-rgb: 255, 90, 31;
    --qm-link-rgb: 194, 65, 12;
    --qm-banner-wash-opacity: 0.94;
}

[data-qm-theme="midnight-gold"] {
    --qm-bg: #1c1c1e;
    --qm-surface: #242426;
    --qm-surface-subtle: #2a2a2d;
    --qm-surface-accent: #302c24;
    --qm-surface-muted: #333336;
    --qm-border: #4a4538;
    --qm-text: #ece6d8;
    --qm-text-muted: #b8ae98;
    --qm-accent: #c9a95c;
    --qm-accent-strong: #dcc07a;
    --qm-on-accent: #1c1c1e;
    --qm-link: #dcc07a;
    --qm-focus: #c9a95c;
    --qm-success: #9fd49a;
    --qm-danger: #ef8f86;
    --qm-bg-rgb: 28, 28, 30;
    --qm-text-rgb: 236, 230, 216;
    --qm-accent-rgb: 201, 169, 92;
    --qm-link-rgb: 220, 192, 122;
    --qm-font-heading: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
}

[data-qm-theme="candy-pop"] {
    --qm-bg: #fff5fb;
    --qm-surface: #ffffff;
    --qm-surface-subtle: #fdeaf5;
    --qm-surface-accent: #eaf6ff;
    --qm-surface-muted: #f3e6fa;
    --qm-border: #e9a9cd;
    --qm-text: #3b2347;
    --qm-text-muted: #6b4f78;
    --qm-accent: #ff7eb6;
    --qm-accent-strong: #c3a6ff;
    --qm-on-accent: #3b2347;
    --qm-link: #a3246b;
    --qm-focus: #c2185b;
    --qm-success: #2e7d4f;
    --qm-danger: #b3261e;
    --qm-bg-rgb: 255, 245, 251;
    --qm-text-rgb: 59, 35, 71;
    --qm-accent-rgb: 255, 126, 182;
    --qm-link-rgb: 163, 36, 107;
    --qm-banner-wash-opacity: 0.98;
    --qm-font-body: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    --qm-font-heading: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    --qm-radius: 1.25rem;
}

/* ----- Bootstrap mapping for every theme except Light ----- */
html[data-qm-theme]:not([data-qm-theme="light"]) {
    --bs-body-bg: var(--qm-bg);
    --bs-body-bg-rgb: var(--qm-bg-rgb);
    --bs-body-color: var(--qm-text);
    --bs-body-color-rgb: var(--qm-text-rgb);
    --bs-emphasis-color: var(--qm-text);
    --bs-emphasis-color-rgb: var(--qm-text-rgb);
    --bs-heading-color: var(--qm-text);
    --bs-secondary-color: var(--qm-text-muted);
    --bs-tertiary-color: var(--qm-text-muted);
    --bs-secondary-bg: var(--qm-surface-muted);
    --bs-tertiary-bg: var(--qm-surface-subtle);
    --bs-border-color: var(--qm-border);
    --bs-border-color-translucent: var(--qm-border);
    --bs-link-color: var(--qm-link);
    --bs-link-color-rgb: var(--qm-link-rgb);
    --bs-link-hover-color: var(--qm-link);
    --bs-link-hover-color-rgb: var(--qm-link-rgb);
    --bs-primary-text-emphasis: var(--qm-link);
    --bs-success-text-emphasis: var(--qm-success);
    --bs-danger-text-emphasis: var(--qm-danger);
    --bs-focus-ring-color: rgba(var(--qm-accent-rgb), .45);
    --bs-border-radius: var(--qm-radius, .375rem);
    /* Light-only shades from site.css follow the theme's own tested tokens. */
    --qm-border-soft: var(--qm-border);
    --qm-border-strong: var(--qm-border);
    --qm-text-subtle: var(--qm-text-muted);
    --qm-hero-end: var(--qm-surface-subtle);
    --qm-feedback-bg: var(--qm-surface-accent);
    --qm-feedback-border: var(--qm-border);
    background-color: var(--qm-bg);
}

html[data-qm-theme]:not([data-qm-theme="light"]) body {
    color: var(--qm-text);
    background-color: var(--qm-bg);
    font-family: var(--qm-font-body, 'Segoe UI', system-ui, -apple-system, sans-serif);
}

html[data-qm-theme]:not([data-qm-theme="light"]) :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .display-1, .display-2, .display-3, .display-4, .navbar-brand) {
    font-family: var(--qm-font-heading, inherit);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .card,
html[data-qm-theme]:not([data-qm-theme="light"]) .list-group {
    --bs-card-bg: var(--qm-surface);
    --bs-card-cap-bg: var(--qm-surface-subtle);
    --bs-list-group-bg: var(--qm-surface);
    --bs-list-group-color: var(--qm-text);
}

html[data-qm-theme]:not([data-qm-theme="light"]) :is(.bg-white, .bg-light, .bg-body, .bg-body-tertiary) {
    background-color: var(--qm-surface-subtle) !important;
    color: var(--qm-text);
}

/* Bootstrap's --bs-primary/success/danger RGB values are deliberately left alone: they also
   paint .bg-* badges and buttons that keep white text, and the theme text tokens are too
   light for that. Only the text utilities use the theme's tested text colors. */
html[data-qm-theme]:not([data-qm-theme="light"]) .text-primary {
    color: var(--qm-link) !important;
}

html[data-qm-theme]:not([data-qm-theme="light"]) .text-success {
    color: var(--qm-success) !important;
}

html[data-qm-theme]:not([data-qm-theme="light"]) .text-danger {
    color: var(--qm-danger) !important;
}

/* Dark text only follows the theme on the light surfaces this file re-colors, including the
   .table-light header whose sortable column links use .text-dark (#2976). Elsewhere, such as a
   .bg-warning badge, it keeps Bootstrap's dark foreground. */
html[data-qm-theme]:not([data-qm-theme="light"]) :is(.bg-white, .bg-light, .bg-body, .bg-body-tertiary, .table-light):is(.text-dark, .text-black),
html[data-qm-theme]:not([data-qm-theme="light"]) :is(.bg-white, .bg-light, .bg-body, .bg-body-tertiary, .table-light) :is(.text-dark, .text-black):not([class*="bg-"]) {
    color: var(--qm-text) !important;
}

/* Plan labels, plan tables and informational alerts follow the active theme (#2960). Bootstrap's
   fixed blue .bg-primary/.alert-info and the white .table-light header ignore the theme tokens. */
html[data-qm-theme]:not([data-qm-theme="light"]) .badge:is(.bg-primary, .bg-info) {
    background-color: var(--qm-accent) !important;
    color: var(--qm-on-accent) !important;
}

html[data-qm-theme]:not([data-qm-theme="light"]) .alert-info {
    --bs-alert-color: var(--qm-text);
    --bs-alert-bg: var(--qm-surface-accent);
    --bs-alert-border-color: var(--qm-accent);
    --bs-alert-link-color: var(--qm-link);
}

html[data-qm-theme]:not([data-qm-theme="light"]) :is(.table-light, .table > .table-light, .table > thead.table-light) {
    --bs-table-color: var(--qm-text);
    --bs-table-bg: var(--qm-surface-muted);
    --bs-table-border-color: var(--qm-border);
    --bs-table-striped-bg: var(--qm-surface-muted);
    --bs-table-hover-bg: var(--qm-surface-muted);
    color: var(--qm-text);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .btn-primary {
    --bs-btn-color: var(--qm-on-accent);
    --bs-btn-bg: var(--qm-accent);
    --bs-btn-border-color: var(--qm-accent);
    --bs-btn-hover-color: var(--qm-on-accent);
    --bs-btn-hover-bg: var(--qm-accent-strong);
    --bs-btn-hover-border-color: var(--qm-accent-strong);
    --bs-btn-active-color: var(--qm-on-accent);
    --bs-btn-active-bg: var(--qm-accent-strong);
    --bs-btn-active-border-color: var(--qm-accent-strong);
    --bs-btn-disabled-color: var(--qm-on-accent);
    --bs-btn-disabled-bg: var(--qm-accent);
    --bs-btn-disabled-border-color: var(--qm-accent);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .btn-outline-primary {
    --bs-btn-color: var(--qm-link);
    --bs-btn-border-color: var(--qm-accent);
    --bs-btn-hover-color: var(--qm-on-accent);
    --bs-btn-hover-bg: var(--qm-accent);
    --bs-btn-hover-border-color: var(--qm-accent);
    --bs-btn-active-color: var(--qm-on-accent);
    --bs-btn-active-bg: var(--qm-accent-strong);
    --bs-btn-active-border-color: var(--qm-accent-strong);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .qm-cta,
html[data-qm-theme]:not([data-qm-theme="light"]) .qm-cta:hover,
html[data-qm-theme]:not([data-qm-theme="light"]) .qm-cta:focus {
    color: var(--qm-on-accent);
}

/* Focus rings use each theme's focus token, which is tested for 3:1 contrast; the accent
   color alone can be too faint against some theme backgrounds. */
html[data-qm-theme]:not([data-qm-theme="light"]) :focus-visible {
    outline-color: var(--qm-focus);
}

/* Bottom CTA on every themed (non-Light) palette (#3058). site.css paints the landing page's
   closing call to action as an accent-to-accent gradient with white text and a white button, which
   is glaring on dark themes (Midnight Gold, Ayu Dark, ...) and low contrast on pale accents. Here
   it sits on the theme's accent surface framed by hairlines, with the heading and body text in the
   tested --qm-text token (contrast against --qm-surface-accent is covered by the theme tests)
   and the themed primary button. */
html[data-qm-theme]:not([data-qm-theme="light"]) .qm-bottom-cta {
    background: var(--qm-surface-accent);
    border-block: 1px solid var(--qm-border);
    color: var(--qm-text);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .qm-bottom-cta h2,
html[data-qm-theme]:not([data-qm-theme="light"]) .qm-bottom-cta .text-muted {
    color: var(--qm-text) !important;
}

html[data-qm-theme]:not([data-qm-theme="light"]) .qm-bottom-cta .btn-primary {
    background: var(--bs-btn-bg);
    border-color: var(--bs-btn-border-color);
    color: var(--bs-btn-color);
}

html[data-qm-theme]:not([data-qm-theme="light"]) .qm-bottom-cta .btn-primary:hover {
    background: var(--bs-btn-hover-bg);
    border-color: var(--bs-btn-hover-border-color);
    color: var(--bs-btn-hover-color);
}

/* Immediate "correct" feedback (#3072), dark themes only: light themes keep Bootstrap's pale green.
   Bootstrap's dark colour mode paints .bg-success-subtle as a
   near-black green (#051b11) that looks heavy on warm dark themes such as Midnight Gold. Tint the
   theme's own surface with a little of its tested --qm-success token instead, so the highlight is a
   soft green that follows each theme. --qm-text and --qm-success stay readable on it (see the
   theme tests). */
html[data-bs-theme="dark"][data-qm-theme]:not([data-qm-theme="light"]) {
    --bs-success-bg-subtle: color-mix(in srgb, var(--qm-success) 18%, var(--qm-surface));
    --bs-success-border-subtle: color-mix(in srgb, var(--qm-success) 40%, var(--qm-surface));
}

/* Handheld: chunky console-style borders. */
html[data-qm-theme="handheld"] :is(.card, .btn, .form-control, .form-select) {
    border-width: 3px;
}

/* Candy Pop: rounded, pill-shaped buttons. */
html[data-qm-theme="candy-pop"] .btn {
    border-radius: 50rem;
}

/* Quiz Show: bold score-style headings. */
html[data-qm-theme="quiz-show"] :is(h1, h2, .h1, .h2, .display-4) {
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ----- Settings swatches ----- */
.qm-theme-swatch {
    display: block;
    padding: .75rem;
    border: 2px solid var(--qm-border);
    border-radius: .5rem;
    background: var(--qm-bg);
    color: var(--qm-text);
    font-family: var(--qm-font-body, inherit);
}

.qm-theme-swatch__accent {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: .25rem;
    background: var(--qm-accent);
    color: var(--qm-on-accent);
    font-weight: 600;
}

.qm-theme-swatch__link {
    color: var(--qm-link);
    text-decoration: underline;
}

/* Selection is a thick border plus a check mark; keyboard focus is a separate outline, so
   the two states stay distinguishable. */
.qm-theme-option input:checked + .qm-theme-swatch {
    border-width: 4px;
    border-color: var(--qm-focus);
}

.qm-theme-option input:checked + .qm-theme-swatch .qm-theme-swatch__check {
    display: inline;
}

.qm-theme-swatch__check {
    display: none;
    margin-inline-start: .35rem;
}

.qm-theme-option input:focus-visible + .qm-theme-swatch {
    outline: 3px solid var(--bs-body-color);
    outline-offset: 3px;
}

/* ----- Decorative effects -----
   Only for users who have not asked for reduced motion. Everything here is decoration: text
   and controls keep their tested contrast without it. */
@media (prefers-reduced-motion: no-preference) {
    /* CRT phosphor: soft glow, scanlines and a slow flicker. */
    html:is([data-qm-theme="green-phosphor"], [data-qm-theme="orange-phosphor"], [data-qm-theme="red-phosphor"], [data-qm-theme="blue-phosphor"], [data-qm-theme="white-phosphor"]) body {
        text-shadow: 0 0 2px rgba(var(--qm-text-rgb), .45);
    }

    html:is([data-qm-theme="green-phosphor"], [data-qm-theme="orange-phosphor"], [data-qm-theme="red-phosphor"], [data-qm-theme="blue-phosphor"], [data-qm-theme="white-phosphor"]) body::after {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 2000;
        pointer-events: none;
        background-image: repeating-linear-gradient(
            to bottom, rgba(0, 0, 0, .18) 0, rgba(0, 0, 0, .18) 1px, transparent 1px, transparent 3px);
        animation: qm-theme-crt-flicker 6s steps(60) infinite;
    }

    /* Arcade Neon: glowing buttons. */
    html[data-qm-theme="arcade-neon"] .btn {
        box-shadow: 0 0 .5rem rgba(var(--qm-accent-rgb), .75), 0 0 1.25rem rgba(var(--qm-accent-rgb), .35);
    }

    html[data-qm-theme="arcade-neon"] :is(h1, h2, .navbar-brand) {
        text-shadow: 0 0 .5rem rgba(var(--qm-link-rgb), .6);
    }

    /* Handheld: chunky pixel grid on the screen background. */
    html[data-qm-theme="handheld"] body {
        background-image:
            linear-gradient(rgba(15, 56, 15, .06) 1px, transparent 1px),
            linear-gradient(90deg, rgba(15, 56, 15, .06) 1px, transparent 1px);
        background-size: 4px 4px;
    }

    /* Blueprint: technical grid lines. */
    html[data-qm-theme="blueprint"] body {
        background-image:
            linear-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 255, 255, .07) 1px, transparent 1px),
            linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
        background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
    }

    /* Paper & Ink: ruled notebook lines with a margin rule. */
    html[data-qm-theme="paper-and-ink"] body {
        background-image:
            linear-gradient(90deg, transparent 2.9rem, rgba(163, 39, 31, .25) 2.9rem, rgba(163, 39, 31, .25) 3rem, transparent 3rem),
            repeating-linear-gradient(to bottom, transparent 0, transparent 1.7rem, rgba(29, 63, 138, .09) 1.7rem, rgba(29, 63, 138, .09) 1.75rem);
    }

    /* Space Console: faint starfield and glowing panel edges. */
    html[data-qm-theme="space-console"] body {
        background-image:
            radial-gradient(1px 1px at 20% 30%, rgba(227, 242, 255, .5), transparent),
            radial-gradient(1px 1px at 70% 60%, rgba(227, 242, 255, .4), transparent),
            radial-gradient(1px 1px at 40% 80%, rgba(227, 242, 255, .3), transparent);
        background-size: 240px 240px;
    }

    html[data-qm-theme="space-console"] .card {
        box-shadow: 0 0 0 1px rgba(var(--qm-accent-rgb), .35), 0 0 1rem rgba(var(--qm-accent-rgb), .12);
    }

    /* Vaporwave: purple-to-peach sky and a sunset grid along the bottom edge. */
    html[data-qm-theme="vaporwave"] body {
        background-image: linear-gradient(180deg, var(--qm-bg) 0%, var(--qm-surface-muted) 100%);
        background-attachment: fixed;
        /* A stacking context lets the grid below paint above this background but under content. */
        isolation: isolate;
    }

    html[data-qm-theme="vaporwave"] body::after {
        content: "";
        position: fixed;
        inset: auto 0 0 0;
        height: 18vh;
        z-index: -1;
        pointer-events: none;
        background-image:
            linear-gradient(rgba(255, 113, 206, .25) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 113, 206, .25) 1px, transparent 1px);
        background-size: 40px 20px;
        transform: perspective(200px) rotateX(45deg);
        transform-origin: bottom;
    }

    /* Quiz Show: stage spotlights. */
    html[data-qm-theme="quiz-show"] body {
        background-image:
            radial-gradient(ellipse 30% 40% at 15% 0%, rgba(245, 197, 24, .12), transparent),
            radial-gradient(ellipse 30% 40% at 85% 0%, rgba(245, 197, 24, .12), transparent);
        background-attachment: fixed;
    }

    /* Candy Pop: playful polka dots. */
    html[data-qm-theme="candy-pop"] body {
        background-image: radial-gradient(rgba(255, 126, 182, .15) 2px, transparent 2px);
        background-size: 28px 28px;
    }

    @keyframes qm-theme-crt-flicker {
        0%, 100% { opacity: .9; }
        50% { opacity: 1; }
    }
}
