        :root {
            --bg: #0f0f0f;
            --bg-card: #1a1a1a;
            --bg-card-hover: #222;
            --accent: #3b82f6;
            --accent-dim: #2563eb;
            --accent-glow: rgba(59, 130, 246, 0.15);
            --green: #4ade80;
            --orange: #fb923c;
            --red: #f87171;
            --text: #eee;
            --text-dim: #888;
            --text-mid: #bbb;
            --border: #333;
            --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            --radius: 16px;
            --radius-sm: 10px;
        }

        * { margin: 0; padding: 0; box-sizing: border-box; }

        body {
            font-family: var(--sans);
            background: var(--bg);
            color: var(--text);
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* Grain texture overlay */
        body::before {
            content: '';
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            opacity: 0.01;
            background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
            pointer-events: none;
            z-index: 9999;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 24px 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* Header */
        .header {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 16px 0 8px;
            position: relative;
        }
        .header h1 {
            font-size: 1.75rem;
            color: var(--text);
            letter-spacing: 0;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 10px;
            font-weight: 700;
            font-family: "Libre Baskerville", Georgia, "Times New Roman", serif;
        }
        .header-logo {
            height: 44px;
            width: auto;
        }
        .lang-indicator {
            font-size: 0.75rem;
            font-family: var(--sans); /* the UI font, not the title's serif */
            color: var(--text-dim);
            background: var(--bg-card);
            padding: 2px 8px;
            border-radius: 4px;
            border: 1px solid #333;
            cursor: pointer;
            transition: color 0.15s, border-color 0.15s, background 0.15s;
            user-select: none;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }
        .lang-indicator-caret {
            width: 10px;
            height: 10px;
            flex-shrink: 0;
        }
        .lang-indicator:hover {
            color: var(--accent);
            border-color: var(--accent-dim);
            background: var(--bg-card-hover);
        }

        /* Settings */
        .settings-btn {
            position: absolute;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: var(--text-dim);
            cursor: pointer;
            padding: 8px;
            border-radius: 8px;
            transition: color 0.2s, background 0.2s;
            line-height: 1;
        }
        .settings-btn:hover {
            color: var(--text);
            background: var(--bg-card);
        }
        .settings-btn svg {
            width: 20px;
            height: 20px;
            display: block;
        }
        .settings-menu {
            display: none;
            position: absolute;
            right: 0;
            top: calc(100% + 4px);
            background: var(--bg-card);
            border: 1px solid #333;
            border-radius: var(--radius-sm);
            min-width: 180px;
            z-index: 100;
            box-shadow: 0 8px 24px rgba(0,0,0,0.4);
            overflow: hidden;
        }
        .settings-menu.open { display: block; }
        .settings-item {
            display: block;
            width: 100%;
            padding: 12px 16px;
            border: none;
            background: none;
            color: var(--text-mid);
            font-family: var(--sans);
            font-size: 0.9rem;
            text-align: left;
            cursor: pointer;
            transition: background 0.15s, color 0.15s;
        }
        .settings-item:hover {
            background: var(--bg-card-hover);
            color: var(--text);
        }
        .settings-item.danger { color: var(--red); }
        .settings-item.danger:hover { background: rgba(248,113,113,0.1); }
        .settings-toggle {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            width: 100%;
            padding: 12px 16px;
            border: none;
            background: none;
            color: var(--text-mid);
            font-family: var(--sans);
            font-size: 0.9rem;
            cursor: pointer;
            transition: background 0.15s, color 0.15s;
        }
        .settings-toggle:hover {
            background: var(--bg-card-hover);
            color: var(--text);
        }
        .theme-value {
            font-size: 0.8rem;
            color: var(--text-mid);
            font-family: var(--sans);
        }
        .toggle-switch {
            width: 36px;
            height: 20px;
            background: #444;
            border-radius: 10px;
            position: relative;
            transition: background 0.2s;
            flex-shrink: 0;
        }
        .toggle-switch.on { background: var(--accent); }
        .toggle-switch::after {
            content: '';
            position: absolute;
            width: 16px;
            height: 16px;
            background: #fff;
            border-radius: 50%;
            top: 2px;
            left: 2px;
            transition: transform 0.2s;
        }
        .toggle-switch.on::after { transform: translateX(16px); }

        /* Modal */
        .modal-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.6);
            z-index: 200;
            align-items: center;
            justify-content: center;
        }
        .modal-overlay.open {
            display: flex;
        }
        .modal.modal-chat {
            width: min(900px, 96vw);
            max-width: min(900px, 96vw);
            height: min(720px, 92vh);
            max-height: 92vh;
            display: flex;
            flex-direction: column;
            padding: 0;
            overflow: hidden;
            text-align: left;
            position: relative;
        }
        /* On phones the chat fills the whole screen. With
           interactive-widget=resizes-content the fixed overlay is resized by the
           browser when the keyboard opens, so no JS height tracking is needed. */
        @media (max-width: 640px) {
            #ai-help-modal.modal-overlay {
                padding: 0;
                align-items: stretch;
            }
            #ai-help-modal .modal.modal-chat {
                width: 100%;
                max-width: 100%;
                height: 100%;
                max-height: 100%;
                border: none;
                border-radius: 0;
            }
        }
        .ai-chat-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 14px 18px;
            border-bottom: 1px solid var(--border);
        }
        .ai-chat-header h3 { margin: 0; font-size: 1.1rem; }
        .ai-chat-header-actions { display: flex; align-items: center; gap: 8px; }
        .ai-chat-reset {
            background: none;
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-dim);
            font-size: 0.8rem;
            padding: 4px 10px;
            cursor: pointer;
            transition: all 0.15s;
        }
        .ai-chat-reset:hover { color: var(--text); border-color: var(--accent); }
        .ai-chat-header .modal-close {
            position: static;
            top: auto;
            right: auto;
            flex-shrink: 0;
        }
        /* The sentence card stays pinned above the chat so the learner can
           refer back to what the sentence contains; the translation appears
           once it has been revealed (the question answered — blank questions
           show it upfront). */
        .ai-help-context {
            flex-shrink: 0;
            padding: 10px 18px 12px;
            border-bottom: 1px solid var(--border);
            text-align: center;
        }
        .ai-help-context[hidden] { display: none; }
        .ai-help-context .target-sentence {
            font-size: calc(1.1rem * var(--text-scale, 1));
            line-height: 1.6;
        }
        .ai-help-context .eng-translation {
            margin-bottom: 0;
            padding-right: 0;
        }
        .ai-chat-messages {
            flex: 1 1 auto;
            overflow-y: auto;
            padding: 14px 18px;
            display: flex;
            flex-direction: column;
            gap: 10px;
            min-height: 0;
            box-sizing: border-box;
            overscroll-behavior: contain;
        }
        .ai-chat-msg {
            max-width: 85%;
            padding: 9px 13px;
            border-radius: 12px;
            font-size: 0.92rem;
            line-height: 1.45;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .ai-chat-msg.user {
            align-self: flex-end;
            background: var(--accent);
            color: #fff;
            border-bottom-right-radius: 4px;
        }
        .ai-chat-msg.bot {
            align-self: flex-start;
            background: var(--input-bg);
            border: 1px solid var(--border);
            border-bottom-left-radius: 4px;
        }
        .ai-chat-msg code {
            background: rgba(128, 128, 128, 0.15);
            padding: 1px 5px;
            border-radius: 5px;
            font-size: 0.85em;
            font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        }
        .ai-chat-msg a {
            color: var(--accent);
            text-decoration: underline;
        }
        .ai-chat-msg.bot.typing::after {
            content: '▍';
            animation: blink 1s infinite;
        }
        @keyframes blink { 50% { opacity: 0; } }
        .ai-chat-input-row {
            display: flex;
            gap: 8px;
            padding: 12px 18px;
            border-top: 1px solid var(--border);
            flex-shrink: 0;
            box-sizing: border-box;
        }
        .ai-chat-input-row input {
            flex: 1;
            min-width: 0;
            padding: 9px 12px;
            border-radius: 10px;
            border: 1px solid var(--border);
            background: var(--input-bg);
            color: var(--text);
            font-size: 0.92rem;
            outline: none;
            box-sizing: border-box;
        }
        .ai-chat-input-row input:focus { border-color: var(--accent); }
        .ai-chat-input-row .btn {
            flex-shrink: 0;
            white-space: nowrap;
        }

        .modal {
            background: var(--bg-card);
            border: 1px solid #333;
            border-radius: var(--radius);
            padding: 28px 24px;
            max-width: 360px;
            width: 90%;
            text-align: center;
        }
        .modal.modal-wide {
            max-width: 520px;
            text-align: left;
            max-height: 85vh;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            padding: 0;
        }
        /* WELCOME — first-lesson card. Pinned to the light palette so the
           landing page door art blends into the card with no borders,
           whatever theme the app itself is in. */
        .welcome-modal {
            max-width: 400px;
            padding: 0;
            overflow: hidden;
            background: #fbfcfd;
            border-color: #dfe6ec;
            color: #1c2733;
        }
        .welcome-modal .welcome-art {
            display: block;
            width: 100%;
            /* Crop the top tenth of the art (percent margins are relative
               to the card width; the PNG is 1122x1402, so its top tenth is
               12.5% of width). The card clips the overflow. */
            margin: -12.5% 0 0;
            border-radius: 0;
            /* The art's blank base fades into the card instead of ending
               in a hard edge; the text block sits on the faded zone. */
            -webkit-mask-image: linear-gradient(to bottom,
                black 74%, transparent 97%);
            mask-image: linear-gradient(to bottom,
                black 74%, transparent 97%);
            /* The art overlaps the text block; it must not eat clicks or
               selection drags, and Ctrl+A must skip it. */
            -webkit-user-select: none;
            user-select: none;
            pointer-events: none;
        }
        .welcome-modal .welcome-body {
            /* The art's bottom fifth is nearly blank — the text sits on
               it instead of below it, keeping the card compact. */
            margin-top: -21%;
            padding: 16px 26px 26px;
        }
        .welcome-modal .welcome-body h2 {
            font-size: 1.3rem;
            margin: 0 0 10px;
            color: #101820;
        }
        .welcome-modal .welcome-body p {
            color: #3d5063;
            line-height: 1.55;
            margin-bottom: 14px;
        }
        .welcome-modal .welcome-body .welcome-note {
            font-size: 0.8rem;
            color: #7d8b98;
            margin-bottom: 0;
        }
        .welcome-modal .welcome-body a {
            color: var(--accent);
        }
        .welcome-modal .btn {
            width: 100%;
            margin-top: 18px;
        }
        /* Theme pin: the welcome card keeps its light palette and drops the
           aero glass effect — the door art only blends on a solid light
           card. ID-level specificity beats every [data-theme] .modal rule
           regardless of rule order. */
        #welcome-modal .welcome-modal,
        #about-modal .welcome-modal {
            background: #fbfcfd;
            border-color: #dfe6ec;
        }
        [data-theme="aero"] #welcome-modal .welcome-modal,
        [data-theme="aero"] #about-modal .welcome-modal {
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
        }

        .modal h3 {
            font-size: 1.1rem;
            margin-bottom: 8px;
        }
        .modal p {
            font-size: 0.9rem;
            color: var(--text-dim);
            margin-bottom: 20px;
            line-height: 1.5;
        }
        .modal-close {
            position: absolute;
            top: 20px;
            right: 20px;
            background: none;
            border: none;
            color: var(--text-dim);
            font-size: 1.5rem;
            cursor: pointer;
            padding: 4px 8px;
            line-height: 1;
            z-index: 1;
        }
        .modal-close:hover { color: var(--text); }
        .dict-topbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 14px 18px;
            border-bottom: 1px solid var(--border);
        }
        .dict-topbar h3 { margin: 0; font-size: 1.1rem; }
        .dict-topbar .modal-close {
            position: static;
            top: auto;
            right: auto;
            flex-shrink: 0;
            margin-left: 12px;
            padding: 4px 8px;
        }
        .account-modal-body {
            padding: 16px 18px 20px;
            flex: 1 1 auto;
            min-height: 0;
            overflow-y: auto;
            overscroll-behavior: contain;
        }
        /* A long device list scrolls in its own box so the actions above and
           the "Log in" link below stay reachable. */
        .account-loading {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            padding: 30px 0;
            color: var(--text-mid);
            font-size: 0.9rem;
        }
        .account-spinner {
            width: 16px;
            height: 16px;
            border: 2px solid var(--border);
            border-top-color: var(--accent);
            border-radius: 50%;
            animation: account-spin 0.8s linear infinite;
        }
        @keyframes account-spin { to { transform: rotate(360deg); } }
        .account-modal-body p {
            color: var(--text-mid);
            font-size: 0.9rem;
            margin: 0 0 8px 0;
            text-align: left;
        }
        .account-consent-row {
            display: flex;
            align-items: flex-start;
            gap: 10px;
            font-size: 0.85rem;
            color: var(--text-mid);
            margin: 12px 0;
            text-align: left;
            cursor: pointer;
        }
        .account-consent-row input[type="checkbox"] {
            appearance: none;
            -webkit-appearance: none;
            width: 20px;
            height: 20px;
            border: 2px solid #555;
            border-radius: 4px;
            background: var(--bg-card);
            cursor: pointer;
            flex-shrink: 0;
            margin-top: 1px;
            position: relative;
            transition: all 0.15s;
        }
        .account-consent-row input[type="checkbox"]:hover { border-color: var(--text-dim); }
        .account-consent-row input[type="checkbox"]:checked {
            background: var(--accent);
            border-color: var(--accent);
        }
        .account-consent-row input[type="checkbox"]:checked::after {
            content: '';
            position: absolute;
            left: 5px;
            top: 1px;
            width: 6px;
            height: 10px;
            border: solid #fff;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }
        .account-consent-row label { cursor: pointer; }
        .account-code-box {
            font-family: monospace;
            font-size: 1.1rem;
            text-align: center;
            letter-spacing: 0.1em;
            padding: 14px;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            word-break: break-all;
        }
        .account-login-row {
            display: flex;
            gap: 8px;
            margin-top: 8px;
        }
        .account-login-row input {
            flex: 1;
            padding: 10px 12px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg);
            color: var(--text);
            font-family: monospace;
            font-size: 0.95rem;
            outline: none;
            min-width: 0;
        }
        .account-login-row input:focus { border-color: var(--accent-dim); }
        .account-error { color: #e5534b; font-size: 0.85rem; margin-top: 8px; text-align: left; }
        .account-success { color: var(--green); font-size: 0.85rem; margin-top: 8px; text-align: left; font-weight: 600; }
        .account-toast {
            position: fixed;
            top: 16px;
            left: 50%;
            transform: translateX(-50%) translateY(-120%);
            background: var(--bg-card);
            color: var(--text);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 11px 18px;
            font-size: 0.9rem;
            max-width: 92vw;
            text-align: center;
            z-index: 300;
            box-shadow: 0 10px 28px rgba(0,0,0,0.35);
            opacity: 0;
            transition: opacity 0.25s, transform 0.25s;
            pointer-events: none;
        }
        .account-toast.show {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
        .account-toast.toast-error { border-color: #e5534b; color: #e5534b; }
        .account-back-btn {
            display: block;
            margin-top: 16px;
            padding: 0;
            background: none;
            border: none;
            color: var(--text-mid);
            font-family: var(--sans);
            font-size: 0.9rem;
            cursor: pointer;
            opacity: 0.7;
            transition: opacity 0.2s;
        }
        .account-back-btn:hover { opacity: 1; color: var(--text); }
        #account-modal .dict-topbar { flex-shrink: 0; gap: 10px; }
        #account-modal .dict-topbar h3 { flex: 1; }
        .account-topbar-back { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; }
        .account-topbar-back[hidden] { display: none; }
        .account-topbar-back svg { width: 18px; height: 18px; flex-shrink: 0; }
        .account-status-line {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 14px;
            border-radius: var(--radius-sm);
            font-size: 0.9rem;
            font-weight: 600;
            margin-bottom: 4px;
        }
        .account-status-line .status-icon { font-size: 1rem; flex-shrink: 0; }
        .account-sync-line {
            font-size: 0.78rem;
            color: var(--text-dim);
            padding: 2px 14px 0;
        }
        .status-line-cancel {
            flex-shrink: 0;
            display: flex;
            align-items: center;
            background: none;
            border: none;
            color: inherit;
            opacity: 0.7;
            cursor: pointer;
            padding: 2px;
            transition: opacity 0.15s;
        }
        .status-line-cancel:hover { opacity: 1; }
        .account-status-line .status-icon svg { display: block; width: 1em; height: 1em; }
        .account-status-line.unprotected {
            background: rgba(251, 146, 60, 0.1);
            color: var(--orange);
            border: 1px solid rgba(251, 146, 60, 0.25);
        }
        .account-status-line.backed-up {
            background: rgba(74, 222, 128, 0.08);
            color: var(--green);
            border: 1px solid rgba(74, 222, 128, 0.2);
        }
        .account-status-line.pending {
            background: rgba(251, 146, 60, 0.08);
            color: var(--orange);
            border: 1px solid rgba(251, 146, 60, 0.2);
        }
        .account-text-link {
            background: none;
            border: none;
            color: var(--text-mid);
            font-family: var(--sans);
            font-size: 0.85rem;
            cursor: pointer;
            padding: 6px 0;
            opacity: 0.7;
            transition: opacity 0.15s;
            text-decoration: underline;
            text-underline-offset: 2px;
        }
        .account-text-link:hover { opacity: 1; color: var(--text); }
        .backup-prompt {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 14px;
            margin: 8px 0;
            background: rgba(251, 146, 60, 0.08);
            border: 1px solid rgba(251, 146, 60, 0.2);
            border-radius: var(--radius-sm);
            font-size: 0.85rem;
            color: var(--text-mid);
        }
        .backup-prompt span { flex: 1; }
        .backup-prompt .btn-sm { padding: 6px 14px; font-size: 0.8rem; flex-shrink: 0; }
        .backup-prompt-dismiss {
            background: none;
            border: none;
            color: var(--text-dim);
            font-size: 1.1rem;
            cursor: pointer;
            padding: 0 4px;
            line-height: 1;
            flex-shrink: 0;
        }
        .backup-prompt-dismiss:hover { color: var(--text); }
        .account-id-heading {
            margin: 0 0 10px;
            font-size: 1rem;
            text-align: left;
            color: var(--text);
        }
        .account-field-label {
            display: block;
            font-size: 0.85rem;
            color: var(--text-mid);
            margin: 0 0 6px;
            text-align: left;
            font-weight: 600;
        }
        .account-login-row input::placeholder {
            color: var(--text-dim);
            font-style: italic;
        }
        .account-done-btn {
            width: 100%;
            margin-top: 14px;
        }
        .account-email-row {
            display: flex;
            gap: 8px;
            margin-top: 8px;
        }
        .account-email-row input {
            flex: 1;
            padding: 10px 12px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg);
            color: var(--text);
            font-family: var(--sans);
            font-size: 0.95rem;
            outline: none;
            min-width: 0;
        }
        .account-email-row input:focus { border-color: var(--accent-dim); }
        .account-email-row input::placeholder { color: var(--text-dim); font-style: italic; }
        .account-grant-timer {
            font-size: 0.8rem;
            color: var(--text-dim);
            text-align: center;
            margin-top: 6px;
        }
        .account-grant-timer.expiring { color: var(--orange); }
        .account-info-box {
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 12px 14px;
            margin: 8px 0;
            font-size: 0.85rem;
            color: var(--text-mid);
            text-align: left;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }
        .account-info-box strong { color: var(--text); }
        .account-info-box .info-text { flex: 1; min-width: 0; }
        .account-bin-btn {
            flex-shrink: 0;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: none;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            color: var(--text-dim);
            cursor: pointer;
            transition: color 0.15s, border-color 0.15s;
            padding: 0;
        }
        .account-bin-btn:hover { color: #e5534b; border-color: #e5534b; }
        .account-devices { margin-top: 16px; text-align: left; }
        .account-devices-heading {
            margin: 0 0 8px;
            font-size: 0.85rem;
            font-weight: 600;
            color: var(--text-mid);
        }
        #remove-email-modal { z-index: 250; }
        #import-modal { z-index: 300; }
        .import-lang-row {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 6px 0;
            font-size: 0.9rem;
        }
        .import-lang-bar {
            flex: 1;
            height: 6px;
            background: var(--bg);
            border-radius: 3px;
            overflow: hidden;
            border: 1px solid var(--border);
        }
        .import-lang-bar-fill {
            height: 100%;
            background: var(--accent);
            border-radius: 3px;
            transition: width 0.3s;
        }
        .import-lang-label {
            min-width: 30px;
            text-align: right;
            color: var(--text-mid);
            font-size: 0.8rem;
        }
        .import-warning {
            background: rgba(251, 146, 60, 0.08);
            border: 1px solid rgba(251, 146, 60, 0.2);
            border-radius: var(--radius-sm);
            padding: 10px 14px;
            margin: 12px 0;
            font-size: 0.85rem;
            color: var(--orange);
        }
        .import-spinner {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255,255,255,0.3);
            border-top-color: #fff;
            border-radius: 50%;
            animation: import-spin 0.8s linear infinite;
            margin-right: 8px;
            vertical-align: middle;
        }
        @keyframes import-spin { to { transform: rotate(360deg); } }
        .btn-outline-danger {
            background: none;
            border: 1px solid #e5534b;
            color: #e5534b;
            padding: 10px 16px;
            border-radius: var(--radius-sm);
            font-family: var(--sans);
            font-size: 0.9rem;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.15s;
            width: 100%;
        }
        .btn-outline-danger:hover { background: rgba(229, 83, 75, 0.1); }
        .account-code-display {
            font-family: monospace;
            font-size: 1.1rem;
            text-align: center;
            letter-spacing: 0.1em;
            padding: 14px;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            word-break: break-all;
            color: var(--text);
            flex: 1;
            min-width: 0;
        }
        .account-copy-btn {
            flex-shrink: 0;
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: none;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            color: var(--text-dim);
            cursor: pointer;
            transition: color 0.15s, border-color 0.15s;
            padding: 0;
        }
        .account-copy-btn:hover { color: var(--accent); border-color: var(--accent); }
        .account-section-label {
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: var(--text-dim);
            margin: 16px 0 6px;
            text-align: left;
            font-weight: 600;
        }

        .dict-header {
            flex-shrink: 0;
            padding: 12px 18px;
        }
        .dict-search {
            width: 100%;
            padding: 10px 14px;
            border: 1px solid #333;
            border-radius: var(--radius-sm);
            background: var(--bg);
            color: var(--text);
            font-family: var(--sans);
            font-size: 0.9rem;
            outline: none;
            transition: border-color 0.2s;
        }
        .dict-search:focus { border-color: var(--accent-dim); }
        .dict-search::placeholder { color: #555; }
        .dict-body {
            flex: 1;
            overflow-y: auto;
            margin-top: 14px;
            padding: 0 18px;
            scrollbar-width: thin;
            scrollbar-color: #333 transparent;
        }
        .dict-body::-webkit-scrollbar {
            width: 5px;
        }
        .dict-body::-webkit-scrollbar-track {
            background: transparent;
        }
        .dict-body::-webkit-scrollbar-thumb {
            background: #333;
            border-radius: 3px;
        }
        .dict-body::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        .dict-section-label {
            font-size: 0.75rem;
            color: var(--text-dim);
            text-transform: uppercase;
            letter-spacing: 0.08em;
            padding: 4px 0;
        }
        .dict-entry + .dict-section-label {
            margin-top: 18px;
        }
        .dict-entry:has(+ .dict-section-label) {
            border-bottom: none;
        }
        .dict-entry {
            display: flex;
            align-items: baseline;
            gap: 10px;
            padding: 8px 0;
            border-bottom: 1px solid #2a2a2a;
            font-size: 0.9rem;
        }
        .dict-entry:last-child { border-bottom: none; }
        button.dict-entry {
            width: 100%;
            text-align: left;
            background: transparent;
            color: var(--text);
            border: 0;
            border-bottom: 1px solid var(--border);
            font-family: inherit;
            cursor: pointer;
        }
        button.dict-entry:hover { background: var(--accent-glow); }
        button.dict-entry:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
        /* Live-question dictionary: definitions hidden until revealed.
           The placeholder keeps the row's layout stable and surfaces only
           on hover/keyboard focus, so the list stays uncluttered. */
        .dict-def-hidden { visibility: hidden; color: var(--text-dim); font-style: italic; opacity: 0.75; }
        button.dict-entry:hover .dict-def-hidden,
        button.dict-entry:focus-visible .dict-def-hidden { visibility: visible; }
        #words-modal .modal.word-viewer-open { height: min(640px, calc(100dvh - 24px)); max-height: calc(100dvh - 24px); }
        #words-modal .dict-topbar { flex-shrink: 0; gap: 10px; }
        #words-modal .dict-topbar h3 { flex: 1; }
        .dict-topbar .word-viewer-back { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; }
        .word-viewer-back[hidden] { display: none; }
        .word-viewer-back svg { width: 18px; height: 18px; flex-shrink: 0; }
        .word-viewer { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 16px 18px; gap: 14px; }
        .word-viewer[hidden] { display: none; }
        .word-viewer h2 { margin: 0 0 8px; color: var(--accent); overflow-wrap: anywhere; font-size: calc(1.5rem * var(--text-scale, 1)); }
        .word-viewer h2 ruby { ruby-position: over; }
        .word-viewer h2 rt {
            font-size: 0.55em; /* same proportion as the sentence ruby */
            color: var(--text-dim);
            letter-spacing: 0.02em;
            line-height: 1;
            user-select: none;
        }
        .word-viewer-title-row { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; }
        /* The speak button sits right after the word (the row's gap is the
           spacing), not pushed to the far right. */
        .word-viewer-title-row h2 { margin: 0; }
        .word-viewer-title-row .word-pronounce-btn { flex-shrink: 0; }
        .word-viewer-summary { line-height: 1.5; font-size: 0.9rem; }
        .word-viewer-summary .dict-entry-pos { margin-right: 8px; vertical-align: 1px; }
        .word-viewer-meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }
        #word-viewer-family:empty, .word-viewer-meta:empty { display: none; }
        /* The viewer's section labels ("Sentences", "Base word",
           "Variants") match the dashboard's section subtitles ("Up next",
           "Your words"): normal case, medium weight, mid tone. */
        .word-viewer .dict-section-label {
            margin: 0;
            font-size: 14px;
            line-height: 20px;
            font-weight: 500;
            color: var(--text-mid);
            text-transform: none;
            letter-spacing: normal;
        }
        .word-viewer-family { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
        .word-viewer-section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
        .word-viewer-family-nav { display: flex; align-items: center; gap: 8px; font-size: 0.7rem; color: var(--text-dim); }
        #word-viewer-sentences { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
        .word-viewer-sentence { line-height: 1.5; overflow-wrap: anywhere; }
        .word-viewer-sentence + .word-viewer-sentence { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
        .word-viewer-translation { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }
        .word-viewer .word-list-pagination { justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--text-dim); }
        .word-viewer-status { min-height: 1.2em; font-size: 0.75rem; color: var(--text-dim); }
        .word-viewer .ref-btn { white-space: normal; }
        @media (max-height: 600px) {
            .word-viewer { gap: 10px; padding: 12px 18px; }
            .word-viewer h2 { font-size: 1.25rem; margin-bottom: 4px; }
            #words-modal .dict-topbar { padding-top: 8px; padding-bottom: 8px; }
        }
        .dict-entry-word {
            font-weight: 600;
            color: var(--accent);
            min-width: 80px;
            flex-shrink: 0;
            /* Only the word scales per language — the definition keeps the
               row's base size. */
            font-size: calc(0.9rem * var(--text-scale, 1));
        }
        .dict-entry-pos {
            font-size: 0.7rem;
            color: var(--text-dim);
            background: #2a2a2a;
            padding: 1px 6px;
            border-radius: 4px;
            flex-shrink: 0;
        }
        /* Chinese pinyin reading: ruby annotation above the word (like in
           sentences and the word viewer), where other courses show the word
           type as a pill. */
        .dict-entry-word ruby {
            ruby-position: over;
        }
        .dict-entry-word rt {
            font-size: 0.55em; /* same proportion as the sentence ruby */
            color: var(--text-dim);
            letter-spacing: 0.02em;
            line-height: 1;
            user-select: none;
        }
        .dict-entry-forms {
            font-size: 0.8rem;
            color: var(--text-dim);
            margin-top: 2px;
        }
        .dict-entry-def {
            color: var(--text);
        }
        [data-theme="aero"] .dict-search {
            background: rgba(255, 255, 255, 0.5);
            border-color: rgba(255, 255, 255, 0.7);
        }
        [data-theme="aero"] .dict-search:focus {
            border-color: var(--accent);
        }
        [data-theme="aero"] .dict-body {
            scrollbar-color: rgba(0, 80, 140, 0.2) transparent;
        }
        [data-theme="aero"] .dict-body::-webkit-scrollbar-thumb {
            background: rgba(0, 80, 140, 0.2);
        }
        [data-theme="aero"] .dict-body::-webkit-scrollbar-thumb:hover {
            background: rgba(0, 80, 140, 0.35);
        }
        [data-theme="aero"] .dict-entry {
            border-bottom-color: rgba(0, 80, 140, 0.1);
        }
        [data-theme="aero"] .dict-entry-pos {
            background: rgba(0, 119, 204, 0.1);
            color: var(--accent-dim);
        }
        .modal-actions {
            display: flex;
            gap: 10px;
            justify-content: center;
        }
        .modal-actions .btn { padding: 10px 24px; font-size: 0.9rem; }
        .btn-danger {
            background: var(--red);
            color: #111;
        }
        .btn-danger:hover { background: #fca5a5; }

        /* Screens */
        .screen { display: none; flex-direction: column; flex: 1; }
        .screen.active { display: flex; }

        /* ===== LANGUAGE SELECTOR ===== */
        .lang-select {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            /* Centre when the list fits, start-align when it doesn't: plain
               centring clips the heading above the fold on short screens. */
            justify-content: safe center;
            gap: 28px;
            padding: 8px 0 20px;
        }
        /* Seven languages plus heading and footer do not fit comfortably on a
           short laptop; tighten the cards rather than let the page look
           clipped. The page still scrolls when even this doesn't fit. */
        @media (max-height: 760px) {
            .lang-select { gap: 16px; padding-top: 0; }
            .lang-card { padding: 13px 20px; }
            .lang-flag-img { width: 2.5rem; height: 1.5rem; }
            .lang-flag { font-size: 1.6rem; }
            .lang-card-info h3 { font-size: 1rem; }
        }
        .lang-select h2 {
            font-size: 1.3rem;
            color: var(--text-mid);
            font-weight: 500;
        }
        .lang-cards {
            display: flex;
            flex-direction: column;
            gap: 12px;
            width: 100%;
            max-width: 340px;
        }
        .lang-card {
            background: var(--bg-card);
            border: 1px solid #2a2a2a;
            border-radius: var(--radius);
            padding: 20px 24px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 16px;
        }
        .lang-card:hover {
            border-color: var(--accent-dim);
            background: var(--bg-card-hover);
            transform: translateY(-2px);
        }
        .lang-flag {
            font-size: 2rem;
            line-height: 1;
        }
        .lang-flag-img {
            width: 3rem;
            height: 1.8rem;
            object-fit: cover;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.15);
        }
        .lang-flag-img-inline {
            width: 1.4rem;
            height: 0.84rem;
            object-fit: cover;
            border-radius: 2px;
            vertical-align: -0.1em;
            margin-right: 2px;
        }
        .lang-card-info h3 {
            font-size: 1.1rem;
            color: var(--text);
            margin-bottom: 2px;
        }
        .lang-card-info span {
            font-size: 0.85rem;
            color: var(--text-dim);
        }

        /* ===== DASHBOARD ===== */
        .progress-summary {
            text-align: center;
            padding: 32px 0;
        }
        .progress-ring-container {
            position: relative;
            width: 160px;
            height: 160px;
            margin: 0 auto 20px;
        }
        .progress-ring {
            transform: rotate(-90deg);
        }
        .progress-ring-bg {
            fill: none;
            stroke: #2a2a2a;
            stroke-width: 8;
        }
        .progress-ring-fill {
            fill: none;
            stroke: var(--accent);
            stroke-width: 8;
            stroke-linecap: round;
            transition: stroke-dashoffset 0.8s ease;
        }
        .progress-center {
            position: absolute;
            top: 50%; left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        .progress-number {
            font-size: 2.5rem;
            font-weight: 700;
            color: var(--accent);
            line-height: 1;
        }
        .progress-label {
            font-size: 0.8rem;
            color: var(--text-dim);
            margin-top: 4px;
        }
        .progress-subtitle {
            color: var(--text-mid);
            font-size: 0.95rem;
            margin-bottom: 32px;
        }

        /* The 'x of x words' line is a standing link into the progress
           viewer: accent blue with an underline, deepening on hover. */
        .progress-subtitle {
            cursor: pointer;
            color: var(--accent);
            text-decoration: underline;
            transition: color 0.15s;
        }
        .progress-subtitle:hover { color: var(--accent-dim); }
        .progress-subtitle:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 4px;
            border-radius: 4px;
        }

        /* ===== PROGRESS VIEWER ===== */
        .progress-viewer-topbar {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px 0 16px;
        }
        .progress-viewer-topbar h2 {
            font-size: 1.15rem;
            font-weight: 600;
        }
        .pv-back {
            display: grid;
            place-items: center;
            width: 36px;
            height: 36px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg-card);
            color: var(--text-dim);
            cursor: pointer;
            transition: all 0.15s;
        }
        .pv-back svg { width: 18px; height: 18px; }
        .pv-back:hover { color: var(--accent); border-color: var(--accent-dim); }
        .progress-viewer {
            display: flex;
            flex-direction: column;
            gap: 14px;
            padding-bottom: 24px;
        }
        .pv-stats {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
        }
        @media (max-width: 560px) {
            .pv-stats { grid-template-columns: repeat(2, 1fr); }
        }
        .pv-stat-card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 14px 12px;
            text-align: center;
        }
        .pv-stat-value {
            font-size: 1.7rem;
            font-weight: 700;
            color: var(--accent);
            line-height: 1.15;
        }
        .pv-stat-of { font-size: 0.95rem; color: var(--text-dim); font-weight: 600; }
        .pv-stat-label { font-size: 0.78rem; color: var(--text-dim); margin-top: 3px; }
        .pv-card {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 16px;
        }
        .pv-card h3 {
            font-size: 1rem;
            margin-bottom: 12px;
        }
        #pv-curve svg { width: 100%; height: auto; display: block; }
        .pv-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }
        .pv-axis-label { font-size: 11px; fill: var(--text-dim); }
        .pv-axis-title { font-size: 11px; fill: var(--text-dim); }
        .pv-curve-line {
            fill: none;
            stroke: var(--accent);
            stroke-width: 2.5;
            stroke-linecap: round;
            stroke-linejoin: round;
        }
        .pv-curve-area { fill: var(--accent-glow); stroke: none; }
        .pv-curve-dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
        .pv-axis-caption {
            text-align: center;
            font-size: 0.78rem;
            color: var(--text-dim);
            margin-top: 4px;
        }
        .pv-mix {
            display: flex;
            height: 12px;
            border-radius: 6px;
            overflow: hidden;
            margin-bottom: 12px;
            background: var(--bg);
        }
        .pv-seg { display: block; height: 100%; }
        .pv-seg-mastered { background: var(--green); }
        .pv-seg-learning { background: var(--accent); }
        .pv-seg-unseen { background: var(--border); }
        .pv-legend {
            display: flex;
            flex-wrap: wrap;
            gap: 6px 16px;
            font-size: 0.82rem;
            color: var(--text-dim);
        }
        .pv-swatch {
            display: inline-block;
            width: 10px;
            height: 10px;
            border-radius: 3px;
            margin-right: 5px;
        }
        .pv-swatch.pv-seg-mastered { background: var(--green); }
        .pv-swatch.pv-seg-learning { background: var(--accent); }
        .pv-swatch.pv-seg-unseen { background: var(--border); }
        .pv-browser-head {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-bottom: 10px;
        }
        .pv-search {
            width: 100%;
            padding: 10px 14px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg);
            color: var(--text);
            font-family: var(--sans);
            font-size: 0.9rem;
            outline: none;
            transition: border-color 0.2s;
        }
        .pv-search:focus { border-color: var(--accent-dim); }
        .pv-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
        .pv-chip {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 12px;
            border: 1px solid var(--border);
            border-radius: 999px;
            background: var(--bg);
            color: var(--text-dim);
            font-family: var(--sans);
            font-size: 0.82rem;
            cursor: pointer;
            transition: all 0.15s;
        }
        .pv-chip:hover { color: var(--text); border-color: var(--accent-dim); }
        .pv-chip.on {
            color: var(--accent);
            border-color: var(--accent-dim);
            background: var(--accent-glow);
        }
        .pv-chip-count { font-weight: 600; }
        .pv-rows { display: flex; flex-direction: column; }
        .pv-row {
            display: flex;
            align-items: baseline;
            gap: 10px;
            width: 100%;
            padding: 9px 4px;
            border: none;
            border-bottom: 1px solid var(--border);
            background: transparent;
            color: var(--text);
            font-family: var(--sans);
            font-size: 0.9rem;
            text-align: left;
            cursor: pointer;
        }
        .pv-row:hover { background: var(--accent-glow); }
        .pv-row .pv-word { font-weight: 600; white-space: nowrap; }
        .pv-row .pv-def {
            flex: 1;
            color: var(--text-dim);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .pv-badge {
            flex-shrink: 0;
            font-size: 0.72rem;
            font-weight: 600;
            padding: 2px 8px;
            border-radius: 999px;
            border: 1px solid var(--border);
        }
        .pv-badge-mastered { color: var(--green); border-color: var(--green); }
        .pv-badge-learning { color: var(--accent); border-color: var(--accent-dim); }
        .pv-badge-new { color: var(--text-dim); border-color: var(--border); }
        .pv-browser-foot {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 10px;
        }
        .pv-count { font-size: 0.82rem; color: var(--text-dim); }
        .pv-more {
            padding: 8px 18px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg-card);
            color: var(--text);
            font-family: var(--sans);
            font-size: 0.85rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.15s;
        }
        .pv-more:hover { border-color: var(--accent-dim); color: var(--accent); }
        .pv-curve-empty { color: var(--text-dim); font-size: 0.9rem; padding: 12px 0; }

        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 14px 32px;
            border: none;
            border-radius: var(--radius);
            font-family: var(--sans);
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
        }
        .btn-primary {
            background: var(--accent);
            color: #fff;
        }
        .btn-primary:hover { background: #60a5fa; transform: translateY(-1px); }
        .btn-primary:active { transform: translateY(0); }
        .btn-secondary {
            background: var(--bg-card);
            color: var(--text);
            border: 1px solid #333;
        }
        .btn-secondary:hover { background: var(--bg-card-hover); }

        /* Dashboard actions */
        .dashboard-actions {
            display: flex;
            gap: 12px;
            justify-content: center;
            margin-bottom: 32px;
        }
        .dashboard-actions .btn {
            flex: 1;
            max-width: 200px;
        }

        /* Word list */
        .word-list-section {
            padding: 0 0 24px;
            flex: 1;
            overflow-y: auto;
        }
        .word-list {
            display: flex;
            flex-direction: column;
            gap: 6px;
        }
        .word-list-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 14px;
            background: var(--bg-card);
            border: 1px solid #2a2a2a;
            border-radius: var(--radius-sm);
            font-size: 0.95rem;
            position: relative;
            cursor: default;
        }
        .word-list-item.dimmed .word-list-actions {
            opacity: 0.7;
            transition: opacity 0.15s;
        }
        .word-list-item.dimmed:hover .word-list-actions {
            opacity: 0.9;
        }
        .word-list-item .word-info {
            display: flex;
            align-items: baseline;
            gap: 8px;
            min-width: 0;
            flex: 1;
        }
        .word-list-item .word-name {
            font-weight: 500;
            flex-shrink: 0;
        }
        .word-list-item .word-def {
            /* 0.9rem: the definition is the point of these rows and the
               old 0.8rem was hard to read. Languages with their own word
               layouts (zh: card grid, stacked 'Up next') never render
               this class, so the bump is list-layout languages only. */
            font-size: 0.9rem;
            color: var(--text-dim);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            opacity: 0;
            transition: opacity 0.15s;
        }
        .word-list-item:hover .word-def,
        .word-list-item.touch-active .word-def {
            opacity: 1;
        }
        .word-list-item.dimmed .word-def {
            opacity: 0.7;
        }
        /* Pinyin languages (registry "pinyin": true, e.g. Chinese): the
           'Up next' row shows the reading above the word (ruby annotation,
           like in sentences) with the full definition to the right. */
        .word-list-item .word-info.word-info-pinyin {
            align-items: center;
            gap: 10px;
        }
        .word-list-item .upnext-word {
            font-size: calc(1.1rem * var(--text-scale, 1));
            line-height: 1.15;
        }
        .word-list-item ruby.upnext-word {
            ruby-position: over;
        }
        .word-list-item .upnext-word rt {
            font-size: 0.55em; /* same proportion as the sentence ruby */
            color: var(--text-dim);
            letter-spacing: 0.02em;
            line-height: 1;
            user-select: none;
        }
        .word-list-item .upnext-def {
            font-size: 0.9rem;
            line-height: 1.3;
            color: var(--text-dim);
            white-space: normal;
            overflow-wrap: break-word;
        }
        .word-list-item.dimmed .upnext-def {
            opacity: 0.8;
        }
        /* "Your words" card grid (languages with "words_layout": "grid"):
           each word is a rectangular card — the character on the first line
           (left-aligned), the pinyin below it, and a strength indicator in
           the bottom right. The word opens the dictionary; its strength opens
           learning progress. The remove button floats at the top right and shows
           on hover (always visible on touch devices). minmax(0, 1fr) keeps
           the four columns exactly equal and stops wide content from growing
           its track and overflowing the container. */
        .word-card-grid {
            display: grid;
            grid-template-columns: repeat(4, minmax(0, 1fr));
            gap: 8px;
            max-width: 100%;
        }
        .word-grid-card {
            position: relative;
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
            min-height: 84px;
            padding: 10px 6px 8px;
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            cursor: default;
            overflow: hidden;
        }
        .word-grid-card:hover {
            background: var(--accent-glow);
        }
        .word-grid-card:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: -2px;
        }
        .word-grid-char {
            flex-shrink: 0;
            font-size: calc(1.5rem * var(--text-scale, 1));
            font-weight: 600;
            color: var(--text);
            line-height: 1.15;
        }
        .word-grid-pinyin {
            font-size: calc(0.75rem * var(--text-scale, 1));
            color: var(--text-dim);
            letter-spacing: 0.02em;
            overflow-wrap: anywhere;
        }
        .word-grid-foot {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            width: 100%;
            min-width: 0;
            margin-top: auto;
        }
        .word-grid-card .word-remove-btn {
            position: absolute;
            top: 4px;
            right: 4px;
            margin: 0;
            border-radius: 10px; /* same radius as the status pill */
            opacity: 0;
            transform: scale(0.8);
        }
        .word-grid-card:hover .word-remove-btn { opacity: 1; transform: scale(1); }
        /* Touch devices have no hover, and a tap opens the word viewer —
           keep the remove button reachable there. */
        @media (hover: none) {
            .word-grid-card .word-remove-btn { opacity: 1; transform: scale(1); }
        }
        @media (max-width: 560px) {
            .word-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        }
        .pronounce-all-btn {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 12px;
            font-size: 0.8rem;
            font-weight: 500;
            margin-left: auto;
            margin-top: 12px;
        }
        .pronounce-all-btn .speaker-icon {
            width: 16px;
            height: 16px;
        }
        .word-card-actions {
            margin-left: auto;
            display: flex;
            gap: 6px;
        }
        .word-pronounce-btn {
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 6px;
            color: var(--accent);
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
        }
        .word-pronounce-btn:hover {
            border-color: var(--accent);
            color: var(--accent-dim);
        }
        .word-pronounce-btn .speaker-icon {
            width: 16px;
            height: 16px;
        }
        .word-card.speaking {
            border-color: var(--accent);
            box-shadow: 0 0 24px rgba(59, 130, 246, 0.4);
            transform: scale(1.02);
            transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
        }
        .word-list-actions {
            display: flex;
            align-items: center;
            gap: 4px;
            flex-shrink: 0;
            margin-left: 8px;
        }
        .word-remove-btn {
            width: 18px;
            height: 18px;
            border-radius: 50%;
            flex-shrink: 0;
            cursor: pointer;
            transition: all 0.15s;
            border: 1px solid rgba(128, 128, 128, 0.35);
            background: rgba(128, 128, 128, 0.12);
            color: var(--text-mid);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin-right: 6px;
            opacity: 0;
            transform: scale(0.8);
            user-select: none;
            padding: 0;
        }
        .word-remove-btn:hover {
            filter: brightness(1.3);
            border-color: var(--red);
            color: var(--red);
        }
        .word-remove-btn svg {
            width: 11px;
            height: 11px;
        }
        .word-list-item:hover .word-remove-btn {
            opacity: 1;
            transform: scale(1);
        }
        .word-list-item.touch-active .word-remove-btn {
            opacity: 1;
            transform: scale(1);
        }
        .word-dictionary-link {
            appearance: none; border: 0; padding: 2px 0; background: none;
            color: inherit; font: inherit; text-align: left; cursor: pointer;
            border-radius: 3px; min-width: 0;
        }
        .word-dictionary-link:hover { color: var(--accent); }
        .word-list-item .word-dictionary-link { flex-shrink: 0; max-width: 100%; overflow-wrap: anywhere; }
        .word-grid-main { display: flex; flex-direction: column; gap: 5px; width: 100%; }
        .word-strength {
            display: inline-flex; align-items: center; justify-content: center; gap: 6px;
            flex-shrink: 0; padding: 5px 8px; min-height: 30px;
            border: 1px solid var(--border); border-radius: 8px;
            background: none; color: var(--accent); font-family: var(--sans);
            font-size: 0.7rem; font-weight: 500; white-space: nowrap; cursor: pointer;
        }
        .word-strength:hover { background: var(--accent-glow); border-color: var(--accent); }
        .word-strength[data-tone="neutral"], .word-progress-strength[data-tone="neutral"] { color: var(--text-dim); }
        .word-strength[data-tone="secure"], .word-progress-strength[data-tone="secure"] { color: var(--accent); }
        .word-strength[data-tone="mastered"], .word-progress-strength[data-tone="mastered"] { color: var(--green); }
        .word-strength-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
        .word-strength-bars span { width: 3px; background: currentColor; opacity: 0.18; border-radius: 1px; }
        .word-strength-bars span:nth-child(1) { height: 5px; }
        .word-strength-bars span:nth-child(2) { height: 8px; }
        .word-strength-bars span:nth-child(3) { height: 11px; }
        .word-strength-bars span:nth-child(4) { height: 14px; }
        .word-strength-bars .is-filled { opacity: 1; }
        .word-dictionary-link:focus-visible, .word-strength:focus-visible,
        .word-remove-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
        .word-list-item:focus-within .word-def { opacity: 1; }
        .word-list-item:focus-within .word-remove-btn { opacity: 1; transform: scale(1); }
        /* Learning progress is another pane in the existing dictionary
           window: same width, heading, padding, controls, and typography. */
        #words-modal .modal.word-progress-open { max-height: min(640px, calc(100dvh - 24px)); }
        .word-progress { overflow-y: auto; gap: 12px; }
        .word-progress-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
        .word-progress-heading .word-viewer-title-row { min-width: 0; margin: 0; }
        .word-progress-heading .ref-btn { flex-shrink: 0; }
        .word-progress-overview { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 0.85rem; }
        .word-progress-strength { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); }
        .word-progress-stats { margin: 0; }
        .word-progress-stat { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
        .word-progress-stat:last-child { border-bottom: 0; }
        .word-progress-stat dt { color: var(--text-dim); }
        .word-progress-stat dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
        .word-progress-details { border-top: 1px solid var(--border); padding-top: 12px; font-size: 0.8rem; }
        .word-progress-details summary { cursor: pointer; color: var(--text-mid); }
        .word-progress-details dl { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin: 14px 0 0; }
        .word-progress-details dt { color: var(--text-dim); }
        .word-progress-details dd { margin: 0; text-align: right; }
        .word-progress-mastery { border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
        .word-progress-mastery p { margin: 0; color: var(--text-dim); font-size: 0.8rem; line-height: 1.5; }
        .word-progress-mastery .ref-btn { flex-shrink: 0; }
        .word-progress-mastery .word-mastery-btn {
            padding: 4px 10px; border-radius: 10px;
            font-size: 0.75rem; font-weight: 600; line-height: 1.25;
        }
        .word-progress-mastery .word-mastery-btn[aria-pressed="false"] {
            background: none; border-color: var(--green); color: var(--green);
        }
        .word-progress-mastery .word-mastery-btn[aria-pressed="false"]:hover:not(:disabled) {
            background: color-mix(in srgb, var(--green) 10%, transparent);
            border-color: var(--green); color: var(--green);
        }
        .word-progress-mastery .word-mastery-btn:focus-visible {
            outline: 2px solid var(--green); outline-offset: 3px;
        }
        .word-progress-mastery .word-mastery-btn:disabled {
            opacity: 0.45; cursor: not-allowed; box-shadow: none;
        }
        @media (max-width: 480px) {
            .word-progress-mastery { align-items: flex-start; flex-direction: column; gap: 10px; }
            .word-grid-card .word-strength { padding: 6px 9px; min-width: 38px; }
            .word-grid-card .word-strength > span:last-child { display: none; }
        }
        .word-mark-known-btn {
            opacity: 0;
            pointer-events: none;
            font-size: 0.7rem;
            font-weight: 600;
            padding: 2px 8px;
            border-radius: 10px;
            border: 1px solid var(--border);
            background: none;
            color: var(--text-dim);
            cursor: pointer;
            transition: all 0.15s;
            font-family: var(--sans);
            white-space: nowrap;
        }
        @media (hover: hover) {
            .word-list-item:hover .word-mark-known-btn { opacity: 1; pointer-events: auto; }
        }
        .word-list-item.touch-active .word-mark-known-btn,
        .word-list-item:focus-within .word-mark-known-btn { opacity: 1; pointer-events: auto; }
        .word-mark-known-btn:hover, .word-mark-known-btn:active, .word-mark-known-btn:focus-visible {
            border-color: var(--accent);
            color: var(--accent);
            background: var(--accent-glow);
        }
        .word-mark-known-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
        .word-list-divider {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin: 0;
            font-size: 14px;
            line-height: 20px;
            font-weight: 500;
            color: var(--text-mid);
            padding: 12px 12px 4px;
        }
        .word-list-divider:first-child,
        .word-list-item + .word-list-divider {
            margin-top: 8px;
        }
        .word-list-view-all {
            padding: 0;
            border: 0;
            background: none;
            color: var(--accent);
            font-family: var(--sans);
            font-size: 0.85rem;
            line-height: inherit;
            font-weight: 500;
            white-space: nowrap;
            cursor: pointer;
        }
        .word-list-view-all:hover {
            text-decoration: underline;
            text-underline-offset: 3px;
        }
        .word-list-view-all:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 4px;
            border-radius: 2px;
        }
        .word-list-pagination {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 16px;
            padding: 12px 0 4px;
        }
        /* Keep short pages' words beside the pager, not above a blank viewport. */
        #word-list > .word-list-page-start { margin-top: auto; }
        .word-list-pagination button {
            background: none;
            border: 1px solid #333;
            border-radius: 6px;
            color: var(--text-dim);
            font-family: var(--sans);
            font-size: 0.8rem;
            padding: 5px 12px;
            cursor: pointer;
            transition: all 0.15s;
        }
        .word-list-pagination button:hover {
            color: var(--accent);
            border-color: var(--accent-dim);
        }
        .word-list-pagination button:disabled {
            opacity: 0.3;
            cursor: default;
        }
        .word-list-pagination button:disabled:hover {
            color: var(--text-dim);
            border-color: #333;
        }
        .word-list-pagination span {
            font-size: 0.75rem;
            color: var(--text-dim);
        }
        [data-theme="aero"] .word-list-item {
            background: rgba(255, 255, 255, 0.4);
            border-color: rgba(255, 255, 255, 0.6);
        }

        /* ===== WORD INTRODUCTION ===== */
        .word-intro {
            flex: 1;
            display: flex;
            flex-direction: column;
        }
        .lesson-header {
            text-align: center;
            padding: 16px 0 24px;
        }
        .lesson-header h2 {
            font-size: 1.1rem;
            color: var(--text-mid);
            font-weight: 500;
        }

        .word-cards {
            display: flex;
            flex-direction: column;
            gap: 16px;
            flex: 1;
        }
        .word-card {
            background: var(--bg-card);
            border-radius: var(--radius);
            padding: 24px;
            border: 1px solid #2a2a2a;
            transition: all 0.3s;
            opacity: 0;
            transform: translateY(20px);
        }
        .word-card.visible {
            opacity: 1;
            transform: translateY(0);
        }
        .word-card-top {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 10px;
            min-width: 0;
        }
        .word-target {
            font-size: calc(2rem * var(--text-scale, 1));
            color: var(--accent);
            font-weight: 600;
        }
        .word-pinyin {
            font-size: calc(0.85rem * var(--text-scale, 1));
            color: var(--text-dim);
            font-weight: 400;
            letter-spacing: 0.02em;
        }
        .word-pos {
            font-size: 0.75rem;
            color: var(--text-dim);
            background: #2a2a2a;
            padding: 2px 8px;
            border-radius: 4px;
        }
        .word-tense {
            font-size: 0.7rem;
            color: var(--accent);
            background: var(--accent-glow);
            padding: 2px 8px;
            border-radius: 4px;
            font-weight: 500;
        }
        .word-base-reference {
            display: grid;
            grid-template-columns: auto minmax(0, 1fr) auto;
            align-items: center;
            gap: 10px;
            margin-top: 16px;
            padding: 11px 12px;
            border: 1px solid rgba(59, 130, 246, 0.24);
            border-radius: 10px;
            background: var(--accent-glow);
        }
        .word-base-label {
            padding: 3px 7px;
            border-radius: 5px;
            background: rgba(59, 130, 246, 0.14);
            color: var(--accent);
            font-size: 0.68rem;
            font-weight: 650;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            white-space: nowrap;
        }
        .word-base-content {
            min-width: 0;
            color: var(--text);
            line-height: 1.35;
        }
        .word-base-word {
            color: var(--accent);
            font-size: 1rem;
        }
        .word-base-definition {
            margin-left: 4px;
            color: var(--text-mid);
            font-size: 0.9rem;
        }
        .word-base-reference .word-pronounce-btn {
            width: 32px;
            height: 32px;
            padding: 6px;
            flex-shrink: 0;
        }
        .word-def i,
        .dict-entry-def i {
            font-style: italic;
            color: var(--text-mid);
        }

        .word-def {
            font-size: 1.05rem;
            color: var(--text);
            line-height: 1.5;
        }

        .word-intro-actions {
            padding: 16px 0;
            text-align: center;
            position: sticky;
            bottom: 0;
            background: linear-gradient(transparent, var(--bg) 30%);
            padding-top: 32px;
        }

        /* ===== UNLOCKED WORDS (end-of-lesson reveal) ===== */
        .unlocked-subtitle {
            max-width: 460px;
            margin: 6px auto 0;
            font-size: 0.92rem;
            line-height: 1.5;
            color: var(--text-mid);
        }
        /* The one summary card for unlocked generated numbers (a range like
           "20-29" — never a card per value). */
        .unlocked-number-card .word-target {
            letter-spacing: 0.01em;
        }

        /* ===== PRACTICE ===== */
        .practice-top {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 4px 0 12px;
        }
        .practice-lesson-label {
            font-size: 0.85rem;
            color: var(--text-dim);
        }
        .practice-ref-btns {
            display: flex;
            gap: 6px;
        }
        .ref-btn {
            padding: 5px 10px;
            border: 1px solid #333;
            border-radius: 6px;
            background: none;
            color: var(--text-dim);
            font-family: var(--sans);
            font-size: 0.75rem;
            cursor: pointer;
            transition: all 0.15s;
        }
        .ref-btn:hover {
            color: var(--accent);
            border-color: var(--accent-dim);
        }
        .practice-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 0 16px;
        }
        .practice-progress {
            font-size: 0.85rem;
            color: var(--text-dim);
        }
        .streak-badge {
            font-size: 0.85rem;
            color: var(--accent);
            font-weight: 600;
        }

        .progress-bar-container {
            height: 4px;
            background: #2a2a2a;
            border-radius: 2px;
            margin-bottom: 32px;
            overflow: hidden;
        }
        .progress-bar-fill {
            height: 100%;
            background: var(--accent);
            border-radius: 2px;
            transition: width 0.4s ease;
        }

        /* Multi-word expression hint: a "Show hint" button in the practice
           toolbar toggles a card below the sentence card listing the
           expressions. */
        .hint-toggle-btn {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 4px 10px;
            border: 1px solid #333;
            border-radius: 6px;
            background: none;
            color: var(--accent);
            font-family: var(--sans);
            font-size: 0.75rem;
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.15s;
        }
        .hint-toggle-btn:hover {
            border-color: var(--accent-dim);
            background: var(--accent-glow);
        }
        .hint-toggle-btn svg {
            width: 13px;
            height: 13px;
        }
        .expression-hint-card {
            background: var(--bg-card);
            border: 1px solid #2a2a2a;
            border-radius: var(--radius);
            padding: 14px 20px;
            margin-bottom: 24px;
        }
        .expression-hint-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 8px;
        }
        .expression-hint-label {
            font-size: 0.9rem;
            color: var(--text-dim);
        }
        .expression-hint-close {
            background: none;
            border: none;
            padding: 0 4px;
            color: var(--text-dim);
            font-size: 1.25rem;
            line-height: 1;
            cursor: pointer;
        }
        .expression-hint-close:hover {
            color: var(--text);
        }
        .expression-hint-list {
            list-style: none;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .expression-hint-item {
            font-size: 0.95rem;
            line-height: 1.45;
            color: var(--text);
        }
        .expression-hint-item .expression-hint-expression {
            font-weight: 600;
        }
        .sentence-card {
            background: var(--bg-card);
            border-radius: var(--radius);
            padding: 28px 24px;
            border: 1px solid #2a2a2a;
            margin-bottom: 24px;
            transition: border-color 0.3s;
            position: relative;
        }
        .sentence-card.correct {
            border-color: var(--green);
            box-shadow: 0 0 30px rgba(74, 222, 128, 0.1);
        }
        .sentence-card.ungraded {
            border-color: var(--orange);
        }
        .sentence-card.pending {
            border-color: var(--orange);
            box-shadow: 0 0 30px rgba(251, 146, 60, 0.12);
        }
        .sentence-card.incorrect {
            border-color: var(--red);
            box-shadow: 0 0 30px rgba(248, 113, 113, 0.1);
        }
        .card-actions {
            position: absolute;
            top: 12px;
            right: 12px;
            display: flex;
            gap: 4px;
        }
        .card-action-btn {
            background: none;
            border: none;
            color: var(--text-dim);
            cursor: pointer;
            padding: 5px;
            border-radius: 6px;
            line-height: 0;
            transition: color 0.15s, background 0.15s;
        }
        .card-action-btn:hover {
            color: var(--accent);
            background: var(--accent-glow);
        }
        .card-action-btn svg {
            width: 18px;
            height: 18px;
            display: block;
        }
        .card-action-btn.saved {
            color: var(--accent);
        }
        .card-action-btn.saved svg {
            fill: currentColor;
        }
        .report-comment {
            width: 100%;
            box-sizing: border-box;
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 10px 12px;
            font-size: 0.9rem;
            font-family: inherit;
            color: var(--text);
            resize: vertical;
            margin-bottom: 6px;
        }
        .report-comment:focus {
            outline: none;
            border-color: var(--accent);
        }
        .report-error {
            color: var(--red);
            font-size: 0.85rem;
            margin-bottom: 8px;
        }

        .eng-translation {
            font-size: 0.9rem;
            color: var(--text-dim);
            margin-bottom: 16px;
            font-style: italic;
            white-space: pre-line;
            padding-right: 64px;
        }
        .target-line {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 6px;
            text-align: center;
        }
        .target-sentence {
            font-size: calc(1.4rem * var(--text-scale, 1));
            line-height: 1.6;
            color: var(--text);
            overflow-wrap: break-word;
            min-width: 0;
        }
        .target-sentence .dialogue-line {
            display: block;
            padding: 4px 0;
        }
        .target-sentence .dialogue-line + .dialogue-line {
            margin-top: 4px;
            padding-top: 8px;
            border-top: 1px solid #222;
        }
        .target-sentence .punct {
            color: var(--text-dim);
        }
        /* A word glued to touching punctuation (word., …word, “word) —
           keeps a trailing full stop from wrapping alone to the next line. */
        .target-sentence .tok-group {
            white-space: nowrap;
        }
        .target-sentence .blank {
            display: inline-block;
            min-width: 80px;
            border-bottom: 2px solid var(--accent-dim);
            text-align: center;
            color: var(--accent);
            font-weight: 600;
            padding: 0 4px;
            vertical-align: baseline;
            transition: all 0.3s;
        }
        .target-sentence .blank:empty {
            height: 1.2em;
            vertical-align: text-bottom;
        }
        .target-sentence .blank.filled-correct {
            color: var(--green);
            border-bottom-color: var(--green);
        }
        .target-sentence .blank.revealed-answer {
            color: var(--accent);
            border-bottom-color: var(--accent);
        }
        /* Sentence words open their dictionary entry on click, with a dotted
           underline on hover only and no hover popover. */
        .word-dict-link {
            appearance: none; border: 0; padding: 0; margin: 0;
            background: none; color: inherit; font: inherit;
            cursor: pointer; border-radius: 3px; text-align: inherit;
        }
        .word-dict-link:hover {
            color: var(--accent);
            text-decoration: underline;
            text-decoration-style: dotted;
            text-underline-offset: 3px;
        }
        .word-dict-link:focus-visible {
            outline: 2px solid var(--accent); outline-offset: 2px;
        }
        /* Pinyin ruby annotation (Chinese): reading above each word. */
        .target-sentence ruby {
            ruby-position: over;
        }
        .target-sentence ruby rt {
            font-size: 0.55em;
            color: var(--text-dim);
            letter-spacing: 0.02em;
            line-height: 1;
            user-select: none;
        }

        .choices {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 8px;
        }
        .choice-btn {
            padding: 14px;
            border: 1px solid #333;
            border-radius: var(--radius-sm);
            background: var(--bg-card);
            color: var(--text);
            font-family: var(--sans);
            font-size: calc(1.1rem * var(--text-scale, 1));
            cursor: pointer;
            transition: all 0.2s;
        }
        .choice-btn:hover:not(:disabled) {
            background: var(--bg-card-hover);
            border-color: var(--accent-dim);
        }
        .choice-btn:disabled { cursor: default; }
        .choice-btn.selected-correct,
        .choice-btn.reveal-correct {
            background: rgba(74, 222, 128, 0.15);
            border-color: var(--green);
            color: var(--green);
        }
        .choice-btn.selected-incorrect {
            background: rgba(248, 113, 113, 0.15);
            border-color: var(--red);
            color: var(--red);
        }
        .choice-btn.selected-correct::before,
        .choice-btn.reveal-correct::before {
            content: '✓ ';
            font-weight: 700;
        }
        .choice-btn.selected-incorrect::before {
            content: '✕ ';
            font-weight: 700;
        }
        .choice-btn .choice-word {
            display: block;
        }
        .choice-btn .choice-pinyin {
            display: block;
            font-size: calc(0.7rem * var(--text-scale, 1));
            font-weight: 400;
            color: var(--text-dim);
            letter-spacing: 0.02em;
        }
        /* Type-to-select: the matched prefix letters go blue; the single
           remaining match gets a blue outline plus the hint below. */
        .choice-btn .type-match { color: var(--accent); }
        .choice-btn.type-unique {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px var(--accent-glow);
        }
        .type-select-hint {
            text-align: center;
            color: var(--accent);
            font-size: 0.85rem;
            margin-top: 8px;
            min-height: 1.1em;
        }

        /* Translation input */
        .translate-input-area {
            display: flex;
            gap: 10px;
            margin-top: 8px;
        }
        .blank-input-area {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: wrap;
            margin-top: 8px;
        }
        .blank-input-area .translate-submit {
            margin-left: auto;
            flex-shrink: 0;
        }
        .blank-hint {
            font-size: 0.75rem;
            color: var(--text-dim);
        }
        .special-chars {
            display: flex;
            gap: 6px;
            flex-wrap: wrap;
        }
        .special-char-btn {
            min-width: 34px;
            padding: 6px 10px;
            border: 1px solid var(--border);
            border-radius: var(--radius-sm);
            background: var(--bg-card);
            color: var(--text);
            font-family: var(--sans);
            font-size: 1rem;
            cursor: pointer;
            transition: border-color 0.15s, background 0.15s;
        }
        .special-char-btn:hover:not(:disabled) { border-color: var(--accent-dim); background: var(--accent-glow); }
        .special-char-btn:disabled { opacity: 0.5; cursor: default; }
        .target-sentence .blank-input {
            display: inline-block;
            min-width: 3ch;
            border: none;
            border-bottom: 2px solid var(--accent-dim);
            background: transparent;
            color: var(--text);
            font-family: var(--sans);
            font-size: inherit;
            font-weight: 600;
            text-align: center;
            padding: 0 4px;
            margin: 0 2px;
            vertical-align: baseline;
            outline: none;
        }
        .target-sentence .blank-input:focus { border-bottom-color: var(--accent); }
        .target-sentence .blank-input.filled-correct { color: var(--green); border-bottom-color: var(--green); }
        .target-sentence .blank-input.revealed-answer { color: var(--red); border-bottom-color: var(--red); }
        .translate-input {
            flex: 1;
            min-width: 0; /* allow the box to shrink so the Check button fits */
            padding: 14px 16px;
            border: 1px solid #333;
            border-radius: var(--radius-sm);
            background: var(--bg-card);
            color: var(--text);
            font-family: var(--sans);
            font-size: 1.1rem;
            outline: none;
            transition: border-color 0.2s;
        }
        /* On narrow screens shrink the input slightly rather than clipping the
           Check button. */
        @media (max-width: 420px) {
            .translate-input {
                font-size: 0.95rem;
                padding: 12px 12px;
            }
            .translate-submit {
                padding: 12px 14px;
                font-size: 0.9rem;
            }
        }
        .translate-input:focus {
            border-color: var(--accent-dim);
        }
        .translate-input::placeholder {
            color: #555;
        }
        .translate-submit {
            padding: 14px 24px;
            border: none;
            border-radius: var(--radius-sm);
            background: var(--accent);
            color: #fff;
            font-family: var(--sans);
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s;
            white-space: nowrap;
        }
        .translate-submit:hover {
            background: #60a5fa;
        }
        .translate-submit:disabled {
            opacity: 0.5;
            cursor: default;
        }
        .accepted-translations {
            font-size: 0.85rem;
            color: var(--text-dim);
            margin-top: 8px;
            line-height: 1.6;
        }

        /* Listen question */
        .listen-prompt {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 12px;
            padding: 8px 0 4px;
        }
        .listen-prompt .listen-instruction {
            font-size: 0.9rem;
            color: var(--text-dim);
        }
        .listen-skip-btn {
            background: none;
            border: 1px solid #555;
            border-radius: 999px;
            color: var(--text-dim);
            font-family: var(--sans);
            font-size: 0.8rem;
            padding: 4px 14px;
            cursor: pointer;
            transition: all 0.2s;
        }
        .listen-skip-btn:hover {
            color: var(--text);
            border-color: var(--text-mid);
        }
        .listen-play-btn {
            width: 72px;
            height: 72px;
            border-radius: 50%;
            border: 2px solid var(--accent);
            background: var(--accent-glow);
            color: var(--accent);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
        }
        .listen-play-btn:hover {
            background: var(--accent);
            color: #fff;
            transform: scale(1.05);
        }
        .listen-play-btn svg {
            width: 32px;
            height: 32px;
        }
        .listen-reveal {
            margin-top: 12px;
            font-size: 1.2rem;
            color: var(--text-mid);
            display: flex;
            align-items: center;
            gap: 6px;
        }
        .listen-replay-btn {
            background: none;
            border: none;
            color: var(--text-dim);
            cursor: pointer;
            padding: 4px;
            border-radius: 6px;
            transition: color 0.15s, background 0.15s;
            line-height: 1;
        }
        .listen-replay-btn:hover {
            color: var(--accent);
            background: var(--accent-glow);
        }
        .listen-replay-btn svg {
            width: 16px;
            height: 16px;
            display: block;
        }

        .audio-btn {
            background: none;
            border: none;
            color: var(--text-dim);
            cursor: pointer;
            padding: 4px 6px;
            border-radius: 6px;
            transition: color 0.15s, background 0.15s;
            vertical-align: middle;
            line-height: 1;
            flex: none;
        }
        .audio-btn:hover {
            color: var(--accent);
            background: var(--accent-glow);
        }
        .audio-btn svg {
            width: 18px;
            height: 18px;
            display: block;
        }

        .feedback-area {
            min-height: 60px;
            padding: 16px 0;
            text-align: center;
        }
        .feedback-text {
            font-size: 0.95rem;
            padding: 12px 16px;
            border-radius: var(--radius-sm);
            display: inline-block;
        }
        .feedback-text.correct {
            background: rgba(74, 222, 128, 0.1);
            color: var(--green);
        }
        .feedback-text.incorrect {
            background: rgba(248, 113, 113, 0.1);
            color: var(--red);
        }
        .feedback-text.warn {
            background: rgba(251, 191, 36, 0.12);
            color: var(--amber, #fbbf24);
        }

        .grade-recheck-btn {
            display: block;
            margin: 10px auto 0;
            padding: 4px 10px;
            border: 1px solid var(--text-muted);
            border-radius: 8px;
            background: transparent;
            color: var(--text-muted);
            font: inherit;
            font-size: 0.75rem;
            cursor: pointer;
        }
        .grade-recheck-btn:hover, .grade-recheck-btn:focus-visible {
            border-color: var(--accent);
            color: var(--accent);
        }
        .next-btn-area {
            text-align: center;
            padding-top: 8px;
        }

        /* ===== LESSON COMPLETE ===== */
        .confetti-canvas {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 9998;
        }
        .complete-screen {
            text-align: center;
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 24px;
        }
        .complete-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            justify-content: center;
            align-items: center;
            max-width: 100%;
        }
        .complete-actions .btn {
            white-space: nowrap;
        }
        /* When there isn't enough room for all three on one line, the layout
           becomes: a large full-width primary button on top, with the two
           secondary buttons below it — each half the width, their outer edges
           lining up with the primary's edges. On wider screens all three stay
           on one line. */
        @media (max-width: 560px) {
            .complete-actions .btn:first-child {
                flex-basis: 100%;
                width: 100%;
            }
            .complete-actions .btn:not(:first-child) {
                flex: 1 1 calc(50% - 6px);
                min-width: 0;
            }
        }
        .complete-icon {
            font-size: 4rem;
            line-height: 1;
        }
        .complete-title {
            font-size: 1.8rem;
            color: var(--accent);
            font-weight: 700;
        }
        .complete-stats {
            display: flex;
            gap: 32px;
            justify-content: center;
        }
        .stat {
            text-align: center;
        }
        .stat-value {
            font-size: 2rem;
            font-weight: 700;
            color: var(--text);
        }
        .stat-label {
            font-size: 0.8rem;
            color: var(--text-dim);
            margin-top: 4px;
        }
        .mastery-words-list {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            justify-content: center;
            padding: 12px 0;
            max-width: 500px;
            margin: 0 auto;
        }
        .mastery-hint {
            color: var(--text-mid);
            font-size: 0.9rem;
            margin-top: -12px;
            margin-bottom: 8px;
            text-align: center;
        }
        .mastery-chip {
            position: relative;
            padding: 8px 14px;
            border-radius: 10px;
            background: var(--input-bg);
            border: 1.5px solid var(--border);
            color: var(--text);
            font-size: 0.95rem;
            cursor: pointer;
            transition: all 0.15s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        .mastery-chip:hover { border-color: var(--accent); }
        .mastery-chip.mastered {
            border-color: var(--green);
            color: var(--green);
            background: rgba(74, 222, 128, 0.08);
        }
        .mastery-chip.mastered::after {
            content: '✓';
            font-weight: 700;
        }

        .words-learned-list {
            display: flex;
            gap: 12px;
            justify-content: center;
            flex-wrap: wrap;
        }
        .words-learned-chip {
            font-size: 1.1rem;
            color: var(--accent);
            background: var(--accent-glow);
            padding: 6px 16px;
            border-radius: 20px;
            border: 1px solid var(--accent-dim);
        }

        /* Animations */
        @keyframes fadeInUp {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-5px); }
            75% { transform: translateX(5px); }
        }
        .shake { animation: shake 0.3s ease; }

        /* ===== FRUTIGER AERO THEME ===== */
        [data-theme="aero"] {
            --bg: #c5e8f7;
            --bg-card: rgba(255, 255, 255, 0.55);
            --bg-card-hover: rgba(255, 255, 255, 0.75);
            --accent: #0077cc;
            --accent-dim: #005fa3;
            --accent-glow: rgba(0, 119, 204, 0.2);
            --green: #2e9e3e;
            --orange: #c2410c;
            --red: #d63333;
            --text: #1a2a3a;
            --text-dim: #5a7a8a;
            --text-mid: #3a5a6a;
            --radius: 18px;
            --radius-sm: 12px;
        }

        [data-theme="aero"] body {
            background: linear-gradient(170deg, #7cc8f0 0%, #b0e0f4 30%, #cdeef8 55%, #9adfc4 80%, #7ed0c8 100%);
        }

        /* Remove grain overlay */
        [data-theme="aero"] body::before {
            display: none;
        }

        /* Glassy card effect */
        [data-theme="aero"] .settings-menu,
        [data-theme="aero"] .modal,
        [data-theme="aero"] .word-card,
        [data-theme="aero"] .sentence-card,
        [data-theme="aero"] .expression-hint-card,
        [data-theme="aero"] .lang-card {
            background: rgba(255, 255, 255, 0.6);
            backdrop-filter: blur(16px);
            -webkit-backdrop-filter: blur(16px);
            border: 1px solid rgba(255, 255, 255, 0.8);
            box-shadow:
                0 4px 24px rgba(0, 80, 140, 0.1),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
        }

        [data-theme="aero"] .lang-card:hover {
            background: rgba(255, 255, 255, 0.8);
            border-color: var(--accent);
            box-shadow:
                0 8px 32px rgba(0, 80, 140, 0.18),
                inset 0 1px 0 rgba(255, 255, 255, 0.95);
        }

        [data-theme="aero"] .sentence-card.correct {
            border-color: var(--green);
            box-shadow:
                0 0 24px rgba(46, 158, 62, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
        }
        [data-theme="aero"] .sentence-card.pending {
            border-color: var(--orange);
            box-shadow:
                0 0 24px rgba(194, 65, 12, 0.12),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
        }
        [data-theme="aero"] .sentence-card.incorrect {
            border-color: var(--red);
            box-shadow:
                0 0 24px rgba(214, 51, 51, 0.12),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
        }

        /* Glossy buttons */
        [data-theme="aero"] .btn-primary {
            background: linear-gradient(180deg, #3fadee 0%, #0077cc 50%, #005fa3 100%);
            color: #fff;
            border: 1px solid rgba(0, 80, 140, 0.3);
            box-shadow:
                0 2px 8px rgba(0, 80, 140, 0.25),
                inset 0 1px 0 rgba(255, 255, 255, 0.4);
            text-shadow: 0 1px 2px rgba(0, 40, 80, 0.3);
        }
        [data-theme="aero"] .btn-primary:hover {
            background: linear-gradient(180deg, #5fc0f5 0%, #1a8fd8 50%, #0070bb 100%);
            box-shadow:
                0 4px 16px rgba(0, 80, 140, 0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.5);
        }
        [data-theme="aero"] .btn-secondary {
            background: linear-gradient(180deg, rgba(255,255,255,0.8) 0%, rgba(235,245,252,0.7) 100%);
            border: 1px solid rgba(0, 80, 140, 0.15);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
            color: var(--text);
        }
        [data-theme="aero"] .btn-secondary:hover {
            background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(235,245,252,0.9) 100%);
        }

        [data-theme="aero"] .btn-danger {
            background: linear-gradient(180deg, #f07070 0%, #d63333 50%, #b82a2a 100%);
            color: #fff;
            box-shadow:
                0 2px 8px rgba(180, 40, 40, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
            text-shadow: 0 1px 2px rgba(100, 20, 20, 0.3);
        }
        [data-theme="aero"] .btn-danger:hover {
            background: linear-gradient(180deg, #f59090 0%, #e04444 50%, #c83333 100%);
        }

        /* Choice buttons */
        [data-theme="aero"] .choice-btn {
            background: linear-gradient(180deg, rgba(255,255,255,0.75) 0%, rgba(240,248,255,0.6) 100%);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.7);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
            color: var(--text);
        }
        [data-theme="aero"] .choice-btn:hover:not(:disabled) {
            background: linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(220,240,255,0.8) 100%);
            border-color: var(--accent);
        }
        [data-theme="aero"] .choice-btn.selected-correct,
        [data-theme="aero"] .choice-btn.reveal-correct {
            background: linear-gradient(180deg, rgba(200, 240, 200, 0.7) 0%, rgba(180, 230, 180, 0.5) 100%);
            border-color: var(--green);
            color: var(--green);
        }
        [data-theme="aero"] .choice-btn.selected-incorrect {
            background: linear-gradient(180deg, rgba(250, 200, 200, 0.7) 0%, rgba(240, 180, 180, 0.5) 100%);
            border-color: var(--red);
            color: var(--red);
        }

        /* Inputs */
        [data-theme="aero"] .translate-input {
            background: rgba(255, 255, 255, 0.7);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.8);
            box-shadow: inset 0 2px 4px rgba(0, 60, 120, 0.08);
            color: var(--text);
        }
        [data-theme="aero"] .translate-input:focus {
            border-color: var(--accent);
            box-shadow: inset 0 2px 4px rgba(0, 60, 120, 0.08), 0 0 0 3px rgba(0, 119, 204, 0.15);
        }
        [data-theme="aero"] .translate-input::placeholder {
            color: #8ab0c8;
        }
        [data-theme="aero"] .translate-submit {
            background: linear-gradient(180deg, #3fadee 0%, #0077cc 50%, #005fa3 100%);
            box-shadow:
                0 2px 8px rgba(0, 80, 140, 0.25),
                inset 0 1px 0 rgba(255, 255, 255, 0.4);
            text-shadow: 0 1px 2px rgba(0, 40, 80, 0.3);
        }
        [data-theme="aero"] .translate-submit:hover {
            background: linear-gradient(180deg, #5fc0f5 0%, #1a8fd8 50%, #0070bb 100%);
        }

        /* Listen prompt */
        [data-theme="aero"] .listen-play-btn {
            border-color: var(--accent);
            background: rgba(0, 119, 204, 0.1);
        }
        [data-theme="aero"] .listen-play-btn:hover {
            background: linear-gradient(180deg, #3fadee 0%, #0077cc 100%);
            color: #fff;
        }

        /* Progress ring */
        [data-theme="aero"] .progress-ring-bg {
            stroke: rgba(0, 80, 140, 0.1);
        }

        /* Progress bar */
        [data-theme="aero"] .progress-bar-container {
            background: rgba(0, 80, 140, 0.1);
        }

        /* Settings menu */
        [data-theme="aero"] .settings-menu {
            box-shadow:
                0 8px 32px rgba(0, 60, 120, 0.18),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
        }
        [data-theme="aero"] .settings-item:hover,
        [data-theme="aero"] .settings-toggle:hover {
            background: rgba(0, 119, 204, 0.08);
        }

        /* Modal overlay */
        [data-theme="aero"] .modal-overlay {
            background: rgba(100, 160, 200, 0.4);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
        }

        /* Toggle switch */
        [data-theme="aero"] .toggle-switch {
            background: rgba(0, 60, 120, 0.15);
        }
        [data-theme="aero"] .toggle-switch.on {
            background: var(--accent);
        }

        /* Feedback */
        [data-theme="aero"] .feedback-text.correct {
            background: rgba(46, 158, 62, 0.12);
        }
        [data-theme="aero"] .feedback-text.incorrect {
            background: rgba(214, 51, 51, 0.1);
        }

        /* Word intro sticky area */
        [data-theme="aero"] .word-intro-actions {
            background: none;
        }

        /* Lang indicator */
        [data-theme="aero"] .lang-indicator {
            background: rgba(255, 255, 255, 0.5);
            border: 1px solid rgba(255, 255, 255, 0.7);
        }
        [data-theme="aero"] .lang-indicator:hover {
            background: rgba(255, 255, 255, 0.8);
            border-color: var(--accent);
            color: var(--accent-dim);
        }

        /* Word POS chip */
        [data-theme="aero"] .word-pos {
            background: rgba(0, 119, 204, 0.1);
            color: var(--accent-dim);
        }
        [data-theme="aero"] .word-tense {
            background: rgba(0, 119, 204, 0.12);
        }

        /* Blank in sentence */
        [data-theme="aero"] .target-sentence .blank {
            border-bottom-color: var(--accent);
        }

        /* Ref buttons */
        [data-theme="aero"] .ref-btn {
            border-color: rgba(0, 80, 140, 0.15);
            background: rgba(255, 255, 255, 0.4);
        }
        [data-theme="aero"] .ref-btn:hover {
            background: rgba(255, 255, 255, 0.7);
            border-color: var(--accent);
        }

        /* Known chips */
        [data-theme="aero"] .words-learned-chip {
            background: rgba(0, 119, 204, 0.1);
            border: 1px solid rgba(0, 119, 204, 0.3);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
        }

        /* Settings danger */
        [data-theme="aero"] .settings-item.danger:hover {
            background: rgba(214, 51, 51, 0.08);
        }

        /* Dialogue border */
        [data-theme="aero"] .target-sentence .dialogue-line + .dialogue-line {
            border-top: 1px solid rgba(0, 80, 140, 0.1);
        }

        /* ===== LIGHT THEME ===== */
        /* Minimalist flat light variant of the default dark theme — same
           structure, same accent, just inverted surfaces and text. */
        [data-theme="light"] {
            --bg: #f7f7f8;
            --bg-card: #ffffff;
            --bg-card-hover: #eef0f3;
            --accent: #3b82f6;
            --accent-dim: #2563eb;
            --accent-glow: rgba(59, 130, 246, 0.12);
            --green: #16a34a;
            --orange: #d97706;
            --red: #dc2626;
            --text: #1f2937;
            --text-dim: #667085;
            --text-mid: #4b5563;
            --border: #d9dde3;
            --radius: 16px;
            --radius-sm: 10px;
        }

        /* Keep the flat surfaces of the default theme (no gradients/glass). */
        [data-theme="light"] .lang-indicator {
            border-color: var(--border);
        }
        [data-theme="light"] .settings-menu {
            border-color: var(--border);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
        }
        [data-theme="light"] .modal {
            border-color: var(--border);
        }
        [data-theme="light"] .account-consent-row input[type="checkbox"] {
            border-color: #c3c7cc;
        }
        [data-theme="light"] .dict-search {
            border-color: var(--border);
        }
        [data-theme="light"] .dict-search::placeholder {
            color: var(--text-dim);
        }
        [data-theme="light"] .dict-body {
            scrollbar-color: #c3c7cc transparent;
        }
        [data-theme="light"] .dict-body::-webkit-scrollbar-thumb {
            background: #c3c7cc;
        }
        [data-theme="light"] .dict-body::-webkit-scrollbar-thumb:hover {
            background: #a8adb5;
        }
        [data-theme="light"] .dict-entry {
            border-bottom-color: var(--border);
        }
        [data-theme="light"] .dict-entry-pos {
            background: #eef0f3;
        }
        [data-theme="light"] .btn-danger {
            color: #fff;
        }
        [data-theme="light"] .btn-danger:hover {
            background: #ef4444;
        }
        [data-theme="light"] .lang-card {
            border-color: var(--border);
        }
        [data-theme="light"] .progress-ring-bg {
            stroke: var(--border);
        }
        [data-theme="light"] .btn-secondary {
            border-color: #c2c8d0;
        }
        [data-theme="light"] .word-list-item .word-def {
            color: var(--text-mid);
        }
        [data-theme="light"] .word-list-item .upnext-def {
            color: var(--text-mid);
        }
        [data-theme="light"] .word-list-pagination button {
            border-color: #c2c8d0;
            color: var(--text-mid);
        }
        [data-theme="light"] .word-list-item {
            border-color: var(--border);
        }
        [data-theme="light"] .word-list-pagination button:disabled:hover {
            border-color: var(--border);
        }
        [data-theme="light"] .word-card {
            border-color: var(--border);
        }
        [data-theme="light"] .word-pos {
            background: #eef0f3;
        }
        [data-theme="light"] .ref-btn {
            border-color: var(--border);
        }
        [data-theme="light"] .progress-bar-container {
            background: var(--border);
        }
        [data-theme="light"] .sentence-card,
        [data-theme="light"] .expression-hint-card {
            border-color: var(--border);
        }
        [data-theme="light"] .target-sentence .dialogue-line + .dialogue-line {
            border-top-color: var(--border);
        }
        [data-theme="light"] .choice-btn {
            border-color: var(--border);
        }
        [data-theme="light"] .translate-input {
            border-color: var(--border);
        }
        [data-theme="light"] .translate-input::placeholder {
            color: var(--text-dim);
        }
        [data-theme="light"] .listen-skip-btn {
            border-color: #c3c7cc;
        }

        /* Mobile tweaks */
        @media (max-width: 480px) {
            .container { padding: 16px 14px; }
            .word-target { font-size: calc(1.6rem * var(--text-scale, 1)); }
            .word-card { padding: 20px 18px; }
            .word-card-top { flex-wrap: wrap; }
            .word-card-actions { margin-left: auto; }
            .word-base-reference {
                grid-template-columns: auto minmax(0, 1fr) auto;
                gap: 8px;
                padding: 10px;
            }
            .word-base-definition {
                display: block;
                margin: 1px 0 0;
            }
            .target-sentence { font-size: 1.2rem; }
            .choices { gap: 8px; }
            .choice-btn { padding: 12px; font-size: 1rem; }
        }
    
