/* Final theme layer: keeps Bootstrap and page-specific hard-coded surfaces readable. */
:root { color-scheme: light; }

/* Global fallback for the trial notice. Keeping this in the final theme layer
   prevents a stale scoped-style bundle from expanding it into plain text. */
.premium-trial-banner {
    display: flex;
    align-items: center;
    gap: .75rem;
    width: min(70rem, calc(100% - 2rem));
    margin: .65rem auto 0;
    padding: .72rem .8rem;
    border: 1px solid #cfe2d8;
    border-radius: .9rem;
    background: linear-gradient(120deg, #f4faf7, #e8f3ed);
    color: #20352a;
    box-shadow: 0 8px 24px rgba(38, 82, 62, .08);
}
.premium-trial-icon { display:grid; place-items:center; flex:0 0 2.2rem; width:2.2rem; height:2.2rem; border-radius:.7rem; background:#315b47; color:#fff; }
.premium-trial-copy { min-width:0; flex:1; }
.premium-trial-title { display:flex; align-items:center; gap:.55rem; }
.premium-trial-title strong { font-size:.86rem; }
.premium-trial-title > span { padding:.16rem .48rem; border-radius:999px; background:#fff; color:#315b47; font-size:.68rem; font-weight:800; }
.premium-trial-copy small { display:block; margin-top:.24rem; color:#557063; font-size:.7rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.premium-trial-progress { height:3px; margin-top:.4rem; border-radius:999px; background:rgba(49,91,71,.14); overflow:hidden; }
.premium-trial-progress > span { display:block; height:100%; border-radius:inherit; background:#4a8167; }
.premium-trial-banner > a { display:inline-flex; align-items:center; gap:.4rem; padding:.58rem .72rem; border-radius:999px; background:#315b47; color:#fff; font-size:.78rem; font-weight:700; text-decoration:none; white-space:nowrap; }

body.dark-mode .premium-trial-banner {
    border-color: rgba(166, 205, 184, .25);
    background: #24342c;
    color: #f4f7f5;
}

body.dark-mode .premium-trial-copy small {
    color: #bfd0c7;
}
body.dark-mode .premium-trial-title > span { background:#354a40; color:#d9eee3; }
body.dark-mode .premium-trial-banner > a { background:#b7dbc9; color:#183328; }

@media (max-width: 640px) {
    .premium-trial-banner { width:calc(100% - 1rem); margin-top:.45rem; gap:.55rem; padding:.62rem; }
    .premium-trial-icon { flex-basis:2rem; width:2rem; height:2rem; }
    .premium-trial-banner > a { font-size:0; padding:.62rem; }
    .premium-trial-banner > a i { font-size:.9rem; }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bs-body-color: #eee9df;
    --bs-body-bg: #171816;
    --bs-secondary-color: #bdb5a8;
    --bs-secondary-bg: #292a27;
    --bs-tertiary-bg: #31322e;
    --bs-border-color: #4e4c46;
    --bs-heading-color: #f7f3eb;
    --bs-link-color: #b9cdfd;
    --bs-link-hover-color: #d7e2ff;
}

/* The current app pages use the Lexion design tokens extensively.  Override the
   tokens themselves so page-specific CSS cannot accidentally keep light ink or
   paper colours in dark mode. */
:root[data-theme="dark"] body.lx-world {
    --color-bg: #171816;
    --color-surface: #262724;
    --color-surface-muted: #30312d;
    --color-text: #f2eee6;
    --color-text-muted: #bdb5a8;
    --color-accent: #aebfa7;
    --color-accent-dark: #d7e2d1;
    --color-brass: #d5b983;
    --color-border: #504d46;
    --color-sidebar: #20211f;
    --color-paper: #262724;
    --color-book-green: #91a68d;
    --color-book-beige: #9f8c70;
    --color-book-gray: #817d76;
    --shadow-soft: 0 16px 36px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 8px 20px rgba(0, 0, 0, 0.26);
    --lx-ink-mid: #d7d0c5;
    --lx-green-soft: #344139;
    --lx-gold-soft: #443b2e;
    --lx-sidebar-fg: #ddd7cc;
    --lx-sidebar-active: #ffffff;
    --lx-sidebar-hover: #343632;
    --lx-line-soft: #45433e;
}

body.dark-mode {
    background: #171816 !important;
    color: #eee9df;
}

/* Override the legacy light-palette guard, whose selectors intentionally use high specificity. */
html body.lx-world.dark-mode,
html body.lx-world.dark-mode .page:not(.page--landing),
html body.lx-world.dark-mode .page:not(.page--landing) > main,
html body.lx-world.dark-mode .page:not(.page--landing) .content,
html body.lx-world.dark-mode .page:not(.page--landing) .container,
html body.lx-world.dark-mode .page:not(.page--landing) .container-fluid,
html body.lx-world.dark-mode .word-database,
html body.lx-world.dark-mode .vocab-review-page,
html body.lx-world.dark-mode .review-study-shell {
    background: #171816 !important;
    background-color: #171816 !important;
    color: #eee9df !important;
}

html body.lx-world.dark-mode :where(.card, .home-mobile-focus, .home-latest-card, .home-empty-card) {
    background: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .card,
html body.lx-world.dark-mode .page:not(.page--landing) .home-mobile-focus,
html body.lx-world.dark-mode .page:not(.page--landing) .home-latest-card,
html body.lx-world.dark-mode .page:not(.page--landing) .home-empty-card {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .card :where(h1, h2, h3, h4, h5, h6, strong, .display-6),
html body.lx-world.dark-mode .page:not(.page--landing) .home-mobile-focus h1,
html body.lx-world.dark-mode .page:not(.page--landing) .home-mobile-focus h2,
html body.lx-world.dark-mode .page:not(.page--landing) .home-latest-preview {
    color: #f7f3eb !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .home-latest-badge {
    background: #3a3b37 !important;
    color: #f0ece4 !important;
    border-color: #5c5a53 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .card :where(p, span, small, .text-muted),
html body.lx-world.dark-mode .page:not(.page--landing) .home-mobile-focus p {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode :where(.home-mobile-focus h1, .home-latest-card strong,
    .home-empty-card strong, .home-latest-preview, .display-6) {
    color: #f7f3eb !important;
}

html body.lx-world.dark-mode :where(.home-mobile-focus p, .home-empty-card span,
    .home-latest-card .text-muted, .home-mobile-kicker) {
    color: #c8c1b6 !important;
}

body.dark-mode .page,
body.dark-mode main,
body.dark-mode article.content {
    background-color: #171816 !important;
    color: #eee9df;
}

body.dark-mode .sidebar,
body.dark-mode .top-row,
body.dark-mode .lex-rail,
body.dark-mode .bottom-nav {
    background-color: #20211f !important;
    border-color: #45433e !important;
}

body.dark-mode :where(h1, h2, h3, h4, h5, h6, legend, label, strong, th) {
    color: #f7f3eb;
}

body.dark-mode :where(p, li, dd, dt, td, .form-label, .form-check-label) {
    border-color: #4e4c46;
}

body.dark-mode :where(.card, .list-group-item, .modal-content, .dropdown-menu, .offcanvas, .accordion-item) {
    background-color: #262724;
    color: #eee9df;
    border-color: #4e4c46 !important;
}

body.dark-mode :where(.card-body, .modal-body, .modal-header, .modal-footer, .accordion-body) {
    color: #eee9df;
    border-color: #4e4c46 !important;
}

body.dark-mode :where(.text-muted, .form-text, small) {
    color: #bdb5a8 !important;
}

/* AI usage is a scoped component, but the settings theme uses high-specificity
   paper colours. Keep every expanded surface and label readable in dark mode. */
html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator,
html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator summary {
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator summary {
    background: #30312d !important;
    background-color: #30312d !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator__details {
    background: #20211f !important;
    background-color: #20211f !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator :where(span, strong, i) {
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .ai-usage-indicator__details p {
    color: #c8c1b6 !important;
}

/* The header usage popover lives inside the white navigation in light mode.
   Keep its surfaces and text in the same palette instead of inheriting the
   component's dark-mode colours or the generic *-panel overrides. */
html body.lx-world:not(.dark-mode) .ai-usage-header__trigger {
    background: #ffffff !important;
    border-color: #c8ccd3 !important;
    color: #2e3238 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__trigger:hover,
html body.lx-world:not(.dark-mode) .ai-usage-header__trigger:focus-visible,
html body.lx-world:not(.dark-mode) .ai-usage-header__trigger[aria-expanded="true"] {
    background: #f1f3f6 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__trigger i {
    color: #556773 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__panel {
    background: #ffffff !important;
    background-color: #ffffff !important;
    border-color: #c8ccd3 !important;
    color: #2e3238 !important;
    box-shadow: 0 18px 46px rgba(30, 35, 42, .16) !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__panel header span {
    color: #556773 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__panel header strong,
html body.lx-world:not(.dark-mode) .ai-usage-header__meters strong,
html body.lx-world:not(.dark-mode) .ai-usage-header__upgrade-copy strong {
    color: #25282d !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__panel header button {
    background: #e8ebf0 !important;
    color: #34383f !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__meters > div {
    background: #eef0f3 !important;
    background-color: #eef0f3 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__meters span,
html body.lx-world:not(.dark-mode) .ai-usage-header__panel > p,
html body.lx-world:not(.dark-mode) .ai-usage-header__upgrade-copy span {
    color: #656b73 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__upgrade-copy {
    border-color: #c8ccd3 !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__cta {
    background: #30343a !important;
    color: #ffffff !important;
}

html body.lx-world:not(.dark-mode) .ai-usage-header__cta:hover,
html body.lx-world:not(.dark-mode) .ai-usage-header__cta:focus-visible {
    background: #1f2226 !important;
    color: #ffffff !important;
}

body.dark-mode :where(.form-control, .form-select, textarea, input:not([type="checkbox"]):not([type="radio"]), code) {
    background-color: #20211f;
    color: #f7f3eb;
    border-color: #5a5750;
}

body.dark-mode :where(.form-control, textarea, input)::placeholder {
    color: #aaa296;
    opacity: 1;
}

body.dark-mode :where(.table, .table > :not(caption) > * > *) {
    --bs-table-color: #eee9df;
    --bs-table-bg: #262724;
    --bs-table-border-color: #4e4c46;
    color: #eee9df;
    background-color: #262724;
    border-color: #4e4c46;
}

body.dark-mode :where(.border, .border-top, .border-end, .border-bottom, .border-start) {
    border-color: #4e4c46 !important;
}

body.dark-mode :where(.bg-white, .bg-light) {
    background-color: #262724 !important;
    color: #eee9df !important;
}

body.dark-mode :where(.btn-outline-secondary, .btn-outline-dark) {
    color: #e5dfd4;
    border-color: #777168;
}

body.dark-mode :where(.btn-outline-secondary, .btn-outline-dark):hover {
    background-color: #e5dfd4;
    color: #20211f;
}

body.dark-mode :where(.alert-info, .alert-secondary, .alert-light) {
    background-color: #28313a;
    color: #dcecff;
    border-color: #4e6275;
}

body.dark-mode :where(.badge.text-bg-light, .badge.bg-light) {
    background-color: #3a3a36 !important;
    color: #f2eee6 !important;
}

body.dark-mode hr {
    border-color: #5a5750;
    opacity: 1;
}

body.dark-mode :focus-visible { outline-color: #d4c5ff; }

body.dark-mode .theme-toggle {
    border-color: #56524b;
    background: rgba(38, 37, 34, 0.94);
    color: #f4f0e8;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
}

body.dark-mode .theme-toggle:hover,
body.dark-mode .theme-toggle:focus-visible {
    border-color: #cbbda8;
    color: #ffffff;
}

/* Diary's journal layout intentionally uses physical-paper colours in light
   mode.  These late, high-specificity declarations provide the equivalent
   dark notebook instead of mixing a white sheet with dark controls. */
body.dark-mode .diary-workspace {
    color: var(--color-text) !important;
}

body.dark-mode .diary-workspace .diary-writing-card {
    background:
        linear-gradient(90deg, rgba(221, 209, 188, 0.035) 1px, transparent 1px) 0 0 / 100% 100%,
        repeating-linear-gradient(to bottom, transparent 0 31px, rgba(184, 162, 122, 0.10) 32px),
        var(--color-surface) !important;
    border-color: var(--color-border) !important;
    box-shadow: 0 5px 0 #393731, 0 15px 34px rgba(0, 0, 0, 0.34) !important;
}

body.dark-mode .diary-workspace .diary-toolbar-pill,
body.dark-mode .diary-calendar-card,
body.dark-mode .diary-whisper-card,
body.dark-mode .diary-notes-panel,
body.dark-mode .diary-new-entry,
body.dark-mode .diary-add-vocab,
body.dark-mode .diary-note-actions button,
body.dark-mode .diary-vocab-bulk-actions button,
body.dark-mode .diary-learning-point,
body.dark-mode .diary-practice-brief,
body.dark-mode .diary-diff-heading button {
    background: var(--color-surface) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border) !important;
}

body.dark-mode .diary-history-entry.is-active,
body.dark-mode .diary-diff-box,
body.dark-mode .diary-revision-compare,
body.dark-mode .diary-expression-saver {
    background: var(--color-surface-muted) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border) !important;
}

body.dark-mode .diary-workspace :where(
    .diary-history-entry small,
    .diary-whisper-card p,
    .diary-suggestion-box span,
    .diary-learning-point small,
    .diary-learning-points-note,
    .diary-practice-brief > div:first-child span,
    .diary-phrase-option span,
    .diary-vocab-help,
    .diary-expression-saver-heading span) {
    color: var(--color-text-muted) !important;
}

body.dark-mode .diary-workspace :where(
    .diary-diff-heading h3,
    .diary-diff-row p,
    .diary-expression-saver-heading strong,
    .diary-suggestion-box strong) {
    color: var(--color-text) !important;
}

body.dark-mode .diary-workspace .diary-diff-token--removed {
    color: #ffc0ba;
    background: rgba(166, 68, 61, 0.28);
}

body.dark-mode .diary-workspace .diary-diff-token--added {
    color: #c7ebd0;
    background: rgba(72, 128, 86, 0.30);
}

/* Collection screens use the same high-contrast surfaces in dark mode. */
body.dark-mode .collection-shell {
    background: #171816;
    color: #eee9df;
}

body.dark-mode :where(.qs-shelf-card, .qs-month-card, .book-cover-reveal, .book-index, .diary-reader) {
    background: #353632;
    border-color: #56544e;
}

body.dark-mode :where(.book-index .paper-page, .diary-reader .paper-page, .selected-cover) {
    background: #252623;
    color: #f4f0e8;
    border-color: #56544e;
}

body.dark-mode :where(.qs-title, .qs-month-name, .month-overview h2, .month-index h3,
    .reader-meta-page h2, .reader-copy, .reader-facts dd, .entry-index span) {
    color: #f7f3eb;
}

body.dark-mode :where(.qs-sub, .qs-year-label, .qs-month-period, .qs-month-stat,
    .reader-month, .reader-weekday, .reader-facts dt, .entry-index small,
    .reader-correction-speech-note) {
    color: #c8c1b6;
}

body.dark-mode :where(.qs-book, .qs-book.is-empty) {
    background: #2d2e2a;
    color: #d6d0c6;
    border-color: #56544e;
}

body.dark-mode :where(.qs-book.is-current, .qs-book.is-previewed) {
    background: #334239;
    color: #f1f6f2;
    border-color: #8fa997;
}

body.dark-mode :where(.index-toolbar button, .reader-toolbar button, .reader-toolbar a,
    .page-navigation .page-navigation-index) {
    background: #292a27;
    color: #eee9df;
    border-color: #5e5b54;
}

body.dark-mode :where(.index-toolbar button.is-active, .book-calendar button.has-entry) {
    background: #8fa997;
    color: #121713;
    border-color: #8fa997;
}

body.dark-mode .entry-index button {
    color: #eee9df;
    border-color: #494a46;
}

body.dark-mode .entry-index button:hover { background: #30332f; }

body.dark-mode :where(.reader-rule, .reader-notes, .reader-vocabulary) {
    border-color: #54534e;
}

body.dark-mode :where(.page-label, .reader-notes summary, .reader-correction-heading > span) {
    color: #b8d0be;
}

body.dark-mode .reader-correction-speech { color: #b8d0be; }

/* Keep native controls and disabled text legible in either theme. */
body.dark-mode button:disabled,
body.dark-mode [aria-disabled="true"] {
    color: #aaa399;
}

body.dark-mode ::selection {
    background: #76917e;
    color: #0f1511;
}

/* App-wide contrast guard for legacy pages that still carry light-only text colors. */
html body.lx-world.dark-mode .page:not(.page--landing) :where(
    h1, h2, h3, h4, h5, h6, legend, strong, label, dt, dd, summary, th,
    .lx-page-title, .month-label, .qs-title, .qs-month-name,
    .audio-review-back, .audio-review-link, .ic-tab, .ic-session-title,
    .ic-session-count, .ic-session-progress-label, .pf-section-label,
    .pf-ring-text, .pf-radar-label, .pf-name, .pf-text-link,
    .review-plan, .ranking-col-rank, .ranking-col-name, .ranking-col-stat
) {
    color: #f3efe7 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    p, small, .text-muted, .form-text, .lx-page-kicker, .lx-page-sub,
    .qs-sub, .qs-month-period, .qs-month-stat, .character-count,
    .sp-nav-sub, .sp-mic-hint, .sp-hint-bubble, .ic-list-kicker
) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    [class*="card"], [class*="panel"], [class*="surface"],
    .calendar-cell, .database-table-shell, .database-list-row,
    .database-gallery-card, .review-study-shell
):not(.btn):not([class*="badge"]):not([class*="chip"]) {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

/* Named legacy surfaces are kept explicit because several older styles use !important. */
html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .review-today-card, .review-plan-grid article, .vocab-review-row,
    .review-study-card, .review-rating-dock, .quiz-complete-card,
    .database-toolbar, .database-table-shell, .database-board-column,
    .database-gallery-card, .database-list-row, .diary-writing-card,
    .journal-page, .calendar-shell, .pricing-card, .membership-card,
    .billing-shell, .pf-card, .pf-hero-banner, .pf-upgrade-banner,
    .growth-card, .growth-panel, .growth-window, .ranking-card,
    .ranking-table-card, .ranking-my-row-card, .ranking-share-card,
    .snap-result-card, .discovery-search, .starter-panel, .saved-groups,
    .discovery-result, .candidate-card, .source-group-card,
    .vocab-review-hero, .vocab-review-summary, .audio-review-card,
    .audio-review-mode, .ic-session-card, .sp-screen, .sp-modal,
    .sp-score-area, .sp-bottom, .release-card, .qs-month-card,
    .qs-shelf-card, .qs-book, .book-index, .diary-reader, .paper-page
) {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    table, thead, tbody, tr, th, td,
    .table, .table > :not(caption) > * > *
) {
    --bs-table-color: #eee9df;
    --bs-table-bg: #262724;
    --bs-table-border-color: #4e4c46;
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .qs-write-btn, .membership-action, .review-primary-button,
    .database-save-button, .btn-primary
) {
    background: #76917e !important;
    color: #101511 !important;
    border-color: #91aa98 !important;
}

/* Page-specific shells that predate the shared card component. */
html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .dashboard-simple, .diary-page, .audio-review-page, .discovery-page,
    .extract-page, .weekly-review, .weakness-profile, .billing-page,
    .release-notes-page, .tester-page, .tester-content
) {
    background: #171816 !important;
    background-color: #171816 !important;
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-content {
    background: #171816 !important;
    background-color: #171816 !important;
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-steps :where(h2, strong) {
    color: #f7f3eb !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-steps :where(small, span) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-steps li {
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-request {
    background: #20352b !important;
    color: #f3efe7 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-form-card input::placeholder {
    color: #aaa296 !important;
    opacity: 1 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .tester-check a {
    color: #b8d0be !important;
    text-decoration-color: #8fa997 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .release-note__link {
    background: #303a34 !important;
    color: #f3efe7 !important;
    border-color: #91aa9d !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .release-note__link :where(i, span) {
    color: #f3efe7 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .dashboard-overview, .dashboard-kpis article,
    .journal-left-page, .journal-right-page,
    .review-today-card, .review-plan-grid article,
    .audio-review-heading, .audio-mode-switch, .audio-mode-switch button,
    .audio-progress-header, .audio-review-stage,
    .discovery-hero, .extract-hero,
    .review-header, .review-start, .review-preview,
    .weakness-profile__header, .weakness-profile__summary,
    .alert-secondary, .release-notes-hero, .release-note
) {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .pf-level-name, .pf-level-sub, .pf-upgrade-title, .pf-upgrade-sub,
    .pf-radar-label, .qs-book-full, .qs-book-count,
    .ranking-username, .ranking-stat, .ranking-stat-unit,
    .membership-card li, .release-note li,
    .dashboard-kpis span, .sp-bottom-side-label
) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .audio-mode-switch button.is-active, .ic-session-mark
) {
    background: #76917e !important;
    color: #101511 !important;
    border-color: #91aa98 !important;
}

/* Final text accents whose original colors are below AA contrast on dark surfaces. */
html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .dashboard-overview a, .journal-writing-heading,
    .review-method-note, .extract-input, .weakness-profile__evidence,
    .sp-avatar-status, .price-tag, .pf-radar-wrap
) {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #f3efe7 !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .database-status-note, .audio-review-page > p,
    .review-header a, .review-header p, .review-header span,
    .weakness-profile p, .weakness-profile span,
    .ic-tab, .sp-avatar-status, .price-tag span,
    .release-notes-page time, .release-notes-page .release-notes-kicker
) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .audio-mode-switch button.is-active :where(strong, small, span) {
    color: #101511 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .growth-stage, .review-filter, .weakness-profile__list article header span,
    .faq-item, .faq-question
) {
    background: #262724 !important;
    background-color: #262724 !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .growth-stage strong, .review-filter span,
    .weakness-profile__list article header span,
    .pf-score-label, .settings-page li a,
    .billing-page .text-muted a, .faq-question,
    .journal-page-signature, .audio-review-page span
) {
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-filter.active {
    background: #76917e !important;
    color: #101511 !important;
    border-color: #91aa98 !important;
}

/* Review quiz: keep helper copy and rating states legible on the dark card/dock.
   These rules live in the global theme because selectors rooted at body.dark-mode
   do not cross Razor CSS-isolation boundaries. */
html body.lx-world.dark-mode .page:not(.page--landing) .review-study-shell :where(
    .flashcard-topline,
    .review-card-prompt > span,
    .review-card-pronunciation,
    .review-answer-divider,
    .quiz-complete-lead
) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-study-shell .review-card-tap {
    background: #30312d !important;
    color: #f3efe7 !important;
    border-color: #69675f !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-study-shell .review-card-tap:hover {
    background: #383a35 !important;
    border-color: #8d9188 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-rating-dock__header > p {
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-delete-button {
    color: #e0b9aa !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-delete-button:hover,
html body.lx-world.dark-mode .page:not(.page--landing) .review-delete-button:focus-visible {
    background: #40332e !important;
    color: #f3d2c4 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-rating-button--easy {
    background: #d6d3cc !important;
    color: #242522 !important;
    border-color: #e4e1da !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-rating-button--good {
    background: #3e3725 !important;
    color: #f0d99d !important;
    border-color: #837347 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-rating-button--hard {
    background: #392f2b !important;
    color: #edc4b2 !important;
    border-color: #7a6257 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .review-rating-button :where(span, small) {
    color: inherit !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .review-filter.active span,
html body.lx-world.dark-mode .page:not(.page--landing)
    .audio-mode-switch button.is-active :where(strong, small, span) {
    color: #101511 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .dashboard-simple a, .weakness-radar__label,
    .pf-account-key, .pf-account-val, .pf-score-val,
    .pf-footer-sub, .pricing-page .check-icon
) {
    color: #e4ddd2 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .database-count span, .audio-review-page p, .audio-review-page > div span,
    .source-tab span, .weakness-profile__header span,
    .release-notes-hero span
) {
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .weakness-profile__evidence :where(span, small) {
    background: #262724 !important;
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .source-tab,
html body.lx-world.dark-mode .page:not(.page--landing) .ic-tab.active {
    background: #30312d !important;
    color: #f3efe7 !important;
    border-color: #646159 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .audio-mode-switch button.is-active :where(strong, small, span) {
    color: #101511 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .ranking-me-badge, .ranking-medal, .home-latest-badge
) {
    background: #3a3b37 !important;
    color: #f3efe7 !important;
    border-color: #646159 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    input, textarea, select, .form-control, .form-select
) {
    background: #20211f !important;
    color: #f3efe7 !important;
    border-color: #625f57 !important;
}

html body.lx-world.dark-mode .release-alert {
    background: #292a27 !important;
    color: #f2eee6 !important;
    border-color: #56534c !important;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42) !important;
}

html body.lx-world.dark-mode .release-alert__icon {
    background: #d7e2d1 !important;
    color: #20211f !important;
}

html body.lx-world.dark-mode :where(.release-alert__eyebrow, .release-alert__body p) {
    color: #bdb5a8 !important;
}

html body.lx-world.dark-mode :where(
    .release-alert__body strong, .release-alert__link, .release-alert__close
) {
    color: #f2eee6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .diary-workspace, .diary-editor-wrapper, .diary-first-run-primary,
    .diary-sample-banner, .diary-toolbar-pill
) {
    background: #262724 !important;
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-editor-scan-area {
    color: #eee9df !important;
}

/* Keep the shared application chrome on one neutral dark palette.  These rules
   intentionally come last so component-scoped mobile styles cannot restore the
   old white header or blue-black bottom navigation. */
html body.lx-world.dark-mode .page:not(.page--landing) > .sidebar,
html body.lx-world.dark-mode .page:not(.page--landing) .top-row,
html body.lx-world.dark-mode .page:not(.page--landing) .lex-rail,
html body.lx-world.dark-mode .page:not(.page--landing) .bottom-nav {
    background: #20211f !important;
    background-color: #20211f !important;
    border-color: #45433e !important;
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .navbar-brand, .brand-wordmark, .navbar-toggler,
    .header-icon, .notification-button,
    .bottom-nav-item, .bottom-nav-hit, .bottom-nav-label,
    .bottom-nav-icon-shell
) {
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) :where(
    .nav-theme-toggle--header, .nav-theme-toggle--rail,
    .bottom-nav-icon-shell
) {
    background: transparent !important;
    background-color: transparent !important;
    border-color: #56534c !important;
    box-shadow: none !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .navbar-toggler {
    background-color: transparent !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23d8d1c6' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2.4' d='M5 8h20M5 15h20M5 22h20'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 1.4rem !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

html body.lx-world .page:not(.page--landing) .nav-more-toggle,
html body.lx-world.dark-mode .page:not(.page--landing) .nav-more-toggle {
    background: transparent !important;
    background-image: none !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .nav-more-toggle > i {
    color: #d8d1c6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .navbar-toggler:hover,
html body.lx-world.dark-mode .page:not(.page--landing) .navbar-toggler:focus-visible {
    background-color: #30312d !important;
}

html body.lx-world .page:not(.page--landing) .nav-scrollable .nav-theme-menu-button {
    background: #30312d !important;
    background-color: #30312d !important;
    border: 1px solid #56534c !important;
    color: #f7f3eb !important;
    box-shadow: none !important;
    opacity: 1 !important;
}

html body.lx-world .page:not(.page--landing) .nav-scrollable .nav-theme-menu-button > i,
html body.lx-world .page:not(.page--landing) .nav-scrollable .nav-theme-menu-button > span {
    color: #f7f3eb !important;
    opacity: 1 !important;
}

html body.lx-world .page:not(.page--landing) .nav-scrollable .nav-theme-menu-button:hover,
html body.lx-world .page:not(.page--landing) .nav-scrollable .nav-theme-menu-button:focus-visible {
    background: #3a3b36 !important;
    background-color: #3a3b36 !important;
    border-color: #77736a !important;
    color: #ffffff !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .bottom-nav-item.active :where(.bottom-nav-hit, .bottom-nav-icon-shell),
html body.lx-world.dark-mode .page:not(.page--landing)
    .bottom-nav-item--primary.active .bottom-nav-icon-shell--primary {
    background: #30312d !important;
    background-color: #30312d !important;
    color: #f7f3eb !important;
}

/* Colored icon tiles must keep their foreground contrast after legacy icon
   normalization runs. Apply the foreground to the glyph itself rather than
   relying only on inherited color. */
:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon, .feature-menu-card-icon,
    .review-plan-icon, .quiz-complete-icon,
    .release-alert__icon, .pf-upgrade-icon,
    .pro-upgrade-icon, .pfg-icon,
    .pt-signup-wall-icon, .pt-result-praise-icon,
    .pt-vocab-icon, .pt-nudge-icon
) > i {
    color: inherit !important;
    opacity: 1 !important;
    filter: none !important;
}

:root[data-theme="dark"] body.lx-world .review-plan-icon,
:root[data-theme="dark"] body.lx-world .quiz-complete-icon {
    background: #344139 !important;
    color: #b8d0be !important;
    border-color: #526158 !important;
}

:root[data-theme="dark"] body.lx-world .review-plan-icon.is-due {
    background: #4a402c !important;
    color: #f0cc82 !important;
    border-color: #6a5c3f !important;
}

:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon--coral, .feature-menu-card-icon--coral
) > i { color: #ffb3a7 !important; }

:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon--amber, .feature-menu-card-icon--amber
) > i { color: #f0cc82 !important; }

:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon--violet, .feature-menu-card-icon--violet
) > i { color: #d9c9ff !important; }

:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon--blue, .feature-menu-card-icon--blue
) > i { color: #b7d4fa !important; }

:root[data-theme="dark"] body.lx-world :where(
    .feature-menu-section-icon--green, .feature-menu-card-icon--green
) > i { color: #b8d0be !important; }

:root[data-theme="dark"] body.lx-world .feature-menu-card-icon--mint > i {
    color: #9bddcf !important;
}

:root[data-theme="dark"] body.lx-world .feature-menu-section-icon--neutral > i {
    color: #ddd6ca !important;
}

/* The diary editor has several legacy paper layers with !important light
   colours.  Treat every visible sheet as a dark surface and retain the ruled
   page with a low-contrast line instead of a white frame. */
html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .diary-writing-card,
html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .journal-left-page,
html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .diary-editor-wrapper,
html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .diary-editor-scan-area {
    background-color: #262724 !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .diary-writing-card {
    background: #262724 !important;
    box-shadow: 0 2px 18px rgba(0, 0, 0, 0.28) !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace .diary-editor-scan-area {
    background:
        repeating-linear-gradient(to bottom, transparent 0 35px, rgba(216, 209, 198, 0.10) 36px),
        #262724 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .diary-workspace :where(
    .diary-editor-textarea, .journal-page-kicker, .journal-writing-heading,
    .journal-writing-heading > span, .journal-left-page time strong,
    .journal-left-page h3, .journal-left-page time span,
    .journal-metadata dt, .journal-metadata dd,
    .journal-words-collected span, .journal-words-collected strong,
    .journal-page-signature
) {
    color: #eee9df !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-editor-textarea::placeholder {
    color: #aaa296 !important;
    opacity: 1 !important;
}

/* AI correction results still contain late light-only component rules. Keep
   every result card and its text on the same readable dark palette. */
html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel .diary-diff-box,
html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel .diary-learning-point,
html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel .diary-phrase-option {
    background: #2d2e2a !important;
    background-color: #2d2e2a !important;
    color: #eee9df !important;
    border-color: #56544e !important;
    box-shadow: none !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel .diary-phrase-option.is-selected {
    background: #334239 !important;
    background-color: #334239 !important;
    border-color: #8fa997 !important;
    box-shadow: inset 0 0 0 1px rgba(143, 169, 151, 0.2) !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel :where(
        .diary-diff-row p,
        .diary-learning-point p,
        .diary-learning-point strong,
        .diary-phrase-option strong
    ) {
    color: #f3efe7 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel :where(
        .diary-diff-label,
        .diary-learning-point small,
        .diary-learning-points-note,
        .diary-phrase-option span,
        .diary-vocab-help
    ) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel .diary-learning-point > span {
    background: #3a3b37 !important;
    color: #eee9df !important;
    border-color: #646159 !important;
}

/* Billing is CSS-isolated; keep its dark palette in the global theme layer so
   the body theme selector is never rewritten with a component scope. */
html body.lx-world.dark-mode .billing-page {
    color: var(--color-text) !important;
}

html body.lx-world.dark-mode .billing-page :where(.current-plan-badge, .plan-comparison) {
    background: var(--color-surface) !important;
    color: var(--color-text) !important;
    border-color: var(--color-border) !important;
    box-shadow: none !important;
}

html body.lx-world.dark-mode .billing-page :where(.billing-header, .plan-comparison__heading, .plan-table th, .plan-table td) {
    border-color: var(--color-border) !important;
}

html body.lx-world.dark-mode .billing-page .plan-table thead th {
    background: #292a27 !important;
}

html body.lx-world.dark-mode .billing-page .plan-table .is-recommended {
    background: #2d342e !important;
}

html body.lx-world.dark-mode .billing-page :where(h1, h2, .plan-name, .plan-table thead strong, .current-plan-badge strong) {
    color: #f7f3eb !important;
}

html body.lx-world.dark-mode .billing-page :where(.billing-header p, .plan-comparison__heading p, .current-plan-badge span, .plan-table tbody th, .plan-table td, .plan-current-text) {
    color: #d2cbc0 !important;
}

html body.lx-world.dark-mode .billing-page .plan-select-button.is-secondary {
    background: #30312d !important;
    color: #f2eee6 !important;
    border-color: #646159 !important;
}

/* These are layout containers, not progress tracks or indicator dots.
   Neutralize the legacy substring rules so the surrounding theme shows through. */
html body.lx-world .collection-shell :where(.qs-shelf-track, .qs-year-dots) {
    background: transparent !important;
    background-color: transparent !important;
}

/* Vocabulary board: keep status accents without leaving pale columns or
   near-black cards that make headings and supporting text hard to scan. */
html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-column {
    --board-accent: #c8c1b6;
    --board-pill: #3a3b37;
    --board-surface: #262724;
    --board-item: #30312d;
    background: var(--board-surface) !important;
    color: #eee9df !important;
    border-color: #4e4c46 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-column.is-due {
    --board-accent: #9dc9f3;
    --board-pill: #293b4d;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-column.is-reviewed {
    --board-accent: #9dd8b8;
    --board-pill: #2d4438;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-column > header h2 {
    background: var(--board-pill) !important;
    color: #f7f3eb !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-column > header .word-board-count {
    color: var(--board-accent) !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item {
    background: var(--board-item) !important;
    color: #eee9df !important;
    border-color: #55534d !important;
    box-shadow: none !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item:hover {
    border-color: var(--board-accent) !important;
    background: #353632 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item :where(strong, p) {
    color: #f3efe7 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item :where(small, footer) {
    color: #c8c1b6 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database :where(.word-board-empty, .database-count) {
    color: #bdb5a8 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item :where(.category-tag, .status-badge),
html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item .word-item-actions > button {
    background: #3a3b37 !important;
    color: #f2eee6 !important;
    border-color: #646159 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing) .word-database .word-board-item .word-item-actions > .word-delete-button {
    color: #ffc2ba !important;
    border-color: #8e5f59 !important;
}

html body.lx-world.dark-mode .page:not(.page--landing)
    .diary-workspace .diary-notes-panel :where(
        .diary-diff-heading button,
        .diary-note-actions button,
        .diary-vocab-bulk-actions button
    ) {
    background: #30312d !important;
    background-color: #30312d !important;
    color: #f3efe7 !important;
    border-color: #646159 !important;
}
