/* ============================================================
   GRAMMARWERK — "Ink" Design System
   Monochrome ink-on-paper, light + dark. The single accent
   (soft yellow highlighter) is reserved exclusively for the
   grammatical structure being drilled. Everything else is
   ink, paper, and 1px hairlines. States use contrast, not color.
   ============================================================ */

*  {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

/* ─── Tokens · Dark (default) ─── */
:root {
    --canvas: #121211;
    --surface: #1C1B18;
    --surface-2: #26251F;
    --ink: #F0EFEC;
    --on-ink: #121211;
    --ink-2: #CBCAC4;
    --ink-3: #7A7972;
    --ink-faint: #5F5E58;
    --hairline: #2A2A27;
    --hairline-2: #2A2A27;
    --accent: #F2E59A;          /* highlighter — same in both modes */
    --accent-text: #1A1A17;
    --note-bg: #26240F;
    --note-border: #423D18;
    --note-label: #F2E59A;

    --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    --font-sans: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
    --font-mono: 'Space Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --r-chip: 6px;
    --r-control: 10px;
    --r-card: 13px;
    --r-sheet: 17px;
    --r-pill: 999px;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.22);
    --shadow-float: 0 30px 70px rgba(0, 0, 0, 0.40);

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);
    --ease-arrive: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-screen: 320ms;
    --ease-screen: cubic-bezier(0.4, 0, 0.2, 1);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* ─── Tokens · Light ─── */
[data-theme="light"] {
    --canvas: #EFEFED;
    --surface: #FFFFFF;
    --surface-2: #F4F4F2;
    --ink: #0C0C0D;
    --on-ink: #FFFFFF;
    --ink-2: #56544D;
    --ink-3: #86837B;
    --ink-faint: #A3A39E;
    --hairline: #E4E4E2;
    --hairline-2: #DBD9D2;
    --accent: #F2E59A;
    --accent-text: #1A1A17;
    --note-bg: #FBF6DF;
    --note-border: #EFE6B8;
    --note-label: #0C0C0D;

    --shadow-card: 0 1px 2px rgba(12, 12, 13, 0.05);
    --shadow-float: 0 30px 70px rgba(15, 15, 17, 0.16);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--canvas);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

/* ─── Screens ─── */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-screen) var(--ease-screen),
                visibility 0s linear var(--transition-screen);
    pointer-events: none;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-screen) var(--ease-screen),
                visibility 0s linear 0s;
    pointer-events: auto;
}

#homeScreen,
#authScreen {
    background: var(--canvas);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ─── Animations (subtle; no celebratory motion) ─── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sentenceIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes revealText { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-4px); }
    30% { transform: translateX(3px); }
    45% { transform: translateX(-2px); }
    60% { transform: translateX(1px); }
    75% { transform: translateX(-1px); }
}
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Streamed sentences arrive "from the ether": ease in from an alternating side
   and settle with a gentle overshoot (the --ease-arrive spring also nudges the
   scale just past 1, so each row says "I've arrived" rather than stopping flat). */
@keyframes streamInLeft {
    from { opacity: 0; transform: translateX(-34px) scale(0.97); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes streamInRight {
    from { opacity: 0; transform: translateX(34px) scale(0.97); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes streamInUp {
    from { opacity: 0; transform: translateY(26px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   HOME / AUTH
   ============================================================ */

.home-content {
    padding: 0 1.375rem;
    padding-top: calc(var(--safe-top) + 2rem);
    padding-bottom: calc(var(--safe-bottom) + 4rem);
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
}

.app-header {
    text-align: center;
    margin-bottom: 1.75rem;
    animation: slideUp 0.6s var(--ease-smooth) both;
}

.logo-mark {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    overflow: hidden;
    margin: 0 auto 0.85rem;
    background: var(--ink);
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.logo-img-dark { display: none; }
.logo-img-light { display: block; }
[data-theme="light"] .logo-img-dark { display: block; }
[data-theme="light"] .logo-img-light { display: none; }

.app-tagline {
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 400;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

/* ─── Setup / auth card (flat surface, hairline) ─── */
.setup-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-sheet);
    padding: 1.5rem;
    box-shadow: var(--shadow-card);
    animation: slideUp 0.6s var(--ease-smooth) 0.1s both;
    flex-shrink: 0;
}

.setup-section { margin-bottom: 1.15rem; }
.setup-section:last-of-type { margin-bottom: 1.35rem; }

.setup-label {
    display: block;
    font-family: var(--font-mono);
    font-weight: 700;
    margin-bottom: 0.6rem;
    color: var(--ink-3);
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.13em;
}

/* ─── Pill groups (language / level) ─── */
.pill-group {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: var(--r-control);
    padding: 3px;
    position: relative;
    overflow: hidden;
}

.pill-slider {
    position: absolute;
    top: 3px;
    bottom: 3px;
    border-radius: 8px;
    background: var(--ink);
    transition: transform 0.28s var(--ease-screen),
                width 0.28s var(--ease-screen);
    z-index: 0;
}

.pill {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.6rem 0.35rem;
    background: transparent;
    border: none;
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-weight: 500;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.2s var(--ease-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-height: 44px;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.pill.active {
    color: var(--on-ink);
    font-weight: 600;
}

.pill:active { transform: scale(0.97); }
.pill-flag { font-size: 1.05rem; }

#levelPills .pill {
    padding: 0.6rem 0.25rem;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
}

/* ─── Inputs ─── */
.password-wrapper { position: relative; }
.password-wrapper .auth-input { padding-right: 3rem; }

.password-toggle {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}
.password-toggle:hover { color: var(--ink); }

.eye-icon { width: 20px; height: 20px; pointer-events: none; }
.eye-icon.eye-closed { display: none; }
.password-toggle.visible .eye-icon.eye-open { display: none; }
.password-toggle.visible .eye-icon.eye-closed { display: block; }

.auth-input {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-control);
    color: var(--ink);
    font-size: 0.95rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.18s var(--ease-smooth);
    min-height: 48px;
}
.auth-input:focus { border-color: var(--ink); border-width: 1.5px; }
.auth-input::placeholder { color: var(--ink-faint); }

/* Errors stay monochrome — Ink defines no error color. Contrast, not red. */
.auth-error {
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    border-left: 3px solid var(--ink);
    border-radius: var(--r-control);
    padding: 0.7rem 0.9rem;
    color: var(--ink);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.auth-switch {
    width: 100%;
    background: none;
    border: none;
    color: var(--ink-3);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 0.7rem;
}
.auth-switch strong { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.auth-switch:active { opacity: 0.6; }

.logout-btn {
    display: block;
    margin: 0.75rem auto 0;
    background: none;
    border: none;
    color: var(--ink-3);
    font-size: 0.78rem;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 0.5rem 1rem;
}
.logout-btn:active { opacity: 0.5; }

/* ─── Footer links ─── */
.home-footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.85rem;
}
.footer-link {
    background: none;
    border: none;
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    padding: 0.5rem;
}
.footer-link:active { opacity: 0.5; }
.footer-dot { color: var(--ink-faint); font-size: 0.6rem; }

/* ─── Primary / secondary / quiet buttons ─── */
.start-btn {
    width: 100%;
    padding: 0.95rem 1rem;
    background: var(--ink);
    color: var(--on-ink);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    border: none;
    border-radius: var(--r-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 50px;
    transition: transform 0.15s var(--ease-smooth), opacity 0.15s;
}
.start-btn:active:not(:disabled) { transform: scale(0.98); opacity: 0.9; }
.start-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.secondary-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.7rem;
    background: var(--surface);
    border: 1px solid var(--ink);
    border-radius: var(--r-card);
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: transform 0.15s var(--ease-smooth);
}
.secondary-btn:active { transform: scale(0.97); }
.secondary-btn-icon { font-size: 0.9rem; }

.primary-btn-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}
.primary-btn-row .start-btn { flex: 2; }

/* ─── Google sign-in (brand white, both themes) ─── */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.85rem 0;
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--hairline);
}

.oauth-btn {
    width: 100%;
    min-height: 50px;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    background: #FFFFFF;
    color: #3C4043;
    border: 1px solid #DADCE0;
    border-radius: var(--r-card);
    font-size: 0.92rem;
    font-weight: 500;
    font-family: 'Roboto', var(--font-sans);
    cursor: pointer;
    transition: transform 0.15s var(--ease-smooth), background 0.15s;
}
.oauth-btn:hover { background: #F8F9FA; }
.oauth-btn:active { transform: scale(0.97); }
.oauth-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ─── Utility links (Bookmarks · My Drills) ─── */
.utility-link-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.85rem;
    padding: 0.25rem 0;
}
.utility-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: var(--r-chip);
    transition: color 0.15s;
}
.utility-link:active { color: var(--ink); }
.utility-link-icon { font-size: 0.8rem; }
.utility-dot { color: var(--ink-faint); }

/* ─── Topic selector ─── */
.topic-selector {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    color: var(--ink);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    transition: border-color 0.15s var(--ease-smooth);
}
.topic-selector.chosen,
.topic-selector:has(.chosen) { border-color: var(--ink); border-width: 1.5px; }
.topic-selector:active { background: var(--surface-2); }
.topic-selector.needs-attention {
    animation: shake 0.5s ease;
    border-color: var(--ink);
}
.topic-selector-text {
    color: var(--ink-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-align: left;
}
.topic-selector-text.chosen { color: var(--ink); font-weight: 600; }
.topic-selector-arrow { color: var(--ink-faint); font-size: 1.2rem; margin-left: 0.5rem; flex-shrink: 0; }

/* ─── Practice stat tiles ─── */
.practice-stats {
    margin-top: 1.5rem;
    animation: fadeIn 0.45s var(--ease-smooth) 0.15s both;
}
.practice-stats:empty { display: none; }
.practice-stats-header {
    font-family: var(--font-mono);
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--ink-3);
    margin-bottom: 0.75rem;
}
.practice-stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
/* First tile filled ink; the rest outlined */
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    padding: 0.8rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.stat-tile.filled { background: var(--ink); border-color: var(--ink); }
.stat-tile.filled .stat-tile-value { color: var(--on-ink); }
.stat-tile.filled .stat-tile-label,
.stat-tile.filled .stat-tile-denom { color: var(--on-ink); opacity: 0.7; }
.stat-tile-wide { grid-column: 1 / -1; }
.stat-tile-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-tile-denom { font-size: 0.85rem; font-weight: 500; color: var(--ink-faint); margin-left: 1px; }
.stat-tile-topic { font-family: var(--font-display); font-size: 1rem; font-weight: 600; }
.stat-tile-topic-count { color: var(--ink-3); font-weight: 700; margin-left: 0.25rem; }
.stat-tile-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-3);
}

/* ─── Home activity ─── */
.home-activity {
    margin-top: 1.5rem;
    animation: fadeIn 0.45s var(--ease-smooth) 0.2s both;
}
.home-activity:empty { display: none; }
.home-activity-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.home-activity-title {
    font-family: var(--font-mono);
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--ink-3);
}
.home-saved-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-chip);
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.15s;
}
.home-saved-btn:active { border-color: var(--ink); }

.activity-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    margin-bottom: 6px;
    cursor: pointer;
    transition: border-color 0.15s var(--ease-smooth);
}
.activity-item:active { border-color: var(--ink); }
.activity-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--ink); }
.activity-dot.recent { background: var(--ink); }
.activity-dot.stale { background: var(--ink-3); }
.activity-dot.old { background: var(--ink-faint); }
.activity-info { flex: 1; min-width: 0; }
.activity-topic {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.activity-meta {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-3);
    margin-top: 2px;
}
.activity-count {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--ink-3);
    flex-shrink: 0;
}

.home-stats {
    text-align: center;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: 1.5rem;
    animation: fadeIn 0.5s var(--ease-smooth) 0.3s both;
}

/* ============================================================
   HOME M2 — headline, language swap card, level grid
   ============================================================ */
.home-topbar { display: flex; justify-content: flex-end; align-items: center; padding: 0.25rem 0 0.75rem; }
.home-wordmark { font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }

.setup-head { margin-bottom: 1.5rem; animation: slideUp 0.5s var(--ease-smooth) both; }
.overline { display: block; font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.5rem; }
.display-lg { font-family: var(--font-display); font-size: 2.05rem; font-weight: 600; line-height: 1.04; letter-spacing: -0.03em; color: var(--ink); }

/* M1 sign-in (logo tile uses the accent only here, per the Ink spec) */
.auth-content { padding-top: calc(var(--safe-top) + 2.5rem); }
.auth-logo-img { width: 64px; height: 64px; border-radius: 15px; margin-bottom: 1.5rem; display: block; }
[data-theme="light"] .auth-logo-inner { background: var(--accent); }
.auth-headline { font-size: 2rem; margin-bottom: 0.75rem; max-width: 12ch; }
.auth-subline { font-size: 0.92rem; line-height: 1.5; color: var(--ink-2); margin-bottom: 1.75rem; max-width: 32ch; }

.lang-swap-card {
    display: flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    overflow: hidden;
    margin-bottom: 1.5rem;
}
.lang-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    align-items: flex-start;
    text-align: left;
    padding: 0.85rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    min-height: 66px;
    justify-content: center;
}
.lang-side.selected { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--ink); border-radius: var(--r-card); }
.lang-side-target { align-items: flex-end; text-align: right; }
.lang-side-label { font-family: var(--font-mono); font-size: 0.58rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.lang-side-name { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.lang-swap-btn {
    flex-shrink: 0;
    width: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-left: 1px solid var(--hairline);
    border-right: 1px solid var(--hairline);
    color: var(--ink-2);
    font-size: 1.15rem;
    cursor: pointer;
}
.lang-swap-btn:active { background: var(--surface-2); }

.field-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.field-head .overline { margin-bottom: 0; }
.field-link {
    background: none;
    border: none;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 0.2rem 0;
}
.field-link:active { opacity: 0.6; }

.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 1.5rem; }
.level-pill {
    padding: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    min-height: 48px;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.level-pill:active { border-color: var(--ink); }
.level-pill.active { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }

.home-generate { margin-top: 0.6rem; margin-bottom: 0.6rem; }
.home-selftest { width: 100%; flex: none; margin-bottom: 0.25rem; }

/* Language picker dialog */
.lang-pick-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.lang-pick-opt {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-control);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}
.lang-pick-opt.selected { border: 1.5px solid var(--ink); }
.lang-pick-opt .pill-flag { font-size: 1.1rem; }
.lang-pick-name { flex: 1; }
.lang-pick-hint { font-family: var(--font-mono); font-size: 0.56rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }

/* M4 ceiling explainer (inverted callout; bar stays monochrome) */
.ceiling-title { margin: 0.5rem 0 1.25rem; }
.ceiling-callout { background: var(--ink); border-radius: var(--r-sheet); padding: 1.25rem; margin-bottom: 1.5rem; }
.ceiling-callout-label { display: block; font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--on-ink); opacity: 0.55; margin-bottom: 0.85rem; }
.ceiling-bar { position: relative; height: 42px; background: rgba(128,128,128,0.28); border-radius: 9px; overflow: hidden; margin-bottom: 0.9rem; }
.ceiling-bar-fill { height: 100%; background: var(--on-ink); border-radius: 9px; display: flex; align-items: center; padding: 0 0.8rem; min-width: 42%; transition: width 0.35s var(--ease-smooth); }
.ceiling-bar-tag { font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink); white-space: nowrap; }
.ceiling-callout-text { font-size: 0.88rem; line-height: 1.55; color: var(--on-ink); opacity: 0.82; }
.ceiling-callout-text strong { opacity: 1; font-weight: 700; }
.ceiling-levels { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.5rem; }
.ceiling-level-row { display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-start; text-align: left; padding: 0.9rem 1.1rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-card); cursor: pointer; position: relative; }
.ceiling-level-row.selected { background: var(--ink); border-color: var(--ink); }
.ceiling-level-name { font-family: var(--font-display); font-size: 1rem; font-weight: 600; color: var(--ink); }
.ceiling-level-desc { font-size: 0.8rem; color: var(--ink-3); }
.ceiling-level-row.selected .ceiling-level-name { color: var(--on-ink); }
.ceiling-level-row.selected .ceiling-level-desc { color: var(--on-ink); opacity: 0.7; }
.ceiling-level-row.selected::after { content: '✓'; position: absolute; right: 1.1rem; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; border-radius: 50%; background: var(--on-ink); color: var(--ink); font-size: 0.7rem; display: flex; align-items: center; justify-content: center; }

/* ============================================================
   MODALS (full-screen slide-in)
   ============================================================ */
.modal {
    position: fixed;
    inset: 0;
    background: var(--canvas);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.32s var(--ease-screen), opacity 0.22s ease;
    visibility: hidden;
    pointer-events: none;
}
.modal.open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    padding-top: calc(var(--safe-top) + 0.75rem);
    background: var(--canvas);
    border-bottom: 1px solid var(--hairline);
    min-height: 56px;
    flex-shrink: 0;
}
.modal-back {
    background: none;
    border: none;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem;
    min-width: 70px;
    text-align: left;
}
.modal-back:active { opacity: 0.6; }
.modal-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    text-align: center;
}
.modal-spacer { min-width: 70px; }
.modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 1rem;
    padding-bottom: calc(var(--safe-bottom) + 1rem);
}

/* ============================================================
   DIALOG PATTERN (welcome / name-drill / reset / tour intro)
   ============================================================ */
.welcome-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(12, 12, 13, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
.welcome-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }
.welcome-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 20px;
    padding: 1.75rem 1.5rem;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-float);
    transform: scale(0.95);
    transition: transform 0.22s var(--ease-smooth);
}
.welcome-overlay.open .welcome-card { transform: scale(1); }
.welcome-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin-bottom: 0.7rem;
}
.welcome-body {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--ink-2);
    margin-bottom: 1.4rem;
}
.welcome-actions { display: flex; flex-direction: column; gap: 0.6rem; }
.welcome-btn {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: var(--r-control);
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.welcome-btn-primary { background: var(--ink); color: var(--on-ink); border: none; }
.welcome-btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--hairline); }
.welcome-btn:active { opacity: 0.8; }
.welcome-lang-picker { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.welcome-lang-btn {
    flex: 1;
    padding: 0.5rem 0;
    border-radius: var(--r-control);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: var(--surface);
    color: var(--ink-3);
    border: 1px solid var(--hairline);
    cursor: pointer;
}
.welcome-lang-btn.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* ─── Onboarding tour spotlight ─── */
.tour-backdrop { position: fixed; inset: 0; z-index: 300; display: none; }
.tour-backdrop.open { display: block; }
.tour-spotlight {
    position: fixed;
    z-index: 301;
    border-radius: var(--r-card);
    box-shadow: 0 0 0 9999px rgba(12, 12, 13, 0.55), 0 0 0 3px var(--ink);
    pointer-events: none;
    display: none;
    transition: top 0.25s var(--ease-smooth), left 0.25s var(--ease-smooth),
                width 0.25s var(--ease-smooth), height 0.25s var(--ease-smooth);
}
.tour-spotlight.open { display: block; }
.tour-tooltip {
    position: fixed;
    z-index: 302;
    width: calc(100vw - 2.5rem);
    max-width: 320px;
    background: var(--ink);
    border-radius: var(--r-card);
    padding: 1rem 1.1rem 0.85rem;
    box-shadow: var(--shadow-float);
    display: none;
}
.tour-tooltip.open { display: block; }
.tour-tooltip-title { font-family: var(--font-display); font-size: 1rem; font-weight: 600; color: var(--on-ink); margin-bottom: 0.4rem; }
.tour-tooltip-body { font-size: 0.88rem; line-height: 1.5; color: var(--on-ink); opacity: 0.78; margin-bottom: 0.9rem; }
.tour-tooltip-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.tour-counter { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--on-ink); opacity: 0.6; font-variant-numeric: tabular-nums; }
.tour-tooltip-actions { display: flex; gap: 0.5rem; }
.tour-btn { padding: 0.45rem 0.9rem; border-radius: 8px; font-family: var(--font-display); font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.tour-btn-primary { background: var(--on-ink); color: var(--ink); border: none; }
.tour-btn-ghost { background: transparent; color: var(--on-ink); border: 1px solid rgba(255,255,255,0.25); }
.tour-btn:active { opacity: 0.75; }

/* ============================================================
   TOPIC PICKER
   ============================================================ */
.topic-group { margin-bottom: 1.5rem; }
.topic-group-label {
    font-family: var(--font-mono);
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-3);
    padding: 0.5rem 0;
    margin-bottom: 0.25rem;
}
.topic-option {
    width: 100%;
    padding: 1.05rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    margin-bottom: 10px;
    transition: border-color 0.15s var(--ease-smooth);
    min-height: 56px;
    display: flex;
    align-items: center;
    position: relative;
    flex-wrap: wrap;
}
.topic-option::after {
    content: '›';
    margin-left: auto;
    color: var(--ink-faint);
    font-size: 1.1rem;
    padding-left: 0.5rem;
}
.topic-option:active { border-color: var(--ink); }
.topic-option.selected { border-color: var(--ink); border-width: 1.5px; }
.topic-option.selected::after {
    content: '✓';
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--on-ink);
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topic-option.disabled { opacity: 0.35; pointer-events: none; }
.topic-option.mix-option { border: 1.5px solid var(--ink); font-weight: 600; margin-bottom: 1rem; }

/* M3 topic browser: headline + search */
.picker-title { margin: 0.25rem 0 1rem; }
.picker-search { position: relative; margin-bottom: 1.5rem; }
.picker-search-icon { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--ink-faint); font-size: 1rem; pointer-events: none; }
.picker-search-input { width: 100%; padding: 0.85rem 1rem 0.85rem 2.4rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-control); color: var(--ink); font-family: var(--font-sans); font-size: 0.92rem; outline: none; transition: border-color 0.15s; }
.picker-search-input:focus { border-color: var(--ink); border-width: 1.5px; }
.picker-search-input::placeholder { color: var(--ink-faint); }

.topic-stat {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.3rem;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.topic-stat-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--ink); }
.topic-stat-dot.active { background: var(--ink); }
.topic-stat-dot.stale { background: var(--ink-3); }
.topic-stat-dot.new { background: var(--ink-faint); }

/* ============================================================
   INFO PAGE
   ============================================================ */
.info-lang-toggle {
    background: var(--surface);
    border: 1px solid var(--hairline);
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.35rem 0.7rem;
    border-radius: var(--r-chip);
    cursor: pointer;
    min-width: 36px;
    text-align: center;
    letter-spacing: 0.06em;
}
.info-lang-toggle:active { opacity: 0.7; }
.info-body { padding: 0.75rem 1.35rem 3rem; }
.info-card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    padding: 1.35rem;
    margin-bottom: 1rem;
}
.info-card-icon { font-size: 1.3rem; margin-bottom: 0.5rem; display: block; line-height: 1; }
.info-card h3 { font-family: var(--font-display); font-size: 1rem; font-weight: 600; color: var(--ink); margin-bottom: 0.65rem; }
.info-card p { font-size: 0.85rem; color: var(--ink-2); line-height: 1.65; margin-bottom: 0.4rem; }
.info-card p:last-child { margin-bottom: 0; }
.info-tip {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0;
}
.info-tip:not(:last-child) { border-bottom: 1px solid var(--hairline); }
.info-tip-num {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--on-ink);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}
.info-tip-text { flex: 1; font-size: 0.85rem; color: var(--ink-2); line-height: 1.6; }
.info-tip-text strong { color: var(--ink); display: block; margin-bottom: 2px; font-size: 0.88rem; font-weight: 600; }
.info-level-row { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.65rem 0; }
.info-level-row:not(:last-child) { border-bottom: 1px solid var(--hairline); }
.info-level-badge {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: var(--surface-2);
    border: 1px solid var(--hairline);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.3rem 0.55rem 0.35rem;
    border-radius: var(--r-chip);
    white-space: nowrap;
    margin-top: 0.1rem;
    min-width: 90px;
    text-align: center;
}
.info-level-label { font-size: 0.56rem; font-weight: 400; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; }
.info-level-desc { font-size: 0.85rem; color: var(--ink-2); line-height: 1.5; }
.info-version { font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-faint); margin-top: 0.6rem; letter-spacing: 0.04em; }
.info-link-btn {
    display: block;
    width: 100%;
    padding: 0.85rem;
    margin-top: 0.75rem;
    border-radius: var(--r-control);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--hairline);
    color: var(--ink-2);
}
.info-link-btn:active { opacity: 0.7; }
.info-delete-btn { color: var(--ink); border-color: var(--ink); }

/* ============================================================
   DRILL SCREEN
   ============================================================ */
#drillScreen { background: var(--canvas); }

.drill-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    padding-top: calc(var(--safe-top) + 0.5rem);
    background: var(--canvas);
    border-bottom: 1px solid var(--hairline);
    min-height: 52px;
    flex-shrink: 0;
    gap: 0.5rem;
}
.topbar-btn {
    background: none;
    border: none;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topbar-btn:active { background: var(--surface-2); }
.drill-progress { flex: 1; text-align: center; overflow: hidden; }
.drill-progress-text {
    font-family: var(--font-display);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* explainer + tags row */
.drill-instructions-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.15rem;
    cursor: pointer;
    flex-shrink: 0;
    border-bottom: 1px solid var(--hairline);
}
.instructions-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--on-ink);
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.instructions-toggle-label { font-size: 0.85rem; color: var(--ink-2); font-weight: 500; }
.drill-instructions-toggle.open .instructions-toggle-label { color: var(--ink); }
.drill-tags { margin-left: auto; display: flex; gap: 0.4rem; align-items: center; }
.drill-tag {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.25rem 0.45rem;
    border-radius: var(--r-chip);
    background: var(--surface-2);
    color: var(--ink-2);
    white-space: nowrap;
}
.drill-tag.level { background: var(--ink); color: var(--on-ink); }

.drill-instructions-panel {
    display: none;
    padding: 0.85rem 1.15rem;
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
}
.drill-instructions-panel.open { display: block; }
.instructions-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.instructions-panel-title { font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); }
.instructions-close-btn { background: none; border: none; color: var(--ink); font-size: 0.82rem; font-weight: 600; cursor: pointer; padding: 0.25rem 0.5rem; }
.drill-instructions-panel p { font-size: 0.85rem; color: var(--ink-2); line-height: 1.55; margin: 0; }

.drill-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 1rem;
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* ─── Sentence row (hero) ─── */
.sentence-item {
    padding: 1rem 2.4rem 1rem 1.1rem;
    margin-bottom: 8px;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    display: grid;
    grid-template-columns: 26px 1fr;
    align-items: start;
    gap: 0.6rem;
    transition: border-color 0.2s var(--ease-smooth), box-shadow 0.2s var(--ease-smooth);
    cursor: pointer;
    min-height: 54px;
    position: relative;
    opacity: 0;
    transform: translateY(5px);
    animation: sentenceIn 0.45s var(--ease-smooth) both;
}
.sentence-item:active { background: var(--surface-2); }
.sentence-item.revealed { border-color: var(--ink); box-shadow: var(--shadow-card); }

/* Streamed arrival: alternating origins, soft overshoot-and-settle. Two-class
   specificity overrides the base .sentence-item sentenceIn fade above. */
.sentence-item.stream-in-left  { animation: streamInLeft  0.55s var(--ease-arrive) both; }
.sentence-item.stream-in-right { animation: streamInRight 0.55s var(--ease-arrive) both; }
.sentence-item.stream-in-up    { animation: streamInUp    0.55s var(--ease-arrive) both; }

/* Inline retry shown if a stream drops after some sentences already landed. */
.error.stream-partial { margin-top: 0.5rem; padding: 1.1rem 1.5rem; }

/* Respect reduced-motion: fade only, no slide, no lingering offset. */
@media (prefers-reduced-motion: reduce) {
    .sentence-item,
    .sentence-item.stream-in-left,
    .sentence-item.stream-in-right,
    .sentence-item.stream-in-up {
        animation: fadeIn 0.2s var(--ease-smooth) both;
        transform: none;
    }
}

.sentence-number {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
    font-weight: 700;
    font-size: 0.7rem;
    padding-top: 4px;
}
.sentence-item.revealed .sentence-number { color: var(--ink-2); }

.sentence-content { display: flex; flex-direction: column; gap: 0.4rem; }
.target-text {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.35;
}
/* The single accent rule — only the drilled structure is highlighted. */
.target-text .highlight,
.highlight {
    background: var(--accent);
    color: var(--accent-text);
    padding: 0 4px;
    border-radius: 2px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.base-text {
    font-size: 0.88rem;
    color: var(--ink-2);
    font-style: italic;
    display: none;
    line-height: 1.45;
    padding-top: 0.5rem;
    border-top: 1px solid var(--hairline);
    margin-top: 0.15rem;
}
.sentence-item.revealed .base-text { display: block; animation: revealText 0.28s var(--ease-smooth) both; }

/* Per-sentence "tricky for" note card */
.sentence-note {
    display: none;
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    border-radius: var(--r-control);
    padding: 0.65rem 0.8rem;
    margin-top: 0.55rem;
}
.sentence-item.revealed .sentence-note { display: block; animation: revealText 0.28s var(--ease-smooth) both; }
.sentence-note-label {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--note-label);
    margin-bottom: 0.3rem;
}
.sentence-note-text { font-size: 0.82rem; color: var(--ink-2); line-height: 1.5; }

/* Flipped mode */
.drill-output-flipped .sentence-item .target-text { display: none; }
.drill-output-flipped .sentence-item .base-text {
    display: block;
    font-style: normal;
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}
.drill-output-flipped .sentence-item.revealed .target-text {
    display: block;
    font-size: 0.9rem;
    color: var(--ink-2);
    font-style: italic;
    font-weight: 500;
}
.drill-output-flipped .sentence-item.revealed .base-text { display: block; }
.drill-output-flipped .sentence-content { flex-direction: column-reverse; }

/* ─── Bottom bar ─── */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem 1.15rem;
    padding-bottom: calc(var(--safe-bottom) + 0.85rem);
    background: var(--canvas);
    border-top: 1px solid var(--hairline);
    z-index: 50;
}
.bottom-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--r-card);
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: border-color 0.15s var(--ease-smooth);
}
.bottom-btn[data-action="save-drill"], .bottom-btn.primary-bottom { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.bottom-btn:active { transform: scale(0.98); }
.bottom-btn-icon { font-size: 1.05rem; }
.bottom-btn.drill-saved { opacity: 0.55; pointer-events: none; }

/* ─── Loading / error ─── */
.loading { text-align: center; padding: 5rem 2.5rem; color: var(--ink-2); animation: fadeIn 0.4s var(--ease-smooth) both; }
.loading-message { font-size: 0.95rem; font-weight: 500; margin-bottom: 1.5rem; color: var(--ink); }
.loading-bar-track { width: 100%; max-width: 220px; height: 3px; background: var(--surface-2); border-radius: 2px; margin: 0 auto; overflow: hidden; }
.loading-bar-fill { height: 100%; background: var(--ink); border-radius: 2px; width: 0%; animation: loadingFill 15s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
@keyframes loadingFill { 0% { width: 0%; } 15% { width: 25%; } 40% { width: 50%; } 65% { width: 70%; } 85% { width: 85%; } 100% { width: 95%; } }
.loading-subtext { font-family: var(--font-mono); font-size: 0.66rem; color: var(--ink-faint); margin-top: 1.25rem; letter-spacing: 0.04em; }

.error {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-left: 3px solid var(--ink);
    border-radius: var(--r-card);
    padding: 1.5rem;
    margin: 1.5rem 1rem;
    color: var(--ink-2);
    font-size: 0.88rem;
    text-align: center;
    line-height: 1.6;
}
.error-icon { font-size: 1.8rem; margin-bottom: 0.75rem; color: var(--ink); }
.error-message { margin-bottom: 1.25rem; color: var(--ink); }
.error-retry {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.5rem;
    background: var(--ink);
    border: none;
    border-radius: var(--r-control);
    color: var(--on-ink);
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s var(--ease-smooth);
}
.error-retry:active { opacity: 0.85; }

/* ─── Bookmark star ─── */
.bookmark-btn {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 0.95rem;
    color: var(--ink-faint);
    cursor: pointer;
    opacity: 0.6;
    transition: color 0.2s, opacity 0.2s;
    padding: 0;
    z-index: 2;
}
.sentence-item:hover .bookmark-btn,
.sentence-item:active .bookmark-btn,
.sentence-item .bookmark-btn.bookmarked { opacity: 1; }
.bookmark-btn.bookmarked { color: var(--ink); }

/* ─── Saved sentences ─── */
.saved-empty { text-align: center; padding: 3rem 2rem; color: var(--ink-3); font-size: 0.88rem; line-height: 1.6; }
.saved-empty-icon { font-size: 2rem; margin-bottom: 0.75rem; opacity: 0.5; }
.saved-topic-group { margin-bottom: 1.25rem; }
.saved-topic-label { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); padding: 0.5rem 0; }
.saved-sentence { padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-card); margin-bottom: 6px; position: relative; }
.saved-sentence .target-text { font-size: 0.95rem; margin-bottom: 0.3rem; }
.saved-sentence .base-text { display: block; font-size: 0.82rem; color: var(--ink-2); font-style: italic; border-top: none; padding-top: 0; margin-top: 0; }
.saved-remove { position: absolute; top: 0.6rem; right: 0.6rem; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; background: none; border: none; font-size: 0.85rem; color: var(--ink-faint); cursor: pointer; opacity: 0.6; transition: opacity 0.15s; }
.saved-remove:active { opacity: 1; }

/* ─── Saved drills ─── */
.saved-drill-item { display: flex; align-items: center; padding: 1rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-card); margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s var(--ease-smooth); }
.saved-drill-item:active { border-color: var(--ink); }
.saved-drill-info { flex: 1; min-width: 0; }
.saved-drill-name { font-family: var(--font-display); font-size: 0.95rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-drill-meta { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); margin-top: 0.25rem; }
.saved-drill-delete { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; background: none; border: none; font-size: 0.85rem; color: var(--ink-faint); cursor: pointer; opacity: 0.6; transition: opacity 0.15s; flex-shrink: 0; margin-left: 0.5rem; }
.saved-drill-delete:active { opacity: 1; }

/* ============================================================
   SELF-TEST — "completion is fill, not color" (no red/green)
   ============================================================ */
.test-content { flex: 1; display: flex; flex-direction: column; padding: 0.85rem 1rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.test-progress-bar { display: flex; gap: 4px; padding: 0.5rem 0 1.25rem; }
.test-progress-pip { flex: 1; height: 4px; border-radius: 2px; background: var(--hairline); transition: background 0.3s ease, box-shadow 0.3s ease; }
.test-progress-pip.done-correct { background: var(--ink); }
.test-progress-pip.done-wrong { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-3); }
.test-progress-pip.current { background: var(--ink); box-shadow: 0 0 0 1.5px var(--canvas), 0 0 0 3px var(--ink); }

.test-prompt-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-sheet); padding: 1.5rem 1.25rem; margin-bottom: 1.25rem; text-align: center; }
.test-prompt-label { font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin-bottom: 0.75rem; }
.test-prompt-text { font-family: var(--font-sans); font-size: 1.25rem; font-weight: 600; line-height: 1.4; color: var(--ink); }

.test-input-area { margin-bottom: 1rem; }
.test-input { width: 100%; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-control); color: var(--ink); font-size: 0.95rem; font-family: var(--font-sans); font-weight: 400; line-height: 1.5; outline: none; transition: border-color 0.18s ease; box-sizing: border-box; }
.test-input:focus { border-color: var(--ink); border-width: 1.5px; }
.test-input::placeholder { color: var(--ink-faint); }
.test-check-btn { width: 100%; padding: 0.85rem; background: var(--ink); border: none; border-radius: var(--r-control); color: var(--on-ink); font-family: var(--font-display); font-size: 0.9rem; font-weight: 700; cursor: pointer; min-height: 48px; margin-top: 0.6rem; transition: opacity 0.15s ease; }
.test-check-btn:active { opacity: 0.85; }
.test-check-btn:disabled { opacity: 0.4; cursor: default; }

.test-comparison { animation: fadeSlideUp 0.32s ease forwards; }
.test-comparison-row { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-control); padding: 1rem 1.15rem; margin-bottom: 0.6rem; }
.test-comparison-label { font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.4rem; }
.test-comparison-text { font-size: 0.95rem; font-weight: 400; line-height: 1.5; color: var(--ink); }
.test-comparison-row.original { background: var(--surface-2); }
.test-comparison-row.correct { border: 1.5px solid var(--ink); }
.test-comparison-row.correct .test-comparison-label::before {
    content: '✓';
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--on-ink);
    font-size: 0.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.test-judge-row { display: flex; gap: 0.6rem; margin-top: 1rem; }
.test-judge-btn { flex: 1; padding: 0.85rem; border: 1px solid var(--hairline); border-radius: var(--r-control); font-family: var(--font-display); font-size: 0.88rem; font-weight: 600; cursor: pointer; min-height: 48px; transition: transform 0.15s ease; background: var(--surface); color: var(--ink); }
.test-judge-btn:active { transform: scale(0.97); }
.test-judge-btn.got-it { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.test-judge-btn.missed-it { background: var(--surface); border: 1.5px solid var(--ink-3); color: var(--ink-2); }

.test-summary { text-align: center; padding: 2rem 0.5rem 1rem; animation: fadeSlideUp 0.4s ease forwards; }
.test-summary-score { font-family: var(--font-display); font-size: 3rem; font-weight: 600; letter-spacing: -0.03em; color: var(--ink); line-height: 1.1; margin-bottom: 0.25rem; }
.test-summary-score .denom { color: var(--ink-faint); }
.test-summary-label { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin-bottom: 2rem; }
.test-summary-missed { text-align: left; margin-bottom: 1.5rem; }
.test-summary-missed-title { font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); margin-bottom: 0.6rem; }
.test-missed-item { background: var(--surface); border: 1px solid var(--hairline); border-left: 3px solid var(--ink); border-radius: var(--r-control); padding: 0.85rem 1rem; margin-bottom: 0.5rem; }
.test-missed-item .target-text { font-size: 0.92rem; font-weight: 600; color: var(--ink); margin-bottom: 0.2rem; }
.test-missed-item .base-text { display: block !important; font-size: 0.8rem; color: var(--ink-2); font-style: italic; border-top: none; padding-top: 0; margin-top: 0; }
.test-summary-actions { display: flex; gap: 0.6rem; margin-top: 1.5rem; }
.test-summary-btn { flex: 1; padding: 0.85rem; border: 1px solid var(--ink); border-radius: var(--r-control); font-family: var(--font-display); font-size: 0.88rem; font-weight: 600; cursor: pointer; min-height: 48px; transition: transform 0.15s ease; background: var(--surface); color: var(--ink); }
.test-summary-btn:active { transform: scale(0.97); }
.test-summary-btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }

.test-loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; }
.test-loading-message { font-size: 0.9rem; color: var(--ink-2); }

/* ============================================================
   RESPONSIVE — tablets
   ============================================================ */
@media (min-width: 768px) {
    .home-content { max-width: 480px; margin: 0 auto; padding-top: 4rem; }
    .setup-card { padding: 2rem; }
    .drill-list { max-width: 700px; width: 100%; margin: 0 auto; }
    .bottom-bar { max-width: 700px; margin: 0 auto; }
    .modal-body { max-width: 540px; margin: 0 auto; }
    .test-content { max-width: 540px; margin: 0 auto; width: 100%; }
}

/* ============================================================
   RESPONSIVE — large screens (Chromebook / desktop)
   Ink desktop blueprints are refined in Phase 4.
   ============================================================ */
@media (min-width: 1024px) {
    .home-content { max-width: 560px; width: 100%; margin: 0 auto; }
    .drill-list {
        max-width: 1000px;
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 0.75rem;
        align-content: start;
        align-items: start;
    }
    .drill-list > :not(.sentence-item) { grid-column: 1 / -1; }
    .bottom-bar { max-width: 1000px; }
    .target-text { font-size: 1.06rem; }

    #topicPicker { overflow-y: auto; }
    #topicPicker .modal-header { position: sticky; top: 0; z-index: 1; }
    #topicPickerBody { flex: none; overflow: visible; width: 100%; max-width: 900px; columns: 2; column-gap: 2rem; }
    #topicPickerBody .topic-group { break-inside: avoid; }
    .picker-title, .picker-search { column-span: all; }
    .modal-body { max-width: 600px; }
    .info-body { max-width: 700px; }
    .test-content { max-width: 600px; }
}

/* ============================================================
   DESKTOP INK BLUEPRINTS (D1–D4)
   Faithful to the Claude Design handoff desktop frames. Placed
   after the interim 1024px block above and deliberately
   supersedes it where the two overlap.
   ============================================================ */

/* Mobile defaults — desktop-only scaffolding stays hidden / transparent. */
.auth-aside { display: none; }
.auth-form-heading { display: none; }
.home-config, .home-action { display: contents; }
.home-subline { display: none; }
.drill-sidebar { display: contents; }
.picker-nav { display: none; }
.picker-main { display: contents; }

@media (min-width: 1024px) {
    /* ---------- D1 · Split sign-in ---------- */
    #authScreen { flex-direction: row; overflow: hidden; }

    .auth-aside {
        display: flex;
        flex-direction: column;
        width: 46%;
        flex: none;
        padding: 54px;
        background: #000;                 /* always-dark hero panel */
        color: #F0EFEC;
    }
    [data-theme="light"] .auth-aside { background: #0C0C0D; }
    .auth-aside .auth-logo-img { margin-bottom: 0; }
    .auth-aside-foot { margin-top: auto; }
    .auth-aside-headline {
        font-family: var(--font-display);
        font-size: 2.6rem;
        line-height: 1.05;
        font-weight: 600;
        letter-spacing: -0.03em;
        color: #F0EFEC;
    }
    .auth-aside-subline {
        font-size: 1rem;
        line-height: 1.55;
        color: var(--ink-3);
        margin-top: 1.1rem;
        max-width: 21rem;
    }
    .auth-aside-chips { display: flex; gap: 0.5rem; margin-top: 1.6rem; }
    .auth-chip {
        font-family: var(--font-mono);
        font-size: 0.68rem;
        font-weight: 700;
        letter-spacing: 0.06em;
        color: #86857F;
        border: 1px solid #2A2A27;
        padding: 6px 10px;
        border-radius: 7px;
    }

    /* Right panel = the existing form column */
    #authScreen .auth-content {
        width: 54%;
        max-width: none;
        flex: 1;
        margin: 0;
        padding: 3.4rem 3.75rem;
        justify-content: center;
        background: var(--surface);
        overflow-y: auto;
    }
    .auth-content .auth-logo-mobile,
    .auth-content .auth-headline,
    .auth-content .auth-subline { display: none; }
    .auth-form-heading {
        display: block;
        font-family: var(--font-display);
        font-size: 1.6rem;
        font-weight: 600;
        letter-spacing: -0.02em;
        color: var(--ink);
        margin-bottom: 1.6rem;
    }
    #authScreen .auth-form { max-width: 380px; }
    #authScreen .home-footer-links {
        max-width: 380px;
        justify-content: flex-start;
        margin-top: 1.25rem;
    }

    /* ---------- D2 · Two-column home / new drill ---------- */
    #homeScreen .home-content {
        max-width: 1040px;
        width: 100%;
        margin: 0 auto;
        padding: 48px 64px 64px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 380px;
        column-gap: 48px;
        row-gap: 2rem;
        align-items: start;
    }
    .home-topbar { grid-column: 1 / -1; }

    .home-config {
        display: flex;
        flex-direction: column;
        grid-column: 1;
        min-width: 0;
    }
    .home-config .setup-head { margin-bottom: 1.1rem; }
    .home-subline {
        display: block;
        font-size: 1rem;
        line-height: 1.55;
        color: var(--ink-3);
        max-width: 24rem;
        margin: 0 0 1.75rem;
    }
    .home-config .lang-swap-card,
    .home-config .level-grid,
    .home-config .field-head { max-width: 27.5rem; }
    .home-config .level-grid { grid-template-columns: repeat(4, 1fr); }

    .home-action {
        display: flex;
        flex-direction: column;
        grid-column: 2;
        background: var(--surface);
        border: 1px solid var(--hairline);
        border-radius: 18px;
        padding: 1.6rem;
        box-shadow: 0 1px 2px rgba(12, 12, 13, 0.04);
    }
    .home-action .home-generate { margin-top: 0.4rem; }
    .home-action .home-selftest { margin-bottom: 0; }

    /* Practice dashboard + footer span full width below the two columns. */
    #homeScreen .utility-link-row,
    #homeScreen .practice-stats,
    #homeScreen .home-activity,
    #homeScreen .home-footer-links { grid-column: 1 / -1; }
    #homeScreen .practice-stats,
    #homeScreen .home-activity { max-width: 640px; }

    /* ---------- D4 · Sidebar drill ---------- */
    #drillScreen { flex-direction: row; }
    .drill-sidebar {
        display: flex;
        flex-direction: column;
        width: 300px;
        flex: none;
        background: var(--surface-2);
        border-right: 1px solid var(--hairline);
        overflow-y: auto;
    }

    /* Topbar becomes the sidebar header: back / flip on one row, big title below. */
    .drill-sidebar .drill-topbar {
        background: transparent;
        border-bottom: none;
        flex-wrap: wrap;
        padding: 1.5rem 1.25rem 0;
        min-height: 0;
    }
    .drill-sidebar .drill-progress {
        order: 3;
        flex: 1 0 100%;
        text-align: left;
        margin-top: 0.85rem;
    }
    .drill-sidebar .drill-progress-text {
        font-size: 1.5rem;
        line-height: 1.1;
        letter-spacing: -0.02em;
        white-space: normal;
    }

    /* Explainer is always shown as a card; its toggle is a static header. */
    .drill-sidebar .drill-instructions-toggle {
        flex-wrap: wrap;
        border-bottom: none;
        padding: 1.25rem 1.25rem 0.6rem;
        cursor: default;
    }
    .drill-sidebar .drill-tags {
        margin-left: 0;
        width: 100%;
        margin-top: 0.6rem;
    }
    .drill-sidebar .drill-instructions-panel {
        display: block;
        background: var(--surface);
        border: 1px solid var(--hairline);
        border-radius: var(--r-card);
        margin: 0 1.25rem;
        padding: 0.9rem 1rem;
    }
    .drill-sidebar .instructions-close-btn { display: none; }

    /* Action bar -> sidebar foot, stacked full width. */
    .drill-sidebar .bottom-bar {
        position: static;
        flex-direction: column;
        margin-top: auto;
        gap: 0.6rem;
        padding: 1.25rem;
        background: transparent;
        border-top: none;
    }
    .drill-sidebar .bottom-btn { width: 100%; }

    /* Main column = single-column sentence list, larger type. */
    #drillScreen #drillOutput.drill-list {
        flex: 1;
        display: block;
        max-width: none;
        padding: 1.875rem 2.375rem 2.5rem;
    }
    #drillScreen .target-text { font-size: 1.125rem; }

    /* ---------- D3 · Sidebar topic browser ---------- */
    #topicPicker { overflow: hidden; }
    #topicPickerBody {
        display: flex;
        /* Fill the modal's remaining height and allow shrinking so the inner
           .picker-main is the scroll container. Resets `flex: none` that leaks
           in from the <=768px tablet rule -- without this the body grows to its
           full content height, overflows #topicPicker (overflow:hidden), and can
           only be moved by the category scroll-jump, never scrolled back up. */
        flex: 1;
        min-height: 0;
        align-items: stretch;
        gap: 0;
        padding: 0;
        max-width: none;
        columns: auto;
        overflow: hidden;
    }
    .picker-nav {
        display: flex;
        flex-direction: column;
        gap: 3px;
        width: 240px;
        flex: none;
        background: var(--surface-2);
        border-right: 1px solid var(--hairline);
        padding: 1.75rem 1.25rem;
        overflow-y: auto;
    }
    .picker-nav-item {
        text-align: left;
        padding: 0.6rem 0.8rem;
        border: none;
        background: none;
        border-radius: 9px;
        font-family: var(--font-sans);
        font-size: 0.88rem;
        font-weight: 600;
        color: var(--ink-2);
        cursor: pointer;
        transition: background 0.15s, color 0.15s;
    }
    .picker-nav-item:hover { color: var(--ink); }
    .picker-nav-item.active { background: var(--ink); color: var(--on-ink); }

    .picker-main {
        display: block;
        flex: 1;
        min-width: 0;
        padding: 2rem 2.25rem 2.5rem;
        overflow-y: auto;
    }
    .picker-main .picker-title { margin-top: 0; }
    .picker-main .topic-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        align-items: start;
        scroll-margin-top: 1rem;
        margin-bottom: 2rem;
    }
    .picker-main .topic-group-label { grid-column: 1 / -1; margin-bottom: 0; }
    .picker-main .topic-option { margin-bottom: 0; }
    .picker-main .topic-option.mix-option { margin-bottom: 1rem; }
}
