/* ---------- Design tokens ----------
 * Light values live on bare `:root`. Dark values are declared twice: once
 * behind `prefers-color-scheme` (skipped when the user forced light) and once
 * behind `[data-theme="dark"]`, so the in-app toggle wins in both directions.
 * No color literal belongs anywhere else in the stylesheets. */
:root {
    color-scheme: light;

    /* Surfaces & text */
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-sunken: #f1f5f9;
    --surface-inverse: #0f172a;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #1e293b;
    --text-strong: #0f172a;
    --text-soft: #475569;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;

    /* Accent */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-contrast: #ffffff;
    --accent-text: #1e40af;
    --accent-bg: #eff6ff;
    --accent-bg-strong: #dbeafe;
    --accent-border: #bfdbfe;
    --accent-soft: rgba(37, 99, 235, 0.12);

    /* Success */
    --success: #16a34a;
    --success-text: #166534;
    --success-bg: #f0fdf4;
    --success-bg-strong: #dcfce7;
    --success-border: #bbf7d0;

    /* Danger */
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-text: #991b1b;
    --danger-bg: #fef2f2;
    --danger-bg-strong: #fee2e2;
    --danger-border: #fecaca;
    --danger-glow: rgba(220, 38, 38, 0.35);
    --danger-glow-fade: rgba(220, 38, 38, 0);

    /* Warning */
    --warning: #d97706;
    --warning-text: #92400e;
    --warning-bg: #fffbeb;
    --warning-bg-strong: #fef3c7;
    --warning-border: #fcd34d;
    --warning-glow: rgba(245, 158, 11, 0.35);

    /* Always read on top of a saturated fill (accent bubble, inverse panel),
     * so these stay identical in both themes. */
    --on-solid: #ffffff;
    --on-accent-soft: rgba(255, 255, 255, 0.85);
    --on-accent-faint: rgba(255, 255, 255, 0.25);
    --on-inverse: #f8fafc;
    --on-inverse-faint: rgba(255, 255, 255, 0.1);
    --success-bright: #4ade80;
    --warning-bright: #fbbf24;
    --danger-bright: #f87171;

    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-soft: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-strong: 0 4px 12px rgba(15, 23, 42, 0.25);

    /* Liquid glass. Reserved for floating chrome -- header, tab bar, grading
     * rail, mic, composer -- laid over the accent halo. Page content stays
     * opaque on --surface so text never fights a blurred backdrop. */
    --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.44));
    --glass-border: rgba(255, 255, 255, 0.65);
    --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 -1px 0 rgba(15, 23, 42, 0.05), 0 8px 26px rgba(15, 23, 42, 0.13);
    --glass-panel: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.48));
    --glass-panel-border: rgba(255, 255, 255, 0.7);
    --glass-panel-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 10px 30px rgba(15, 23, 42, 0.1);
    --glass-blur: blur(26px) saturate(190%);
    --glass-divider: rgba(15, 23, 42, 0.09);

    /* Ambient halo behind the glass, and the ring track it reads against. */
    --halo: radial-gradient(58% 52% at 32% 26%, rgba(37, 99, 235, 0.2), transparent 72%),
            radial-gradient(46% 40% at 88% 8%, rgba(22, 163, 74, 0.12), transparent 74%);
    --ring-track: rgba(15, 23, 42, 0.1);

    --radius: 12px;
    --nav-height: 64px;
    --header-height: 46px;
    --chrome-gutter: 12px;
    --content-width: 720px;

    /* How much room the floating chrome takes at each edge. Content padding,
     * the review card's height and the chat column all derive from these, so
     * the three stay in step when the chrome changes size. */
    --chrome-top: calc(env(safe-area-inset-top) + var(--chrome-gutter) + var(--header-height) + 1rem);
    --chrome-bottom: calc(env(safe-area-inset-bottom) + 14px + var(--nav-height) + 1.25rem);
}

/* Dark values, factored out so the two selectors below stay in sync. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg: #0f172a;
        --surface: #1e293b;
        --surface-alt: #172033;
        --surface-sunken: #131c2e;
        --surface-inverse: #0b1120;
        --border: #334155;
        --border-strong: #475569;
        --text: #e2e8f0;
        --text-strong: #f8fafc;
        --text-soft: #cbd5e1;
        --text-muted: #94a3b8;
        --text-subtle: #7c8ba1;

        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --accent-contrast: #ffffff;
        --accent-text: #93c5fd;
        --accent-bg: #172554;
        --accent-bg-strong: #1e3a8a;
        --accent-border: #1e40af;
        --accent-soft: rgba(96, 165, 250, 0.18);

        --success: #16a34a;
        --success-text: #86efac;
        --success-bg: #0b2e1d;
        --success-bg-strong: #14532d;
        --success-border: #166534;

        --danger: #dc2626;
        --danger-hover: #b91c1c;
        --danger-text: #fca5a5;
        --danger-bg: #2f1214;
        --danger-bg-strong: #7f1d1d;
        --danger-border: #991b1b;
        --danger-glow: rgba(248, 113, 113, 0.35);
        --danger-glow-fade: rgba(248, 113, 113, 0);

        --warning: #d97706;
        --warning-text: #fcd34d;
        --warning-bg: #2b1d05;
        --warning-bg-strong: #78350f;
        --warning-border: #92400e;
        --warning-glow: rgba(251, 191, 36, 0.35);

        --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-strong: 0 4px 12px rgba(0, 0, 0, 0.55);

        --glass: linear-gradient(180deg, rgba(30, 41, 59, 0.62), rgba(15, 23, 42, 0.46));
        --glass-border: rgba(255, 255, 255, 0.12);
        --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.3), 0 8px 26px rgba(0, 0, 0, 0.5);
        --glass-panel: linear-gradient(180deg, rgba(30, 41, 59, 0.66), rgba(15, 23, 42, 0.48));
        --glass-panel-border: rgba(255, 255, 255, 0.13);
        --glass-panel-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 10px 30px rgba(0, 0, 0, 0.5);
        --glass-divider: rgba(255, 255, 255, 0.12);

        --halo: radial-gradient(58% 52% at 32% 26%, rgba(59, 130, 246, 0.3), transparent 72%),
                radial-gradient(46% 40% at 88% 8%, rgba(22, 163, 74, 0.16), transparent 74%);
        --ring-track: rgba(255, 255, 255, 0.14);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #172033;
    --surface-sunken: #131c2e;
    --surface-inverse: #0b1120;
    --border: #334155;
    --border-strong: #475569;
    --text: #e2e8f0;
    --text-strong: #f8fafc;
    --text-soft: #cbd5e1;
    --text-muted: #94a3b8;
    --text-subtle: #7c8ba1;

    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-contrast: #ffffff;
    --accent-text: #93c5fd;
    --accent-bg: #172554;
    --accent-bg-strong: #1e3a8a;
    --accent-border: #1e40af;
    --accent-soft: rgba(96, 165, 250, 0.18);

    --success: #16a34a;
    --success-text: #86efac;
    --success-bg: #0b2e1d;
    --success-bg-strong: #14532d;
    --success-border: #166534;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-text: #fca5a5;
    --danger-bg: #2f1214;
    --danger-bg-strong: #7f1d1d;
    --danger-border: #991b1b;
    --danger-glow: rgba(248, 113, 113, 0.35);
    --danger-glow-fade: rgba(248, 113, 113, 0);

    --warning: #d97706;
    --warning-text: #fcd34d;
    --warning-bg: #2b1d05;
    --warning-bg-strong: #78350f;
    --warning-border: #92400e;
    --warning-glow: rgba(251, 191, 36, 0.35);

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-strong: 0 4px 12px rgba(0, 0, 0, 0.55);

    --glass: linear-gradient(180deg, rgba(30, 41, 59, 0.62), rgba(15, 23, 42, 0.46));
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), inset 0 -1px 0 rgba(0, 0, 0, 0.3), 0 8px 26px rgba(0, 0, 0, 0.5);
    --glass-panel: linear-gradient(180deg, rgba(30, 41, 59, 0.66), rgba(15, 23, 42, 0.48));
    --glass-panel-border: rgba(255, 255, 255, 0.13);
    --glass-panel-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 10px 30px rgba(0, 0, 0, 0.5);
    --glass-divider: rgba(255, 255, 255, 0.12);

    --halo: radial-gradient(58% 52% at 32% 26%, rgba(59, 130, 246, 0.3), transparent 72%),
            radial-gradient(46% 40% at 88% 8%, rgba(22, 163, 74, 0.16), transparent 74%);
    --ring-track: rgba(255, 255, 255, 0.14);
}

* {
    box-sizing: border-box;
}

/* The `hidden` attribute is the app's only way of showing and hiding things
 * from JS (review reveal, hands-free panel, flash rows). The UA rule behind it
 * is `[hidden] { display: none }`, which any author `display:` on the same
 * element beats on specificity -- and half the elements we hide carry a
 * `display: flex`/`grid` of their own. Restating it here, with the weight the
 * attribute is meant to have, keeps `el.hidden = true` meaning hidden. */
[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    /* The chrome floats: content clears the header pill on top and the tab
     * bar pill at the bottom, both of which sit inside the safe area. */
    padding-top: var(--chrome-top);
    padding-bottom: var(--chrome-bottom);
}

a {
    color: var(--accent);
    text-decoration: none;
}

/* Text kept for assistive tech and removed from the visual layout. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Ambient halo the floating glass reads against. Fixed, so it stays put
 * behind the chrome while the page scrolls under it. */
.app-halo {
    position: fixed;
    top: -40px;
    left: -20px;
    right: -20px;
    height: 420px;
    background: var(--halo);
    pointer-events: none;
    z-index: 0;
}

/* ---------- Floating glass chrome ---------- */
.glass {
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Shared geometry for the pills pinned over the content column. */
.app-header,
.app-nav,
.grade-rail {
    position: fixed;
    left: var(--chrome-gutter);
    right: var(--chrome-gutter);
    max-width: var(--content-width);
    margin: 0 auto;
    z-index: 30;
}

/* Header */
.app-header {
    top: calc(env(safe-area-inset-top) + var(--chrome-gutter));
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--header-height);
    padding: 0 14px;
    border-radius: calc(var(--header-height) / 2);
}

.app-brand {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-strong);
}

/* Labelled back affordance: chevron + destination, as on iOS. */
.app-header-back {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--accent);
}

/* Centred by growing between the two edge slots, so an asymmetric pair of
 * affordances still leaves the title visually mid-pill. */
.app-header-title {
    flex-grow: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-strong);
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

/* Pushes the actions to the right on screens that carry no centred title. */
.app-header-spacer {
    flex-grow: 1;
}

.app-header-icon {
    display: block;
    width: 20px;
    height: 20px;
}

.app-header-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 999px;
    color: var(--accent);
}

.app-header-icon-link:hover {
    background: var(--accent-soft);
}

/* Three-state theme switch, driven by assets/controllers/theme_controller.js */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
}

.theme-toggle:hover {
    background: var(--accent-soft);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Main */
.app-main {
    position: relative;
    z-index: 1;
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 1rem 1rem;
}

/* Hero */
.hero {
    margin-bottom: 1.5rem;
}

.hero h1 {
    font-size: 1.6rem;
    margin: 0 0 0.25rem;
}

.hero-sub {
    color: var(--text-muted);
    margin: 0;
}

/* Large screen-opening title, used where the header pill carries no title. */
.page-title {
    margin: 0;
    font-size: 2.125rem;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: -0.026em;
    color: var(--text-strong);
}

.page-subtitle {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

/* Module grid */
.module-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.module-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    color: var(--text);
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.module-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.module-icon {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 0.5rem;
}

.module-card h2 {
    font-size: 1.1rem;
    margin: 0 0 0.35rem;
}

.module-card p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

/* Bottom nav */
.app-nav {
    bottom: calc(env(safe-area-inset-bottom) + 14px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    height: var(--nav-height);
    padding: 5px;
    border-radius: 26px;
}

.app-nav a {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 21px;
    color: var(--text-subtle);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* The selected tab is a tinted lozenge, the only chrome that carries accent. */
.app-nav a.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.app-nav a:hover {
    color: var(--accent);
}

.app-nav-icon {
    display: block;
    width: 23px;
    height: 23px;
}

/* Four entries on a narrow phone: keep every label on one line. */
.app-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Auth */
.auth {
    display: flex;
    justify-content: center;
    padding-top: 2rem;
}

.auth-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    width: 100%;
    max-width: 380px;
}

.auth-form h1 {
    margin: 0 0 1rem;
    font-size: 1.35rem;
}

.auth-form label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    margin-top: 0.85rem;
}

.auth-form input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
}

.auth-form input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.auth-form button {
    margin-top: 1.25rem;
    width: 100%;
    padding: 0.7rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.auth-form button:hover {
    background: var(--accent-hover);
}

.auth-error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

/* Larger screens: cards side by side, nav stays bottom for app feel */
@media (min-width: 640px) {
    .module-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ---------- Generic inline TTS listen button ---------- */
.tts-button {
    border: none;
    background: transparent;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.1rem;
    opacity: 0.55;
    transition: opacity 0.15s;
}
.tts-button:hover {
    opacity: 1;
}

/* ---------- Shared buttons ---------- */
.btn {
    display: inline-block;
    padding: 0.7rem 1.4rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--accent-contrast);
}

/* ---------- SRS editing forms ----------
 * Two shapes share one look: `.srs-form` is a stacked card for create/edit
 * screens; `.srs-form-inline` is a horizontal row for filter bars and the
 * per-field / per-template action forms in the note-type editor. */
.srs-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin: 0.5rem 0 1.5rem;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.srs-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* A checkbox belongs beside its label, not above it. */
.srs-form label:has(> input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.srs-form input:not([type="checkbox"]),
.srs-form select,
.srs-form textarea {
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 400;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    width: 100%;
}

.srs-form textarea {
    resize: vertical;
}

.srs-form input:focus,
.srs-form select:focus,
.srs-form textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.srs-form .btn {
    align-self: flex-start;
}

/* Inline variant: controls flow on one wrapping row, bottom-aligned. */
.srs-form-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.6rem;
    margin: 0.5rem 0 1.25rem;
}

.srs-form-inline label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.srs-form-inline label:has(> input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
}

.srs-form-inline input:not([type="checkbox"]),
.srs-form-inline select,
.srs-form-inline textarea {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

.srs-form-inline input:focus,
.srs-form-inline select:focus,
.srs-form-inline textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

/* Danger button variant, for the delete forms. */
.btn-danger {
    background: var(--danger);
    color: var(--on-solid);
}

.btn-danger:hover {
    background: var(--danger-hover);
    color: var(--on-solid);
}

/* ---------- Shared layout primitives ----------
 * The six screens share one grammar: a stack of sections, each a 13px grey
 * header over an iOS-style grouped list, plus the ring that stands for
 * "how far through" everywhere it appears. */

.stack {
    display: flex;
    flex-direction: column;
    gap: 1.125rem;
}

.section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.section-title {
    padding: 0 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--text-muted);
}

/* Grouped list: rows share one rounded card, separators inset from the left
 * so they start under the text rather than the icon. */
.list-group {
    --list-sep-inset: 15px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.list-group--icons {
    --list-sep-inset: 48px;
}

.list-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    min-height: 52px;
    padding: 0.4rem 15px;
    color: var(--text-strong);
    font-size: 1.0625rem;
    letter-spacing: -0.012em;
}

.list-row + .list-row::before {
    content: "";
    position: absolute;
    top: 0;
    left: var(--list-sep-inset);
    right: 0;
    height: 1px;
    background: var(--border);
}

.list-row:hover {
    background: var(--surface-alt);
}

.list-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.list-label {
    flex-grow: 1;
    min-width: 0;
}

/* Two-line row: title over a grey caption. Taller than a plain row. */
.list-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
    min-width: 0;
}

.list-caption {
    font-size: 0.8125rem;
    letter-spacing: normal;
    color: var(--text-subtle);
}

.list-value {
    flex-shrink: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
}

.list-value--muted {
    font-size: 0.9375rem;
    font-weight: 400;
    color: var(--text-subtle);
}

.list-chevron {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    color: var(--border-strong);
}

.list-row--done .list-label,
.list-row--done .list-stack > span:first-child {
    color: var(--text-muted);
}

/* ---------- Ring ----------
 * One SVG, two circles: a track and the value arc. Callers set the arc's
 * stroke-dasharray from the progress they want to show. */
.ring {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
}

.ring svg {
    display: block;
    transform: rotate(-90deg);
}

.ring-track {
    fill: none;
    stroke: var(--ring-track);
}

.ring-value {
    fill: none;
    stroke: var(--accent);
    stroke-linecap: round;
}

.ring-value--success { stroke: var(--success); }
.ring-value--warning { stroke: var(--warning); }
.ring-value--danger { stroke: var(--danger); }

.ring-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
}

.ring-number {
    font-size: 2.5rem;
    line-height: 1.05;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-strong);
}

.ring-caption {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Glass panel: the one non-chrome use of glass, for the hero summary card. */
.glass-panel {
    border-radius: 24px;
    background: var(--glass-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-panel-border);
    box-shadow: var(--glass-panel-shadow);
}

/* Figures split by hairlines, under a ring or beside it. */
.figure-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    width: 100%;
}

.figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    min-width: 0;
}

.figure + .figure {
    border-left: 1px solid var(--glass-divider);
}

.figure-value {
    font-size: 1.25rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--text-strong);
}

.figure-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* ---------- Segmented control ---------- */
.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 2px;
    height: 34px;
    padding: 2px;
    border-radius: 9px;
    background: var(--surface-sunken);
}

.segmented a {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.segmented a.is-active {
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
    font-weight: 600;
    color: var(--text-strong);
}

/* ---------- Filter chips ---------- */
.chip-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chip-row::-webkit-scrollbar {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    height: 34px;
    padding: 0 15px;
    border-radius: 17px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text-soft);
    white-space: nowrap;
}

.chip.is-active {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    font-weight: 600;
    color: var(--accent-text);
}

/* ---------- Grading rail ----------
 * The fourth piece of floating glass: four self-grade buttons, each showing
 * the interval it would schedule. Sits just above the tab bar. */
.grade-rail {
    bottom: calc(env(safe-area-inset-bottom) + 14px + var(--nav-height) + 10px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: 72px;
    border-radius: 24px;
    overflow: hidden;
}

.grade-rail button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0 2px;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}

.grade-rail button + button {
    border-left: 1px solid var(--glass-divider);
}

.grade-rail button:hover:not(:disabled) {
    background: var(--accent-soft);
}

.grade-rail button:disabled {
    opacity: 0.5;
    cursor: default;
}

.grade-label {
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.grade-interval {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.grade-1 .grade-label { color: var(--danger-text); }
.grade-2 .grade-label { color: var(--warning-text); }
.grade-3 .grade-label { color: var(--accent-text); }
.grade-4 .grade-label { color: var(--success-text); }
