/* The site switch sets data-bs-theme before the initial paint. */
html[data-bs-theme="dark"] {
  color-scheme: dark;
  --night: #091525;
  --panel: #101f33;
  --raised: #162a42;
  --hover: #1e3652;
  --line: #304962;
  --soft: #192f47;
  --paper: var(--panel);
  --ink: #ecf4ff;
  --muted: #adc1d7;
  --blue: #83cefa;
  --orange: #ffc279;
  --green: #83deb7;
  --bad: #ffb3a5;
  --result-total: var(--blue);
  --result-correct: var(--green);
  --result-wrong: var(--bad);
  --result-skipped: #d3c4f8;
  --amber-surface: #372917;
  --green-surface: #13352f;
  --red-surface: #392730;
  --art-paper: #bfcfdd;
  --art-line: #7793ac;
  --shadow: 0 12px 26px #02071075;
  --portal-blue-metal: linear-gradient(180deg,#2a6287,#1b4769 27%,#153752 60%,#0b263e);
  --portal-blue-sheen: radial-gradient(ellipse at 78% -85%,#9ddcff65 0%,transparent 65%);
  --guide-ink: var(--ink);
  --guide-muted: var(--muted);
  --guide-edge: var(--line);
  background: var(--night);
}

[data-bs-theme="dark"] body {
  background: radial-gradient(ellipse at 72% 0%,#162d48 0%,transparent 38rem),var(--night);
  color: var(--ink);
}

[data-bs-theme="dark"] :is(.topbar,.guide-bar) {
  background: var(--portal-blue-sheen),var(--portal-blue-metal);
  border-bottom-color: #805a3b;
}

[data-bs-theme="dark"] .welcome {
  background: radial-gradient(ellipse at 12% -65%,#446e91,transparent 63%),
    linear-gradient(125deg,#172e49,#14334f 45%,#0d2340);
  border-color: #3a5778;
  box-shadow: var(--shadow);
}

[data-bs-theme="dark"] :is(.setup,.smart-home,.skill-card,.progress-panel,.result-panel,.ig-play,.ig-summary,
  .solution-panel,.grade-dialog,.share-dialog,.board-setup-panel,.board-step-notes,.guide-index,.guide-skill-group) {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

[data-bs-theme="dark"] :is(.quiz-view,.result-view,body.interactive-playing #interactive-view) {
  background: radial-gradient(ellipse at 50% -25%,#182e48,transparent 68%),var(--night);
}

[data-bs-theme="dark"] :is(.smart-home-copy h2,.section-header h2,.skill-content h3,.question-title,
  .ig-play-top h2,.grade-dialog h2,.grade-choice-copy strong,.solution-explain h3,.message strong) {
  color: var(--ink);
}

[data-bs-theme="dark"] :is(.section-eyebrow,.skill-tag,.grade-kicker,.ig-target-label,.ig-relation-title,
  .ig-progress>strong,.progress-summary strong,.day-column strong,.skill-stat strong,.recent-caption,
  .recent-row strong,.ig-stats-row b,.ig-summary-numbers span) {
  color: var(--blue);
}

[data-bs-theme="dark"] :is(.setup-fields label,.mode-info,.skill-content p,.choice-caption,.ig-instruction,
  .ig-board-help,.ig-intro p,.ig-task-top>small,.ig-feedback p,.ig-summary p,.ig-stats-row small,
  .grade-dialog p,.grade-dialog .grade-privacy,.grade-choice-copy small,.step-indicator,.solution-explain p,
  .recommend-line small,.day-column small,.recent-row,.mistake-row p,#board-counter) {
  color: var(--muted);
}

[data-bs-theme="dark"] :is(.setup-fields select,.board-fields select,.share-link-tools input,.ig-toolbar select) {
  background: var(--raised);
  border-color: var(--line);
  color: var(--ink);
}

[data-bs-theme="dark"] :is(.button-light,.button-ghost,.button-skip,.button-hint,.button-solution,
  .board-dialog .button-light,.board-dialog .button-ghost,.solution-close,.instruction-audio,.teach-control,
  .mistake-review,.skill-work) {
  background: var(--raised);
  color: var(--blue);
  border-color: var(--line);
  box-shadow: none;
}

[data-bs-theme="dark"] :is(.button-blue,.button-green,.start-green,.board-dialog .button-blue) {
  background: linear-gradient(180deg,#ffcd87,#f6ad5e);
  border-color: #edaa65;
  color: #23180d;
  box-shadow: 0 2px 6px #04091455,inset 0 1px #ffdcac;
  text-shadow: none;
}

[data-bs-theme="dark"] :is(.button-blue,.button-green,.start-green,.board-dialog .button-blue):hover:not(:disabled) {
  background: #ffd397;
}

[data-bs-theme="dark"] .setup-actions .button-metal {
  border-color: #557793;
  box-shadow: inset 0 1px #b2d5ee4d,0 2px 8px #050c19a0;
}

[data-bs-theme="dark"] :is(.button-light,.button-ghost,.button-skip,.button-hint,.button-solution,
  .board-dialog .button-light,.board-dialog .button-ghost,.solution-close,.instruction-audio,.teach-control,
  .mistake-review,.skill-work):hover:not(:disabled) {
  background: var(--hover);
  border-color: #678ba7;
  color: var(--ink);
}

[data-bs-theme="dark"] :is(.button-danger,.message--wrong,.ig-cell.is-miss,.ig-choice.is-miss) {
  background: var(--red-surface);
  color: var(--bad);
  border-color: #ac716c;
}

[data-bs-theme="dark"] :is(.catalog .section-header,.skill-foot,.quiz .progress-track,.board-navigation) {
  border-color: var(--line);
}

[data-bs-theme="dark"] :is(.quiz-cat,.quiz .answer-letter,.board-option .board-option-letter,.preview-label,
  .smart-home-mark,.ig-intro-icon,.ig-choice span,.message-icon,.recommend-no,.privacy-chip,.section-count) {
  background: #203d57;
  color: var(--blue);
  border-color: #416480;
  box-shadow: none;
}

[data-bs-theme="dark"] .skill-card--interactive .preview-label--interactive {
  background: var(--green-surface);
  color: var(--green);
  border-color: #437464;
}

[data-bs-theme="dark"] .skill-preview:not(:has(> .skill-cover)) {
  background: radial-gradient(ellipse at 65% 0%,#254966,transparent 72%),#14283e;
  border-bottom-color: var(--line);
}

[data-bs-theme="dark"] :is(.skill-preview>svg,.skill-card--interactive .ig-unified-svg,.teach-motion-canvas) { filter: brightness(.84); }

[data-bs-theme="dark"] :is(.shared-skill-notice,.progress-summary>div,.result-stat,
  .recommend-line,.mistake-row,.backup-actions,.empty-state,.ig-task-top,.ig-feedback,.message) {
  background: var(--raised);
  border-color: var(--line);
}

[data-bs-theme="dark"] :is(.recommend-line strong,.ig-task-top>strong,.ig-feedback strong) { color: var(--ink); }

[data-bs-theme="dark"] :is(.progress-track,.ig-progress-track,.skill-meter,.day-track,.ig-stats-track,
  .solution-progress>span:not(.is-done)) {
  background: #293f57;
  border-color: #3b536c;
}

[data-bs-theme="dark"] .mistake-index { color: var(--muted); }
[data-bs-theme="dark"] :is(.quiz-status strong,.ig-summary-list .ig-dot--ok) { color: var(--green); }
[data-bs-theme="dark"] :is(.ig-summary-numbers,.ig-relation-pair b,.grade-choice-arrow) { color: var(--orange); }

[data-bs-theme="dark"] :is(.grade-overlay,.solution-overlay),
[data-bs-theme="dark"] .share-dialog::backdrop { background: #030911bd; }
[data-bs-theme="dark"] .grade-choice { background: var(--raised); border-color: var(--line); box-shadow: none; }
[data-bs-theme="dark"] :is(.grade-choice:hover,.grade-choice.is-selected) { background: var(--hover); border-color: var(--orange); }
[data-bs-theme="dark"] .grade-cancel { color: var(--blue); }

[data-bs-theme="dark"] :is(.message,.ig-feedback) { color: var(--muted); }
[data-bs-theme="dark"] :is(.message--correct,.ig-feedback--ok,.result-recommendation,.ig-summary-list .ig-dot--ok) {
  background: var(--green-surface);
  color: var(--green);
  border-color: #487d6c;
}

[data-bs-theme="dark"] :is(.message--hint,.ig-feedback--retry,.ig-summary-list .ig-dot--work,
  .teach-control[aria-pressed="true"],.board-status) {
  background: var(--amber-surface);
  color: var(--orange);
  border-color: #8b673e;
}

[data-bs-theme="dark"] .message--correct .message-icon { background: #225244; color: var(--green); }
[data-bs-theme="dark"] .message--hint .message-icon { background: #533818; color: var(--orange); }
[data-bs-theme="dark"] .message--wrong { background: var(--red-surface); color: var(--bad); border-color: #99615c; }

[data-bs-theme="dark"] :is(.ig-board--grid,.ig-board--pairs,.ig-board--relations) {
  background: #0b192b;
  border-color: var(--line);
}

[data-bs-theme="dark"] :is(.ig-cell,.ig-choice,.ig-memory-card,.ig-relation-pair,.ig-relation-cue,.ig-target-bubble) {
  background: var(--raised);
  border-color: #47637f;
  box-shadow: none;
}

[data-bs-theme="dark"] .ig-memory-back {
  background: linear-gradient(145deg,#254d71,#1a344e);
  border-color: #4c7799;
  color: #a3d6f7;
}

[data-bs-theme="dark"] .ig-cell-dot { background: #62809a; }
[data-bs-theme="dark"] :is(.ig-cell.is-flashing,.ig-cell.is-showing) {
  background: linear-gradient(135deg,#287f91,#115c75);
  border-color: #8ee7e6;
}

[data-bs-theme="dark"] :is(.ig-cell.is-picked,.ig-choice.is-picked,.ig-memory-card.is-picked) {
  background: #2c4057;
  border-color: var(--orange);
}

[data-bs-theme="dark"] :is(.ig-cell.is-answer,.ig-choice.is-answer,.ig-memory-card.is-matched) {
  background: #1c493c;
  border-color: var(--green);
}

[data-bs-theme="dark"] :is(.ig-cell.is-miss,.ig-choice.is-miss) {
  background: var(--red-surface);
  border-color: var(--bad);
}

/* A low-glare drawing surface preserves dark strokes and authored cue colors. */
[data-bs-theme="dark"] :is(.quiz,.board-lesson) {
  --puzzle-ink: var(--ink);
  --puzzle-line: var(--art-line);
  --puzzle-paper: var(--art-paper);
}
[data-bs-theme="dark"] :is(.quiz,.board-lesson) :is(.question-figure,.board-figure) {
  background: radial-gradient(ellipse at 50% 30%,#d4dfeb,var(--art-paper));
  border-color: var(--art-line);
  box-shadow: none;
}

[data-bs-theme="dark"] :is(.quiz,.board-lesson) :is(.answer,.board-option) {
  background: var(--raised);
  border-color: #57758e;
  box-shadow: none;
}

[data-bs-theme="dark"] :is(.quiz,.board-lesson) :is(.answer,.board-option):not(.is-correct,.is-wrong) :is(.answer-letter,.board-option-letter) {
  background: #203d57;
  color: var(--ink);
  border-color: #416480;
}

[data-bs-theme="dark"] :is(.quiz,.board-lesson) :is(.answer,.board-option)>svg {
  background: var(--art-paper);
  border-radius: 5px;
}

[data-bs-theme="dark"] .quiz .answer:hover:not(:disabled) { border-color: var(--orange); }
[data-bs-theme="dark"] :is(.quiz,.board-lesson) :is(.answer,.board-option).is-correct {
  background: var(--green-surface);
  border-color: var(--green);
}

[data-bs-theme="dark"] .quiz .answer.is-wrong { background: var(--red-surface); border-color: var(--bad); }
[data-bs-theme="dark"] .board-option.is-correct::after { color: var(--green); }
[data-bs-theme="dark"] :is(.solution-figure,.board-solution-figure) {
  background: var(--art-paper);
  border-color: var(--art-line);
}

[data-bs-theme="dark"] .motion-scrub-label { color: var(--muted); }
[data-bs-theme="dark"] input[type="range"] { accent-color: var(--orange); }

[data-bs-theme="dark"] .board-dialog {
  --board-navy: var(--ink);
  --board-blue: var(--blue);
  --board-line: var(--line);
  background: var(--night);
}
[data-bs-theme="dark"] .board-dialog::backdrop,
[data-bs-theme="dark"] .board-shell:fullscreen { background: var(--night); }
[data-bs-theme="dark"] .board-solution-actions { background: var(--panel); }
[data-bs-theme="dark"] .board-dialog #board-info[aria-expanded="true"] { background: var(--hover); border-color: var(--blue); }
[data-bs-theme="dark"] #board-scrub::-webkit-slider-runnable-track { background: #42617d; }
[data-bs-theme="dark"] #board-scrub::-moz-range-track { background: #42617d; }
[data-bs-theme="dark"] #board-scrub::-webkit-slider-thumb { background: var(--blue); border-color: var(--raised); }
[data-bs-theme="dark"] #board-scrub::-moz-range-thumb { background: var(--blue); border-color: var(--raised); }

[data-bs-theme="dark"] .tone-blue { --guide-accent: #a1dcff; --guide-tint: #1b3851; }
[data-bs-theme="dark"] .tone-mint { --guide-accent: #96e3cc; --guide-tint: #173c39; }
[data-bs-theme="dark"] .tone-violet { --guide-accent: #d4c7ff; --guide-tint: #302c49; }
[data-bs-theme="dark"] .guide-intro { border-color: #425c77; box-shadow: var(--shadow); }
[data-bs-theme="dark"] .guide-path span::before { color: var(--muted); }
[data-bs-theme="dark"] :is(.guide-tile,.guide-skill) { background: var(--raised); }
[data-bs-theme="dark"] :is(.guide-tile:hover,.guide-skill[open]) { background: var(--hover); }
[data-bs-theme="dark"] .guide-page .guide-skill-actions a { background: var(--guide-accent); color: var(--night); }
[data-bs-theme="dark"] :is(.exercise-picture,.example-choices li) {
  background: var(--art-paper);
  border-color: var(--art-line);
}

[data-bs-theme="dark"] .example-letter { background: #203d57; color: var(--ink); }
[data-bs-theme="dark"] .example-answer>div { background: var(--panel); border-color: var(--line); }
[data-bs-theme="dark"] .example-answer strong { color: var(--green); }
[data-bs-theme="dark"] :is(.guide-page,.guide-index,.quiz,.board-dialog) :focus-visible { outline-color: var(--orange); }

[data-bs-theme="dark"] :is(.quiz,.board-lesson)[data-kind="twoview"] .option-svg {
  background: radial-gradient(ellipse at 50% 35%, #d5e0eb, var(--art-paper));
}
