/* Theme controls are available in both color modes. */
.setting-toggle {
    position: relative;
    flex: 0 0 auto;
    width: 46px !important;
    height: 26px !important;
    margin: 0;
    border: 1px solid #aebdb6;
    border-radius: 999px;
    appearance: none;
    background: #dce5e1;
    cursor: pointer;
    transition:
        border-color 160ms ease,
        background-color 160ms ease;
}

.setting-toggle::before {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(24, 32, 29, 0.24);
    content: "";
    transition: transform 160ms ease;
}

.setting-toggle:checked {
    border-color: #2d7358;
    background: #2d7358;
}

.setting-toggle:checked::before {
    transform: translateX(20px);
}

.setting-toggle:focus-visible {
    outline: 3px solid rgba(57, 113, 92, 0.24);
    outline-offset: 3px;
}

html[data-theme="dark"] {
    --dark-bg: #0e1512;
    --dark-surface: #17211d;
    --dark-surface-raised: #1c2924;
    --dark-surface-soft: #22322c;
    --dark-surface-hover: #293d35;
    --dark-border: #344b41;
    --dark-border-strong: #486458;
    --dark-text: #edf5f1;
    --dark-muted: #afbeb7;
    --dark-accent: #79c9a8;
    --dark-danger: #ff9ba2;
    color: var(--dark-text);
    background: var(--dark-bg);
    color-scheme: dark;
}

html[data-theme="dark"] body {
    color: var(--dark-text);
    background: var(--dark-bg);
}

html[data-theme="dark"] body[data-module-theme="anatomy"] {
    background:
        radial-gradient(circle at 86% 4%, rgba(91, 170, 211, 0.17), transparent 32rem),
        linear-gradient(180deg, #101a20 0%, #10232d 100%);
}

html[data-theme="dark"] body[data-module-theme="disease"] {
    background:
        radial-gradient(circle at 86% 4%, rgba(222, 101, 115, 0.15), transparent 32rem),
        linear-gradient(180deg, #1c1316 0%, #28171c 100%);
}

html[data-theme="dark"] body[data-module-theme="medication"] {
    background:
        radial-gradient(circle at 86% 4%, rgba(234, 190, 61, 0.14), transparent 32rem),
        linear-gradient(180deg, #191812 0%, #272311 100%);
}

html[data-theme="dark"] body[data-module-theme="clinical"] {
    background:
        radial-gradient(circle at 86% 4%, rgba(86, 180, 159, 0.14), transparent 32rem),
        linear-gradient(180deg, #101a17 0%, #102720 100%);
}

html[data-theme="dark"] :where(h1, h2, h3, h4, legend, label, th, td) {
    color: var(--dark-text);
}

html[data-theme="dark"][data-theme] main p:not(.eyebrow) {
    color: var(--dark-muted);
}

html[data-theme="dark"][data-theme] main p.eyebrow {
    color: #8bd5b5;
}

html[data-theme="dark"][data-theme] .home-level-message {
    color: #e3f2eb;
}

html[data-theme="dark"] :where(small, .settings-save-note, .confirmation-panel p) {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(input, select, textarea):not([type="checkbox"]):not([type="radio"]) {
    border-color: var(--dark-border);
    background: #111a16;
    color: var(--dark-text);
}

html[data-theme="dark"] :where(input, textarea)::placeholder {
    color: #82938b;
}

html[data-theme="dark"] :where(a, .text-button) {
    color: var(--dark-accent);
}

html[data-theme="dark"] :where(.eyebrow, .answer-key tbody th) {
    color: #8bd5b5;
}

html[data-theme="dark"] .site-footer {
    border-color: var(--dark-border);
    color: var(--dark-muted);
}

html[data-theme="dark"] .site-footer__label {
    color: #91a39b;
}

html[data-theme="dark"] .site-footer__nav-links a {
    color: #b6c7bf;
}

html[data-theme="dark"] .site-footer__nav-links a:hover,
html[data-theme="dark"] .site-footer__nav-links a:focus-visible {
    color: var(--dark-accent);
}

html[data-theme="dark"] .site-footer__version {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: #c2d0ca;
}

html[data-theme="dark"] :where(.site-footer__link, .site-footer__feedback) {
    color: #9bd8bd;
}

html[data-theme="dark"] :where(.site-footer__feedback, .icon-button, .back-button) {
    border-color: var(--dark-border-strong);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(.site-footer__link, .site-footer__feedback):hover,
html[data-theme="dark"] :where(.icon-button, .back-button):hover {
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] .site-footer__actions {
    border-color: var(--dark-border);
}

/* Global dialogs, settings, authentication and community. */
html[data-theme="dark"] :where(
    .feedback-dialog,
    .consent-banner,
    .auth-dialog,
    .settings-panel,
    .community-dialog
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
}

html[data-theme="dark"] :where(.feedback-context, .auth-profile, .community-profile-stats span) {
    background: var(--dark-surface-soft);
    color: #c8d8d1;
}

html[data-theme="dark"] :where(.feedback-context small, .auth-profile span, .auth-profile small) {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(.setting-row, .settings-danger-zone) {
    border-color: var(--dark-border);
}

html[data-theme="dark"] .setting-toggle {
    border-color: #526a60;
    background: #34483f;
}

html[data-theme="dark"] .setting-toggle:checked {
    border-color: #74c7a4;
    background: #438d70;
}

html[data-theme="dark"] .setting-toggle::before {
    background: #f2f8f5;
}

html[data-theme="dark"] :where(.auth-verification-note, .auth-setup-note) {
    background: #24342d;
    color: #c7d7d0;
}

html[data-theme="dark"] :where(.auth-message:not(:empty), .feedback-admin-notice--error) {
    background: #422328;
    color: #ffc1c5;
}

html[data-theme="dark"] .auth-message--warning:not(:empty) {
    background: #3d341d;
    color: #f3d987;
}

html[data-theme="dark"] :where(.account-button, .app-xp-toast) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(.primary-button, .submit-button) {
    border-color: #58a786;
    background: #397a61;
    color: #ffffff;
}

html[data-theme="dark"] :where(.secondary-button, .mode-button) {
    border-color: var(--dark-border-strong);
    background: var(--dark-surface-raised);
    color: #dce9e3;
}

html[data-theme="dark"] :where(.secondary-button, .mode-button):hover:not(:disabled) {
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] .danger-button {
    border-color: #8e4d53;
    background: #3a2226;
    color: #ffb0b5;
}

html[data-theme="dark"] .danger-button:hover:not(:disabled) {
    background: #4a292e;
}

/* Home and shared learning surfaces. */
html[data-theme="dark"] .home-daily-session {
    border-color: #35584a;
    background:
        radial-gradient(circle at 96% 12%, rgba(238, 196, 75, 0.12), transparent 30%),
        linear-gradient(145deg, #18251f, #1c3028);
}

html[data-theme="dark"] .app-boot-screen__logo {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .app-boot-screen__card strong {
    color: var(--dark-text);
}

html[data-theme="dark"] .app-boot-screen__card p {
    color: var(--dark-muted);
}

html[data-theme="dark"] .app-boot-screen__progress {
    background: #334a40;
}

html[data-theme="dark"] .home-header p:last-child {
    color: var(--dark-muted);
}

html[data-theme="dark"] .home-announcement {
    border-color: #4c735f;
    background:
        radial-gradient(circle at 100% 0%, rgba(238, 196, 75, 0.13), transparent 34%),
        linear-gradient(135deg, #17372b, #214b3a 72%, #2b5945);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .home-announcement__action {
    border-color: #6d9b85;
    background: #e8f2ed;
    color: #173f30;
}

html[data-theme="dark"] .home-latest-blog {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

html[data-theme="dark"] .home-latest-blog__heading h2,
html[data-theme="dark"] .home-latest-blog__content > strong {
    color: var(--dark-text);
}

html[data-theme="dark"] .home-latest-blog__heading > a,
html[data-theme="dark"] .home-latest-blog__action {
    color: #8bd5b5;
}

html[data-theme="dark"] .home-latest-blog__card {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .home-latest-blog__card:hover,
html[data-theme="dark"] .home-latest-blog__card:focus-visible {
    border-color: var(--dark-border-strong);
    box-shadow: 0 13px 30px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .home-latest-blog__meta,
html[data-theme="dark"] .home-latest-blog__content > span:last-child,
html[data-theme="dark"] .home-latest-blog__loading {
    color: var(--dark-muted);
}

html[data-theme="dark"] .home-latest-blog__loading {
    border-color: var(--dark-border);
}

html[data-theme="dark"] .home-today-plan {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"] .home-today-plan__heading h2,
html[data-theme="dark"] .home-today-task__content h3 {
    color: var(--dark-text);
}

html[data-theme="dark"] .home-today-plan__heading > div > p:last-child,
html[data-theme="dark"] .home-today-task__content > p:last-of-type {
    color: var(--dark-muted);
}

html[data-theme="dark"] .home-today-plan__heading > span {
    color: #a7dfc6;
    background: #294338;
}

html[data-theme="dark"] .home-today-task {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .home-today-task--terms { --home-task-accent: #b9a0ef; }
html[data-theme="dark"] .home-today-task--lesson { --home-task-accent: #85c7ed; }
html[data-theme="dark"] .home-today-task--quiz { --home-task-accent: #e6b779; }
html[data-theme="dark"] .home-today-task--medicine { --home-task-accent: #7fd3ad; }

html[data-theme="dark"] .home-today-task__number {
    color: #15251e;
}

html[data-theme="dark"] :where(
    .intro p,
    .home-daily-session__content > p:not(.eyebrow),
    .home-daily-session__week p,
    .topic-description,
    .home-top-five-intro,
    .home-top-five-card--signed-out > p,
    .home-top-five-note
) {
    color: var(--dark-muted);
}

html[data-theme="dark"] .home-daily-session__content .eyebrow {
    color: #8bd5b5;
}

html[data-theme="dark"] .home-daily-session__content > p:not(.eyebrow),
html[data-theme="dark"] .home-daily-session__week p {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .home-daily-session__modules legend,
    .home-daily-session__today span,
    .home-daily-session__goal-copy > span,
    .home-daily-session__goal-copy small,
    .home-daily-session__continuity > small
) {
    color: #a8b9b1;
}

html[data-theme="dark"] :where(
    .home-daily-session__today strong,
    .home-daily-session__goal-copy strong,
    .home-daily-session__meter strong,
    .home-daily-session__week,
    .home-daily-session__week strong
) {
    color: var(--dark-text);
}

html[data-theme="dark"] .home-daily-session__meter {
    background: conic-gradient(#70c29e var(--home-daily-progress), #334a40 0);
}

html[data-theme="dark"] .home-daily-session__meter::before {
    background: #21322b;
}

html[data-theme="dark"] .home-daily-session__meter small {
    color: #a8b9b1;
}

html[data-theme="dark"] .home-daily-session__week > span {
    border: 1px solid var(--dark-border-strong);
    background: var(--dark-surface-soft);
    color: #8bd5b5;
}

html[data-theme="dark"] .home-daily-session__modules input:checked + span {
    border-color: #67b895;
    background: #2b4b3d;
    color: #e6f2ed;
    box-shadow: inset 0 0 0 1px rgba(103, 184, 149, 0.22);
}

html[data-theme="dark"] :where(
    .home-daily-session__recipe li,
    .home-daily-session__modules span,
    .home-daily-session__continuity
) {
    border-color: var(--dark-border);
    background: rgba(33, 50, 43, 0.88);
    color: #d7e5df;
}

html[data-theme="dark"] .home-top-five-card {
    border-color: #574f2e;
    background:
        radial-gradient(circle at 100% 0, rgba(255, 215, 106, 0.13), transparent 34%),
        linear-gradient(145deg, #211f17, #292515);
}

html[data-theme="dark"] :where(.home-top-five-list .scoreboard-row, .scoreboard-row) {
    border-color: var(--dark-border);
    background: rgba(28, 41, 35, 0.92);
    color: var(--dark-text);
}

/* The home leaderboard has more specific light-theme selectors than the
   shared scoreboard. Keep every non-current row dark as well. */
html[data-theme="dark"] .home-top-five-list .scoreboard-row {
    border-color: var(--dark-border);
    background: #1c2923;
    color: var(--dark-text);
}

html[data-theme="dark"] .home-top-five-list .scoreboard-row:nth-child(2) {
    border-color: #657078;
    background: #222c2a;
}

html[data-theme="dark"] .home-top-five-list .scoreboard-row:nth-child(3) {
    border-color: #745b45;
    background: #2c2823;
}

html[data-theme="dark"] .scoreboard-row:hover,
html[data-theme="dark"] .scoreboard-row:focus-visible {
    border-color: #6eaa91;
    background: var(--dark-surface-hover);
    color: var(--dark-text);
    outline-color: rgba(121, 201, 168, 0.28);
}

html[data-theme="dark"] .scoreboard-row--current {
    border-color: #579477;
    background: #213b30;
}

html[data-theme="dark"] .scoreboard-rank {
    color: #b7c7bf;
}

html[data-theme="dark"] .scoreboard-user strong {
    color: #f1f7f4;
}

html[data-theme="dark"] :where(
    .scoreboard-user small,
    .scoreboard-score small,
    .scoreboard-own-position > span,
    .scoreboard-note
) {
    color: #b5c5bd;
}

html[data-theme="dark"] .scoreboard-score strong {
    color: #91d8b9;
}

html[data-theme="dark"] .home-top-five-list .scoreboard-score strong {
    color: #a9e8cb;
}

html[data-theme="dark"] .home-top-five-list .scoreboard-score small {
    color: #d5e1dc;
}

html[data-theme="dark"] .scoreboard-own-position {
    border-color: var(--dark-border-strong);
}

html[data-theme="dark"] .home-top-five-list .scoreboard-row:nth-child(1) {
    border-color: #746332;
    background: linear-gradient(145deg, #393018, #25251e);
}

html[data-theme="dark"] .home-top-five-list .scoreboard-row:nth-child(1) .scoreboard-score strong {
    color: #f1d477;
}

html[data-theme="dark"] :where(
    .home-top-five-periods button[aria-pressed="true"],
    .scoreboard-periods button[aria-pressed="true"],
    .scoreboard-friends-toggle
) {
    border-color: var(--dark-border-strong);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] .scoreboard-card {
    border-color: var(--dark-border);
    background:
        radial-gradient(circle at 100% 0, rgba(255, 215, 106, 0.1), transparent 27%),
        linear-gradient(145deg, var(--dark-surface), #1b2b24);
}

html[data-theme="dark"] :where(.scoreboard-motivation, .community-profile-note) {
    background: #1c3027;
    color: #bad2c8;
}

html[data-theme="dark"] .scoreboard-motivation[data-tone="leader"] {
    background: #393219;
    color: #f2d77a;
}

html[data-theme="dark"] .topic-card {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

html[data-theme="dark"] .topic-card--theme-anatomy {
    border-color: #31566a;
    background: linear-gradient(145deg, #17232a, #183343);
}

html[data-theme="dark"] .topic-card--theme-disease {
    border-color: #684047;
    background: linear-gradient(145deg, #271b1f, #3a2026);
}

html[data-theme="dark"] .topic-card--theme-medication {
    border-color: #6c5d2c;
    background: linear-gradient(145deg, #29271c, #3a3216);
}

html[data-theme="dark"] .topic-card--theme-clinical {
    border-color: #315d52;
    background: linear-gradient(145deg, #172721, #18382f);
}

html[data-theme="dark"] :where(.topic-card--theme-resources, .topic-card--resource) {
    border-color: #385c4d;
    background: linear-gradient(145deg, #19251f, #1b3429);
}

html[data-theme="dark"] .topic-grid--upcoming .topic-card {
    border-color: #39473f;
    background: linear-gradient(135deg, #1b2420, #222a26);
}

html[data-theme="dark"] :where(
    .topic-learning-status,
    .category-mastery,
    .answer-confidence button
) {
    border-color: var(--dark-border);
    background: rgba(17, 28, 23, 0.68);
    color: #c9d8d1;
}

html[data-theme="dark"] :where(
    .topic-learning-status strong,
    .open-label,
    .resource-site-label
) {
    color: #91d8b9;
}

html[data-theme="dark"] :where(.home-upcoming__heading > span, .status-label) {
    background: var(--dark-surface-soft);
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .learning-status-badge--mastered,
    .topic-learning-status--mastered,
    .category-mastery--mastered
) {
    border-color: #74622c;
    background: #3c3319;
    color: #f0d471;
}

/* Shared quizzes, daily learning, vitals and NEWS2. */
html[data-theme="dark"] :where(
    .daily-question-card,
    .daily-results-card,
    .daily-xp-summary,
    .quiz-stats div,
    .quiz-card,
    .adult-vital-choice,
    .news2-mode-card,
    .news2-workspace,
    .news2-table-wrapper,
    .news2-info
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(.daily-answer, .adult-vital-choice--primary) {
    border-color: var(--dark-border);
    background: var(--dark-surface);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(.daily-answer:hover:not(:disabled), .adult-vital-choice:hover) {
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] .quiz-mastery-change {
    color: var(--dark-muted);
}

html[data-theme="dark"] .quiz-mastery-change__arrow {
    background: #303936;
    color: #b4c0ba;
}

html[data-theme="dark"] .quiz-mastery-change--up .quiz-mastery-change__arrow {
    background: #173d2e;
    color: #72d5a5;
}

html[data-theme="dark"] .quiz-mastery-change--down .quiz-mastery-change__arrow {
    background: #4a2428;
    color: #ff9da3;
}

html[data-theme="dark"] .quiz-mastery-list h2,
html[data-theme="dark"] .quiz-mastery-list__content > strong {
    color: var(--dark-text);
}

html[data-theme="dark"] .quiz-mastery-list__item {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .quiz-mastery-list__content > span {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .daily-xp-summary__total,
    .daily-next-session,
    .daily-results-breakdown > div,
    .daily-results-level,
    .daily-results-review
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] :where(
    .daily-answer--wrong,
    .daily-explanation--wrong,
    .daily-results-review-list li
) {
    border-color: #864d53;
    background: #42252a;
    color: #ffc0c4;
}

html[data-theme="dark"] :where(
    .daily-answer--correct,
    .daily-explanation--correct
) {
    border-color: #579477;
    background: #1d392d;
    color: #d5f2e3;
}

html[data-theme="dark"][data-theme] .daily-explanation--correct p {
    color: #bed7cb;
}

html[data-theme="dark"] :where(.daily-answer-feedback-heading span, .daily-deepen-button) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
}

html[data-theme="dark"] .daily-deep-explanation section {
    background: rgba(28, 43, 36, 0.82);
}

html[data-theme="dark"] :where(.audience-switch__button--active, .symbol-button) {
    border-color: var(--dark-border-strong);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] .answer-key thead th {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: #dce9e3;
}

html[data-theme="dark"] :where(
    .quiz-feedback--correct,
    .feedback-submit-status--success
) {
    color: #8cddb8;
}

html[data-theme="dark"] :where(
    .quiz-feedback--wrong,
    .feedback-submit-status--error,
    .medication-inline-feedback--error
) {
    color: #ff9fa6;
}

html[data-theme="dark"] :where(
    .quiz-feedback--warning,
    .feedback-submit-status--warning
) {
    color: #f2cf6d;
}

html[data-theme="dark"] :where(.news2-parameter-heading, .news2-row-heading) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: #d5e2dc;
}

html[data-theme="dark"] .news2-progress span {
    background: #e9f2ed;
}

html[data-theme="dark"] .news2-tone--medium {
    background: #493d16;
    color: #f4da77;
}

html[data-theme="dark"] .news2-tone--high {
    background: #522e20;
    color: #ffba93;
}

html[data-theme="dark"] .news2-tone--critical {
    background: #53262b;
    color: #ffc0c4;
}

/* Anatomy and disease share the same learning UI, but retain distinct accents. */
html[data-theme="dark"] :where(.anatomy-overall-stats, .disease-overall-stats) {
    border-color: var(--dark-border);
    background: linear-gradient(135deg, var(--dark-surface-raised), var(--dark-surface-soft));
}

html[data-theme="dark"] .anatomy-overall-stats {
    border-color: #31566a;
    background: linear-gradient(135deg, #18242b, #173342);
}

html[data-theme="dark"] .anatomy-stat-ring {
    background: conic-gradient(
        #62a7cb var(--anatomy-stat-angle),
        #293e49 0
    );
}

html[data-theme="dark"] .disease-overall-stats {
    border-color: #684047;
    background: linear-gradient(135deg, #281c20, #3b2127);
}

html[data-theme="dark"] .disease-stat-ring {
    background: conic-gradient(
        #d07079 var(--disease-stat-angle),
        #493238 0
    );
}

html[data-theme="dark"] :where(.anatomy-stat-ring::before, .disease-stat-ring::before) {
    background: var(--dark-surface-raised);
}

html[data-theme="dark"] :where(
    .anatomy-count-badge,
    .disease-count-badge,
    .anatomy-mode-card,
    .disease-mode-card,
    .anatomy-library-filters,
    .disease-library-filters,
    .anatomy-library-question,
    .disease-library-question,
    .anatomy-library-empty,
    .disease-library-empty,
    .anatomy-filter-card,
    .disease-filter-card,
    .anatomy-category-card,
    .disease-category-card,
    .anatomy-recommendation,
    .disease-recommendation,
    .anatomy-count-options span,
    .disease-count-options span,
    .anatomy-question-card,
    .disease-question-card,
    .anatomy-flashcard-area,
    .disease-flashcard-area,
    .anatomy-results-card,
    .disease-results-card,
    .anatomy-xp-summary,
    .disease-xp-summary,
    .anatomy-rating-buttons button,
    .disease-rating-buttons button
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .anatomy-mode-card:first-child,
    .disease-mode-card:first-child
) {
    background: linear-gradient(145deg, #192720, #1c352b);
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-mode-card:first-child,
    .disease-mode-card:first-child
) {
    background: linear-gradient(145deg, #192720, #1c352b);
}

html[data-theme="dark"] :where(
    .anatomy-mode-card:nth-child(2),
    .disease-mode-card:nth-child(2),
    .disease-mode-card--multiple-choice
) {
    background: linear-gradient(145deg, #211f27, #30263b);
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-mode-card:nth-child(2),
    .disease-mode-card:nth-child(2),
    .disease-mode-card--multiple-choice
) {
    background: linear-gradient(145deg, #211f27, #30263b);
}

html[data-theme="dark"] :where(.anatomy-exam-cta, .disease-exam-cta) {
    border-color: #426b59;
    background: linear-gradient(135deg, #1b2c24, #21392e);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(.anatomy-exam-cta__icon, .disease-exam-cta__icon) {
    background: #29483b;
}

html[data-theme="dark"] :where(.disease-mode-card--flashcards) {
    background: linear-gradient(145deg, #1a242b, #1e3040);
}

html[data-theme="dark"] .disease-learning-note {
    border-color: #574864;
    background: #2c2535;
    color: #d8c9e8;
}

html[data-theme="dark"] .disease-learning-path-entry {
    border-color: #39594d;
    background: linear-gradient(135deg, #142a23, #171f1c 58%, #2a1b1d);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

html[data-theme="dark"] .disease-learning-path-entry--pulmonary {
    border-color: #365867;
    background: linear-gradient(135deg, #14262d, #171f1c 58%, #17233a);
}

html[data-theme="dark"] .disease-learning-path-entry--pulmonary .disease-learning-path-entry__icon {
    background: #263f49;
}

html[data-theme="dark"] .disease-learning-path-entry__icon {
    background: #263f35;
}

html[data-theme="dark"] .disease-learning-path-entry div > p:not(.eyebrow) {
    color: #b8c8c0;
}

html[data-theme="dark"] .disease-learning-path-entry div > span {
    color: #8fcbb0;
}

html[data-theme="dark"] :where(
    .anatomy-mode-card--mistakes,
    .disease-mode-card--mistakes,
    .anatomy-error-bank-stat,
    .disease-error-bank-stat,
    .anatomy-library-toggle,
    .disease-library-toggle
) {
    border-color: #75454b;
    background: linear-gradient(145deg, #2a1d20, #402329);
}

html[data-theme="dark"] :where(.anatomy-mode-card__icon, .disease-mode-card__icon) {
    background: #29483b;
    color: #8bd5b5;
}

html[data-theme="dark"] .anatomy-mode-card__icon,
html[data-theme="dark"] .disease-mode-card__icon {
    background: #29483b;
    color: #8bd5b5;
}

html[data-theme="dark"] :where(
    .anatomy-mode-card:nth-child(2) .anatomy-mode-card__icon,
    .disease-mode-card:nth-child(2) .disease-mode-card__icon
) {
    background: #352c47;
    color: #c8afe8;
}

html[data-theme="dark"] .anatomy-mode-card:nth-child(2) .anatomy-mode-card__icon,
html[data-theme="dark"] .disease-mode-card:nth-child(2) .disease-mode-card__icon {
    background: #352c47;
    color: #c8afe8;
}

html[data-theme="dark"] :where(
    .anatomy-mode-card--mistakes .anatomy-mode-card__icon,
    .disease-mode-card--mistakes .disease-mode-card__icon
) {
    background: #4a292e;
    color: #ffb0b5;
}

html[data-theme="dark"] .anatomy-mode-card--mistakes .anatomy-mode-card__icon,
html[data-theme="dark"] .disease-mode-card--mistakes .disease-mode-card__icon {
    background: #4a292e;
    color: #ffb0b5;
}

html[data-theme="dark"] :where(.anatomy-mode-warning, .disease-mode-warning) {
    background: #3d341c;
    color: #f1d77f;
}

html[data-theme="dark"] :where(
    .anatomy-error-bank-stat span,
    .disease-error-bank-stat span
) {
    color: #d3adb0;
}

html[data-theme="dark"] :where(
    .anatomy-library-status div,
    .disease-library-status div,
    .anatomy-smart-button,
    .disease-smart-button,
    .anatomy-library-button,
    .disease-library-button,
    .anatomy-library-pagination button,
    .disease-library-pagination button
) {
    border-color: var(--dark-border);
    background: rgba(29, 43, 37, 0.92);
    color: #d9e6e0;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-library-status strong,
    .disease-library-status strong
) {
    color: var(--dark-text);
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-library-status span,
    .disease-library-status span,
    .anatomy-smart-button small,
    .disease-smart-button small
) {
    color: var(--dark-muted);
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-smart-button em,
    .disease-smart-button em
) {
    color: #91d8b9;
}

html[data-theme="dark"] :where(
    .anatomy-coming-later,
    .disease-coming-later
) {
    border-color: var(--dark-border);
}

html[data-theme="dark"] :where(
    .anatomy-coming-later span,
    .disease-coming-later span
) {
    background: var(--dark-surface-soft);
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .anatomy-segmented-control,
    .disease-segmented-control,
    .anatomy-start-bar,
    .disease-start-bar,
    .anatomy-next-session,
    .disease-next-session,
    .anatomy-level-progress,
    .disease-level-progress,
    .anatomy-flash-summary span,
    .disease-flash-summary span
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] :where(
    .anatomy-segmented-control input:checked + span,
    .disease-segmented-control input:checked + span
) {
    background: #334b40;
    color: #f0f6f3;
}

html[data-theme="dark"] :where(
    .anatomy-category-card:has(input:checked),
    .disease-category-card:has(input:checked),
    .anatomy-recommendations,
    .disease-recommendations
) {
    border-color: #426a59;
    background: linear-gradient(135deg, #1b2c24, #21372e);
}

/* Category cards define several light-theme colors with higher specificity.
   These explicit selectors ensure both selected and unselected cards remain
   readable in dark mode. */
html[data-theme="dark"] .anatomy-category-card:has(input:checked),
html[data-theme="dark"] .disease-category-card:has(input:checked) {
    border-color: #5c9a7e;
    background: linear-gradient(135deg, #1b2c24, #21372e);
    box-shadow: inset 0 0 0 1px rgba(110, 180, 149, 0.3), 0 7px 18px rgba(0, 0, 0, 0.18);
}

html[data-theme="dark"] :is(.anatomy-category-card, .disease-category-card) :is(
    .anatomy-category-card__heading strong,
    .disease-category-card__heading strong,
    .anatomy-category-card__mastery b,
    .disease-category-card__mastery b
) {
    color: #f1f7f4;
}

html[data-theme="dark"] :is(.anatomy-category-card, .disease-category-card) :is(
    .anatomy-category-card__mastery small,
    .disease-category-card__mastery small,
    .anatomy-category-card__review,
    .disease-category-card__review,
    .anatomy-category-card__coverage,
    .disease-category-card__coverage
) {
    color: #c4d2cb;
}

html[data-theme="dark"] :is(
    .anatomy-category-card__review--ready,
    .disease-category-card__review--ready
) {
    color: #f1d477;
}

html[data-theme="dark"] :is(
    .anatomy-category-card__review,
    .disease-category-card__review
) > span {
    background: #2b4338;
    color: #d9e6e0;
}

html[data-theme="dark"] :is(
    .anatomy-category-card__review--ready,
    .disease-category-card__review--ready
) > span {
    background: #493a1e;
    color: #f1d477;
}

html[data-theme="dark"] :is(.anatomy-mastery-progress, .disease-mastery-progress) {
    background: #344840;
}

html[data-theme="dark"] :is(.anatomy-category-card, .disease-category-card) {
    --anatomy-mastery-color: #aebfb7;
    --disease-mastery-color: #aebfb7;
}

html[data-theme="dark"] :is(.anatomy-category-card--good, .disease-category-card--good) {
    --anatomy-mastery-color: #70caa5;
    --disease-mastery-color: #70caa5;
}

html[data-theme="dark"] :is(.anatomy-category-card--developing, .disease-category-card--developing) {
    --anatomy-mastery-color: #e4bd62;
    --disease-mastery-color: #e4bd62;
}

html[data-theme="dark"] :is(.anatomy-category-card--weak, .disease-category-card--weak) {
    --anatomy-mastery-color: #ef9277;
    --disease-mastery-color: #ef9277;
}

html[data-theme="dark"] :where(
    .anatomy-difficulty-option,
    .disease-difficulty-option,
    .anatomy-answer,
    .disease-answer
) {
    border-color: var(--dark-border);
    background: var(--dark-surface);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .anatomy-difficulty-option:not(.anatomy-difficulty-option--disabled):hover,
    .disease-difficulty-option:not(.disease-difficulty-option--disabled):hover
) {
    background: var(--dark-surface-hover);
}

/* Setup and answer controls use :has(), :not() and hover selectors in the
   light theme. Match that specificity explicitly so they cannot turn light
   while retaining dark-mode text. */
html[data-theme="dark"] .anatomy-difficulty-option:has(input:checked),
html[data-theme="dark"] .disease-difficulty-option:has(input:checked) {
    border-color: #5c9a7e;
    background: #21382f;
    color: #f1f7f4;
    box-shadow: inset 0 0 0 1px rgba(110, 180, 149, 0.3);
}

html[data-theme="dark"] .anatomy-difficulty-option:not(.anatomy-difficulty-option--disabled):hover,
html[data-theme="dark"] .disease-difficulty-option:not(.disease-difficulty-option--disabled):hover,
html[data-theme="dark"] .anatomy-difficulty-option:has(input:focus-visible),
html[data-theme="dark"] .disease-difficulty-option:has(input:focus-visible) {
    border-color: #6eaa91;
    background: #2a4338;
    color: #f1f7f4;
}

html[data-theme="dark"] :is(.anatomy-difficulty-option, .disease-difficulty-option) :is(small, em) {
    color: #c4d2cb;
}

html[data-theme="dark"] .anatomy-answer:not(:disabled):hover,
html[data-theme="dark"] .disease-answer:not(:disabled):hover,
html[data-theme="dark"] .anatomy-answer:not(:disabled):focus-visible,
html[data-theme="dark"] .disease-answer:not(:disabled):focus-visible {
    border-color: #6eaa91;
    background: #2a4338;
    color: #f1f7f4;
}

html[data-theme="dark"] .anatomy-answer:not(:disabled):focus-visible,
html[data-theme="dark"] .disease-answer:not(:disabled):focus-visible {
    outline: 2px solid #6eaa91;
    outline-offset: 2px;
}

html[data-theme="dark"] :is(.anatomy-answer, .disease-answer) > span {
    border: 1px solid #526c61;
    background: #314a3f;
    color: #f1f7f4;
}

html[data-theme="dark"] :is(.anatomy-answer, .disease-answer) strong {
    color: #f1f7f4;
}

html[data-theme="dark"] :where(
    .anatomy-answer--wrong,
    .disease-answer--wrong,
    .anatomy-explanation--wrong,
    .disease-explanation--wrong
) {
    border-color: #874d53;
    background: #42252a;
    color: #ffc1c5;
}

html[data-theme="dark"] :where(
    .anatomy-answer--correct,
    .disease-answer--correct,
    .anatomy-explanation--correct,
    .disease-explanation--correct
) {
    border-color: #579477;
    background: #1d392d;
    color: #d5f2e3;
}

html[data-theme="dark"] :is(.anatomy-answer--correct, .disease-answer--correct) > span {
    border-color: #70b493;
    background: #3d765d;
    color: #ffffff;
}

html[data-theme="dark"] :is(.anatomy-answer--wrong, .disease-answer--wrong) > span {
    border-color: #ba6971;
    background: #7c3e46;
    color: #ffffff;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-explanation--correct p,
    .disease-explanation--correct p
) {
    color: #bed7cb;
}

html[data-theme="dark"] :where(
    .anatomy-answer-feedback-heading span,
    .disease-answer-feedback-heading span,
    .anatomy-deepen-button,
    .disease-deepen-button,
    .anatomy-deep-illustration,
    .disease-deep-illustration
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
}

html[data-theme="dark"] :where(.anatomy-deep-explanation, .disease-deep-explanation) {
    border-color: var(--dark-border);
    background: rgba(27, 42, 35, 0.94);
}

html[data-theme="dark"] :where(.anatomy-deep-section--primary, .disease-deep-section--primary) {
    background: #1b3026;
}

html[data-theme="dark"] .anatomy-learning-outcome-card {
    border-color: #416a58;
    background: linear-gradient(145deg, #1b3026, #202d27);
    box-shadow: none;
}

html[data-theme="dark"] .anatomy-learning-outcome-card__heading > span,
html[data-theme="dark"] .anatomy-learning-outcome-list li {
    border-color: #3e594d;
    background: #253a31;
}

html[data-theme="dark"] .anatomy-learning-outcome-list strong {
    color: #8fd3b4;
}

html[data-theme="dark"] .anatomy-learning-outcome-list span,
html[data-theme="dark"] .anatomy-learning-outcome-card .anatomy-learning-outcome-card__source {
    color: #bfd0c7;
}

html[data-theme="dark"] :where(.anatomy-deep-section--abbreviations, .disease-deep-section--abbreviations) {
    background: #1b2934;
}

html[data-theme="dark"] :where(.anatomy-deep-section--mnemonic, .disease-deep-section--mnemonic) {
    background: linear-gradient(135deg, #342e1a, #292719);
}

html[data-theme="dark"] :where(.anatomy-flashcard, .disease-flashcard) {
    border-color: #3d6252;
    background: linear-gradient(145deg, #19271f, #20372c);
}

html[data-theme="dark"] :where(.anatomy-flashcard--flipped, .disease-flashcard--flipped) {
    border-color: #5b4d6b;
    background: linear-gradient(145deg, #24202a, #332a3e);
}

html[data-theme="dark"] :where(
    .anatomy-xp-summary__total,
    .disease-xp-summary__total
) {
    background: linear-gradient(135deg, #1d3329, #24382f);
}

html[data-theme="dark"] :where(.anatomy-difficulty-chip--intermediate, .disease-difficulty-chip--intermediate) {
    background: #483a15;
    color: #f2d26c;
}

html[data-theme="dark"] :where(.anatomy-difficulty-chip--advanced, .disease-difficulty-chip--advanced) {
    background: #48272c;
    color: #ffb4ba;
}

/* Clinical assessment keeps its teal tint. */
html[data-theme="dark"] .clinical-assessment-hero {
    border-color: #315f54;
    background:
        radial-gradient(circle at 94% 8%, rgba(119, 193, 181, 0.15), transparent 42%),
        linear-gradient(140deg, #17241f, #16372f);
}

html[data-theme="dark"] :where(
    .clinical-assessment-flow,
    .clinical-area-card,
    .clinical-assessment-note,
    .clinical-terms-xp,
    .term-mastery-summary article,
    .term-session-picker,
    .term-catalog,
    .term-filter-dialog,
    .term-detail-dialog,
    .term-practice-metrics span,
    .term-results-stats span
) {
    border-color: #355b51;
    background: rgba(26, 43, 36, 0.94);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .term-filter-dialog__header,
    .term-filter-dialog__footer,
    .term-catalog-card,
    .term-catalog-tools,
    .term-filter-option span
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .term-filter-open,
    .term-reset-button,
    .term-match-state button,
    .term-quick-picks button,
    .term-size-options button,
    .term-dialog-close,
    .term-detail-header button
) {
    border-color: var(--dark-border-strong);
    background: var(--dark-surface-soft);
    color: #a9dec7;
}

html[data-theme="dark"] :where(.term-quick-picks button[aria-pressed="true"], .term-size-options button.is-selected, .term-filter-option input:checked + span) {
    border-color: #68ae93;
    background: #254c3d;
    color: #d9f4e8;
}

html[data-theme="dark"] .term-match-state {
    background: #203b31;
    color: #c8e5d9;
}

html[data-theme="dark"] .term-match-state.is-empty {
    background: #42282a;
    color: #ffc1c3;
}

html[data-theme="dark"] :where(.term-filter-chip, .term-catalog-card i, .term-detail-tags i) {
    border-color: #497564;
    background: #25483c;
    color: #c3e5d7;
}

html[data-theme="dark"] .term-catalog-card:hover {
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] :where(
    .clinical-assessment-flow span,
    .clinical-assessment-flow i,
    .clinical-area-card__content > span:not(.clinical-area-card__tags, .open-label),
    .clinical-assessment-note
) {
    color: var(--dark-muted);
}

html[data-theme="dark"] .clinical-assessment-heading > span {
    background: #28483e;
    color: #c6e5d8;
}

html[data-theme="dark"] .clinical-area-card__content > small {
    color: #91c8b6;
}

html[data-theme="dark"][data-theme] .clinical-area-card__content > span:not(.clinical-area-card__tags, .open-label) {
    color: var(--dark-muted);
}

html[data-theme="dark"] .clinical-area-card__tags em {
    background: #2b4038;
    color: #c7d8d1;
}

html[data-theme="dark"] .clinical-area-card__icon {
    background: #29483d;
}

html[data-theme="dark"] .clinical-area-card--news2 .clinical-area-card__icon {
    background: #2b3042;
}

html[data-theme="dark"] .clinical-area-card--abcde .clinical-area-card__icon {
    background: #443023;
}

html[data-theme="dark"] .clinical-area-card--terms .clinical-area-card__icon {
    background: #372d48;
}

html[data-theme="dark"] .clinical-terms-hero {
    border-color: #315f54;
    background:
        radial-gradient(circle at 8% 0%, rgba(134, 205, 193, 0.14), transparent 35%),
        linear-gradient(135deg, #18251f, #17352d);
}

html[data-theme="dark"] :where(.clinical-terms-rewards span, .term-difficulty) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .term-catalog-row--head {
    background: #22372f;
}

html[data-theme="dark"] .term-question-card {
    border-color: #355b51;
    background:
        radial-gradient(circle at 100% 0%, rgba(104, 188, 169, 0.1), transparent 38%),
        var(--dark-surface-raised);
}

html[data-theme="dark"] :where(
    .term-question-meta span,
    .term-practice-metrics span
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: #c6d8d0;
}

html[data-theme="dark"] .anatomy-question-meta .anatomy-card-status {
    background: var(--dark-surface-soft);
    color: #c6d8d0;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-question-meta .anatomy-card-status--learning,
    .term-question-meta .term-card-status--learning
) {
    background: #483a15;
    color: #f2d26c;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-question-meta .anatomy-card-status--known,
    .term-question-meta .term-card-status--known
) {
    background: #1d3846;
    color: #9ed5ee;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-question-meta .anatomy-card-status--mastered,
    .term-question-meta .term-card-status--mastered
) {
    background: #1d3b2e;
    color: #99d8b9;
}

html[data-theme="dark"][data-theme] :where(
    .anatomy-question-meta .anatomy-card-status--difficult,
    .term-question-meta .term-card-status--difficult
) {
    background: #48272c;
    color: #ffb4ba;
}

html[data-theme="dark"] :where(
    .term-question-label,
    #term-answer-form label
) {
    color: #91d8b9;
}

html[data-theme="dark"] .term-question-instruction {
    color: var(--dark-muted);
}

html[data-theme="dark"] .term-report-question {
    color: #b7c8c0;
}

html[data-theme="dark"] .term-report-question:hover,
html[data-theme="dark"] .term-report-question:focus-visible {
    background: var(--dark-surface-soft);
    color: #91d8b9;
}

html[data-theme="dark"] .term-practice-progress > div:first-child {
    color: #b7c8c0;
}

html[data-theme="dark"] .term-practice-progress > div:last-child {
    background: #2b4037;
}

html[data-theme="dark"] :where(.term-question-card blockquote, .term-answer-row input) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: var(--dark-text);
}

html[data-theme="dark"] .term-question-card mark {
    background: #5a4817;
    color: #ffe58b;
}

html[data-theme="dark"] .term-answer-feedback__result {
    border: 1px solid #426b59;
    background: #1d392d;
    color: #e5f4ed;
}

html[data-theme="dark"] .term-question-card--retry .term-answer-feedback__result {
    border-color: #7c6835;
    background: #3b321c;
    color: #fff0b2;
}

html[data-theme="dark"] .term-question-card--revealed .term-answer-feedback__result {
    border-color: #875057;
    background: #42252a;
    color: #ffd4d7;
}

html[data-theme="dark"] .term-answer-feedback__result strong {
    color: inherit;
}

html[data-theme="dark"][data-theme] .term-answer-feedback__result p {
    color: #c0d1c9;
}

html[data-theme="dark"][data-theme] .term-question-card--retry .term-answer-feedback__result p {
    color: #e7d79e;
}

html[data-theme="dark"][data-theme] .term-question-card--revealed .term-answer-feedback__result p {
    color: #efb7bb;
}

html[data-theme="dark"] .term-answer-feedback__result b {
    color: #8cddb8;
}

html[data-theme="dark"] .term-question-card--revealed .term-answer-feedback__result b {
    color: #ffadb3;
}

html[data-theme="dark"] .term-answer-row input[aria-invalid="true"] {
    border-color: #b56b73;
    background: #2b1f22;
}

html[data-theme="dark"] .term-dont-know {
    color: #a9d9c5;
    text-decoration-color: #557b6c;
}

html[data-theme="dark"] .term-dont-know:hover,
html[data-theme="dark"] .term-dont-know:focus-visible {
    color: #d4f1e5;
}

html[data-theme="dark"] .term-learning-support {
    border-color: var(--dark-border);
    background: linear-gradient(145deg, #1d2d27, #18251f);
}

html[data-theme="dark"] .term-learning-section + .term-learning-section {
    border-color: var(--dark-border);
}

html[data-theme="dark"] .term-learning-section h3 {
    color: #8bd5b5;
}

html[data-theme="dark"][data-theme] :where(
    .term-learning-section p,
    .term-learning-section li
) {
    color: #c3d1cb;
}

html[data-theme="dark"] .term-word-parts span {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .term-word-parts b {
    color: #a6dfc6;
}

html[data-theme="dark"] .term-word-parts small {
    color: #b9c8c1;
}

html[data-theme="dark"] .term-learning-note {
    border-color: #b99545;
    background: #39311c;
}

html[data-theme="dark"] .term-learning-note strong {
    color: #f1cf75;
}

html[data-theme="dark"][data-theme] .term-learning-note p {
    color: #e0d2aa;
}

html[data-theme="dark"] .term-results-card {
    border-color: #355b51;
    background: linear-gradient(145deg, #192720, #1b382e);
}

/* ABCDE uses the shared clinical green with warm alert states. */
html[data-theme="dark"] :where(
    .abcde-hero,
    .abcde-progress-card,
    .abcde-activity-card,
    .abcde-case-context,
    .abcde-question-card,
    .abcde-xp-summary
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] .abcde-hero {
    border-color: #355c4d;
    background:
        radial-gradient(circle at 8% 10%, rgba(79, 155, 123, 0.12), transparent 32%),
        #182720;
}

html[data-theme="dark"] .abcde-activity-card--featured {
    border-color: #426b59;
    background: linear-gradient(135deg, #19261f, #1d362b);
}

html[data-theme="dark"] :where(
    .abcde-safety-note,
    .abcde-review-context,
    .abcde-sort-card,
    .abcde-order-slots span,
    .abcde-case-summary,
    .abcde-xp-summary__total
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] .abcde-mistake-callout {
    border-color: #705d32;
    background: #342e1c;
}

html[data-theme="dark"] .abcde-answer:not(:disabled):hover {
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] :where(.abcde-answer--wrong, .abcde-sort-target--wrong) {
    border-color: #874d53 !important;
    background: #42252a !important;
    color: #ffc1c5 !important;
}

html[data-theme="dark"] :where(.abcde-answer--correct, .abcde-sort-target--correct) {
    border-color: #579477 !important;
    background: #1d392d !important;
    color: #d5f2e3 !important;
}

html[data-theme="dark"] .abcde-feedback--correct {
    border-color: #579477;
    background: #1d392d;
    color: #d5f2e3;
}

html[data-theme="dark"] .abcde-feedback--wrong {
    border-color: #80643b;
    background: #392f1e;
    color: #efd397;
}

/* Medication calculation stays recognisably warm and yellow. */
html[data-theme="dark"] .medication-hero {
    border-color: #6d5e2b;
    background:
        radial-gradient(circle at 100% 0, rgba(235, 194, 66, 0.15), transparent 40%),
        linear-gradient(135deg, #252318, #393115);
}

html[data-theme="dark"] :where(
    .medication-hero__formula,
    .medication-progress-card,
    .medication-type-card,
    .medication-activity-card,
    .medication-calculator,
    .medication-question-card,
    .medication-drag-card,
    .medication-case-card,
    .medication-answer,
    .medication-drag-tile,
    .medication-sort-zone em,
    .medication-case-prompt,
    .medication-stepper li > span,
    .medication-identity-grid fieldset
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] .medication-progress-ring {
    background:
        radial-gradient(circle closest-side, var(--dark-surface-raised) 78%, transparent 80% 99%),
        conic-gradient(#79c9a8 var(--medication-progress), #34483f 0);
}

html[data-theme="dark"] :where(
    .medication-type-insights,
    .medication-activity-card--featured
) {
    border-color: #436454;
    background: linear-gradient(145deg, #19251f, #20352b);
}

html[data-theme="dark"] :where(
    .medication-safety-note,
    .medication-type-recommendation,
    .medication-calculator__keys button.is-tool,
    .medication-feedback--incomplete,
    .medication-learning-callout,
    .medication-hint,
    .medication-formula-vocabulary span
) {
    border-color: #705e31;
    background: #37301b;
    color: #eed48a;
}

html[data-theme="dark"] :where(
    .medication-category-grid article,
    .medication-calculator__body input,
    .medication-calculator__keys button,
    .medication-drop-zone,
    .medication-sort-zone,
    .medication-scenario,
    .medication-guided-worksheet,
    .medication-stage-form,
    .medication-exam-form,
    .medication-target-choice,
    .medication-solution-steps li
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .medication-answer--wrong,
    .medication-feedback--wrong,
    .medication-drop-zone--wrong,
    .medication-sort-zone em.is-wrong
) {
    border-color: #874d53;
    background: #42252a;
    color: #ffc1c5;
}

html[data-theme="dark"] :where(
    .medication-answer--correct,
    .medication-feedback--correct
) {
    border-color: #579477;
    background: #1d392d;
    color: #d5f2e3;
}

/* Profile. Avatar artwork keeps its original color palettes. */
html[data-theme="dark"] :where(
    .profile-hero,
    .profile-panel,
    .activity-level-card,
    .profile-summary-card,
    .profile-avatar-option
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
}

html[data-theme="dark"] .profile-hero {
    background:
        radial-gradient(circle at 95% 5%, rgba(111, 171, 143, 0.13), transparent 34%),
        var(--dark-surface-raised);
}

html[data-theme="dark"] :where(
    .feedback-admin-card,
    .feedback-admin-context,
    .profile-friend-card,
    .community-empty-state--compact,
    .profile-friend-search,
    .profile-friend-search-message,
    .profile-module-statistic
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: var(--dark-text);
}

html[data-theme="dark"] .profile-friend-card:hover,
html[data-theme="dark"] .profile-friend-card:focus-visible {
    border-color: #6eaa91;
    background: var(--dark-surface-hover);
    outline-color: rgba(121, 201, 168, 0.28);
}

html[data-theme="dark"] :where(
    .profile-friend-card strong,
    .profile-request-card strong,
    .profile-friend-search-result__profile strong
) {
    color: var(--dark-text);
}

html[data-theme="dark"] :where(
    .profile-friend-card small,
    .profile-request-card small,
    .profile-friend-search-result__profile small
) {
    color: #b5c5bd;
}

html[data-theme="dark"] .profile-friend-search-result__profile {
    color: var(--dark-text);
}

html[data-theme="dark"] .profile-friend-search-result__profile:hover strong,
html[data-theme="dark"] .profile-friend-search-result__profile:focus-visible strong {
    color: #91d8b9;
}

html[data-theme="dark"] :where(.profile-friend-search-result, .profile-friend-search input) {
    border-color: var(--dark-border);
    background: var(--dark-surface);
    color: var(--dark-text);
}

html[data-theme="dark"] .profile-request-section {
    border-color: #684148;
    background: #2b1f22;
}

html[data-theme="dark"] .profile-request-card {
    background: #37301e;
}

html[data-theme="dark"] :where(
    .feedback-admin-notice,
    .profile-sync-status--syncing,
    .profile-verification--pending
) {
    background: #3d341c;
    color: #f1d77f;
}

html[data-theme="dark"] :where(
    .profile-community-heading > .profile-community-heading__alert,
    .profile-friend-search-message--error,
    .profile-sync-status--error,
    .profile-sync-status--offline
) {
    background: #42252a;
    color: #ffc1c5;
}

html[data-theme="dark"] .profile-avatar-option--milestone {
    border-color: #8b7130;
    background: linear-gradient(145deg, #2c281b, #403617);
}

/* Primary navigation and top-level hubs. */
html[data-theme="dark"] #primary-navigation-root {
    border-color: var(--dark-border);
    background: rgba(18, 28, 24, 0.94);
    box-shadow: 0 5px 22px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .primary-navigation__brand {
    color: #dff2e9;
}

html[data-theme="dark"] .primary-navigation__tab {
    color: #aebdb6 !important;
}

html[data-theme="dark"] .primary-navigation__brand-mark {
    background: transparent;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2));
}

html[data-theme="dark"] .primary-navigation__tab:hover,
html[data-theme="dark"] .primary-navigation__tab:focus-visible {
    background: var(--dark-surface-soft);
    color: #b9e7d3 !important;
}

html[data-theme="dark"] .primary-navigation__tab--active {
    color: #87d3b3 !important;
}

html[data-theme="dark"] .primary-navigation__tab::after {
    background: #79c9a8;
}

html[data-theme="dark"] .primary-navigation__tab::before {
    background: #3b4541;
}

html[data-theme="dark"] .primary-navigation__actions .account-button,
html[data-theme="dark"] .primary-navigation__settings {
    border-color: var(--dark-border);
    background: var(--dark-surface-soft);
    color: #d9e7e1;
}

html[data-theme="dark"] .primary-navigation__settings:hover,
html[data-theme="dark"] .primary-navigation__settings:focus-visible {
    border-color: #56836f;
    background: #263c33;
    color: #9ee0c3;
}

html[data-theme="dark"] :where(
    .home-progress-preview,
    .home-progress-preview__grid > article,
    .hub-card,
    .games-coming-soon,
    .progress-summary-grid article,
    .mastery-card,
    .achievement-card
) {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
    color: var(--dark-text);
    box-shadow: 0 9px 26px rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"] :where(
    .home-progress-preview__grid > article,
    .hub-card--disabled,
    .achievement-card
) {
    background: var(--dark-surface-soft);
}

html[data-theme="dark"] :where(
    .home-progress-preview__icon,
    .topic-icon,
    .profile-module-statistic__icon
) {
    background: #f7fbf9;
}

html[data-theme="dark"] :where(
    .hub-card__body > strong + span,
    .hub-card__body > em,
    .hub-section__intro,
    .games-coming-soon p:last-child,
    .hub-page-header p:last-child,
    .mastery-card small,
    .progress-summary-grid article > small
) {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .hub-card__icon,
    .mastery-card__icon,
    .hub-section__heading > span
) {
    background: #263a31;
    color: #cce7db;
}

html[data-theme="dark"] :where(
    .hub-card__progress,
    .home-progress-preview__grid div[role="progressbar"],
    .mastery-card div[role="progressbar"]
) {
    background: #334a40;
}

html[data-theme="dark"] .hub-card:hover:not(:disabled),
html[data-theme="dark"] .hub-card:focus-visible:not(:disabled) {
    border-color: #679a84;
    background: var(--dark-surface-hover);
}

html[data-theme="dark"] .practice-smart-card {
    border-color: #4f7564;
    background:
        radial-gradient(circle at 92% 8%, rgba(255, 215, 106, 0.12), transparent 30%),
        linear-gradient(145deg, #182720, #213a2f);
}

html[data-theme="dark"] :where(
    .practice-smart-card__icon,
    .games-coming-soon__mascot
) {
    background: #f7fbf9;
}

html[data-theme="dark"] .practice-smart-card p:last-child {
    color: #bed0c7;
}

html[data-theme="dark"] .achievement-card--unlocked {
    border-color: #806c34;
    background: linear-gradient(145deg, #322d1d, #27261e);
    color: #f2e5b8;
}

html[data-theme="dark"] .module-avatar-achievements {
    border-color: var(--dark-border);
    background: var(--dark-surface-raised);
}

html[data-theme="dark"] .module-avatar-achievements__heading strong,
html[data-theme="dark"] .profile-avatar-group__heading strong {
    color: var(--dark-text);
}

html[data-theme="dark"] .module-avatar-achievements__heading small,
html[data-theme="dark"] .profile-avatar-group__heading small {
    color: var(--dark-muted);
}

html[data-theme="dark"] .profile-avatar-group + .profile-avatar-group {
    border-top-color: var(--dark-border);
}

html[data-theme="dark"] .module-avatar-unlock-toast {
    border-color: #806c34;
    background: linear-gradient(145deg, #322d1d, #24241e);
    color: #f2e5b8;
}

html[data-theme="dark"] .progress-level-overview {
    border-color: #4d8c72;
    background: linear-gradient(135deg, #173c2e, #285740 60%, #35684f);
}

/* Learning paths. */
html[data-theme="dark"] :where(
    .learning-path-catalog__intro,
    .learning-subject-hero,
    .learning-subject-card,
    .learning-topic-card,
    .learning-path-hero,
    .learning-path-step > button,
    .learning-lesson-hero,
    .learning-lesson-block,
    .learning-lesson-completion
) {
    border-color: #385769;
    background: var(--dark-surface-raised);
    color: var(--dark-text);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

html[data-theme="dark"] :where(
    .learning-path-catalog__intro,
    .learning-subject-hero,
    .learning-path-hero,
    .learning-lesson-hero
) {
    background:
        radial-gradient(circle at 90% 6%, rgba(244, 201, 79, 0.1), transparent 28%),
        linear-gradient(145deg, #17242b, #1a303b);
}

html[data-theme="dark"] :where(
    .learning-path-catalog__mascot,
    .learning-subject-card__icon,
    .learning-subject-hero__icon,
    .learning-path-hero__icon
) {
    background: #eef7fb;
}

html[data-theme="dark"] :where(
    .learning-path-catalog__intro p:last-child,
    .learning-subject-hero p:last-child,
    .learning-subject-card__body > strong + span,
    .learning-topic-card__body > strong + span,
    .learning-path-hero__heading p:last-child,
    .learning-path-module__heading p:last-child,
    .learning-path-step__body > strong + span,
    .learning-lesson-hero > p:not(.eyebrow),
    .learning-lesson-section p,
    .learning-lesson-block--understand > p,
    .learning-lesson-completion p:last-child
) {
    color: var(--dark-muted);
}

html[data-theme="dark"] :where(
    .learning-subject-card__progress,
    .learning-topic-card__progress,
    .learning-path-progress-summary__bar
) {
    background: #304a57;
}

html[data-theme="dark"] :where(
    .learning-path-header__badge,
    .learning-topic-section__heading > span,
    .learning-path-module__heading > span,
    .learning-lesson-meta span
) {
    background: #263f4c;
    color: #b9dbe9;
}

html[data-theme="dark"] .learning-path-legend {
    border-color: var(--dark-border);
    background: rgba(24, 37, 43, 0.85);
    color: var(--dark-muted);
}

html[data-theme="dark"] .learning-lesson-outcomes {
    border-color: #385769;
    background: rgba(18, 32, 39, 0.76);
}

html[data-theme="dark"] .learning-lesson-outcomes__heading > span,
html[data-theme="dark"] .learning-lesson-outcomes li {
    background: #263f4c;
}

html[data-theme="dark"] .learning-lesson-outcomes li span,
html[data-theme="dark"] .learning-lesson-outcomes > p {
    color: var(--dark-muted);
}

html[data-theme="dark"] .learning-lesson-illustration {
    border-color: #385769;
    background: #17242b;
}

html[data-theme="dark"] .learning-lesson-illustration figcaption,
html[data-theme="dark"] .learning-lesson-illustration figcaption small {
    color: var(--dark-muted);
}

html[data-theme="dark"] .learning-path-map::before {
    background: repeating-linear-gradient(to bottom, #456474 0 10px, transparent 10px 17px);
}

html[data-theme="dark"] .learning-path-step__marker {
    border-color: #57707c;
    background: #22333b;
    color: #bdccd2;
}

html[data-theme="dark"] .learning-status-chip {
    background: #2c3c43;
    color: #c0cdd2;
}

html[data-theme="dark"] .learning-path-step--started > button {
    border-color: #8c6e2e;
}

html[data-theme="dark"] .learning-path-step--started .learning-path-step__marker,
html[data-theme="dark"] .learning-status-chip--started {
    background: #4b3d1f;
    color: #f0d27c;
}

html[data-theme="dark"] .learning-path-step--completed > button {
    border-color: #497d66;
    background: #192d25;
}

html[data-theme="dark"] .learning-status-chip--completed {
    background: #244536;
    color: #9bd5b8;
}

html[data-theme="dark"] .learning-path-step--mastered > button {
    border-color: #6d5999;
    background: #272137;
}

html[data-theme="dark"] .learning-status-chip--mastered {
    background: #3a2e55;
    color: #c6b3ef;
}

html[data-theme="dark"] .learning-path-step--recommended > button {
    border-color: #a98128;
    box-shadow: 0 0 0 5px rgba(245, 204, 82, 0.1), 0 13px 30px rgba(0, 0, 0, 0.25);
}

html[data-theme="dark"] .learning-quiz-checkpoint {
    border-color: #8b6d2c;
    background: linear-gradient(145deg, #302a19, #3c3217);
    color: var(--dark-text);
}

html[data-theme="dark"] .learning-quiz-checkpoint--passed {
    border-color: #4b856b;
    background: linear-gradient(145deg, #192b24, #1e3a2d);
}

html[data-theme="dark"] :where(
    .learning-quiz-checkpoint__body > p:not(.eyebrow),
    .learning-quiz-checkpoint__body > small,
    .learning-quiz-checkpoint__score
) {
    color: #d4c79f;
}

html[data-theme="dark"] .learning-quiz-checkpoint__action {
    border-color: #987a36;
    background: #261f12;
    color: #efd078;
}

html[data-theme="dark"] .learning-quiz-checkpoint__action:hover {
    background: #3a3019;
}

html[data-theme="dark"] .learning-lesson-block--understand {
    border-color: #716032;
    background: #2d291d;
}

html[data-theme="dark"] .learning-term {
    border-color: #675b37;
    background: #211f18;
}

html[data-theme="dark"] .learning-term > button {
    color: #eed990;
}

html[data-theme="dark"] :where(
    .learning-term__definition p,
    .learning-term__definition small
) {
    color: #c9c0a4;
}

html[data-theme="dark"] .learning-self-check {
    border-color: #385361;
    background: #19272e;
}

html[data-theme="dark"] .learning-self-check > p:first-child {
    color: var(--dark-text);
}

html[data-theme="dark"] .learning-self-check__options button {
    border-color: #435d69;
    background: #202f36;
    color: #d8e6ec;
}

html[data-theme="dark"] .learning-self-check__options button:hover:not(:disabled) {
    border-color: #6092a8;
    background: #263d48;
}

html[data-theme="dark"] .learning-self-check__options .learning-self-check__option--correct {
    border-color: #4c8b6d;
    background: #1d3a2c;
    color: #a8dfc1;
}

html[data-theme="dark"] .learning-self-check__options .learning-self-check__option--wrong {
    border-color: #94555b;
    background: #412328;
    color: #ffc1c5;
}

html[data-theme="dark"] .learning-lesson-block--remember {
    border-color: #615180;
    background: #272133;
}

html[data-theme="dark"] .learning-lesson-block--remember ul {
    color: #d1c6e5;
}

html[data-theme="dark"] .learning-flashcard-note {
    background: #352c48;
    color: #c9bbe3;
}

html[data-theme="dark"] .learning-lesson-completion {
    border-color: #45765f;
    background: linear-gradient(145deg, #192b24, #1e382d);
}

html[data-theme="dark"] .learning-lesson-navigation button {
    border-color: #3d5b68;
    background: var(--dark-surface-raised);
    color: #9ed2e7;
}

@media (prefers-reduced-motion: reduce) {
    .setting-toggle,
    .setting-toggle::before {
        transition: none;
    }
}
