/* ============================================================
   NETS Builder — App Styles
   Apple-style glassmorphism · Base + Editor patches
   ============================================================ */

/* -------- CSS Variables -------- */
:root {
    --bg: #f5f5f7;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-elevated: rgba(255, 255, 255, 0.92);
    --text: #1d1d1f;
    --text-muted: #86868b;
    --text-subtle: #a1a1a6;
    --accent: #0066CC;
    --accent-hover: #0056b3;
    --accent-glow: rgba(0, 102, 204, 0.28);
    --accent-light: rgba(0, 102, 204, 0.08);
    --border: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.04);
    --line: rgba(0, 0, 0, 0.08);
    --shadow-low: 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-mid: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-card: 0 20px 48px rgba(0, 0, 0, 0.10);
    --glass-blur: blur(40px) saturate(180%);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --family-aniq: #0066CC;
    --family-tabiy: #34C759;
    --family-til: #AF52DE;
    --family-ijtimoiy: #FF9500;
    --status-draft: #86868b;
    --status-generating: #FF9500;
    --status-ready: #34C759;
    --status-error: #FF3B30;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: rgba(15, 23, 42, 0.78);
    --surface-elevated: rgba(15, 23, 42, 0.94);
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --accent: #006FE0;
    --accent-hover: #0050B0;
    --accent-glow: rgba(0, 111, 224, 0.38);
    --accent-light: rgba(0, 111, 224, 0.18);
    --border: rgba(148, 163, 184, 0.22);
    --border-light: rgba(148, 163, 184, 0.12);
    --line: rgba(148, 163, 184, 0.18);
    --shadow-low: 0 1px 4px rgba(0, 0, 0, 0.24);
    --shadow-mid: 0 8px 24px rgba(0, 0, 0, 0.38);
    --shadow-card: 0 20px 48px rgba(0, 0, 0, 0.48);
}

/* -------- Reset & Base -------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(0, 122, 255, 0.10), transparent 40%),
        radial-gradient(circle at 100% 0%, rgba(175, 82, 222, 0.08), transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(52, 199, 89, 0.08), transparent 45%),
        radial-gradient(circle at 0% 100%, rgba(255, 149, 0, 0.08), transparent 45%);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[data-theme="dark"] body {
    background-image:
        radial-gradient(circle at 0% 0%, rgba(10, 132, 255, 0.14), transparent 40%),
        radial-gradient(circle at 100% 0%, rgba(28, 160, 149, 0.10), transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(200, 151, 56, 0.10), transparent 45%),
        linear-gradient(180deg, #0f172a 0%, #111827 100%);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 150ms ease;
}

a:hover {
    color: var(--accent-hover);
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    border: 0;
    background: transparent;
    cursor: pointer;
}

img,
svg {
    display: block;
    max-width: 100%;
}

/* -------- Typography -------- */
h1,
h2,
h3,
h4 {
    margin: 0;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

h1 {
    font-size: 1.75rem;
    line-height: 1.2;
}

h2 {
    font-size: 1.4rem;
    line-height: 1.25;
}

h3 {
    font-size: 1.1rem;
    line-height: 1.3;
    font-weight: 600;
}

p {
    margin: 0 0 0.5rem 0;
}

p:last-child {
    margin-bottom: 0;
}

.eyebrow {
    margin: 0 0 4px 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.muted-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

code {
    font-family: "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85em;
}

/* -------- Layout Shells -------- */
.app-shell {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.builder-shell {
    display: flex;
    flex-direction: row;
    width: 100%;
    min-height: 100vh;
    padding: 16px;
    gap: 16px;
}

.dashboard-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.builder-layout {
    display: flex;
    gap: 16px;
    width: 100%;
    height: 100%;
}

.builder-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.builder-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    min-width: 0;
    overflow: hidden;
}

/* -------- Top Bars -------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    min-height: 72px;
    position: sticky;
    top: 16px;
    z-index: 40;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-nav .is-active {
    color: var(--accent);
    font-weight: 600;
}

.builder-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 4px 4px 16px 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.builder-title-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.builder-title-block h2 {
    font-size: 1.3rem;
    margin: 0;
}

.builder-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* -------- Branding -------- */
.brand-block {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-block h1 {
    font-size: 1.35rem;
    margin: 0;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent), #5856D6);
    box-shadow: 0 4px 14px var(--accent-glow);
}

a.brand-mark {
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
a.brand-mark:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 18px var(--accent-glow);
}
a.brand-mark:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* -------- Cards & Glass -------- */
.glass-card {
    background: var(--surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-mid);
    padding: 24px;
    animation: fadeIn 0.3s ease;
}

.hero-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 32px;
    align-items: center;
    padding: 32px;
}

.hero-card h2 {
    font-size: 1.6rem;
    margin: 4px 0 8px 0;
    max-width: 640px;
}

.editor-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-low);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 14px 20px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    min-width: 96px;
}

.stat-card span {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.stat-card small {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}

/* -------- Library & Grid -------- */
.library-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.section-heading h2 {
    font-size: 1.4rem;
}

.hero-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-row label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.homework-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
}

.homework-grid .glass-card,
.homework-grid .homework-card {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
    overflow: hidden;  /* clip children so long titles can't escape card boundary */
    min-width: 0;      /* allow flex children to shrink below intrinsic content width */
}

.homework-grid .glass-card:hover,
.homework-grid .homework-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card);
    border-color: rgba(0, 122, 255, 0.22);
}

/* -------- Unified search bar --------
   Shared by dashboard (#search-input), library (#lib-search), and the
   quote picker modal (.js-quote-search). Goal: one premium, compact,
   accessible pill — subtle inset shadow, smooth focus-ring expansion,
   light/dark parity. Edit here once, every search inherits. */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 220px;
    height: 38px;
    padding: 0 10px 0 12px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 11px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 1px 2px rgba(15, 23, 42, 0.04);
    transition:
        border-color 180ms cubic-bezier(0.2, 0.9, 0.32, 1.1),
        box-shadow 220ms cubic-bezier(0.2, 0.9, 0.32, 1.1),
        background-color 180ms ease;
}

.search-box:hover {
    border-color: rgba(0, 102, 204, 0.28);
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow:
        0 0 0 4px var(--accent-glow),
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 1px 2px rgba(15, 23, 42, 0.04);
}

.search-box .search-box__icon,
.search-box > span[aria-hidden="true"] {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    transition: color 180ms ease;
    user-select: none;
    pointer-events: none;
}

.search-box:focus-within .search-box__icon,
.search-box:focus-within > span[aria-hidden="true"] {
    color: var(--accent);
}

/* SEARCH-INNER-BOX-01: the global `input[type="search"]` / `[type="text"]`
   rules below at app.css:886 set their own background, 1px border, padding,
   and border-radius — they tie on specificity with `.search-box input`
   (both (0,1,1)) and win by source order, so the input ends up painting
   a SECOND visible box inside the wrapper pill (a faint inner border on
   the right side, a subtle background mismatch). The `[data-theme=dark]
   input[type="search"]` override at app.css:3292 ties at (0,2,1) with
   `.search-box input[type="search"]` and wins by source order too — so
   we also need a dark-mode-scoped reset below to keep the inside flush.
   Selector here uses `[type=…]` to bump specificity to (0,2,1)
   regardless of theme. */
.search-box input,
.search-box input[type="search"],
.search-box input[type="text"] {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    height: 100%;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* Hide the browser-native search clear UI — we render our own button
   so the design + dark mode stays consistent across browsers. */
.search-box input[type="search"]::-webkit-search-decoration,
.search-box input[type="search"]::-webkit-search-cancel-button,
.search-box input[type="search"]::-webkit-search-results-button,
.search-box input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
}

.search-box .search-box__clear {
    flex: 0 0 auto;
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-right: -2px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition:
        color 140ms ease,
        background-color 140ms ease,
        transform 140ms cubic-bezier(0.2, 0.9, 0.32, 1.1);
}

.search-box.is-filled .search-box__clear {
    display: inline-flex;
}

/* SEARCH-PAD-01: When the input is empty the X button is display:none, so the
   wrapper's 10px padding-right is the only thing inside the right edge. With
   the X visible the button's `margin-right: -2px` makes the effective right
   inset 8px — that 2px difference reads as "extra padding when empty". Match
   the empty-state inset to the filled-state inset so the bar feels balanced
   in both states. Applies to every .search-box (dashboard / library / quote
   picker), since the asymmetry is in the shared component. */
.search-box:not(.is-filled) {
    padding-right: 8px;
}

.search-box .search-box__clear:hover {
    color: var(--text);
    background: var(--accent-light);
}

.search-box .search-box__clear:active {
    transform: scale(0.92);
}

.search-box .search-box__clear:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 2px var(--accent-glow);
}

[data-theme="dark"] .search-box {
    background: var(--surface-elevated);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 1px 2px rgba(0, 0, 0, 0.32);
}

[data-theme="dark"] .search-box:focus-within {
    box-shadow:
        0 0 0 4px var(--accent-glow),
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 1px 2px rgba(0, 0, 0, 0.32);
}

[data-theme="dark"] .search-box .search-box__clear:hover {
    background: var(--accent-light);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    flex-wrap: wrap;
}

/* -------- Buttons -------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease, transform 120ms ease, box-shadow 150ms ease;
    white-space: nowrap;
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.icon-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* -------- Pills & Status -------- */
.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-radius: 999px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    color: var(--text);
}

.status-pill[data-status="draft"] {
    color: var(--status-draft);
}

.status-pill[data-status="generating"] {
    color: var(--status-generating);
    background: rgba(255, 149, 0, 0.08);
    border-color: rgba(255, 149, 0, 0.22);
}

.status-pill[data-status="ready"] {
    color: var(--status-ready);
    background: rgba(52, 199, 89, 0.08);
    border-color: rgba(52, 199, 89, 0.22);
}

.status-pill[data-status="error"] {
    color: var(--status-error);
    background: rgba(255, 59, 48, 0.08);
    border-color: rgba(255, 59, 48, 0.22);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-subtle);
    flex-shrink: 0;
}

.status-dot.draft {
    background: var(--status-draft);
}

.status-dot.generating {
    background: var(--status-generating);
    box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.16);
}

.status-dot.ready {
    background: var(--status-ready);
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.16);
}

.status-dot.error {
    background: var(--status-error);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.16);
}

.status-dot.muted {
    background: var(--text-subtle);
}

.health-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

/* -------- Modals -------- */
.modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    padding: 24px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal:not([open]) {
    display: none;
}

.modal-card {
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 48px);
    overflow: auto;
    padding: 28px;
    background: var(--surface-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 18px;
    animation: fadeIn 0.25s ease;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.modal-header h2 {
    font-size: 1.3rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

/* -------- Forms -------- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field.full-span,
.form-note.full-span {
    grid-column: span 2;
}

.field span,
label > span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-note {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 10px 14px;
    background: var(--accent-light);
    border: 1px solid rgba(0, 122, 255, 0.14);
    border-radius: var(--radius-sm);
}

input[type="text"],
input[type="number"],
input[type="search"],
input[type="email"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: 0;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
    min-height: 90px;
    resize: vertical;
    line-height: 1.5;
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%2386868b' d='M6 8.5 2 4h8z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #fafafa;
}

/* -------- Builder Sidebar -------- */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 32px);
    position: sticky;
    top: 16px;
    overflow: auto;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header h1 {
    font-size: 1.1rem;
    line-height: 1.25;
    margin: 0;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-muted);
}

.phase-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

.phase-item,
.phase-list button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.phase-item:hover,
.phase-list button:hover {
    background: var(--accent-light);
    border-color: rgba(0, 122, 255, 0.14);
}

.phase-item.active,
.phase-list button.active,
.phase-item[aria-current="true"] {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.phase-item.active .status-dot,
.phase-list button.active .status-dot {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

/* -------- Editor Area -------- */
.editor-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 4px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.editor-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.editor-header h3 {
    font-size: 1.15rem;
    margin: 2px 0 0 0;
}

.save-state {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0;
}

.save-state[data-state="saving"] {
    color: var(--status-generating);
}

.save-state[data-state="saved"] {
    color: var(--status-ready);
}

.save-state[data-state="error"] {
    color: var(--status-error);
}

/* -------- Save Indicator (toolbar) -------- */
.save-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-muted);
    transition: all 150ms ease;
    white-space: nowrap;
}

.save-indicator .save-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.save-indicator[data-state="saving"] {
    background: rgba(0, 122, 255, 0.08);
    color: var(--accent);
}

.save-indicator[data-state="saving"] .save-dot {
    background: var(--accent);
    animation: save-indicator-pulse 1.2s ease infinite;
}

.save-indicator[data-state="saved"] {
    background: rgba(52, 199, 89, 0.08);
    color: #0a7b31;
}

.save-indicator[data-state="saved"] .save-dot {
    background: var(--status-ready);
}

.save-indicator[data-state="error"] {
    background: rgba(255, 59, 48, 0.1);
    color: var(--status-error);
    font-weight: 600;
}

.save-indicator[data-state="error"] .save-dot {
    background: var(--status-error);
    animation: save-indicator-pulse 0.6s ease infinite;
}

.save-indicator[data-state="offline"] {
    background: rgba(255, 149, 0, 0.12);
    color: #a05a00;
    font-weight: 600;
}

.save-indicator[data-state="offline"] .save-dot {
    background: var(--status-generating);
}

@keyframes save-indicator-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.save-banner-error {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 59, 48, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(255, 59, 48, 0.3);
    z-index: 9999;
    max-width: calc(100vw - 48px);
    text-align: center;
}

/* -------- Preview Panel -------- */
.preview-panel {
    min-width: 0;
    padding: 8px;
    display: flex;
    flex-direction: column;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    /* Pin to viewport so the preview stays visible as the editor scrolls,
       and doesn't stretch to match the editor's height. */
    position: sticky;
    top: 16px;
    align-self: start;
    height: calc(100vh - 120px);
    max-height: 900px;
}

.preview-frame {
    width: 100%;
    height: 100%;
    flex: 1;
    border: 0;
    border-radius: var(--radius-md);
    background: #fff;
    min-height: 400px;
}

/* -------- Empty States & Loaders -------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state h3 {
    color: var(--text);
    font-size: 1.1rem;
}

.empty-state p {
    max-width: 380px;
    color: var(--text-muted);
}

.empty-orb {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin: 0 auto 4px;
    background: linear-gradient(135deg, var(--accent-light), rgba(175, 82, 222, 0.12));
    border: 1px solid rgba(0, 122, 255, 0.18);
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 60px 24px;
    color: var(--text-muted);
    text-align: center;
}

.spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(0, 122, 255, 0.16);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

/* -------- Toasts -------- */
.toast-region {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    pointer-events: none;
}

.toast-region > * {
    pointer-events: auto;
    min-width: 280px;
    max-width: 380px;
    padding: 14px 16px;
    background: var(--surface-elevated);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    font-size: 14px;
    color: var(--text);
    animation: slideIn 0.25s ease;
}

.toast-region .toast-success,
.toast-region > .success {
    border-left: 3px solid var(--status-ready);
}

.toast-region .toast-error,
.toast-region > .error {
    border-left: 3px solid var(--status-error);
}

.toast-region .toast-info,
.toast-region > .info {
    border-left: 3px solid var(--accent);
}

/* -------- Utility -------- */
.hidden {
    display: none !important;
}

.full-span {
    grid-column: 1 / -1;
}

/* -------- Animations -------- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* -------- Responsive -------- */
@media (max-width: 1200px) {
    .builder-content {
        grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
    }
}

@media (max-width: 1023px) {
    .app-shell {
        padding: 20px;
    }

    .hero-card {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .homework-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .builder-shell {
        flex-direction: column;
        padding: 12px;
    }

    .sidebar {
        width: 100%;
        position: static;
        max-height: none;
    }

    .phase-list {
        flex-direction: row;
        overflow-x: auto;
        gap: 6px;
    }

    .phase-item,
    .phase-list button {
        flex-shrink: 0;
        min-width: 160px;
    }

    .builder-content {
        grid-template-columns: 1fr;
    }

    .preview-panel {
        /* Below tablet breakpoint the grid is single-column; drop sticky behavior. */
        position: static;
        height: 520px;
        max-height: none;
    }
}

@media (max-width: 639px) {
    body {
        font-size: 14px;
    }

    .app-shell {
        padding: 14px;
        gap: 16px;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
        position: static;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .hero-card {
        padding: 22px;
    }

    .hero-card h2 {
        font-size: 1.3rem;
    }

    .hero-stats {
        width: 100%;
    }

    .stat-card {
        flex: 1;
    }

    .homework-grid {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .field.full-span,
    .form-note.full-span {
        grid-column: span 1;
    }

    .builder-topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .builder-actions {
        width: 100%;
    }

    .modal {
        padding: 12px;
    }

    .modal-card {
        padding: 20px;
    }

    .toast-region {
        bottom: 12px;
        right: 12px;
        left: 12px;
    }

    .toast-region > * {
        min-width: 0;
        max-width: none;
    }
}

/* ============================================================
   NETS Builder editor + template loader patch
   Add this to the bottom of frontend/css/app.css
   ============================================================ */

/* Shared editor helpers */
.inline-empty {
  min-height: 220px;
  margin-top: 0;
}

.nested-card {
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(0, 122, 255, 0.1);
  box-shadow: none;
}

.page-card,
.panel-editor-card {
  border-color: rgba(0, 122, 255, 0.14);
}

.compact-header {
  margin-bottom: 10px;
}

.compact-header h3 {
  font-size: 1rem;
}

.inline-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-actions select {
  min-width: 150px;
}

.editor-card code,
.fixture-card code {
  padding: 4px 8px;
  border-radius: 10px;
  color: var(--accent);
  background: rgba(0, 122, 255, 0.08);
  border: 1px solid rgba(0, 122, 255, 0.12);
  font-family: "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 800;
}

.json-preview {
  max-height: 420px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 16px;
  border-radius: 18px;
  color: #24425f;
  background: rgba(239, 248, 255, 0.92);
  border: 1px solid rgba(0, 122, 255, 0.14);
  font-family: "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.tall-textarea {
  min-height: 220px;
}

/* Rows used by options, answers, bullets, pairs */
.option-row,
.quote-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.quote-list {
  display: grid;
  gap: 10px;
}

.empty-mini {
  padding: 16px;
  border-radius: 16px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.58);
  border: 1px dashed rgba(0, 122, 255, 0.18);
}

.empty-mini p {
  margin: 0;
  line-height: 1.5;
}

/* Load Template modal */
.fixture-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  max-height: min(56vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.fixture-card {
  width: 100%;
  min-height: 68px;
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, opacity 150ms ease;
}

.fixture-card:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 122, 255, 0.28);
  background: rgba(255, 255, 255, 0.94);
}

.fixture-card:active {
  transform: translateY(0) scale(0.99);
}

.fixture-card:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.fixture-name {
  font-weight: 850;
  letter-spacing: -0.02em;
}

/* Game Breaks split editor */
.game-break-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.game-tabs {
  display: grid;
  gap: 8px;
  position: sticky;
  top: 12px;
}

.game-tab-btn {
  justify-content: flex-start;
  min-height: 54px;
}

.game-tab-btn .mini-count {
  margin-left: auto;
}

.game-editor-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.mini-count {
  min-width: 26px;
  height: 26px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: var(--accent);
  background: rgba(0, 122, 255, 0.1);
  border: 1px solid rgba(0, 122, 255, 0.16);
  font-size: 0.78rem;
  font-weight: 900;
}

/* Modal sizing polish */
.modal-card .muted-text + .fixture-list {
  margin-top: 16px;
}

/* Better editor scrolling */
.editor-panel::-webkit-scrollbar,
.preview-panel::-webkit-scrollbar,
.phase-list::-webkit-scrollbar,
.fixture-list::-webkit-scrollbar,
.json-preview::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.editor-panel::-webkit-scrollbar-thumb,
.preview-panel::-webkit-scrollbar-thumb,
.phase-list::-webkit-scrollbar-thumb,
.fixture-list::-webkit-scrollbar-thumb,
.json-preview::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.18);
}

.editor-panel::-webkit-scrollbar-track,
.preview-panel::-webkit-scrollbar-track,
.phase-list::-webkit-scrollbar-track,
.fixture-list::-webkit-scrollbar-track,
.json-preview::-webkit-scrollbar-track {
  background: transparent;
}

/* Make nested editor forms less cramped on smaller screens */
@media (max-width: 980px) {
  .game-break-layout {
    grid-template-columns: 1fr;
  }

  .game-tabs {
    position: static;
    grid-auto-flow: column;
    grid-auto-columns: minmax(180px, auto);
    overflow-x: auto;
  }
}

@media (max-width: 680px) {
  .inline-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .inline-actions select,
  .inline-actions .btn,
  .inline-actions .icon-btn {
    width: 100%;
  }

  .option-row,
  .quote-row {
    grid-template-columns: 1fr;
  }

  .fixture-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-tabs {
    grid-auto-columns: minmax(150px, auto);
  }
}

/* ============================================================
   WYSIWYG Preview Editor
   ============================================================ */
.rich-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: rgba(0, 122, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  flex-wrap: wrap;
}
.rich-toolbar button {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, border-color 120ms;
}
.rich-toolbar button:hover { background: rgba(0, 122, 255, 0.1); }
.rich-toolbar button.active { background: var(--accent); color: white; }
.rich-toolbar button.rich-btn-wide { width: auto; padding: 0 12px; }
.rich-toolbar .rich-sep { width: 1px; background: var(--border); margin: 4px 2px; }

.rich-editor {
  min-height: 200px;
  padding: 20px 24px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  outline: none;
  transition: border-color 150ms;
}
.rich-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}
.rich-editor h2 { font-size: 22px; font-weight: 600; margin: 16px 0 8px; color: var(--accent); }
.rich-editor h3 { font-size: 18px; font-weight: 600; margin: 12px 0 6px; color: var(--accent); }
.rich-editor p { margin: 0 0 12px; }
.rich-editor ul, .rich-editor ol { margin: 12px 0; padding-left: 28px; }
.rich-editor blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  background: rgba(0, 122, 255, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  font-style: italic;
}
.rich-editor code {
  background: rgba(0, 122, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.rich-editor img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
.rich-editor svg { max-width: 100%; height: auto; margin: 8px 0; }

.svg-insert-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.svg-insert-modal-card {
  background: var(--surface-elevated);
  padding: 24px;
  border-radius: 20px;
  max-width: 640px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-card);
}
.svg-insert-modal-card textarea {
  width: 100%;
  min-height: 240px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
}

/* ============================================================
   SVG / Image blocks inside the rich editor — movable containers
   ============================================================ */
.rich-editor .svg-wrap {
  display: block;
  margin: 14px 0;
  padding: 12px;
  background: rgba(0, 122, 255, 0.03);
  border: 1px dashed rgba(0, 122, 255, 0.25);
  border-radius: 12px;
  text-align: center;
  position: relative;
  cursor: grab;
  transition: box-shadow 150ms, border-color 150ms;
}
.rich-editor .svg-wrap:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(0, 122, 255, 0.14);
}
.rich-editor .svg-wrap:active { cursor: grabbing; }
.rich-editor .svg-wrap::before {
  content: "⋮⋮  SVG block — drag to reposition";
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  opacity: 0.55;
  pointer-events: none;
}
.rich-editor .svg-wrap svg {
  max-width: 100%;
  height: auto;
  margin: 8px 0 0;
  display: inline-block;
}
.rich-editor .svg-wrap.drag-over-top {
  box-shadow: 0 -3px 0 var(--accent), 0 6px 18px rgba(0, 122, 255, 0.14);
}
.rich-editor .svg-wrap.drag-over-bottom {
  box-shadow: 0 3px 0 var(--accent), 0 6px 18px rgba(0, 122, 255, 0.14);
}
.rich-editor p + .svg-wrap,
.rich-editor .svg-wrap + p { margin-top: 14px; }

.rich-editor img {
  max-width: 100%;
  border-radius: 10px;
  margin: 10px 0;
  display: block;
}

/* ============================================================
   Image block — invisible container, still draggable for reorder
   ============================================================ */
.rich-editor .image-wrap {
  display: block;
  /* Sensible default — user can drag the bottom-right corner to resize */
  width: 400px;
  max-width: 100%;
  margin: 10px auto;
  padding: 0;
  background: transparent;
  border: 0;
  position: relative;
  cursor: grab;
  transition: box-shadow 150ms;
  border-radius: 10px;
  /* Native resize handle in bottom-right corner */
  resize: both;
  overflow: hidden;
  min-width: 80px;
  min-height: 60px;
}
.rich-editor .image-wrap:hover {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.35);
}
.rich-editor .image-wrap:active { cursor: grabbing; }
.rich-editor .image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 10px;
  margin: 0;
  pointer-events: none; /* let wrapper own drag/resize */
  -webkit-user-drag: none;
  user-drag: none;
}
/* Subtle resize-handle visibility hint */
.rich-editor .image-wrap::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  border-right: 2px solid rgba(0, 122, 255, 0.4);
  border-bottom: 2px solid rgba(0, 122, 255, 0.4);
  border-bottom-right-radius: 8px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;
}
.rich-editor .image-wrap:hover::after { opacity: 1; }
.rich-editor .image-wrap.drag-over-top {
  box-shadow: 0 -3px 0 var(--accent);
}
.rich-editor .image-wrap.drag-over-bottom {
  box-shadow: 0 3px 0 var(--accent);
}

/* ============================================================
   Image insert modal — dropzone
   ============================================================ */
.image-upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
  background: rgba(0, 122, 255, 0.02);
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.image-upload-dropzone:hover,
.image-upload-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(0, 122, 255, 0.06);
}
.image-upload-dropzone .image-upload-cta {
  color: var(--text);
}
.image-upload-dropzone .js-image-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

/* ============================================================
   Compact rich field — for per-field image/SVG insertion
   (memory-sprint, flashcards def, boss q, real-life q prompts, etc.)
   ============================================================ */
.rich-field {
  display: flex;
  flex-direction: column;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.rich-field .rich-toolbar {
  padding: 4px;
  background: rgba(0,0,0,0.02);
  border-bottom: 1px solid var(--border-light);
  border-radius: 0;
}
.rich-field .rich-toolbar button {
  width: 28px;
  height: 28px;
  font-size: 12px;
}
.rich-field .rich-toolbar button.rich-btn-wide {
  width: auto;
  padding: 0 8px;
  font-size: 11px;
}
.rich-field .js-rich-mini {
  min-height: 90px;
  padding: 10px 14px;
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  outline: none;
  border: 0;
}
.rich-field .js-rich-mini:focus {
  box-shadow: 0 0 0 2px var(--accent-glow) inset;
}
.rich-field .js-rich-mini:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}
.rich-field.compact .js-rich-mini {
  min-height: 60px;
  padding: 8px 12px;
  font-size: 13px;
}
.rich-field .js-rich-mini h2 { font-size: 16px; margin: 6px 0 4px; color: var(--accent); }
.rich-field .js-rich-mini p { margin: 0 0 8px; }
.rich-field .js-rich-mini p:last-child { margin-bottom: 0; }
.rich-field .js-rich-mini code { background: rgba(0,122,255,0.08); padding: 1px 4px; border-radius: 3px; }
.rich-field .js-rich-mini img { max-width: 100%; border-radius: 8px; margin: 4px 0; }
.rich-field .js-rich-mini svg { max-width: 100%; height: auto; margin: 4px 0; }
.rich-field .js-rich-mini .image-wrap {
  display: block;
  width: 300px;
  max-width: 100%;
  margin: 8px auto;
  padding: 0;
  background: transparent;
  border: 0;
  position: relative;
  cursor: grab;
  border-radius: 8px;
  resize: both;
  overflow: hidden;
  min-width: 80px;
  min-height: 60px;
}
.rich-field .js-rich-mini .image-wrap:hover {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}
.rich-field .js-rich-mini .image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  margin: 0;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}
.rich-field .js-rich-mini .svg-wrap {
  display: block;
  margin: 8px 0;
  padding: 6px;
  border-radius: 8px;
  background: rgba(0,122,255,0.03);
}
.rich-field .js-rich-mini .svg-wrap svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* ============================================================
   Flashcard editor — warm educational palette, matches the runtime
   player. Cream surface in light, dark navy in dark. Turquoise
   cluster badge, gold accents. Soft rounded, subtle shadow,
   thin colored border. No heavy decorations.
   ============================================================ */
.flashcard-builder-card {
  --fc-bar: #1ca095;            /* turquoise — replaces old per-cluster blue */
  --fc-cream: #fdf8eb;
  --fc-cream-soft: #f5edd5;
  --fc-navy: #142847;
  --fc-navy-soft: #1d3258;
  --fc-ink: #1a2840;
  --fc-ink-dark: #e9eef7;
  --fc-turquoise: #1ca095;
  --fc-gold: #c89738;
  --fc-card-border: rgba(28, 160, 149, 0.30);

  position: relative;
  background: var(--fc-cream);
  border: 1px solid var(--fc-card-border);
  border-radius: 18px;
  max-width: 640px;
  margin: 20px auto;
  padding: 22px 24px 22px;
  box-shadow:
    0 1px 3px rgba(20, 40, 71, 0.06),
    0 12px 32px -16px rgba(20, 40, 71, 0.20);
  overflow: hidden;
  color: var(--fc-ink);
}
[data-theme="dark"] .flashcard-builder-card {
  background: var(--fc-navy);
  color: var(--fc-ink-dark);
  --fc-card-border: rgba(28, 160, 149, 0.40);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.30),
    0 16px 36px -18px rgba(0, 0, 0, 0.55);
}
/* Top hairline accent — gold, thin, replaces the old 6px bar */
.flashcard-builder-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--fc-gold) 50%, transparent 100%);
}

.flashcard-builder-card .fc-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.flashcard-builder-card .fc-card-num {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.flashcard-builder-card .fc-cluster-pill {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  /* Turquoise badge per spec — overrides the per-cluster bg/text the JS sets. */
  background: rgba(28, 160, 149, 0.14) !important;
  color: var(--fc-turquoise) !important;
}
.flashcard-builder-card .fc-card-head .js-remove-card {
  margin-left: 8px;
  font-size: 11px;
  padding: 4px 10px;
  color: #c0392b;
}

/* Media zone at top of card — soft cream-tinted dashed frame */
.flashcard-builder-card .fc-media-zone {
  border: 1px dashed var(--fc-card-border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: var(--fc-cream-soft);
}
[data-theme="dark"] .flashcard-builder-card .fc-media-zone {
  background: var(--fc-navy-soft);
}
.flashcard-builder-card .fc-media-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.flashcard-builder-card .fc-media-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.flashcard-builder-card .fc-media-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}
.flashcard-builder-card .fc-media-actions .btn {
  font-size: 11px;
  padding: 4px 10px;
}
.flashcard-builder-card .fc-media-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 4px;
}
.flashcard-builder-card .fc-media-empty .fc-media-icon {
  font-size: 18px;
}
.flashcard-builder-card .fc-media-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px;
  background: var(--fc-cream);
  border-radius: 10px;
}
[data-theme="dark"] .flashcard-builder-card .fc-media-preview {
  background: var(--fc-navy-soft);
}
.flashcard-builder-card .fc-media-preview img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  display: block;
}
.flashcard-builder-card .fc-media-preview.fc-media-svg svg {
  max-width: 100%;
  max-height: 260px;
  height: auto;
  display: block;
}

/* Front / back faces */
.flashcard-builder-card .fc-face {
  margin-bottom: 4px;
}
.flashcard-builder-card .fc-face-label {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fc-gold);
  font-weight: 700;
  margin-bottom: 6px;
}
.flashcard-builder-card .fc-face .rich-field {
  border-radius: 12px;
}

/* Divider between front and back */
.flashcard-builder-card .fc-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
  user-select: none;
}
.flashcard-builder-card .fc-divider-line {
  flex: 1;
  height: 1px;
  background: repeating-linear-gradient(
    to right,
    var(--border) 0,
    var(--border) 4px,
    transparent 4px,
    transparent 8px
  );
}
.flashcard-builder-card .fc-divider-chip {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.04);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}

/* Meta row: cluster + hint */
.flashcard-builder-card .fc-meta-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light, var(--border));
}
.flashcard-builder-card .fc-meta-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.flashcard-builder-card .fc-meta-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}
.flashcard-builder-card .fc-meta-field select,
.flashcard-builder-card .fc-meta-field textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-elevated);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
}
.flashcard-builder-card .fc-meta-field textarea {
  resize: vertical;
  min-height: 56px;
  line-height: 1.45;
  font-family: inherit;
}
.flashcard-builder-card .fc-meta-field select:focus,
.flashcard-builder-card .fc-meta-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow, rgba(0, 122, 255, 0.18));
}

@media (max-width: 560px) {
  .flashcard-builder-card {
    padding: 22px 18px 18px;
    border-radius: 16px;
  }
  .flashcard-builder-card .fc-meta-row {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Adaptive Quiz card — extends .flashcard-builder-card
   Adds: card-head summary line, dedicated answer-grading section,
   2-up meta row that wraps cleanly on mobile.
   Light/dark colors derive from the shared --fc-* palette.
   ============================================================ */
.aq-card .fc-card-head {
  flex-wrap: wrap;
  gap: 8px 10px;
}
.aq-card .aq-card-summary {
  flex: 1 1 100%;
  order: 5;
  min-width: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-top: 2px;
}

/* Numbered sections: Question / Media / Answer / Settings.
   Each opens with an eyebrow + hint, then the existing inner card
   content. The dotted divider above each section reinforces the
   "this is a separate region" reading. Subtle staggered fade-in
   on first paint so the card doesn't feel like one undifferentiated
   wall of inputs. */
.aq-section {
  position: relative;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-light, var(--border));
  animation: aq-section-fade-in 320ms ease both;
}
.aq-section:first-of-type {
  margin-top: 14px;
  padding-top: 0;
  border-top: 0;
}
.aq-section--media   { animation-delay: 40ms; }
.aq-section--answer  { animation-delay: 80ms; }
.aq-section--settings{ animation-delay: 120ms; }

@keyframes aq-section-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .aq-section { animation: none; }
}

.aq-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.aq-section-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--accent);
}
.aq-section-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
  flex: 1 1 auto;
  min-width: 140px;
  text-align: right;
}

/* When the inner Answer-grading panel sits directly inside an
   aq-section, drop its top margin so the section padding stays in
   charge of vertical rhythm. */
.aq-section--answer .aq-grading {
  margin-top: 0;
}
/* The Question rich-host now stands on its own without an inner
   "Question" face label (the section eyebrow took over). Tighten
   the bottom margin so the next section's divider sits closer. */
.aq-section--question .fc-face {
  margin-bottom: 4px;
}

.aq-grading {
  margin: 18px 0 4px;
  padding: 16px 16px 14px;
  background: rgba(0, 122, 255, 0.05);
  border: 1px solid rgba(0, 122, 255, 0.18);
  border-radius: 14px;
}
[data-theme="dark"] .aq-grading {
  background: rgba(0, 122, 255, 0.10);
  border-color: rgba(0, 122, 255, 0.30);
}
.aq-grading-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.aq-grading-head .fc-face-label {
  margin-bottom: 0;
}
.aq-grading-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.01em;
}

.aq-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}
.aq-rubric-grid {
  margin-top: 10px;
}
.aq-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.aq-field-wide { grid-column: 1 / -1; }
.aq-field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.aq-field-hint {
  font-weight: 400;
  font-size: 10px;
  font-style: italic;
  margin-left: 6px;
  color: var(--text-muted);
}
.aq-field input[type="text"],
.aq-field input[type="number"],
.aq-field select,
.aq-field textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-elevated);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.aq-field textarea {
  resize: vertical;
  min-height: 56px;
  line-height: 1.45;
  font-family: inherit;
}
.aq-field input:focus,
.aq-field select:focus,
.aq-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow, rgba(0, 122, 255, 0.18));
}

.aq-toggle {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid var(--border);
  border-radius: 10px;
}
[data-theme="dark"] .aq-toggle {
  background: rgba(255, 255, 255, 0.04);
}
.aq-toggle input[type="checkbox"] {
  margin: 4px 0 0;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.aq-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.aq-toggle-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.aq-toggle-sub {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.aq-rubric {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.02);
}
[data-theme="dark"] .aq-rubric {
  background: rgba(255, 255, 255, 0.02);
}
.aq-rubric > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 10px;
  list-style: none;
  user-select: none;
}
.aq-rubric > summary::before {
  content: "▸";
  display: inline-block;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 120ms ease;
}
.aq-rubric[open] > summary::before {
  transform: rotate(90deg);
}
.aq-rubric > summary::-webkit-details-marker { display: none; }
.aq-rubric-meta {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
}

.aq-preview {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--border);
}
[data-theme="dark"] .aq-preview {
  background: rgba(255, 255, 255, 0.04);
}
.aq-preview-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.aq-preview-content {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.45;
}
.aq-preview-tag {
  display: inline-block;
  padding: 3px 8px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  background: rgba(0, 122, 255, 0.10);
  color: var(--accent);
  border: 1px solid rgba(0, 122, 255, 0.22);
  border-radius: 6px;
}
.aq-preview-empty {
  font-style: italic;
  color: var(--text-muted);
  font-size: 12px;
}

.aq-card .fc-meta-row.aq-meta-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.aq-card .fc-meta-row .aq-meta-wide { grid-column: 1 / -1; }

@media (max-width: 640px) {
  .aq-card .fc-meta-row.aq-meta-row,
  .aq-grid {
    grid-template-columns: 1fr;
  }
  .aq-card .fc-card-head {
    align-items: flex-start;
  }
  .aq-card .aq-card-summary {
    white-space: normal;
    text-overflow: clip;
  }
  .aq-grading { padding: 14px 12px; }
  .aq-section-head {
    flex-direction: column;
    gap: 4px;
  }
  .aq-section-hint {
    text-align: left;
    min-width: 0;
  }
  .aq-section { margin-top: 14px; padding-top: 12px; }
}

/* ============================================================
   Notebook Capture toggle (real-life sub-questions)
   ============================================================ */
.capture-toggle-row {
  display: flex;
  width: 100%;
}
.js-capture-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.02);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
  width: 100%;
  justify-content: flex-start;
}
.js-capture-btn:hover {
  border-color: var(--accent);
  background: rgba(0, 122, 255, 0.04);
}
.js-capture-btn .capture-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 150ms ease;
}
.js-capture-btn.on {
  background: rgba(255, 149, 0, 0.12);
  border-color: #FF9500;
  color: #a85400;
  font-weight: 600;
}
.js-capture-btn.on .capture-dot {
  background: #FF9500;
  box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.25);
}

/* ============================================================
   Floating Action Button (FAB) — "Add X" always reachable
   ============================================================ */
.fab-add {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #5856D6);
  color: white;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 10px 32px rgba(0, 122, 255, 0.38), 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 80;
  transition: transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 180ms ease,
              background 180ms ease;
  -webkit-tap-highlight-color: transparent;
}
.fab-add:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 16px 38px rgba(0, 122, 255, 0.48), 0 4px 12px rgba(0, 0, 0, 0.12);
}
.fab-add:active {
  transform: translateY(0) scale(0.98);
}
.fab-add .fab-icon {
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  margin-top: -2px;
}
.fab-add .fab-label {
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Keep FAB out of the way on narrow screens — still visible, smaller */
@media (max-width: 639px) {
  .fab-add {
    bottom: 16px;
    right: 16px;
    height: 52px;
    padding: 0 18px;
    font-size: 14px;
  }
}

/* Don't stack with the preview panel footer — push up if preview is visible */
.builder-content:not(:has(.preview-panel[style*="display:none"])) ~ .fab-add,
body:has(.preview-panel:not([hidden])) .fab-add {
  /* default position is fine — FAB appears inside the main area visually */
}

/* =========================================================================
   Dashboard additions — library tabs, card menu, versions, trash, retry, responsive
   ========================================================================= */

/* Responsive grid */
@media (max-width: 1024px) {
  .homework-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .homework-grid {
    grid-template-columns: 1fr;
  }
}

/* Homework card internal structure */
.homework-card {
  position: relative;
  border-top: 3px solid var(--family-color, var(--accent));
  overflow: hidden;   /* clip children — prevents flex children escaping card boundary */
  min-width: 0;       /* allow card to shrink below intrinsic content width in flex/grid */
}
.homework-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.homework-card .subject-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  background: color-mix(in srgb, var(--family-color, var(--accent)) 12%, transparent);
  color: var(--family-color, var(--accent));
  border: 1px solid color-mix(in srgb, var(--family-color, var(--accent)) 28%, transparent);
}
.homework-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.homework-card .homework-title {
  overflow-wrap: break-word; /* break long unbroken strings (no-space titles) at char boundary */
  word-break: break-word;    /* older-browser fallback */
}
.homework-id {
  margin: 2px 0 0 0;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-subtle);
}
.homework-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.homework-meta span { line-height: 1.4; }

/* Mode + grade pills */
.mode-pill,
.grade-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
/* Pill text colors darkened from #FF3B30 (~3.2:1) and #34C759 (~2.0:1)
   on their tinted backgrounds — both failed WCAG AA. The new shades
   keep the same hue but pass 4.5:1. */
.mode-pill[data-mode="hard"] {
  color: #b91d24;
  border-color: rgba(255, 59, 48, 0.28);
  background: rgba(255, 59, 48, 0.08);
}
.mode-pill[data-mode="easy"] {
  color: #117a3d;
  border-color: rgba(52, 199, 89, 0.28);
  background: rgba(52, 199, 89, 0.08);
}

/* Card action row — push to bottom */
.homework-card .card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  position: relative;
}
.homework-card .card-actions .btn { flex: 1 1 auto; }
.homework-card .card-actions .btn + .card-menu { flex: 0 0 auto; }
.btn.danger,
.menu-item.danger {
  color: #FF3B30;
}
.btn.danger:hover {
  background: rgba(255, 59, 48, 0.08);
  border-color: rgba(255, 59, 48, 0.32);
  color: #FF3B30;
}

/* Card more-menu dropdown */
.card-menu {
  position: relative;
}
.card-menu .js-menu-toggle {
  background: var(--surface-elevated);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-low);
}
.card-menu .js-menu-toggle:hover,
.card-menu .js-menu-toggle:focus-visible,
.card-menu.is-open .js-menu-toggle {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.card-menu .menu-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 6px;
  display: none;
  z-index: 20;
}
.card-menu.is-open .menu-dropdown {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.menu-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}
.menu-item.danger:hover {
  background: rgba(255, 59, 48, 0.10);
  color: #FF3B30;
}

/* Library / Trash tabs */
.library-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.library-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.library-tab:hover { color: var(--text); }
.library-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.library-tab .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}
.library-tab.is-active .tab-count {
  background: var(--accent-light);
  border-color: rgba(0, 122, 255, 0.22);
  color: var(--accent);
}

/* Section-heading layout so tabs + refresh don't collide */
.section-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.section-heading > div:first-child { margin-right: auto; }

/* Retry / error state */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
}
.error-state h3 { margin: 0; }
.error-state p { margin: 0; color: var(--text-muted); }

/* Versions modal */
.versions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 0;
}
.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.version-row .version-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.version-row .version-meta strong { color: var(--text); }
.version-row .version-meta .muted-text { font-size: 11px; }

/* Trash-specific card tweaks */
.homework-card.is-trashed { opacity: 0.9; }
.trash-empty-hint {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* ===== Gate Quote (Phase 0-A) ===== */

.gate-quote-slot {
  border-left: 3px solid var(--accent);
}

.gate-quote-modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 12px 0 16px;
  background: var(--accent-light);
  border-radius: 10px;
  width: fit-content;
}
.gate-quote-mode-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 180ms ease;
}
.gate-quote-mode-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
}
.gate-quote-mode-btn.is-active {
  color: var(--accent);
  background: var(--surface-elevated);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.gate-quote-body {
  padding: 4px 0;
}
.gate-quote-body--auto p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.quote-card-preview {
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent-light), rgba(255, 255, 255, 0.6));
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}
.quote-card-preview-text {
  font-size: 15px;
  font-style: italic;
  line-height: 1.55;
  color: var(--text);
}
.quote-card-preview-meta {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.quote-card-preview-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.quote-picker-chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--border-light);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.quote-chip-origin-national {
  background: rgba(0, 153, 102, 0.12);
  color: #00744f;
  border-color: rgba(0, 153, 102, 0.25);
}
.quote-chip-origin-global {
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
  border-color: rgba(0, 122, 255, 0.25);
}

.gate-quote-body--pinned-empty {
  padding: 24px 18px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.015);
}
.gate-quote-body--pinned-empty p { margin: 0 0 14px; }

.gate-quote-body--custom .field { margin-bottom: 12px; }
.gate-quote-body--custom textarea.form-input {
  font-style: italic;
  line-height: 1.5;
  resize: vertical;
}

/* ===== Quote Picker Modal ===== */

.quote-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: quotePickerFadeIn 180ms ease-out;
}
@keyframes quotePickerFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.quote-picker-card {
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-elevated);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  animation: quotePickerSlideUp 220ms cubic-bezier(0.2, 0.9, 0.32, 1.1);
}
@keyframes quotePickerSlideUp {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.quote-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.quote-picker-header h3 { margin: 2px 0 0; font-size: 17px; }

.quote-picker-filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
  padding: 14px 20px 4px;
}
.quote-picker-filters .form-input {
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
}
/* Quote picker search now uses the shared .search-box pill — span the
   full row width and keep the field height in line with the selects. */
.quote-picker-filters .quote-picker-search {
  grid-column: 1 / -1;
  min-width: 0;
}

.quote-picker-meta {
  padding: 8px 20px 0;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quote-picker-list {
  overflow-y: auto;
  padding: 8px 14px 14px;
  flex: 1;
  min-height: 240px;
}
.quote-picker-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 140ms ease;
}
.quote-picker-row:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
}
.quote-picker-row.is-pinned {
  border-color: var(--accent);
  background: var(--accent-light);
}
.quote-picker-row-text {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.quote-picker-icon {
  flex: 0 0 auto;
  font-size: 14px;
  line-height: 1.3;
}
.quote-picker-row-meta {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.quote-picker-author {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.quote-picker-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 540px) {
  .quote-picker-filters { grid-template-columns: 1fr 1fr; }
  .quote-picker-filters .quote-picker-search { grid-column: 1 / -1; }
}

/* ============================================================
   Theme toggle button + dark-mode coverage patches
   Mounts in the navbar of every page; reads/writes `nets_theme`.
   ============================================================ */

.theme-toggle {
  min-width: 40px;
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1;
}

/* Form controls — light defaults at app.css:758 hardcode #fff. */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="url"],
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: rgba(15, 23, 42, 0.90);
  color: var(--text);
  border-color: var(--border);
}

/* SEARCH-INNER-BOX-01 (dark-mode tail): the rule directly above has
   specificity (0,2,1) — same as `.search-box input[type="search"]` —
   and re-paints a dark background + visible border on the inner input.
   This wrapper-scoped reset is (0,3,1) so the input inside the
   `.search-box` pill stays transparent + borderless in dark mode too. */
[data-theme="dark"] .search-box input[type="search"],
[data-theme="dark"] .search-box input[type="text"] {
  background: transparent;
  border: 0;
}

[data-theme="dark"] input:disabled,
[data-theme="dark"] textarea:disabled,
[data-theme="dark"] select:disabled {
  background: rgba(30, 41, 59, 0.60);
  color: var(--text-muted);
}

/* The native <option> popup ignores rgba/transparent backgrounds, so set a
   solid colour so dropdown items stay readable in dark theme. */
[data-theme="dark"] select option {
  background-color: #1e293b;
  color: var(--text);
}

/* Inline panels that hardcode rgba(255,255,255,…) at lines 1325/1405/1435. */
[data-theme="dark"] .nested-card {
  background: rgba(15, 23, 42, 0.58);
  border-color: var(--border);
}

[data-theme="dark"] .empty-mini {
  background: rgba(15, 23, 42, 0.55);
  border-color: rgba(10, 132, 255, 0.22);
}

[data-theme="dark"] .fixture-card {
  background: rgba(15, 23, 42, 0.82);
  border-color: var(--border);
}
[data-theme="dark"] .fixture-card:hover {
  background: rgba(15, 23, 42, 0.94);
  border-color: rgba(10, 132, 255, 0.28);
}

/* Light blue JSON preview tile at app.css:1373–1374. */
[data-theme="dark"] .json-preview {
  background: rgba(15, 23, 42, 0.90);
  color: var(--text);
  border-color: var(--border);
}

/* Save indicator — base bg is invisible on dark, status text colors unreadable. */
[data-theme="dark"] .save-indicator {
  background: rgba(148, 163, 184, 0.10);
}
[data-theme="dark"] .save-indicator[data-state="saved"] {
  color: var(--status-ready);
}
[data-theme="dark"] .save-indicator[data-state="offline"] {
  color: var(--status-generating);
}

/* Homework card hover border — accent alpha is too dim on dark. */
[data-theme="dark"] .homework-grid .glass-card:hover,
[data-theme="dark"] .homework-grid .homework-card:hover {
  border-color: rgba(10, 132, 255, 0.35);
}

/* Active phase ring — slightly dimmer on dark for restraint. */
[data-theme="dark"] .phase-item.active .status-dot,
[data-theme="dark"] .phase-list button.active .status-dot {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.20);
}

/* ── Dark-theme leaks: light-only hardcoded colors that never
   re-resolved on the slate background. Surfaced by the 2026-04-29
   audit (Sonnet + Opus passes). Each rule below pins the same
   semantic role (success / danger / link) to a value with ≥4.5:1
   contrast on the dark surface.
   ──────────────────────────────────────────────────────────────── */

/* Builder live-preview iframe — was solid #fff inside a dark sidebar,
   creating a harsh white slab. Match the surface variable. */
[data-theme="dark"] .preview-frame {
  background: var(--surface-elevated);
}

/* Flashcard editor "remove card" pill — #c0392b on dark navy is
   ~3.0:1; brighten for AA. */
[data-theme="dark"] .flashcard-builder-card .fc-card-head .js-remove-card {
  color: #ff8a8a;
}

/* Gate-quote origin chips — green/blue text on tinted bg. The
   #00744f national chip dropped to ~2:1 on dark slate. */
[data-theme="dark"] .quote-chip-origin-national {
  color: #6fdca5;
  background: rgba(0, 153, 102, 0.20);
  border-color: rgba(111, 220, 165, 0.32);
}
[data-theme="dark"] .quote-chip-origin-global {
  background: rgba(0, 111, 224, 0.18);
  border-color: rgba(0, 111, 224, 0.32);
}

/* Wave V (visual polish 2026-04-29):
   Gate-quote mode bar + preview card — the light-mode gradient mixed
   60% white into the right side, which blasts through dark surfaces.
   Replace with a same-shape gradient using surface tones. */
[data-theme="dark"] .gate-quote-mode-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .quote-card-preview {
  background: linear-gradient(135deg, rgba(0, 111, 224, 0.18), rgba(15, 23, 42, 0.55));
  border-color: rgba(96, 165, 250, 0.28);
}
[data-theme="dark"] .gate-quote-body--pinned-empty {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(148, 163, 184, 0.24);
}

/* -------- Lang Switch -------- */
.lang-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.lang-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: calc(var(--radius-md) - 3px);
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  line-height: 1.4;
}

.lang-pill:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* Keyboard focus ring — the pills sat in a tight 3-up cluster with no
   visible focus state, so tab-only users couldn't tell which language
   pill was focused. */
.lang-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--accent-light);
  color: var(--accent);
}

.lang-pill.is-active,
.lang-pill[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px var(--accent-glow);
}

/* =========================================================================
   Mobile overflow guard — keep narrow viewports (≤640px / iPhone) from
   producing horizontal scroll. Existing rules already collapse the grids
   to 1 column above; this block hardens the obvious overflow surfaces
   (homework cards, library cards, topbar, gamebreak tab strip).
   ========================================================================= */
@media (max-width: 640px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-shell,
  .builder-shell {
    max-width: 100%;
    overflow-x: hidden;
  }

  .homework-grid {
    grid-template-columns: 1fr;
  }

  .homework-grid .glass-card,
  .homework-grid .homework-card {
    min-width: 0;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .game-break-layout {
    grid-template-columns: 1fr;
  }

  .game-tabs {
    grid-auto-flow: column;
    grid-auto-columns: minmax(140px, max-content);
    overflow-x: auto;
    max-width: 100%;
  }
}

/* ==========================================================================
   Equation Picker + Math Block (MathLive integration)
   ==========================================================================
   The math-block is an inline atomic widget mounted inside the rich editor
   (contenteditable=false so the browser deletes it as one unit). The
   <math-field> Web Component lives inside it. The picker's surface adapts
   to viewport: anchored popover (>=720px), centered modal (480-720px),
   bottom sheet (<480px). All colors come from project CSS variables so
   dark mode works automatically.
   ========================================================================== */

.math-block {
    display: inline-block;
    vertical-align: middle;
    margin: 0 2px;
    padding: 1px 4px;
    border-radius: 6px;
    background: rgba(0, 122, 255, 0.06);
    border: 1px solid rgba(0, 122, 255, 0.18);
    transition: background 120ms, border-color 120ms;
    line-height: 1.2;
    user-select: none;
}
.math-block:hover {
    background: rgba(0, 122, 255, 0.12);
    border-color: rgba(0, 122, 255, 0.32);
}
.math-block:focus-within {
    background: var(--accent-light);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
.math-block math-field {
    font-size: 16px;
    min-width: 28px;
    /* MathLive renders into a Shadow DOM — most styling lives there. The
       outer math-block handles framing + focus state; this inner rule only
       sets the typographic baseline and removes the field's own border. */
    border: 0;
    background: transparent;
    outline: none;
    pointer-events: auto;
    user-select: text;
}
[data-theme="dark"] .math-block {
    background: rgba(0, 122, 255, 0.10);
    border-color: rgba(0, 111, 224, 0.35);
}
[data-theme="dark"] .math-block:focus-within {
    background: rgba(0, 111, 224, 0.20);
    border-color: var(--accent);
}

.equation-picker-root {
    position: fixed;
    inset: 0;
    z-index: 320;
    pointer-events: none;
}
.equation-picker-root[hidden] { display: none !important; }

.equation-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.32);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
}
.equation-picker-root.is-centered .equation-picker-backdrop,
.equation-picker-root.is-sheet .equation-picker-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.equation-picker-panel {
    position: absolute;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: top left;
    animation: equation-picker-pop 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes equation-picker-pop {
    from { opacity: 0; transform: scale(0.96) translateY(-4px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}
@keyframes equation-picker-sheet-slide {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.equation-picker-panel.is-popover {
    width: min(560px, calc(100vw - 24px));
    max-height: min(540px, calc(100vh - 80px));
}
.equation-picker-panel.is-centered {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    transform-origin: center;
    animation: equation-picker-pop 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.equation-picker-panel.is-sheet {
    left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 80vh;
    border-radius: 18px 18px 0 0;
    transform: none;
    transform-origin: bottom center;
    animation: equation-picker-sheet-slide 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.equation-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px 18px;
    border-bottom: 1px solid var(--border-light);
}
.equation-picker-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.equation-picker-header-actions {
    display: flex; align-items: center; gap: 6px;
}
.equation-picker-codeview {
    padding: 4px 10px;
    font-size: 11px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: background 120ms, color 120ms, border-color 120ms;
}
.equation-picker-codeview:hover {
    background: var(--accent-light);
    color: var(--accent);
}
.equation-picker-codeview[aria-pressed="true"] {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.equation-picker-close {
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    transition: background 120ms, color 120ms;
}
.equation-picker-close:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.equation-picker-search {
    padding: 10px 16px 6px 16px;
}
.equation-picker-search-input {
    width: 100%;
    height: 36px;
    padding: 0 12px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    transition: border-color 120ms, box-shadow 120ms;
}
.equation-picker-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.equation-picker-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 12px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-light);
    scrollbar-width: thin;
}
.equation-picker-tab {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border-radius: 8px;
    transition: background 120ms, color 120ms;
    white-space: nowrap;
}
.equation-picker-tab:hover { color: var(--text); background: var(--accent-light); }
.equation-picker-tab.is-active {
    color: white;
    background: var(--accent);
}

.equation-picker-grid {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 12px 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    gap: 6px;
    align-content: start;
}

.equation-picker-tile {
    min-height: 64px;
    padding: 8px 6px 6px 6px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    transition: background 120ms, border-color 120ms, transform 80ms;
    text-align: center;
    overflow: hidden;
}
.equation-picker-tile:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}
.equation-picker-tile:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.equation-picker-tile:active { transform: scale(0.96); }

.equation-picker-tile-glyph {
    font-size: 18px;
    line-height: 1.1;
    color: var(--text);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.equation-picker-tile-glyph .katex { font-size: 1em; }
.equation-picker-tile-glyph .katex-display { margin: 0; }
.equation-picker-tile-label {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.equation-picker-empty {
    grid-column: 1 / -1;
    padding: 32px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.equation-picker-hint {
    padding: 8px 16px 12px 16px;
    font-size: 11px;
    color: var(--text-subtle);
    border-top: 1px solid var(--border-light);
    line-height: 1.5;
}
.equation-picker-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    font-size: 10px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

/* Lazy-load gate banner: shown while MathLive's CDN bundle is downloading
   (first picker open). Replaced by the default kbd-hint once ready. */
.equation-picker-loading {
    color: var(--text-muted);
    font-style: italic;
}
.equation-picker-loading::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    vertical-align: middle;
    animation: equation-picker-spin 700ms linear infinite;
}
@keyframes equation-picker-spin {
    to { transform: rotate(360deg); }
}

/* Error banner: shown if MathLive's CDN load fails (network, SRI mismatch,
   server unreachable). role="alert" on the inner span so screen readers
   announce it. */
.equation-picker-error {
    color: #b91c1c;
    font-weight: 500;
}
[data-theme="dark"] .equation-picker-error {
    color: #fca5a5;
}

@media (min-width: 480px) and (max-width: 719px) {
    .equation-picker-panel.is-centered .equation-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
    }
}
@media (max-width: 479px) {
    .equation-picker-panel.is-sheet .equation-picker-tab {
        padding: 8px 14px;
        font-size: 14px;
    }
    .equation-picker-panel.is-sheet .equation-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
        padding: 12px 12px 18px 12px;
        gap: 8px;
    }
    .equation-picker-panel.is-sheet .equation-picker-tile {
        min-height: 72px;
    }
    .equation-picker-panel.is-sheet .equation-picker-hint {
        display: none;
    }
}

