/*
 * My English Memory — single stylesheet, no build step.
 *
 * Every colour is a semantic token defined twice: the light set below and the
 * dark set further down. The dark values are duplicated for the explicit
 * `data-theme="dark"` case and the `system` case (media query) because the two
 * cannot share one selector. Keep the two dark blocks in sync.
 */

:root {
    color-scheme: light;

    --paper: #f6f7f3;
    --surface: #ffffff;
    --surface-sunk: #f9fbf7;
    --sidebar: #edf1e9;
    --sidebar-line: #dfe5dc;
    --mobile-nav: rgba(255, 255, 255, .97);

    --ink: #20302a;
    --ink-soft: #4d5c53;
    --muted: #78827b;
    --muted-soft: #909a92;
    --nav-ink: #5d6b62;
    --nav-hover: rgba(255, 255, 255, .65);

    --line: #e3e8df;
    --line-strong: #e0e7dc;
    --control-line: #d5ded2;
    --track: #e9eee7;

    --accent: #4B94D8;
    --accent-strong: #27669f;
    --accent-text: #2f6da8;
    --accent-soft: #e6f1fa;
    --accent-wash: #f1f6fb;

    --success: #3f7f66;
    --warning: #a8791f;
    --danger: #b4523a;
    --danger-soft: #f7e8e1;
    --danger-ink: #8a3b28;

    --focus: #9ec6e4;
    --shadow: 0 24px 70px rgba(24, 43, 34, .14);
    --overlay: rgba(18, 30, 24, .48);
    --toast-bg: #27669f;
    --toast-ink: #ffffff;

    --heat-empty: #e9eee7;
    --heat-1: #cfe2f2;
    --heat-2: #a5c9e7;
    --heat-3: #6ea9db;
    --heat-4: #3f7fbf;

    --pattern-a: rgba(220, 234, 191, .22);
    --pattern-b: rgba(229, 239, 226, .4);
    --panel-bg: rgba(255, 255, 255, .96);

    font-family: "Cairo", "Almarai", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

/* Dark tokens for visitors whose system prefers dark and who have not forced light. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --paper: #121914;
        --surface: #1f2822;
        --surface-sunk: #18201b;
        --sidebar: #18201b;
        --sidebar-line: #2b352e;
        --mobile-nav: rgba(24, 32, 27, .97);
        --ink: #e5eae1;
        --ink-soft: #c3ccc2;
        --muted: #abb4ab;
        --muted-soft: #8b968d;
        --nav-ink: #a9b3a9;
        --nav-hover: rgba(255, 255, 255, .07);
        --line: #333d35;
        --line-strong: #39433b;
        --control-line: #44504a;
        --track: #2b352e;
        --accent: #4B94D8;
        --accent-strong: #86beea;
        --accent-text: #8cc4ee;
        --accent-soft: #1c2b36;
        --accent-wash: #1b2429;
        --success: #74bd9c;
        --warning: #d8ae5e;
        --danger: #e59179;
        --danger-soft: #33221f;
        --danger-ink: #f0a897;
        --focus: #4B94D8;
        --shadow: 0 24px 70px rgba(0, 0, 0, .5);
        --overlay: rgba(3, 6, 4, .66);
        --toast-bg: #24455f;
        --toast-ink: #eaf2f8;
        --heat-empty: #232c26;
        --heat-1: #1f3a4f;
        --heat-2: #2a5b80;
        --heat-3: #3d84bf;
        --heat-4: #7db8e6;
        --pattern-a: rgba(75, 148, 216, .07);
        --pattern-b: rgba(75, 148, 216, .04);
        --panel-bg: rgba(31, 40, 34, .96);
    }
}

/* Dark tokens for an explicit choice, regardless of the system setting. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #121914;
    --surface: #1f2822;
    --surface-sunk: #18201b;
    --sidebar: #18201b;
    --sidebar-line: #2b352e;
    --mobile-nav: rgba(24, 32, 27, .97);
    --ink: #e5eae1;
    --ink-soft: #c3ccc2;
    --muted: #abb4ab;
    --muted-soft: #8b968d;
    --nav-ink: #a9b3a9;
    --nav-hover: rgba(255, 255, 255, .07);
    --line: #333d35;
    --line-strong: #39433b;
    --control-line: #44504a;
    --track: #2b352e;
    --accent: #4B94D8;
    --accent-strong: #86beea;
    --accent-text: #8cc4ee;
    --accent-soft: #1c2b36;
    --accent-wash: #1b2429;
    --success: #74bd9c;
    --warning: #d8ae5e;
    --danger: #e59179;
    --danger-soft: #33221f;
    --danger-ink: #f0a897;
    --focus: #4B94D8;
    --shadow: 0 24px 70px rgba(0, 0, 0, .5);
    --overlay: rgba(3, 6, 4, .66);
    --toast-bg: #24455f;
    --toast-ink: #eaf2f8;
    --heat-empty: #232c26;
    --heat-1: #1f3a4f;
    --heat-2: #2a5b80;
    --heat-3: #3d84bf;
    --heat-4: #7db8e6;
    --pattern-a: rgba(75, 148, 216, .07);
    --pattern-b: rgba(75, 148, 216, .04);
    --panel-bg: rgba(31, 40, 34, .96);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Shell ---------- */

.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; min-height: 100vh; padding: 32px 22px 24px; background: var(--sidebar); border-right: 1px solid var(--sidebar-line); }
.wordmark { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font-size: 15px; font-weight: 700; line-height: 1.15; }
.wordmark-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px 12px 12px 4px; background: var(--accent); color: #fff; font-family: Georgia, serif; font-size: 22px; font-weight: 400; }
.sidebar-label, .account-label, .eyebrow { margin: 0; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 1.2px; }
.sidebar-label { margin: 54px 0 12px 12px; }
.main-nav { display: grid; gap: 6px; }
.nav-link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 13px; border: 0; border-radius: 7px; color: var(--nav-ink); background: transparent; text-align: left; cursor: pointer; transition: background .18s ease, color .18s ease; }
.nav-link:hover { background: var(--nav-hover); color: var(--ink); }
.nav-link.is-active { color: #fff; background: var(--accent); }
.nav-icon { display: block; flex: 0 0 20px; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-label { line-height: 1; }
.sidebar-bottom { margin-top: auto; padding: 18px 10px 0; border-top: 1px solid var(--sidebar-line); }
.account-email { margin: 8px 0 12px; overflow: hidden; color: var(--ink-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.text-button { padding: 0; border: 0; color: var(--accent-text); background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }
.text-button:hover { text-decoration: underline; }

/* Appearance segmented control */
.appearance { margin: 0 0 18px; padding-bottom: 16px; border-bottom: 1px solid var(--sidebar-line); }
.appearance-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 1.2px; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 2px; border: 1px solid var(--sidebar-line); border-radius: 5px; background: var(--surface-sunk); }
.segment { min-height: 28px; padding: 0 4px; border: 0; border-radius: 3px; color: var(--nav-ink); background: transparent; font-size: 11px; font-weight: 700; cursor: pointer; }
.segment:hover { color: var(--ink); }
.segment[aria-pressed="true"] { color: var(--accent-text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

.main-content { width: min(100%, 1320px); margin: 0 auto; padding: 50px clamp(24px, 5vw, 72px) 72px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 42px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.page-heading h1, .auth-panel h1 { margin: 8px 0 0; font-family: "Cairo", sans-serif; font-size: 36px; font-weight: 700; line-height: 1.15; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; padding: 0 17px; border: 1px solid transparent; border-radius: 5px; font-size: 13px; font-weight: 700; text-decoration: none; cursor: pointer; transition: transform .16s ease, background .16s ease, border-color .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { border-color: var(--control-line); color: var(--accent-text); background: transparent; }
.button-secondary:hover { border-color: var(--accent); background: var(--accent-wash); }
.button-quiet { border-color: transparent; color: var(--muted); background: transparent; }

/* ---------- Dashboard ---------- */

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat-block { display: grid; align-content: start; min-height: 158px; padding: 22px 24px 18px 0; }
.stat-block + .stat-block { padding-left: 24px; border-left: 1px solid var(--line); }
.stat-label { color: var(--ink-soft); font-size: 12px; }
.stat-block strong { margin-top: 14px; color: var(--accent-text); font-family: "Cairo", sans-serif; font-size: 38px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-new strong { color: var(--warning); }
.stat-due strong { color: var(--danger); }
.stat-known strong { color: var(--success); }
.stat-retention strong { color: var(--danger); }
.stat-streak strong { color: var(--warning); }
.stat-note { margin-top: 10px; color: var(--muted); font-size: 11px; }
.dashboard-bottom { max-width: 760px; margin-top: 74px; padding: 28px 0 0; border-top: 3px solid var(--track); }
.deck-section { max-width: 900px; margin-top: 54px; }
.deck-section .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.deck-list { border-top: 1px solid var(--line); }
.deck-row { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(100px, 180px) auto; align-items: center; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.deck-row-details h3 { margin: 0; font-size: 14px; font-weight: 700; }
.deck-row-details p { margin: 5px 0 0; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.deck-meter { width: 100%; height: 7px; overflow: hidden; appearance: none; border: 0; border-radius: 4px; background: var(--track); }
.deck-meter::-webkit-progress-bar { border-radius: 4px; background: var(--track); }
.deck-meter::-webkit-progress-value { border-radius: 4px; background: var(--success); transition: width .25s ease; }
.deck-meter::-moz-progress-bar { border-radius: 4px; background: var(--success); }
.section-heading h2 { margin: 8px 0 0; font-family: "Cairo", sans-serif; font-size: 26px; font-weight: 700; }
.section-copy { max-width: 540px; margin: 14px 0 22px; color: var(--ink-soft); font-size: 14px; line-height: 1.65; }
.action-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Card management ---------- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: -16px 0 22px; }
.import-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.import-deck-label { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; color: var(--ink-soft); font-size: 12px; }
.import-deck-label select { min-height: 36px; padding: 0 28px 0 9px; border: 1px solid var(--control-line); border-radius: 4px; color: var(--ink); background: var(--surface); }
.deck-filter-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.deck-filter-label select, .card-dialog select { min-height: 40px; padding: 0 30px 0 10px; border: 1px solid var(--control-line); border-radius: 4px; color: var(--ink); background: var(--surface); }
.search-field { display: flex; align-items: center; gap: 10px; width: min(100%, 390px); min-height: 42px; padding: 0 12px; border: 1px solid var(--control-line); border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 19px; }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }
.search-field input:focus-visible { outline: 0; }
.import-button { position: relative; overflow: hidden; }
.import-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
.cards-table { width: 100%; border-collapse: collapse; text-align: left; }
.cards-table th { padding: 14px 12px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; }
.cards-table td { padding: 15px 12px; border-top: 1px solid var(--line); vertical-align: middle; font-size: 13px; }
.cards-table td:first-child { min-width: 210px; font-weight: 700; }
.cards-table td:nth-child(2) { min-width: 170px; color: var(--ink-soft); }
.table-empty { padding: 38px 12px !important; color: var(--muted); text-align: center; }
.row-actions { display: flex; justify-content: end; gap: 7px; white-space: nowrap; }
.row-action { padding: 6px 8px; border: 1px solid transparent; border-radius: 4px; color: var(--ink-soft); background: transparent; font-size: 11px; cursor: pointer; }
.row-action:hover { border-color: var(--line); background: var(--surface); }
.row-action-danger { color: var(--danger); }
.progress-count { color: var(--accent-text); font-size: 12px; font-weight: 700; white-space: nowrap; }
.review-date { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- Review ---------- */

.review-view { min-height: 75vh; }
.review-heading { margin-bottom: 20px; }
.review-scope { margin: 8px 0 0; color: var(--accent-text); font-size: 11px; font-weight: 700; }
.review-stage { max-width: 820px; min-height: 520px; margin: 0 auto; padding: 28px clamp(18px, 5vw, 64px) 48px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: 0 18px 55px rgba(48, 69, 49, .06); }
.review-progress { display: flex; align-items: center; justify-content: space-between; gap: 20px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .9px; }
.progress-track { width: 130px; height: 4px; overflow: hidden; border-radius: 3px; background: var(--track); }
.progress-track span { display: block; width: 8%; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
.review-card { max-width: 620px; margin: 72px auto 0; text-align: center; animation: rise-in .3s ease both; }
.review-hint { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.review-english { min-height: 84px; margin: 0; display: grid; place-items: center; color: var(--ink); font-family: "Cairo", "Almarai", sans-serif; font-size: 36px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.speaker-button { margin: 18px auto 0; padding: 8px 12px; border: 0; color: var(--accent-text); background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }
.speaker-button span { margin-right: 6px; font-size: 15px; }
.speaker-button kbd { display: inline-block; padding: 1px 4px; margin-left: 4px; font-size: 10px; font-family: inherit; border: 1px solid var(--control-line); border-radius: 3px; background: var(--surface-card); color: var(--muted); }

/* Typing test mode */
.typing-container { max-width: 440px; margin: 24px auto 0; text-align: center; }
.type-answer-input { width: 100%; box-sizing: border-box; padding: 12px 16px; border: 2px solid var(--control-line); border-radius: 8px; font-size: 18px; text-align: center; color: var(--ink); background: var(--surface); transition: border-color .2s ease, box-shadow .2s ease; outline: none; }
.type-answer-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.spelling-comparison { margin-top: 14px; font-size: 18px; font-family: Consolas, monospace; letter-spacing: 1px; display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 2px; padding: 8px 14px; border-radius: 6px; background: var(--surface-card); }
.diff-char { display: inline-block; padding: 2px 4px; border-radius: 3px; }
.diff-char.correct { color: #16a34a; background: rgba(34, 197, 94, 0.12); font-weight: 600; }
.diff-char.wrong { color: #dc2626; background: rgba(239, 68, 68, 0.15); text-decoration: line-through; }
.diff-char.missing { color: #d97706; background: rgba(245, 158, 11, 0.15); font-weight: 600; }
.diff-char.expected { color: #2563eb; background: rgba(37, 99, 235, 0.12); font-weight: bold; margin-left: 6px; }

.translation-area { margin-top: 24px; animation: rise-in .24s ease both; }
.translation-rule { width: 56px; height: 2px; margin: 0 auto 20px; background: var(--accent); opacity: .45; }
.review-arabic { margin: 0; color: var(--accent-text); font-family: "Almarai", "Cairo", sans-serif; font-size: 29px; font-weight: 700; line-height: 1.6; overflow-wrap: anywhere; }
.review-notes { margin: 13px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.reveal-button { display: flex; min-width: 190px; margin: 34px auto 0; }
.review-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-top: 30px; animation: rise-in .24s ease both; }
.rating-button { display: grid; gap: 5px; min-height: 60px; padding: 9px 5px; border: 1px solid var(--control-line); border-radius: 5px; color: var(--ink); background: var(--surface); cursor: pointer; }
.rating-button:hover { border-color: var(--accent); background: var(--accent-wash); }
.rating-button strong { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; }
.rating-button span { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.rating-button kbd { display: inline-grid; place-items: center; width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--surface-sunk); font-size: 10px; }
.rating-again strong { color: var(--danger); }
.rating-hard strong { color: var(--warning); }
.rating-good strong { color: var(--success); }
.rating-easy strong { color: var(--accent-text); }
.keyboard-hint { margin: 15px 0 0; color: var(--muted-soft); font-size: 10px; text-align: center; }
.example-sentence { margin: 18px 0 0; color: var(--ink-soft); font-family: Georgia, "Times New Roman", serif; font-size: 16px; font-style: italic; line-height: 1.55; }
.empty-review { max-width: 460px; margin: 90px auto 0; text-align: center; animation: rise-in .3s ease both; }
.empty-mark { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 50%; color: var(--accent-text); background: var(--accent-soft); font-size: 22px; }
.empty-review h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: 400; }
.empty-review p { margin: 10px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- Statistics ---------- */

.record { margin-top: 34px; padding-top: 20px; border-top: 1px solid var(--line); }
.record:first-of-type { margin-top: 0; }
.record-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.record-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 22px; font-weight: 400; }
.record-figures { display: flex; flex-wrap: wrap; gap: 16px; margin: 0; color: var(--muted); font-size: 11px; }
.record-figures strong { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Activity matrix */
.heatmap-scroll { overflow-x: auto; padding-bottom: 8px; }
.heatmap { display: inline-block; min-width: 100%; }
.heatmap-months { display: flex; gap: 3px; padding-left: 34px; margin-bottom: 6px; color: var(--muted); font-size: 10px; }
.heatmap-months span { overflow: hidden; white-space: nowrap; }
.heatmap-body { display: flex; gap: 6px; }
.heat-day-labels { display: grid; grid-template-rows: repeat(7, 14px); gap: 3px; width: 28px; color: var(--muted); font-size: 9px; line-height: 14px; text-align: right; }
.heat-weeks { display: flex; gap: 3px; }
.heat-week { display: grid; grid-template-rows: repeat(7, 14px); gap: 3px; }
.heat-cell { width: 14px; height: 14px; padding: 0; border: 0; border-radius: 3px; background: var(--heat-empty); }
.heat-cell[data-level="1"] { background: var(--heat-1); }
.heat-cell[data-level="2"] { background: var(--heat-2); }
.heat-cell[data-level="3"] { background: var(--heat-3); }
.heat-cell[data-level="4"] { background: var(--heat-4); }
button.heat-cell { cursor: pointer; }
button.heat-cell[data-level="0"] { background: var(--heat-empty); }
button.heat-cell:hover { box-shadow: 0 0 0 1px var(--accent); }
button.heat-cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
button.heat-cell.is-selected { box-shadow: 0 0 0 2px var(--ink); }
.heat-cell.is-empty { background: transparent; }
.heatmap-foot { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-top: 14px; }
.day-detail { margin: 0; color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.heat-legend { display: flex; align-items: center; gap: 10px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 10px; }
.heat-legend li { display: flex; align-items: center; gap: 5px; }
.heat-legend .heat-cell { width: 11px; height: 11px; border-radius: 2px; }

/* Charts */
.chart-row { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 34px; align-items: start; }
.bar-chart { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); align-items: stretch; gap: 6px; height: 190px; padding: 10px 0 6px; border-bottom: 1px solid var(--line); }
.bar-column { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; }
.bar-column:hover .bar-fill, .bar-column:focus-visible .bar-fill { background: var(--accent-strong); }
.bar-fill { width: 100%; max-width: 34px; border-radius: 2px 2px 0 0; background: var(--accent); transition: background .16s ease; }
.bar-fill.is-zero { background: var(--track); }
.bar-value { color: var(--ink-soft); font-size: 10px; font-variant-numeric: tabular-nums; }
.bar-label { color: var(--muted); font-size: 10px; white-space: nowrap; }

.rating-distribution { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.rating-row { display: grid; grid-template-columns: 46px minmax(0, 1fr) 40px; align-items: center; gap: 10px; }
.rating-row .rating-name { color: var(--ink-soft); font-size: 12px; }
.rating-bar { height: 8px; border-radius: 3px; background: var(--track); overflow: hidden; }
.rating-bar span { display: block; height: 100%; width: 0; border-radius: 3px; transition: width .25s ease; }
.rating-row[data-rating="1"] .rating-bar span { background: var(--danger); }
.rating-row[data-rating="3"] .rating-bar span { background: var(--warning); }
.rating-row[data-rating="4"] .rating-bar span { background: var(--success); }
.rating-row[data-rating="5"] .rating-bar span { background: var(--accent); }
.rating-row .rating-count { color: var(--ink); font-size: 12px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

/* Deck comparison table */
.stats-table { width: 100%; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
.stats-table th { padding: 10px 12px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; }
.stats-table th:not(:first-child), .stats-table td:not(:first-child) { text-align: right; }
.stats-table td { padding: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.stats-table td:first-child { font-weight: 700; }
.stats-table tbody tr[data-deck-id] { cursor: pointer; }
.stats-table tbody tr[data-deck-id]:hover td { background: var(--accent-wash); }
.stats-table .recall-none { color: var(--muted-soft); }
.stats-table .due-positive { color: var(--danger); font-weight: 700; }

/* ---------- Dialogs ---------- */

.card-dialog { width: min(560px, calc(100vw - 28px)); max-height: min(90vh, 760px); padding: 0; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.card-dialog::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
.card-dialog form { display: grid; gap: 17px; padding: 26px; }
.import-dialog-content { padding: 26px; }
.import-summary { margin: 14px 0; color: var(--ink-soft); font-size: 13px; }
.import-preview-wrap { max-height: 340px; overflow: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.import-preview-table { width: 100%; border-collapse: collapse; text-align: left; }
.import-preview-table th { position: sticky; top: 0; padding: 10px 8px; color: var(--muted); background: var(--surface-sunk); font-size: 10px; text-transform: uppercase; }
.import-preview-table td { max-width: 180px; padding: 10px 8px; overflow-wrap: anywhere; border-top: 1px solid var(--line); font-size: 11px; }
.import-preview-table td:last-child { color: var(--accent-text); }
.import-dialog .dialog-actions { margin-top: 18px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.dialog-heading h2 { margin: 7px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 27px; font-weight: 400; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: var(--surface); font-size: 21px; cursor: pointer; }
.card-dialog label, .auth-form label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.card-dialog input, .card-dialog textarea, .auth-form input { width: 100%; padding: 11px 12px; border: 1px solid var(--control-line); border-radius: 4px; color: var(--ink); background: var(--surface-sunk); font-size: 14px; font-weight: 400; resize: vertical; }
.optional-label { display: inline; color: var(--muted); font-size: 11px; font-weight: 400; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 2px; }
.form-error { margin: 0; color: var(--danger-ink); font-size: 12px; }
.dialog-copy { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.limit-facts { display: grid; gap: 8px; margin: 0; padding: 14px 0 0; border-top: 1px solid var(--line); }
.limit-facts div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.limit-facts dt { color: var(--muted); font-size: 12px; }
.limit-facts dd { margin: 0; color: var(--ink); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(380px, calc(100vw - 32px)); padding: 13px 17px; border-radius: 5px; color: var(--toast-ink); background: var(--toast-bg); box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

/* ---------- Auth ---------- */

.auth-page { display: grid; place-items: center; padding: 28px 16px; background-color: var(--paper); background-image: linear-gradient(135deg, var(--pattern-a) 25%, transparent 25%), linear-gradient(315deg, var(--pattern-b) 25%, transparent 25%); background-size: 44px 44px; }
.auth-panel { width: min(100%, 460px); padding: 38px clamp(24px, 6vw, 48px) 42px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-bg); box-shadow: var(--shadow); animation: rise-in .3s ease both; }
.auth-panel .wordmark { margin-bottom: 48px; }
.auth-panel .eyebrow { color: var(--danger); }
.auth-panel h1 { margin: 9px 0 10px; font-size: 34px; }
.auth-copy { margin: 0 0 22px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
.auth-form { display: grid; gap: 16px; }
.auth-form .button { width: 100%; margin-top: 4px; }
.auth-footnote { margin: 20px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.auth-footnote a { color: var(--accent-text); font-weight: 700; }
.notice { margin: 16px 0; padding: 11px 13px; border-left: 3px solid var(--danger); color: var(--danger-ink); background: var(--danger-soft); font-size: 12px; line-height: 1.5; }

@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 200px minmax(0, 1fr); }
    .sidebar { padding-right: 16px; padding-left: 16px; }
    .main-content { padding-right: 28px; padding-left: 28px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-block:nth-child(3) { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
    .stat-block:nth-child(4) { border-top: 1px solid var(--line); }
    .chart-row { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 640px) {
    .app-shell { display: flex; flex-direction: column; }
    .sidebar { position: sticky; top: 0; z-index: 10; flex-direction: row; align-items: center; gap: 12px; min-height: auto; padding: 12px 14px; border-right: 0; border-bottom: 1px solid var(--sidebar-line); background: var(--sidebar); }
    .sidebar .wordmark-mark { width: 32px; height: 32px; font-size: 19px; }
    .sidebar .wordmark-text { display: none; }
    .sidebar-label, .account { display: none; }
    .sidebar-bottom { display: flex; align-items: center; margin: 0 0 0 auto; padding: 0; border: 0; }
    .appearance { margin: 0; padding: 0; border: 0; }
    .appearance-label { display: none; }
    .segmented { grid-auto-flow: column; }
    .segment { min-width: 48px; min-height: 30px; font-size: 10px; }
    .main-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--sidebar-line); background: var(--mobile-nav); box-shadow: 0 -8px 24px rgba(18, 30, 24, .08); backdrop-filter: blur(14px); }
    .nav-link { display: flex; flex-direction: column; justify-content: center; gap: 5px; min-height: 52px; padding: 5px 6px; border-radius: 6px; color: var(--muted); font-size: 10px; }
    .nav-link.is-active { color: var(--accent-text); background: transparent; }
    .nav-icon { flex-basis: 21px; width: 21px; height: 21px; }
    .nav-link.is-active .nav-icon { stroke-width: 2.2; }
    .main-content { padding: 29px 18px calc(84px + env(safe-area-inset-bottom)); }
    .page-heading { align-items: start; flex-direction: column; gap: 17px; margin-bottom: 30px; }
    .heading-actions { width: 100%; }
    .heading-actions .button { flex: 1; }
    .page-heading h1 { font-size: 31px; }
    .page-heading > .button { width: 100%; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-block { min-height: 132px; padding: 18px 10px 15px 0; }
    .stat-block + .stat-block { padding-left: 14px; }
    .stat-block:nth-child(3) { padding-left: 0; }
    .stat-block strong { font-size: 36px; }
    .stat-label { font-size: 11px; }
    .stat-note { font-size: 10px; }
    .dashboard-bottom { margin-top: 48px; }
    .toolbar { align-items: stretch; flex-direction: column; margin-top: -6px; }
    .deck-filter-label { justify-content: space-between; }
    .deck-filter-label select { flex: 1; }
    .search-field { width: 100%; }
    .import-button { justify-content: center; width: 100%; }
    .cards-table { min-width: 650px; }
    .review-heading { align-items: center; flex-direction: row; }
    .review-heading .button { width: auto; min-height: 38px; padding: 0 9px; font-size: 11px; }
    .review-heading h1 { font-size: 28px; }
    .review-stage { min-height: 470px; padding: 20px 16px 34px; }
    .review-card { margin-top: 62px; }
    .review-english { min-height: 100px; font-size: 30px; }
    .review-arabic { font-size: 24px; }
    .review-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rating-button { min-height: 56px; }
    .deck-row { grid-template-columns: 1fr auto; gap: 10px; }
    .deck-meter { grid-column: 1; grid-row: 2; }
    .deck-row > .row-action { grid-column: 2; grid-row: 1 / span 2; }
    .auth-panel { padding-top: 30px; }
    .auth-panel .wordmark { margin-bottom: 38px; }
    .toast { right: 16px; bottom: 16px; }
    .record { margin-top: 26px; padding-top: 16px; }
    .record-heading { gap: 10px; margin-bottom: 14px; }
    .record-heading h2 { font-size: 20px; }
    .record-figures { gap: 12px; font-size: 10px; }
    .bar-chart { height: 150px; gap: 3px; }
    .bar-fill { max-width: 18px; }
    .bar-label { font-size: 9px; }
    .stats-table { min-width: 520px; }
    .stats-table th:first-child, .stats-table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--paper); }
    .heatmap-months { padding-left: 30px; }
    .heat-day-labels { width: 24px; }
    .heatmap-foot { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
