/* styles.css — Obsidian Dark Theme (default) + Light Theme */
/*
   Dark Theme Palette:
   Background:  #0a0a0e  (near-black body + context + correct-answer bg)
   Surface 1:   #111117  (sticky header)
   Surface 2:   rgba(124,58,237,0.05)  (cards + meta-controls — purple-tinted glass)
   Surface 3:   transparent  (option items — bare, no surface)
   Border dim:  rgba(255,255,255,0.04)  (hairline separators)
   Border mid:  rgba(167,139,250,0.1)   (q-header bottom rule)
   Border hover:rgba(167,139,250,0.18)  (card hover ring)

   Purple  (primary — h1, q-number, q-header, meta, set, buttons, answers, notes):
           deep  #7c3aed  /  mid  #a78bfa  /  light  #c4b5fd  /  pale  #e0d7ff
   Rose    (option text + opt-label):                  #fb7185 / #fda4af
   Copy-success (accent):                              #7c3aed / #a78bfa
   Text:   #f1f0f7 (primary)  /  #b0aac8 (context)  /  #5858a0 (topic / muted)
*/

:root {
    /* Dark Theme (Default) */
    --bg-color: #0a0a0e;
    --surface-1: #111117;
    --surface-2: rgba(124, 58, 237, 0.05);
    --surface-3: transparent;
    --border-dim: rgba(255, 255, 255, 0.04);
    --border-mid: rgba(167, 139, 250, 0.1);
    --border-hover: rgba(167, 139, 250, 0.18);
    
    --purple-deep: #7c3aed;
    --purple-mid: #a78bfa;
    --purple-light: #c4b5fd;
    --purple-pale: #e0d7ff;
    
    --rose-text: #fb7185;
    --rose-light: #fda4af;
    
    --text-primary: #f1f0f7;
    --text-context: #b0aac8;
    --text-muted: #5858a0;
    --text-strong: #f0abfc;
    
    --shadow-main: 0 8px 18px -10px rgba(0, 0, 0, 0.5);
    --shadow-inner: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    --sidebar-shadow: 20px 0 60px rgba(0, 0, 0, 0.7);
    --pill-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.12);
    --glow-shadow: 0px 4px 10px rgba(255, 255, 255, 0.25);
    
    --modal-bg: rgba(0, 0, 0, 0.85);
    --glass-bg: rgba(17, 17, 23, 0.8);
    --selection-bg: rgba(124, 58, 237, 0.3);
    --green-mid: #4ade80;
    --green-deep: #22c55e;
    --light-glow: rgba(255, 255, 255, 0.4);

    /* Note/panel semantics — each has light-theme equivalent */
    --text-body: #d4d0e8;
    --surface-panel: rgba(10, 10, 14, 0.98);
    --surface-panel-alt: rgba(17, 17, 23, 0.98);
    --panel-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    --notes-wrap-shadow: 0 4px 12px rgba(255, 255, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    --blockquote-accent: rgba(167, 139, 250, 0.08);
    --blockquote-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.18) 0%, rgba(17, 17, 23, 0.98) 100%);
    --blockquote-tip-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.18) 0%, rgba(10, 10, 14, 0.98) 100%);
    --blockquote-border: var(--purple-mid);
    --blockquote-tip-border: var(--purple-deep);
    --blockquote-text: var(--purple-pale);
    --blockquote-strong-decoration: rgba(240, 171, 252, 0.3);
    --callout-tip-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.15) 0%, var(--surface-panel) 100%);
    --callout-tip-accent: rgba(124, 58, 237, 0.06);
    --option-text: var(--text-strong);
    --option-hover: #f5c6fe;
    --opt-label-bg: rgba(217, 70, 239, 0.1);
    --opt-label-color: #d946ef;
    --note-h3-border: rgba(240, 171, 252, 0.5);
    --section-title-border: rgba(167, 139, 250, 0.15);
    --note-h1-border: rgba(196, 181, 253, 0.25);
    --inline-code-bg: linear-gradient(135deg, rgba(124, 58, 237, 0.28) 0%, rgba(167, 139, 250, 0.18) 100%);
    --inline-code-border: rgba(167, 139, 250, 0.25);
    --code-block-border: rgba(167, 139, 250, 0.3);
    --code-block-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.03);
    --formula-bg: rgba(0, 0, 0, 0.28);
    --formula-border: rgba(124, 58, 237, 0.15);
    --formula-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.45);

    /* Headings & MathJax */
    --heading-1-color: #e0d7ff;
    --heading-1-shadow: 0 0 40px rgba(167, 139, 250, 0.25);
    --heading-2-color: #a78bfa;
    --heading-2-shadow: 0 0 30px rgba(167, 139, 250, 0.2);
    --mathjax-color: #c4b5fd;

    /* Theme toggle icons (display) */
    --theme-icon-sun: none;
    --theme-icon-moon: block;

    /* Table */
    --table-header-text: var(--bg-color);
    --table-header-bg: linear-gradient(90deg, rgba(124,58,237,0.92), rgba(167,139,250,0.9));
    --table-header-corner-bg: linear-gradient(90deg, rgba(103,58,183,0.95), rgba(124,58,237,0.95));
    --table-header-corner-text: #ffffff;
    --table-header-border: rgba(255,255,255,0.04);
    --table-first-col-bg: linear-gradient(180deg, rgba(167,139,250,0.04), rgba(124,58,237,0.03));
    --table-cell-text: #e8e6f7;
    --table-cell-border: rgba(255,255,255,0.03);
    --table-alt-row-bg: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
    --table-hover-bg: linear-gradient(90deg, rgba(124,58,237,0.03), rgba(167,139,250,0.02));

    /* TOC items (notes sidebar) */
    --toc-item-bg: rgba(0, 0, 0, 0.28);
    --toc-item-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.45);
    --toc-item-border: rgba(167, 139, 250, 0.1);
    --toc-item-hover-bg: linear-gradient(90deg, rgba(124, 58, 237, 0.18), rgba(167, 139, 250, 0.08));
    --toc-item-hover-border: rgba(167, 139, 250, 0.4);
    --toc-item-active-bg: linear-gradient(90deg, rgba(124, 58, 237, 0.32), rgba(167, 139, 250, 0.18));
    --toc-item-active-border: rgba(167, 139, 250, 0.55);
    --toc-item-active-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    --toc-link-color: var(--purple-light);
    --toc-link-hover-color: #ffffff;
    --toc-link-active-color: #ffffff;

    /* Editor textareas (explanation + notes) */
    --editor-textarea-bg: rgba(0, 0, 0, 0.35);
    --editor-textarea-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
    --editor-textarea-focus-shadow: 0 0 0 2px rgba(124, 58, 237, 0.1), inset 0 2px 10px rgba(0, 0, 0, 0.5);

    /* Login page */
    --login-card-bg: rgba(124, 58, 237, 0.04);
    --login-card-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 8px 32px rgba(0, 0, 0, 0.3);
    --login-input-bg: rgba(17, 17, 23, 0.8);
    --login-input-border: rgba(167, 139, 250, 0.2);
    --login-contact-border: rgba(255, 255, 255, 0.06);
}

.light-theme {
    /* Light theme — exact equivalents for each dark variable (same semantic role) */
    --bg-color: #f7f8fc;
    --surface-1: #ffffff;
    --surface-2: rgba(124, 58, 237, 0.04);
    --surface-3: transparent;
    --border-dim: rgba(0, 0, 0, 0.06);
    --border-mid: rgba(124, 58, 237, 0.15);
    --border-hover: rgba(124, 58, 237, 0.25);

    --purple-deep: #6d28d9;
    --purple-mid: #7c3aed;
    --purple-light: #8b5cf6;
    --purple-pale: #4c4363;

    --rose-text: #e11d48;
    --rose-light: #f43f5e;

    --text-primary: #1e1b4b;
    --text-context: #475569;
    --text-muted: #64748b;
    --text-strong: #c026d3;

    --shadow-main: 0 4px 15px -5px rgba(0, 0, 0, 0.08);
    --shadow-inner: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --card-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.04);
    --sidebar-shadow: 10px 0 40px rgba(0, 0, 0, 0.06);
    --pill-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), inset 0 0 0 1px rgba(124, 58, 237, 0.1);
    --glow-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);

    --modal-bg: rgba(15, 23, 42, 0.35);
    --glass-bg: rgba(255, 255, 255, 0.96);
    --selection-bg: rgba(124, 58, 237, 0.15);
    --green-mid: #16a34a;
    --green-deep: #15803d;
    --light-glow: rgba(124, 58, 237, 0.08);

    --text-body: #1e1b4b;
    --surface-panel: rgba(255, 255, 255, 0.98);
    --surface-panel-alt: rgba(255, 255, 255, 0.98);
    --panel-shadow: 0 4px 16px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --notes-wrap-shadow: 0 4px 16px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --blockquote-accent: rgba(124, 58, 237, 0.12);
    --blockquote-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.18) 0%, var(--surface-panel) 100%);
    --blockquote-tip-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.2) 0%, var(--surface-panel) 100%);
    --blockquote-border: var(--purple-mid);
    --blockquote-tip-border: var(--purple-deep);
    --blockquote-text: var(--purple-pale);
    --blockquote-strong-decoration: rgba(192, 38, 211, 0.4);
    --callout-tip-bg: linear-gradient(165deg, rgba(124, 58, 237, 0.1) 0%, var(--surface-panel) 100%);
    --callout-tip-accent: rgba(124, 58, 237, 0.1);
    --option-text: var(--text-strong);
    --option-hover: #e879f9;
    --opt-label-bg: rgba(192, 38, 211, 0.12);
    --opt-label-color: #c026d3;
    --note-h3-border: rgba(192, 38, 211, 0.45);
    --section-title-border: rgba(124, 58, 237, 0.2);
    --note-h1-border: rgba(124, 58, 237, 0.25);
    --inline-code-bg: rgba(124, 58, 237, 0.15);
    --inline-code-border: rgba(124, 58, 237, 0.25);
    --code-block-border: rgba(124, 58, 237, 0.25);
    --code-block-shadow: 0 2px 8px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --formula-bg: rgba(124, 58, 237, 0.1);
    --formula-border: rgba(124, 58, 237, 0.2);
    --formula-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

    --heading-1-color: var(--purple-pale);
    --heading-1-shadow: none;
    --heading-2-color: var(--purple-mid);
    --heading-2-shadow: none;
    --mathjax-color: var(--purple-light);

    --theme-icon-sun: block;
    --theme-icon-moon: none;

    --table-header-text: #ffffff;
    --table-header-bg: linear-gradient(90deg, rgba(124,58,237,0.92), rgba(167,139,250,0.88));
    --table-header-corner-bg: linear-gradient(90deg, rgba(103,58,183,0.95), rgba(124,58,237,0.92));
    --table-header-corner-text: #ffffff;
    --table-header-border: rgba(255,255,255,0.2);
    --table-first-col-bg: linear-gradient(180deg, rgba(124,58,237,0.06), rgba(167,139,250,0.04));
    --table-cell-text: var(--text-primary);
    --table-cell-border: rgba(0,0,0,0.06);
    --table-alt-row-bg: linear-gradient(180deg, rgba(124,58,237,0.02), transparent);
    --table-hover-bg: linear-gradient(90deg, rgba(124,58,237,0.06), rgba(167,139,250,0.04));

    /* TOC items (notes sidebar) — light equivalents */
    --toc-item-bg: rgba(124, 58, 237, 0.06);
    --toc-item-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.04);
    --toc-item-border: rgba(124, 58, 237, 0.15);
    --toc-item-hover-bg: linear-gradient(90deg, rgba(124, 58, 237, 0.12), rgba(167, 139, 250, 0.06));
    --toc-item-hover-border: rgba(124, 58, 237, 0.35);
    --toc-item-active-bg: linear-gradient(90deg, rgba(124, 58, 237, 0.2), rgba(167, 139, 250, 0.12));
    --toc-item-active-border: rgba(124, 58, 237, 0.45);
    --toc-item-active-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    --toc-link-color: var(--purple-mid);
    --toc-link-hover-color: var(--purple-deep);
    --toc-link-active-color: var(--purple-deep);

    /* Editor textareas — light equivalents */
    --editor-textarea-bg: rgba(255, 255, 255, 0.98);
    --editor-textarea-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.06);
    --editor-textarea-focus-shadow: 0 0 0 2px rgba(124, 58, 237, 0.15), inset 0 1px 4px rgba(0, 0, 0, 0.06);

    /* Login page — light equivalents */
    --login-card-bg: rgba(255, 255, 255, 0.98);
    --login-card-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(124, 58, 237, 0.1);
    --login-input-bg: rgba(255, 255, 255, 0.98);
    --login-input-border: rgba(124, 58, 237, 0.2);
    --login-contact-border: rgba(0, 0, 0, 0.08);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    padding: 20px;
    background-color: var(--bg-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== Sticky Header ===== */
.sticky-header {
    position: sticky;
    top: 0;
    background: var(--surface-1);
    z-index: 1000;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-dim);
    box-shadow: var(--shadow-main), var(--shadow-inner);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.header-top-row {
    display: flex;
    justify-content: center; /* Default centered for narrow screens */
    align-items: center;
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

.theme-toggle-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-2);
    border: 1px solid var(--border-mid);
    color: var(--purple-mid);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--pill-shadow);
}

.theme-toggle-btn:hover {
    background: var(--border-hover);
    transform: translateY(calc(-50% - 1px));
}

.theme-icon-light { display: var(--theme-icon-sun); }
.theme-icon-dark { display: var(--theme-icon-moon); }

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.paper-container {
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

/* ===== Headings ===== */
h1 {
    color: var(--heading-1-color);
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    text-shadow: var(--heading-1-shadow);
    letter-spacing: -0.01em;
    transition: color 0.3s ease;
}

h2 {
    color: var(--heading-2-color);
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    line-height: 1.3;
    text-shadow: var(--heading-2-shadow);
    transition: color 0.3s ease;
}

/* Year section headers inside question files */
.year-section h2 {
    text-align: center;
    color: var(--purple-light);
    border-bottom: none;
    padding-bottom: 12px;
    margin-bottom: 24px;
    box-shadow: 0 2px 0 var(--border-mid);
}

/* ===== Set Indicator (divider style) ===== */
.set-indicator-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 4px 0 8px;
    padding: 0 8px;
}

.set-indicator-line {
    flex: 1;
    height: 1px;
}

.set-indicator-left {
    background: linear-gradient(90deg, transparent 0%, var(--purple-deep) 100%);
    opacity: 0.55;
}

.set-indicator-right {
    background: linear-gradient(90deg, var(--purple-deep) 0%, transparent 100%);
    opacity: 0.55;
}

.auth-row {
    display: flex;
    justify-content: flex-end;
    padding: 0 12px;
}

.auth-wrap {
    display: inline-flex;
}

.auth-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    text-decoration: none;
    color: var(--purple-mid);
    font-size: 0.82rem;
    transition: color 0.25s ease, text-decoration-color 0.25s ease;
    text-underline-offset: 4px;
}

.auth-pill-login {
    text-decoration: underline;
    text-decoration-color: var(--border-hover);
}

.auth-pill-login:hover {
    color: var(--purple-light);
    text-decoration-color: var(--purple-light);
}

.auth-pill .auth-icon {
    display: flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: inherit;
}

.auth-pill .auth-icon svg {
    width: 100%;
    height: 100%;
}

.auth-pill .auth-text {
    font-weight: 500;
}

.auth-login-wrap {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px 4px;
}

.auth-hint {
    font-size: 0.72rem;
    color: var(--text-context);
    font-weight: 400;
}

.auth-pill-logged {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    color: var(--purple-light);
    font-size: 0.82rem;
}

.auth-pill-logged .auth-icon {
    color: inherit;
}

.auth-pill-logged .auth-text strong {
    color: var(--text-strong);
}

.auth-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    margin-left: 4px;
    border: none;
    background: transparent;
    color: var(--purple-light);
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.auth-logout-btn:hover {
    color: var(--purple-pale);
    background: var(--surface-2);
}

.auth-logout-btn svg {
    width: 16px;
    height: 16px;
}

.set-indicator-text {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    color: var(--purple-mid);
    text-transform: uppercase;
    white-space: nowrap;
    user-select: none;
}

.set-dot {
    color: var(--purple-deep);
    font-size: 0.5rem;
    vertical-align: middle;
    margin: 0 3px;
    opacity: 0.8;
}

#set-letter {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--purple-light);
    text-shadow: 0 0 12px rgba(196, 181, 253, 0.55);
    letter-spacing: 0.06em;
}

/* ===== Meta Controls (dashboard panel) ===== */
.meta-controls {
    display: flex;
    align-items: stretch;
    margin: 10px auto 20px;
    max-width: 680px;
    border-radius: 12px;
    background: var(--surface-2);
    overflow: hidden;
    box-shadow: var(--pill-shadow), var(--card-shadow);
}

/* Each control zone */
.meta-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 16px 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    gap: 3px;
    min-width: 0;
}

/* Paper and Year get less flex; Section gets more room for long names */
.meta-paper { flex: 1; }
.meta-year  { flex: 0.8; }
.meta-section { flex: 2; }

.meta-item:hover {
    background: rgba(124, 58, 237, 0.11);
}

/* Dim ALL-CAPS label */
.meta-label {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-muted);
    user-select: none;
    transition: color 0.2s ease;
}

/* Bold display value */
.meta-value {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--purple-light);
    text-shadow: 0 0 8px rgba(196, 181, 253, 0.2);
    user-select: none;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.meta-item:hover .meta-label {
    color: var(--text-context);
}

.meta-item:hover .meta-value {
    color: var(--purple-pale);
    text-shadow: 0 0 16px rgba(196, 181, 253, 0.6);
}

/* Hidden select overlay — covers the whole item zone */
.meta-item select {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: inherit;
    -webkit-appearance: none;
    appearance: none;
}

/* Vertical separator between zones */
.meta-sep-line {
    width: 1px;
    background: var(--border-dim);
    align-self: stretch;
    margin: 10px 0;
    flex-shrink: 0;
}

/* ===== Question Card ===== */
.question-card {
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 28px;
    background-color: var(--surface-2);
    transition: all 0.28s ease;
    position: relative;
    box-shadow: var(--card-shadow), var(--shadow-inner);
    box-sizing: border-box;
}

.question-card:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), var(--shadow-inner), 0 0 0 1px var(--border-hover);
    transform: translateY(-2px);
}

/* ===== Optional: plain card style for content-only cards (no surface) ===== */
.question-card.no-surface {
    background: transparent;
    box-shadow: none;
    padding: 12px 0;
    border-radius: 6px;
}

/* ===== Question Header ===== */
.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px 12px;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
    background: linear-gradient(90deg, var(--border-hover) 0%, var(--surface-2) 100%);
    border-radius: 8px;
    border-bottom: 1px solid var(--border-mid);
    box-shadow: var(--glow-shadow), var(--shadow-inner);
}

.q-header-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.q-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.q-header-actions .q-copy-btn,
.q-header-actions .q-answer-btn,
.q-header-actions .q-ask-ai-btn,
.q-header-actions .edit-question-trigger {
    padding: 6px 8px;
}

.q-number {
    font-weight: 700;
    color: var(--purple-mid);
    font-size: 1.1rem;
    text-shadow: 0 0 10px rgba(167, 139, 250, 0.35);
}

/* ===== Topic — inline annotation style ===== */
.q-topic {
    font-size: 0.78rem;
    font-weight: 500;
    font-style: italic;
    color: var(--text-strong);
    padding-left: 10px;
    line-height: 1.3;
    letter-spacing: 0.01em;
    user-select: none;
}

/* ===== Question Text ===== */
.q-text {
    color: var(--text-primary);
    font-size: 1.125rem;
    line-height: 1.8;
    margin-bottom: 18px;
}

/* MathJax inside q-text and q-context — consistent lavender */
.q-text mjx-container,
.q-context mjx-container, .q-notes-content mjx-container, .note-section-content mjx-container, .callout-content mjx-container {
    color: var(--mathjax-color);
}

/* ===== Context Block — blockquote style ===== */
.q-context {
    color: var(--text-context);
    font-size: 1.0625rem;
    line-height: 1.85;
    padding: 14px 0 14px 20px;
    margin-bottom: 20px;
    position: relative;
    overflow: auto;
    background: var(--bg-color);
    border-radius: 6px;
    box-shadow: var(--glow-shadow), var(--shadow-inner);
}

/* Gradient left stripe — the only visual anchor */
.q-context::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 3px;
    background: linear-gradient(180deg, var(--purple-mid) 0%, var(--purple-deep) 100%);
}

.q-context strong {
    font-weight: 600;
    color: var(--text-strong);
}

/* ===== Data Table ===== */
.q-table {
    overflow-x: auto;
    margin: 18px 0;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    box-shadow: var(--glow-shadow), var(--shadow-inner);
}

.q-table table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    font-size: 1rem;
    background: transparent;
    overflow: hidden;
    border-radius: 8px;
}

/* Elegant header: purple → lavender gradient with subtle gloss
   Support tables that use either a plain first row or a <thead>/<th> structure. */
.q-table:not(:has(thead)) tr:first-child td,
.q-table thead tr th,
.q-table:not(:has(thead)) tr:first-child th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    font-weight: 800;
    padding: 12px 14px;
    text-align: center;
    border-bottom: 1px solid var(--table-header-border);
    letter-spacing: 0.02em;
}

/* First column — soft lavender panel (apply to th and td) */
.q-table td:first-child,
.q-table th:first-child {
    background: var(--table-first-col-bg);
    color: var(--purple-light);
    font-weight: 700;
    padding: 12px;
    text-align: left;
}

/* Top-left corner accent */
.q-table:not(:has(thead)) tr:first-child td:first-child,
.q-table thead tr th:first-child {
    background: var(--table-header-corner-bg);
    color: var(--table-header-corner-text);
    font-weight: 800;
}

/* Data cells — minimal, with thin separators for readability */
.q-table td,
.q-table th {
    padding: 12px 14px;
    word-wrap: break-word;
    background: transparent;
    color: var(--table-cell-text);
    border-bottom: 1px solid var(--table-cell-border);
}

/* Alternating row warmth */
.q-table tr:nth-child(even) td:not(:first-child) {
    background: var(--table-alt-row-bg);
}

/* Row hover elegant lift */
.q-table tr:hover td {
    background: var(--table-hover-bg);
}

/* ===== Options Grid — bare 2-col layout, no surface ===== */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
    padding: 0;
    position: relative;
    background: transparent;
}

/* option items are bare text — no background, border, or box-shadow */

.option-item {
    background: transparent;
    padding: 7px 4px;
    border-radius: 0;
    display: flex;
    align-items: center;
    color: var(--option-text);
    font-size: 1.0625rem;
    line-height: 1.6;
    transition: color 0.15s ease;
}

.option-item:hover {
    color: var(--option-hover);
}

/* Option label — small capsule */
.opt-label {
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 20px;
    border-radius: 5px;
    background: var(--opt-label-bg);
    color: var(--opt-label-color);
    font-weight: 700;
    font-size: 0.7rem;
    margin-right: 10px;
    flex-shrink: 0;
    margin-top: 3px;
    letter-spacing: 0;
}

@media (max-width: 600px) {
    .options-grid { 
        grid-template-columns: 1fr; 
        gap: 6px;
    }
}

/* ===== Touch Devices ===== */
@media (hover: none) and (pointer: coarse) {
    .question-card:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
        transform: none;
    }
    .meta-item:hover {
        background: rgba(124, 58, 237, 0.08);
    }
    .option-item {
        -webkit-tap-highlight-color: rgba(217, 70, 239, 0.08);
    }
    .option-item:hover {
        transform: none;
    }
}

/* ===== Question Bank Loader ===== */
.qb-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 40px;
    gap: 28px;
}

/* Ring wrap holds the three layered rings + symbol */
.qb-loader-ring-wrap {
    position: relative;
    width: 80px;
    height: 80px;
}

/* Dim background ring — always visible */
.qb-loader-ring-bg {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(124, 58, 237, 0.12);
}

/* Mid glow ring — slow counter-rotation */
.qb-loader-ring-mid {
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: rgba(196, 181, 253, 0.25);
    border-left-color: rgba(124, 58, 237, 0.15);
    animation: qb-spin-rev 2.4s linear infinite;
}

/* Main spinning arc — purple to lavender gradient edge */
.qb-loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--purple-mid);
    border-right-color: var(--purple-deep);
    box-shadow: 0 0 18px rgba(167, 139, 250, 0.25);
    animation: qb-spin 1.3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* Centre sigma — pulses with purple glow */
.qb-loader-symbol {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--purple-mid);
    text-shadow: 0 0 24px rgba(167, 139, 250, 0.7), 0 0 6px rgba(124, 58, 237, 0.4);
    animation: qb-symbol-pulse 1.3s ease-in-out infinite;
    user-select: none;
}

/* Three cascading dots below the ring */
.qb-loader-dots {
    display: flex;
    gap: 10px;
    align-items: center;
}

.qb-loader-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    animation: qb-dot-bounce 1.2s ease-in-out infinite;
}

.qb-loader-dot:nth-child(1) {
    background: var(--purple-deep);
    animation-delay: 0s;
}
.qb-loader-dot:nth-child(2) {
    background: var(--purple-mid);
    animation-delay: 0.18s;
}
.qb-loader-dot:nth-child(3) {
    background: var(--purple-light);
    animation-delay: 0.36s;
}

/* Dim uppercase label */
.qb-loader-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--text-muted);
    user-select: none;
}

@keyframes qb-spin {
    to { transform: rotate(360deg); }
}

@keyframes qb-spin-rev {
    to { transform: rotate(-360deg); }
}

@keyframes qb-symbol-pulse {
    0%, 100% { opacity: 0.55; transform: scale(0.9); }
    50%       { opacity: 1;    transform: scale(1.1); }
}

@keyframes qb-dot-bounce {
    0%, 80%, 100% { transform: translateY(0)   scale(0.75); opacity: 0.35; }
    40%           { transform: translateY(-7px) scale(1.15); opacity: 1;    }
}

/* ===== Year Section Container ===== */
.year-section {
    padding: 10px 0;
}

/* ===== Content Viewer ===== */
.content-viewer {
    width: 100%;
    min-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-top: 40px;
}

#iframe-viewer {
    width: 100%;
    min-height: 600px;
}

/* ===== Action row: [Wrong Answer?] ... [Show Answer] [Copy] ===== */
.q-actions-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 18px;
    padding-top: 16px;
}

.q-actions-row::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(167, 139, 250, 0.15) 15%, rgba(124, 58, 237, 0.25) 50%, rgba(167, 139, 250, 0.15) 85%, transparent 100%);
}

.q-actions-left {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    display: flex;
    align-items: center;
    overflow: hidden;
}

.q-actions-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.q-copy-btn,
.q-answer-btn,
.q-ask-ai-btn {
    position: relative;
    background: rgba(255,255,255,0.04);
    color: var(--purple-mid);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.12);
}

.q-copy-btn::after,
.q-answer-btn::after,
.q-ask-ai-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-color);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.q-copy-btn:hover::after,
.q-answer-btn:hover::after,
.q-ask-ai-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

.q-copy-btn:hover,
.q-answer-btn:hover,
.q-ask-ai-btn:hover {
    color: var(--purple-pale);
    transform: scale(1.12);
}

.q-copy-btn:active,
.q-answer-btn:active,
.q-ask-ai-btn:active {
    transform: scale(0.95);
}

.q-copy-btn svg,
.q-ask-ai-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.q-copy-btn.copied {
    color: var(--purple-mid);
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25);
}

.q-answer-btn:hover {
    color: var(--purple-pale);
}

.q-answer-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.q-ask-ai-btn:hover {
    color: var(--text-strong);
    box-shadow: 0 0 0 1px rgba(192, 38, 211, 0.35);
}

/* ===== Collapsible explanation section (shown when answer visible) ===== */
.explanation-collapsible {
    margin-top: 18px;
    border-radius: 12px;
    background: linear-gradient(165deg, rgba(124, 58, 237, 0.06) 0%, var(--surface-panel) 100%);
    border: 1px solid rgba(167, 139, 250, 0.15);
    overflow: hidden;
}

.explanation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.explanation-toggle {
    padding: 0;
    background: transparent;
    border: none;
    color: var(--purple-mid);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.explanation-toggle:hover {
    color: var(--purple-light);
}

.explanation-toggle-label {
    letter-spacing: 0.05em;
}

.explanation-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.explanation-header-right .q-header-action-btn {
    width: 28px;
    height: 28px;
    color: var(--purple-mid);
}

.explanation-header-right .q-header-action-btn:hover {
    color: var(--purple-light);
}

.explanation-header-right .explanation-copy-btn.copied {
    color: var(--purple-mid);
}

.explanation-chevron-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: transparent;
    border: none;
    color: var(--purple-mid);
    cursor: pointer;
    transition: all 0.2s;
}

.explanation-chevron-btn:hover {
    color: var(--purple-light);
}

.explanation-chevron {
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.explanation-collapsible.expanded .explanation-chevron {
    transform: rotate(180deg);
}

.explanation-body {
    display: none;
    padding: 0 16px 16px;
}

.explanation-collapsible.expanded .explanation-body {
    display: block;
}

.q-actions-right {
    flex-shrink: 0;
}

.revealed-triggers-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Icon buttons: Wrong Answer?, Add/Edit Explanation, Edit Question — same style as Copy/Show Answer */
.q-header-action-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--purple-mid);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.q-header-action-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-color);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.q-header-action-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

.q-header-action-btn:hover {
    color: var(--purple-pale);
    transform: scale(1.12);
}

.q-header-action-btn:active {
    transform: scale(0.95);
}

.q-header-action-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Wrong Answer? — flag icon, rose accent */
.wrong-answer-trigger.q-header-action-btn {
    color: var(--rose-text);
}

.wrong-answer-trigger.q-header-action-btn:hover {
    color: #fda4af;
}

/* Edit Explanation — document icon */
.edit-explanation-trigger.q-header-action-btn {
    color: var(--purple-mid);
}

.edit-explanation-trigger.q-header-action-btn:hover {
    color: var(--purple-light);
}

/* Edit Question — pencil icon */
.edit-question-trigger.q-header-action-btn {
    color: var(--purple-mid);
}

.edit-question-trigger.q-header-action-btn:hover {
    color: var(--purple-light);
}

.explanation-body .notes-wrap {
    margin-top: 0;
}

.notes-wrap {
    width: 100%;
    margin-top: 18px;
    padding: 12px;
    border-radius: 14px;
    background: linear-gradient(165deg, rgba(124, 58, 237, 0.08) 0%, var(--surface-panel) 100%);
    border: none;
    box-shadow: var(--notes-wrap-shadow);
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    animation: slideUp 0.3s ease-out;
    text-align: center;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* "Explanation" header label - hide when inside collapsible (toggle already says it) */
.explanation-body .notes-wrap::before {
    content: none !important;
}
/* "Explanation" header label - moved to top-left */
.notes-wrap::before {
    content: 'EXPLANATION';
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    color: var(--text-strong); /* Orchid/Soft Purple for better alignment with theme */
    text-shadow: 0 0 10px rgba(240, 171, 252, 0.35);
    user-select: none;
    pointer-events: none;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* Left accent stripe for visual continuity with context blocks */
.notes-wrap::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--text-strong) 0%, var(--purple-deep) 100%);
    border-radius: 4px 0 0 4px;
}

.q-notes-content {
    width: 100%;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: break-word;
    margin-top: 16px;
}

.q-notes-rich { 
    white-space: pre-wrap; 
    word-break: break-word; 
    overflow-x: auto; 
    overflow-y: hidden;
}

.q-notes-rich code {
    background: var(--inline-code-bg);
    color: var(--text-strong);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    border: 1px solid var(--inline-code-border);
    box-shadow: var(--shadow-inner);
}

.q-notes-rich strong {
    color: var(--purple-light);
    font-weight: 700;
}

.q-notes-empty { 
    color: var(--text-muted); 
    font-style: italic; 
    text-align: center;
    font-size: 0.9rem;
}

.note-editor {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}
.note-editor-text {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 120px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(167,139,250,0.12);
    background: var(--editor-textarea-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    box-sizing: border-box;
}
.note-editor-actions { display: flex; gap: 12px; justify-content: center; }
.note-save-btn, .note-cancel-btn {
    padding: 2px 8px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 700;
}
.note-save-btn {
    background: linear-gradient(135deg, var(--purple-mid) 0%, var(--purple-deep) 100%);
    color: #fff;
    border: 1px solid rgba(167,139,250,0.2);
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12);
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}
.note-save-btn:hover {
    background: linear-gradient(135deg, var(--purple-light) 0%, #8b5cf6 100%);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 8px 26px rgba(124,58,237,0.12);
    border-color: rgba(139,92,246,0.22);
}
.note-save-btn:active {
    transform: translateY(0);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.12);
}
.note-save-btn:focus-visible {
    outline: 3px solid rgba(124,58,237,0.14);
    outline-offset: 2px;
    border-color: rgba(124,58,237,0.28);
}
.note-cancel-btn {
    /* Reddish secondary (cancel) button that fits the theme */
    background: rgba(251, 113, 133, 0.06); /* soft rose surface */
    color: var(--rose-text); /* rose text to indicate cancel/destructive intent */
    border: 1px solid rgba(251, 113, 133, 0.14);
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12);
}
.note-cancel-btn:hover {
    background: linear-gradient(135deg, rgba(251,113,133,0.14), rgba(245,46,117,0.08));
    color: #fff;
    border-color: rgba(245,46,117,0.28);
    box-shadow: 0 6px 20px rgba(245,46,117,0.06);
}
.note-cancel-btn:focus-visible {
    outline: 3px solid rgba(245,46,117,0.14);
    outline-offset: 2px;
    border-color: rgba(245,46,117,0.32);
}

.q-answer-btn.hidden {
    color: #3d3d55;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

/* Active state: showing the answer — glows purple */
.q-answer-btn.showing {
    color: var(--purple-light);
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.4), 0 0 14px rgba(167, 139, 250, 0.15);
}

/* ===== Correct Answer Highlight — purple theme ===== */
.option-item.correct-answer {
    color: var(--purple-pale);
    position: relative;
    padding-right: 36px;
    background: var(--bg-color);
    border-radius: 6px;
    box-shadow: var(--glow-shadow), var(--shadow-inner);
}

.option-item.correct-answer::after {
    content: '✓';
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, var(--purple-mid), var(--purple-deep));
    color: #ffffff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    animation: popIn 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.5);
}

@keyframes popIn {
    0%   { transform: translateY(-50%) scale(0); }
    70%  { transform: translateY(-50%) scale(1.2); }
    100% { transform: translateY(-50%) scale(1); }
}

.option-item.correct-answer .opt-label {
    background: rgba(167, 139, 250, 0.18);
    color: var(--purple-light);
}

.option-item.correct-answer:hover {
    color: var(--purple-pale);
}

/* ===== Wrong Answer? — consistent card-style picker ===== */
.wrong-answer-wrap {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.wrong-answer-wrap.picker-open {
    flex-direction: column;
}

.wrong-answer-picker {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(124, 58, 237, 0.06);
    border: 1px solid rgba(167, 139, 250, 0.2);
}

.wrong-answer-picker.open {
    display: inline-flex;
}

.wrong-answer-hint {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-context);
}

.wrong-answer-hint::after {
    content: ':';
    margin-left: 2px;
    opacity: 0.9;
}

.light-theme .wrong-answer-hint {
    color: #475569;
}

.wrong-answer-chips {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.wrong-answer-chip {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-context);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(167, 139, 250, 0.25);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.light-theme .wrong-answer-chip {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    border-color: rgba(124, 58, 237, 0.2);
}

.wrong-answer-chip:hover {
    color: var(--purple-light);
    border-color: rgba(167, 139, 250, 0.45);
}

.light-theme .wrong-answer-chip:hover {
    border-color: rgba(124, 58, 237, 0.4);
}

.wrong-answer-chip.selected {
    color: var(--purple-pale);
    background: rgba(124, 58, 237, 0.2);
    border-color: rgba(167, 139, 250, 0.5);
}

.light-theme .wrong-answer-chip.selected {
    background: rgba(124, 58, 237, 0.12);
    color: var(--purple-deep);
    border-color: rgba(124, 58, 237, 0.4);
}

.correction-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--surface-1);
    color: var(--purple-mid);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(167, 139, 250, 0.12);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.correction-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== Responsive — 768px ===== */
@media (max-width: 768px) {
    body {
        padding: 10px;
        font-size: 16px;
        background-color: var(--bg-color);
    }

    .meta-controls {
        margin: 10px;
        max-width: 100%;
    }


    .meta-item {
        padding: 8px 10px 10px;
    }

    .meta-value { font-size: 0.82rem; }
    .meta-label { font-size: 0.54rem; }

    h1 { font-size: 1.3rem; margin-bottom: 15px; }

    .question-card { padding: 15px; margin-bottom: 20px; }

    .q-header {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .q-topic   { font-size: 0.75rem; padding: 3px 10px; }
    .q-text    { font-size: 1rem; line-height: 1.7; }
    .q-context { font-size: 1rem; }

    .option-item { padding: 14px; font-size: 0.9rem; }

    .q-table table { font-size: 0.9375rem; }
    .q-table td { padding: 8px 10px; }
    .q-table tr:first-child td { padding: 10px; }
    .q-table td:first-child    { padding: 10px; }

    .year-section { padding: 5px 0; }

    .content-viewer {
        min-height: 300px;
        max-height: calc(100vh - 200px);
    }
    #iframe-viewer { min-height: 400px; }

    .q-copy-btn, .q-answer-btn, .q-ask-ai-btn { padding: 5px; }
    .q-copy-btn svg,
    .q-answer-btn svg,
    .q-ask-ai-btn svg { width: 17px; height: 17px; }
    
    .q-copy-btn::after,
    .q-answer-btn::after,
    .q-ask-ai-btn::after { font-size: 0.7rem; padding: 3px 8px; bottom: -24px; }

    .option-item.correct-answer::after { width: 20px; height: 20px; font-size: 11px; right: 8px; }
    .options-grid { margin-top: 14px; padding: 10px; }
    .q-actions-row {
        align-items: flex-start;
        margin-top: 14px;
        padding-top: 12px;
    }
    .wrong-answer-picker {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 12px;
        border-top: 1px solid rgba(167, 139, 250, 0.2);
    }
    .wrong-answer-chips {
        flex-wrap: wrap;
        gap: 6px;
    }

    .revealed-triggers-row { gap: 8px; }

    .auth-pill { font-size: 0.75rem; }
    .auth-hint { font-size: 0.68rem; }
}

/* ===== Responsive — 480px ===== */
@media (max-width: 480px) {
    body {
        padding: 5px;
        font-size: 16px;
        background-color: var(--bg-color);
    }

    h1 { font-size: 1.1rem; margin-bottom: 10px; }

    .question-card  { padding: 12px; margin-bottom: 15px; }
    .q-number       { font-size: 1rem; }
    .q-text         { font-size: 0.9375rem; line-height: 1.6; }
    .q-context      { font-size: 0.9375rem; }
    .option-item    { padding: 12px; font-size: 0.9375rem; }
    .q-table table  { font-size: 0.875rem; }

    .meta-item  { padding: 7px 8px 9px; }
    .meta-value { font-size: 0.75rem; }
    .meta-label { font-size: 0.5rem; letter-spacing: 0.15em; }

    .set-indicator-text { font-size: 0.65rem; letter-spacing: 0.18em; }
    #set-letter { font-size: 0.72rem; }

    .content-viewer {
        min-height: 250px;
        max-height: calc(100vh - 180px);
    }
    #iframe-viewer { min-height: 300px; }

    .q-actions-row { align-items: flex-start; margin-top: 12px; padding-top: 10px; }
    .q-copy-btn, .q-answer-btn, .q-ask-ai-btn { padding: 4px; }
    .q-copy-btn svg,
    .q-answer-btn svg,
    .q-ask-ai-btn svg { width: 16px; height: 16px; }
    
    .q-copy-btn::after,
    .q-answer-btn::after,
    .q-ask-ai-btn::after { font-size: 0.65rem; padding: 3px 6px; bottom: -22px; }

    .option-item.correct-answer::after { width: 18px; height: 18px; font-size: 10px; right: 6px; }
    .options-grid { margin-top: 12px; padding: 8px; gap: 5px; }
    .wrong-answer-hint { font-size: 0.65rem; }

}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 4vw, 24px);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background-color: var(--bg-color);
}

.login-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--purple-mid);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

.login-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 420px;
}

.login-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-mid);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--purple-mid);
    cursor: pointer;
    transition: all 0.2s ease;
}

.login-theme-toggle:hover {
    background: var(--border-hover);
    color: var(--purple-light);
}

.login-theme-toggle .theme-icon-light { display: var(--theme-icon-sun); }
.login-theme-toggle .theme-icon-dark { display: var(--theme-icon-moon); }

.login-theme-toggle svg {
    width: 20px;
    height: 20px;
}

.login-back-btn:hover {
    color: var(--purple-light);
}

.login-back-btn:focus-visible {
    outline: 2px solid var(--purple-mid);
    outline-offset: 2px;
}

.login-back-btn svg {
    width: 20px;
    height: 20px;
}

.login-card {
    background: var(--login-card-bg);
    border-radius: 16px;
    padding: clamp(24px, 6vw, 32px);
    box-shadow: var(--login-card-shadow);
}

.login-title {
    color: var(--purple-pale);
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-context);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 24px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-field label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--purple-mid);
    text-transform: uppercase;
}

.login-field input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--login-input-border);
    background: var(--login-input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.login-field input:focus {
    outline: none;
    border-color: var(--purple-mid);
    box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

.login-error {
    color: var(--rose-text);
    font-size: 0.875rem;
    margin: 0;
    min-height: 1.6em;
}

.login-btn {
    padding: 12px 20px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--purple-deep) 0%, var(--purple-mid) 100%);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.1s ease;
}

.login-btn:hover {
    opacity: 0.95;
}

.login-btn:active {
    transform: scale(0.98);
}

.login-contact {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--login-contact-border);
    text-align: center;
}

.login-contact-line1 {
    color: var(--text-context);
    font-size: 0.85rem;
    margin: 0 0 6px;
}

.login-contact-line2 {
    color: var(--text-context);
    font-size: 0.85rem;
    margin: 0;
}

.login-contact-link {
    color: var(--purple-light);
    font-weight: 600;
    text-decoration: none;
    text-underline-offset: 3px;
    transition: color 0.2s ease;
}

.login-contact-link:hover {
    color: var(--purple-pale);
}

/* --- Mode Toggle --- */
.mode-toggle-wrap {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px 0;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(167, 139, 250, 0.2);
    color: var(--purple-mid);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--purple-deep);
    color: white;
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.4);
    border-color: var(--purple-mid);
}

/* --- Notes Viewer --- */
.notes-container {
    max-width: 850px;
    margin: 0 auto;
    padding: 20px 0 60px;
    color: var(--text-primary);
    text-align: left;
}

.notes-header {
    margin-bottom: 20px;
}

.notes-header h1 {
    margin: 0;
    font-size: 2.25rem;
    color: var(--heading-1-color);
    text-shadow: var(--heading-1-shadow);
    text-align: left;
}

.topic-badge {
    background: linear-gradient(90deg, var(--purple-deep), var(--purple-mid));
    color: white;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 4px;
    letter-spacing: 0.1em;
}

/* --- Notes Layout & Sidebar --- */
.notes-layout,
.questions-layout {
    display: flex;
    min-height: calc(100vh - 120px);
    position: relative;
    gap: 0;
}

.questions-sidebar .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-dim);
}

.questions-sidebar .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}

.questions-sidebar .sidebar-close-btn svg {
    width: 20px;
    height: 20px;
}

.questions-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 2000;
    box-shadow: var(--sidebar-shadow);
    background: var(--bg-color);
    width: 300px;
    border-right: 1px solid var(--border-dim);
    padding: 24px 16px;
    overflow-y: auto;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 58, 237, 0.2) transparent;
    box-sizing: border-box;
}

.questions-main-content {
    flex: 1;
    padding: 0 40px 40px;
    margin-left: 300px;
    transition: all 0.4s ease;
    min-width: 0;
}

.questions-layout.sidebar-collapsed .questions-sidebar {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.questions-layout.sidebar-collapsed .questions-main-content {
    margin-left: 0;
    padding-left: 20px;
}

.questions-layout.sidebar-collapsed .sidebar-open-btn {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.questions-toc-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.question-toc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 10px;
    background: var(--toc-item-bg);
    box-shadow: var(--toc-item-shadow);
    border: 1px solid var(--toc-item-border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.question-toc-item:hover {
    background: var(--toc-item-hover-bg);
    border-color: var(--toc-item-hover-border);
}

.question-toc-item.active {
    background: var(--toc-item-active-bg);
    border-color: var(--toc-item-active-border);
    box-shadow: var(--toc-item-active-shadow);
}

.question-toc-link {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 12px;
    font-size: 0.9rem;
    color: var(--toc-link-color);
    text-decoration: none;
    transition: all 0.2s;
}

.question-toc-num {
    flex-shrink: 0;
    font-weight: 700;
    color: var(--purple-mid);
}

.question-toc-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.question-toc-topic {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--purple-mid);
}

.question-toc-preview {
    font-size: 0.8rem;
    color: var(--text-context);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.question-toc-link:hover,
.question-toc-link.active {
    color: var(--toc-link-active-color);
}

.question-toc-link:hover .question-toc-num,
.question-toc-link.active .question-toc-num {
    color: var(--purple-pale);
}

.question-toc-actions {
    display: flex;
    gap: 2px;
    padding-right: 8px;
}

.question-toc-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--purple-mid);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.question-toc-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -26px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.question-toc-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

.question-toc-btn:hover {
    background: rgba(124, 58, 237, 0.2);
    color: var(--purple-pale);
}

.question-toc-btn.copied {
    color: var(--purple-mid);
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25);
}

.question-toc-btn svg {
    width: 14px;
    height: 14px;
}

.notes-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 2000;
    box-shadow: var(--sidebar-shadow);
    background: var(--bg-color);
    width: 300px;
    border-right: 1px solid var(--border-dim);
    padding: 24px 16px;
    overflow-y: auto;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 58, 237, 0.2) transparent;
    box-sizing: border-box;
}

.notes-main-content {
    flex: 1;
    padding: 0 40px 40px;
    margin-left: 300px;
    transition: all 0.4s ease;
    min-width: 0;
}

/* Collapsed state */
.sidebar-collapsed .notes-sidebar {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.sidebar-collapsed .notes-main-content {
    margin-left: 0;
    padding-left: 20px;
}

/* Open Button visibility on all sizes */
.sidebar-open-btn {
    position: fixed;
    left: 24px;
    bottom: 30px;
    z-index: 1001;
    background: linear-gradient(135deg, var(--purple-deep) 0%, var(--purple-mid) 100%);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(124, 58, 237, 0.4);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(40px);
    font-weight: 700;
    font-size: 0.9rem;
}

.sidebar-collapsed .sidebar-open-btn {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sidebar-open-btn:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 12px 30px rgba(124, 58, 237, 0.6);
}

.sidebar-close-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-context);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-close-btn:hover {
    color: var(--text-primary);
    background: rgba(124, 58, 237, 0.2);
    border-color: rgba(167, 139, 250, 0.3);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-add-btn {
    margin-top: 20px;
    background: rgba(124, 58, 237, 0.08);
    border: 1px dashed rgba(167, 139, 250, 0.25);
    color: var(--purple-mid);
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.2s;
    text-align: center;
}

.sidebar-add-btn:hover {
    background: rgba(124, 58, 237, 0.15);
    border-color: rgba(167, 139, 250, 0.5);
    color: var(--purple-pale);
}

/* Sidebar TOC links */
.notes-sidebar .toc-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.notes-sidebar .toc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    border-radius: 10px;
    background: var(--toc-item-bg);
    box-shadow: var(--toc-item-shadow);
    border: 1px solid var(--toc-item-border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.notes-sidebar .toc-item:hover {
    background: var(--toc-item-hover-bg);
    border-color: var(--toc-item-hover-border);
}

.notes-sidebar .toc-item.active .toc-link {
    font-weight: 700;
}

.notes-sidebar .toc-item .toc-link {
    flex: 1;
    min-width: 0;
}

.notes-sidebar .toc-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0.7;
    padding-right: 8px;
}

.notes-sidebar .toc-item:hover .toc-item-actions {
    opacity: 1;
}

.notes-sidebar .toc-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--purple-mid);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.notes-sidebar .toc-action-btn:hover {
    background: rgba(124, 58, 237, 0.2);
    color: var(--purple-pale);
}

.notes-sidebar .toc-action-btn.toc-delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--rose-text);
}

.notes-sidebar .toc-action-btn.copied {
    color: var(--purple-mid);
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25);
}

.notes-sidebar .toc-item .toc-link {
    display: block;
    text-align: left;
    padding: 12px 8px 12px 14px;
    font-size: 0.95rem;
    color: var(--toc-link-color);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    line-height: 1.4;
    position: relative;
}

.notes-sidebar .toc-item .toc-link:hover {
    color: var(--toc-link-hover-color);
}

.notes-sidebar .toc-item:has(.toc-link.active) {
    background: var(--toc-item-active-bg);
    border-color: var(--toc-item-active-border);
    box-shadow: var(--toc-item-active-shadow);
}

.notes-sidebar .toc-item .toc-link.active {
    color: var(--toc-link-active-color);
}

.notes-sidebar .toc-item .toc-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--purple-deep);
    transform: scaleY(0);
    transition: transform 0.2s ease;
    border-radius: 0 3px 3px 0;
}

.notes-sidebar .toc-item:hover .toc-link::before,
.notes-sidebar .toc-item .toc-link.active::before {
    transform: scaleY(1);
}

.section-title {
    color: var(--purple-light) !important;
    font-size: 1.75rem !important;
    font-weight: 800 !important;
    margin: 40px 0 24px 0 !important;
    padding-bottom: 16px !important;
    text-align: left !important;
    text-shadow: none !important;
    border-bottom: 2px solid var(--section-title-border) !important;
    letter-spacing: -0.02em;
    position: relative;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--purple-deep);
    border-radius: 2px;
}

/* Note headers — strict visual hierarchy matching Obsidian theme palette */
.note-h1, .note-h2, .note-h3, .note-h4, .note-h5, .note-h6 {
    display: block;
    font-weight: 700;
    margin-left: 0;
    text-align: left;
    line-height: 1.3;
}

/* h1 — pale lavender, full underline. Largest, rarely used inside sections. */
.note-h1 {
    color: var(--purple-pale);
    font-size: 1.5rem;
    margin: 0 0 18px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--note-h1-border);
    letter-spacing: -0.01em;
}

/* h2 — mid-purple, distinct from section-title (var(--purple-light)) and h3 (var(--text-strong)).
   Wide dash marker clearly wider than h3's left-bar to show rank. */
.note-h2 {
    color: var(--purple-mid);
    font-size: 1.35rem;
    margin: 32px 0 12px 0;
    text-shadow: 0 0 18px rgba(167, 139, 250, 0.2);
}

.note-h2::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 3px;
    background: linear-gradient(90deg, var(--purple-mid), rgba(167, 139, 250, 0.5));
    border-radius: 2px;
    margin-right: 10px;
    vertical-align: middle;
}

/* h3 — fuchsia, left border bar. Most common heading inside note sections. */
.note-h3 {
    color: var(--text-strong);
    font-size: 1.18rem;
    margin: 26px 0 10px 0;
    padding-left: 12px;
    border-left: 3px solid var(--note-h3-border);
}

.note-h3::before {
    content: none;
}

/* h4 — mid-lavender, filled triangle. One step below h3. */
.note-h4 {
    color: var(--purple-light);
    font-size: 1.05rem;
    margin: 20px 0 8px 0;
}

.note-h4::before {
    content: '▸';
    color: var(--purple-mid);
    font-size: 0.78em;
    margin-right: 7px;
    vertical-align: middle;
}

/* h5 — muted purple, ALL-CAPS label style. Clearly a sub-label, not a heading. */
.note-h5 {
    color: var(--purple-mid);
    font-size: 0.8rem;
    font-weight: 700;
    margin: 16px 0 6px 0;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* h6 — dim, smallest. Fine-grain annotation only. */
.note-h6 {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin: 12px 0 4px 0;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ─── Note Charts (pure inline SVG) ──────────────────────────────── */
.note-chart-wrap {
    margin: 24px 0;
    background: var(--surface-1);
    border: 1px solid var(--border-mid);
    border-radius: 10px;
    padding: 18px 16px 12px;
    position: relative;
    overflow: hidden;
}
.note-chart-wrap::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--purple-deep), var(--purple-mid), rgba(167,139,250,0.3));
    border-radius: 10px 10px 0 0;
}
.note-chart-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}
.note-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    justify-content: center;
    margin: 8px 0 2px;
}
.note-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.73rem;
    color: var(--text-context);
    white-space: nowrap;
}
.note-chart-caption {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 6px 0 0;
    font-style: italic;
    letter-spacing: 0.01em;
}
.note-chart-error {
    color: var(--rose-text);
    font-size: 0.82rem;
    padding: 8px 12px;
    border: 1px solid var(--rose-text);
    border-radius: 6px;
    margin: 8px 0;
    background: rgba(251,113,133,0.07);
}
@media (max-width: 600px) {
    .note-chart-wrap { padding: 12px 10px 8px; }
}

/* Horizontal rule in notes */
.note-hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent 5%, rgba(167, 139, 250, 0.4) 45%, rgba(167, 139, 250, 0.4) 55%, transparent 95%);
    margin: 24px 0;
}

/* Blockquote in notes — ISS tips. 
   Using a brighter dark gradient that feels "deep" but readable.
   Font styling improved for emphasis while preserving MathJax rendering. */
.note-blockquote {
    margin: 28px 0;
    padding: 22px 28px;
    border-left: 5px solid var(--blockquote-border);
    background: var(--blockquote-bg);
    border-radius: 0 16px 16px 0;
    color: var(--blockquote-text);
    font-style: italic; /* Keep normal on wrapper for MathJax */
    font-weight: 600;
    line-height: 1.8;
    box-shadow: var(--panel-shadow);
    position: relative;
    overflow: hidden;
}

/* Variant for "ISS tip" blockquotes — rose accent for differentiation */
.note-blockquote.tip-style {
    border-left-color: var(--blockquote-tip-border);
    background: var(--blockquote-tip-bg);
}

/* Style the text inside for emphasis without affecting MathJax symbols */
.note-blockquote p, .note-blockquote span {
    font-style: italic;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}

/* Quote mark icon for blockquotes */
.note-blockquote::before {
    content: '“';
    position: absolute;
    top: -15px;
    left: 10px;
    font-size: 6rem;
    color: var(--blockquote-accent);
    font-family: serif;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
    z-index: 0;
}

.note-blockquote strong {
    color: var(--text-strong);
    font-style: normal;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-color: var(--blockquote-strong-decoration);
}

/* Inline markdown in notes — strong, em, code */
.q-notes-content strong, .note-section-content strong,
.q-notes-content .note-p strong, .note-section-content .note-p strong,
.note-list strong {
    color: var(--text-strong); /* Orchid — distinguishable from MathJax var(--purple-light) */
    font-weight: 700;
}

.q-notes-content em, .note-section-content em,
.q-notes-content .note-p em, .note-section-content .note-p em,
.note-list em {
    color: var(--purple-mid);
    font-style: italic;
}

.q-notes-content code, .note-section-content code,
.q-notes-content .note-p code, .note-section-content .note-p code,
.note-list code {
    background: var(--inline-code-bg);
    color: var(--text-strong);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    border: 1px solid var(--inline-code-border);
    box-shadow: var(--shadow-inner);
}

/* Fenced code block in notes */
.note-code-block {
    margin: 18px 0;
    padding: 16px 18px;
    background: linear-gradient(165deg, rgba(124, 58, 237, 0.12) 0%, var(--bg-color) 35%, var(--surface-panel) 100%);
    border: 1px solid var(--code-block-border);
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    box-shadow: var(--code-block-shadow);
}

.note-code-block code {
    background: none;
    padding: 0;
    color: var(--purple-pale);
    border: none;
    box-shadow: none;
}

.note-p {
    margin-bottom: 14px;
    line-height: 1.8;
    color: var(--text-body);
    font-size: 1.02rem;
    overflow-x: auto;
    overflow-y: hidden;
}
.note-list li {
    margin-bottom: 6px;
    position: relative;
    list-style: none;
    color: var(--text-body);
    line-height: 1.75;
    padding-left: 2px;
}

/* Top-level bullet — mid-purple chevron */
.note-list:not(.note-ol) li::before {
    content: '›';
    position: absolute;
    left: -18px;
    color: var(--purple-mid);
    font-weight: 700;
    font-size: 1.1em;
    line-height: 1.75;
}

.note-ol li {
    list-style: decimal;
    padding-left: 2px;
}

.note-ol li::marker {
    color: var(--purple-mid);
    font-weight: 700;
}

/* Nested lists — tighter, dim marker to visually de-emphasise */
.note-list .note-list {
    margin-left: 22px;
    margin-top: 5px;
    margin-bottom: 5px;
    overflow-x: auto;
    overflow-y: hidden;
}

.note-list .note-list:not(.note-ol) li::before {
    content: '·';
    color: var(--text-muted);
    font-size: 1.4em;
    left: -16px;
    line-height: 1.6;
}

/* Formula blocks in notes */
.note-section-content mjx-container[display="true"] {
    background: var(--formula-bg) !important;
    padding: 18px 22px !important;
    border-radius: 8px !important;
    border: 1px solid var(--formula-border) !important;
    border-left: 3px solid var(--purple-mid) !important;
    margin: 18px 0 !important;
    box-shadow: var(--formula-shadow) !important;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Tip Callout — Revision Priorities */
.note-callout.tip {
    margin: 32px 0 40px 0;
    padding: 24px 28px;
    border-left: 5px solid var(--purple-deep);
    background: var(--callout-tip-bg);
    border-radius: 0 16px 16px 0;
    display: flex;
    gap: 18px;
    align-items: flex-start;
    width: 100%;
    box-sizing: border-box;
    box-shadow: var(--panel-shadow);
    position: relative;
    overflow: auto;
}

/* Add a subtle decorative icon in the background */
.note-callout.tip::before {
    content: '★';
    position: absolute;
    top: -20px;
    right: 20px;
    font-size: 8rem;
    color: var(--callout-tip-accent);
    pointer-events: none;
    z-index: 0;
}

.note-callout.tip .callout-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
    filter: drop-shadow(0 0 10px rgba(167, 139, 250, 0.35));
    z-index: 1;
}

.note-callout.tip .callout-content {
    flex: 1;
    font-size: 1rem;
    line-height: 1.75;
    color: var(--purple-pale);
    min-width: 0;
    z-index: 1;
}

.note-callout.tip .tip-label {
    display: block;
    color: var(--purple-mid);
    font-weight: 800;
    font-size: 1.15rem;
    margin-bottom: 12px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ===== Note Editor Styles ===== */
.note-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(167, 139, 250, 0.2);
    color: var(--purple-mid);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.8;
}

.note-edit-btn:hover {
    opacity: 1;
    background: rgba(124, 58, 237, 0.2);
    border-color: rgba(167, 139, 250, 0.4);
    color: var(--purple-pale);
}

.note-editor-wrap {
    width: 100%;
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.note-editor-textarea {
    width: 100%;
    min-height: 250px;
    padding: 15px;
    background: var(--editor-textarea-bg);
    color: var(--text-primary);
    border: 1px solid rgba(167, 139, 250, 0.2);
    border-radius: 8px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    resize: vertical;
    box-shadow: var(--editor-textarea-shadow);
}

.note-editor-textarea:focus {
    outline: none;
    border-color: var(--purple-deep);
    box-shadow: var(--editor-textarea-focus-shadow);
}

/* Formatting help — above editor, compact reference bar */
.note-format-hint {
    margin: 0 0 12px 0;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.08) 0%, rgba(167, 139, 250, 0.04) 100%);
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 10px;
    font-size: 0.8rem;
    color: var(--text-context);
}

.note-format-hint summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--purple-mid);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.note-format-hint summary::-webkit-details-marker { display: none; }
.note-format-hint summary::marker { display: none; }

.note-format-hint summary::before {
    content: '▸';
    font-size: 0.7em;
    transition: transform 0.2s ease;
}
.note-format-hint[open] summary::before { transform: rotate(90deg); }

.note-format-hint summary:hover {
    color: var(--purple-light);
}

.note-format-hint-body {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(167, 139, 250, 0.12);
    line-height: 1.85;
}

.note-format-hint code {
    background: rgba(124, 58, 237, 0.15);
    color: var(--text-strong);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.note-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Full-screen revision notes editor — split source / live preview (same pipeline as read view) */
body.revision-editor-open {
    overflow: hidden;
}

.revision-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: flex;
    flex-direction: column;
    background: var(--modal-bg);
    backdrop-filter: blur(10px);
    animation: fadeIn 0.2s ease-out;
}

.light-theme .revision-editor-overlay {
    background: rgba(30, 41, 59, 0.22);
    backdrop-filter: blur(12px);
}

.revision-editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    max-height: 100vh;
    margin: 0 auto;
    width: 100%;
    max-width: 1600px;
    box-sizing: border-box;
    padding: 10px 12px 14px;
    gap: 0;
    overflow: visible;
}

.light-theme .revision-editor-panel {
    padding: 12px 14px 16px;
}

/* One surface: chrome (breadcrumb, title, toolbar) + split editor share one card */
.revision-editor-unified {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    width: 100%;
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 14px;
    overflow: hidden;
    background: var(--surface-1);
    box-shadow: var(--panel-shadow);
}

.light-theme .revision-editor-unified {
    border-color: var(--border-dim);
    box-shadow: var(--card-shadow);
}

/* Question explanation editor — same overlay as revision notes + in-page question card preview */
.revision-editor-panel--question-explanation {
    max-width: 1080px;
}

/* Single surface with chrome: no nested “second card” around the question block */
.revision-editor-question-hero-wrap {
    margin: 0 0 10px;
    flex-shrink: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    overflow: visible;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Same band as .revision-editor-title-hero: rule + air under the breadcrumb row */
.revision-editor-panel--question-explanation .revision-editor-question-hero-wrap {
    margin-top: 14px;
    margin-bottom: 0;
    padding-top: 14px;
    border-top: 1px solid var(--border-dim);
}

.light-theme .revision-editor-panel--question-explanation .revision-editor-question-hero-wrap {
    border-top-color: rgba(124, 58, 237, 0.12);
}

/* Header row reads as part of the unified chrome, not a separate mini-card */
.revision-editor-panel--question-explanation .revision-editor-question-hero-summary-head .q-header {
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.08) 0%, transparent 100%);
    border: 1px solid rgba(167, 139, 250, 0.12);
    border-radius: 8px;
    box-shadow: none;
    padding: 8px 12px;
}

.light-theme .revision-editor-panel--question-explanation .revision-editor-question-hero-summary-head .q-header {
    background: rgba(124, 58, 237, 0.05);
    border-color: rgba(124, 58, 237, 0.1);
}

.revision-editor-question-hero-summary {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 8px 10px;
    list-style: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-inline-end: 4px;
}

.revision-editor-question-hero-summary::-webkit-details-marker,
.revision-editor-question-hero-summary::marker {
    display: none;
}

/* Cloned .q-header (number + topic) shares the summary row with the chevron */
.revision-editor-question-hero-summary-head {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.revision-editor-question-hero-summary-head .q-header {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    margin-bottom: 0;
    margin-top: 0;
    box-sizing: border-box;
    /* Override global mobile .q-header (column + centered) so the row stays [title | chevron] and can shrink */
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px 10px;
}

.revision-editor-question-hero-summary-head .q-number {
    flex-shrink: 0;
}

.revision-editor-question-hero-summary-head .q-topic {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.revision-editor-question-hero-summary-head .q-header-left {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.revision-editor-question-hero-summary-right {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    flex-shrink: 0;
    width: 28px;
    min-width: 28px;
    height: 28px;
    box-sizing: border-box;
}

.revision-editor-question-hero-summary-chevron {
    display: block;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--purple-mid);
    border-bottom: 2px solid var(--purple-mid);
    transform: rotate(45deg);
    margin-top: -3px;
    transition: transform 0.2s ease;
    opacity: 0.85;
    flex-shrink: 0;
}

.revision-editor-question-hero-wrap[open] > .revision-editor-question-hero-summary .revision-editor-question-hero-summary-chevron {
    transform: rotate(225deg);
    margin-top: 2px;
}

.revision-editor-question-hero {
    margin: 0;
    padding: 16px 0;
    max-height: min(40vh, 460px);
    overflow: auto;
    overflow-x: hidden;
    border-radius: 0 0 11px 11px;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

/* Expanded block: full stem in source order (context preamble, q-text, q-table, …) + options */
.revision-editor-question-expand-body {
    pointer-events: none;
    user-select: none;
    cursor: default;
    padding: 0 4px 4px;
}

.revision-editor-question-expand-body > * + * {
    margin-top: 12px;
}

.revision-editor-question-expand-body > .options-grid {
    margin-top: 16px;
}

/* Match spacing after title row in section editor */
.revision-editor-panel--question-explanation .revision-editor-toolbar-row {
    margin-top: 10px;
}

@media (min-width: 721px) {
    .revision-editor-question-hero-summary {
        cursor: default;
        pointer-events: none;
    }

    .revision-editor-question-hero-summary-right {
        display: none;
    }
}

@media (max-width: 720px) {
    .revision-editor-question-hero {
        max-height: min(42vh, 300px);
    }

    /* Allow the whole panel to scroll if chrome + editor min-height exceed the viewport */
    .revision-editor-panel--question-explanation {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Reserve vertical space for stacked source + live preview after compact question strip */
    .revision-editor-panel--question-explanation .revision-editor-body.revision-editor-layout-split {
        grid-template-rows: minmax(200px, 1fr) minmax(200px, 1fr);
        min-height: min(46vh, 380px);
    }
}

/* Top chrome: sits inside .revision-editor-unified (no second outer card) */
.revision-editor-chrome {
    flex-shrink: 0;
    padding: 12px 14px 12px;
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: visible;
    position: relative;
    z-index: 2;
    border-bottom: 1px solid rgba(167, 139, 250, 0.12);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.light-theme .revision-editor-chrome {
    border-bottom-color: rgba(124, 58, 237, 0.1);
}

/* Top row: breadcrumb | theme + close */
.revision-editor-top-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 14px;
    width: 100%;
}

.revision-editor-breadcrumb {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.light-theme .revision-editor-breadcrumb {
    color: var(--purple-mid);
    opacity: 0.9;
}

.revision-editor-top-bar-end {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

@media (max-width: 720px) {
    .revision-editor-top-bar {
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 8px 10px;
    }

    .revision-editor-top-bar-end {
        flex-shrink: 0;
        justify-content: flex-end;
        padding-top: 2px;
    }

    .revision-editor-breadcrumb {
        font-size: 0.62rem;
        letter-spacing: 0.08em;
        -webkit-line-clamp: 3;
        line-clamp: 3;
    }
}

/* Layout + ? tooltip (left) | Save / Cancel (right) — below title; grid keeps one row */
.revision-editor-toolbar-row {
    --revision-toolbar-control-h: 36px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px 12px;
    padding: 10px 0 0;
    margin-top: 10px;
    border-top: 1px solid var(--border-dim);
}

.light-theme .revision-editor-toolbar-row {
    border-top-color: rgba(124, 58, 237, 0.12);
}

.revision-editor-toolbar-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.revision-editor-toolbar-actions.note-editor-actions {
    justify-content: flex-end;
    margin: 0;
    padding: 0;
    gap: 8px;
    flex-shrink: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
}

.revision-editor-toolbar-actions.note-editor-actions .note-save-btn,
.revision-editor-toolbar-actions.note-editor-actions .note-cancel-btn {
    min-height: var(--revision-toolbar-control-h);
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

@media (max-width: 420px) {
    .revision-editor-toolbar-actions.note-editor-actions .note-save-btn,
    .revision-editor-toolbar-actions.note-editor-actions .note-cancel-btn {
        padding: 0 8px;
        font-size: 0.65rem;
    }

    .revision-editor-layout-btn {
        padding: 0 8px;
        font-size: 0.62rem;
    }
}

/* Row 2: document title — full width, clearly above the editor body */
.revision-editor-title-hero {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-dim);
    width: 100%;
    box-sizing: border-box;
}

.light-theme .revision-editor-title-hero {
    border-top-color: rgba(124, 58, 237, 0.12);
}

.revision-editor-field-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.light-theme .revision-editor-field-label {
    color: var(--purple-mid);
    opacity: 0.85;
}

.revision-editor-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--revision-toolbar-control-h, 36px);
    height: var(--revision-toolbar-control-h, 36px);
    flex-shrink: 0;
    border-radius: 10px;
    border: 1px solid var(--border-mid);
    background: var(--surface-2);
    color: var(--purple-mid);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    box-shadow: var(--pill-shadow);
    box-sizing: border-box;
}

.revision-editor-icon-btn:hover {
    background: rgba(124, 58, 237, 0.14);
    color: var(--purple-pale);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.light-theme .revision-editor-icon-btn:hover {
    color: var(--purple-deep);
}

.revision-editor-format-tip-char {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
    font-family: Georgia, 'Times New Roman', serif;
}

/* Compact ? in Markdown source header (corner) */
.revision-editor-pane-header--source .revision-editor-format-tip-btn.revision-editor-icon-btn {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    border-radius: 6px;
    box-shadow: none;
    transform: none;
}

.revision-editor-pane-header--source .revision-editor-format-tip-btn.revision-editor-icon-btn:hover {
    transform: none;
}

.revision-editor-pane-header--source .revision-editor-format-tip-char {
    font-size: 0.72rem;
    font-weight: 800;
}

.revision-editor-title-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.25;
    min-height: 44px;
    color: var(--purple-light);
    background: var(--surface-2);
    border: 1px solid var(--border-mid);
    border-radius: 10px;
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--editor-textarea-shadow);
}

.light-theme .revision-editor-title-input {
    color: var(--text-primary);
    background: var(--surface-1);
    border-color: var(--border-mid);
}

.revision-editor-title-input:focus {
    border-color: var(--purple-deep);
    box-shadow: 0 0 0 2px var(--selection-bg), var(--editor-textarea-shadow);
}

.revision-editor-static-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--purple-light);
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.light-theme .revision-editor-static-title {
    color: var(--text-primary);
}

/* Segmented layout control — same height band as primary actions */
.revision-editor-layout-toggle {
    display: inline-flex;
    align-items: stretch;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-mid);
    background: var(--surface-2);
    min-height: var(--revision-toolbar-control-h, 36px);
    height: var(--revision-toolbar-control-h, 36px);
    box-shadow: var(--pill-shadow);
    box-sizing: border-box;
}

.revision-editor-layout-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 0 12px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.revision-editor-layout-btn + .revision-editor-layout-btn {
    border-left: 1px solid var(--border-mid);
}

.revision-editor-layout-btn:hover {
    color: var(--purple-pale);
    background: rgba(124, 58, 237, 0.1);
}

.light-theme .revision-editor-layout-btn:hover {
    color: var(--purple-deep);
    background: rgba(124, 58, 237, 0.08);
}

.revision-editor-layout-btn.is-active {
    background: rgba(124, 58, 237, 0.32);
    color: var(--purple-pale);
}

.light-theme .revision-editor-layout-btn.is-active {
    background: rgba(124, 58, 237, 0.18);
    color: var(--purple-deep);
}

/* Hover / focus tooltip — readable contrast vs theme surfaces */
.revision-editor-format-tip-wrap {
    position: relative;
    flex-shrink: 0;
    z-index: 8;
}

.revision-editor-format-tooltip.note-format-hint {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    margin: 0;
    width: min(380px, calc(100vw - 32px));
    max-height: min(65vh, 400px);
    overflow-x: hidden;
    overflow-y: auto;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.16s ease, visibility 0.16s ease;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(186, 167, 255, 0.12);
    z-index: 2280;
    /* Dark: distinct card, not flat on surface */
    background: linear-gradient(
        155deg,
        rgba(28, 24, 48, 0.98) 0%,
        rgba(42, 32, 72, 0.96) 42%,
        rgba(72, 48, 120, 0.35) 100%
    );
    border: 1px solid rgba(186, 167, 255, 0.38);
    color: var(--text-context);
}

.light-theme .revision-editor-format-tooltip.note-format-hint {
    box-shadow: 0 14px 40px rgba(76, 29, 149, 0.14), 0 0 0 1px rgba(124, 58, 237, 0.1);
    background: linear-gradient(
        155deg,
        #f4f0ff 0%,
        #ebe4ff 38%,
        #faf8ff 100%
    );
    border: 1px solid rgba(124, 58, 237, 0.28);
}

/* Corner placement: align to source header right edge */
.revision-editor-pane-header--source .revision-editor-format-tooltip.note-format-hint {
    left: auto;
    right: 0;
    width: min(360px, calc(100vw - 28px));
}

.revision-editor-pane-source {
    position: relative;
    z-index: 1;
}

.revision-editor-pane-preview {
    position: relative;
    z-index: 0;
}

.revision-editor-pane-source:has(.revision-editor-format-tip-wrap:hover),
.revision-editor-pane-source:has(.revision-editor-format-tip-wrap:focus-within) {
    z-index: 6;
}

.revision-editor-format-tooltip-title {
    display: block;
    font-weight: 600;
    color: var(--purple-mid);
    font-size: 0.8rem;
    user-select: none;
}

body:not(.light-theme) .revision-editor-format-tooltip.note-format-hint .revision-editor-format-tooltip-title {
    color: var(--purple-pale);
}

.light-theme .revision-editor-format-tooltip-title {
    color: var(--purple-deep);
}

.revision-editor-format-tooltip .note-format-hint-body {
    margin-top: 10px;
    padding-top: 10px;
    border-top-color: rgba(186, 167, 255, 0.22);
}

.light-theme .revision-editor-format-tooltip .note-format-hint-body {
    border-top-color: rgba(124, 58, 237, 0.18);
}

.revision-editor-format-tip-wrap:hover,
.revision-editor-format-tip-wrap:focus-within {
    z-index: 2285;
}

.revision-editor-format-tip-wrap:hover .revision-editor-format-tooltip,
.revision-editor-format-tip-wrap:focus-within .revision-editor-format-tooltip {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Theme toggle in toolbar — not absolute like header */
.revision-editor-theme-toggle.theme-toggle-btn {
    position: relative;
    top: auto;
    right: auto;
    transform: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    box-sizing: border-box;
}

.revision-editor-theme-toggle.theme-toggle-btn:hover {
    transform: translateY(-1px);
}

.revision-editor-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    border: 1px solid var(--border-mid);
    background: var(--surface-2);
    color: var(--purple-mid);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    box-shadow: var(--pill-shadow);
    box-sizing: border-box;
}

.revision-editor-close-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--rose-text);
    border-color: rgba(239, 68, 68, 0.28);
    transform: translateY(-1px);
}

.revision-editor-body {
    flex: 1;
    min-height: 0;
    display: grid;
    border: none;
    border-radius: 0;
    overflow: hidden;
    background: transparent;
    box-shadow: none;
    position: relative;
    z-index: 1;
}

.revision-editor-body.revision-editor-layout-split {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.revision-editor-body.revision-editor-layout-source-only {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.revision-editor-body.revision-editor-layout-source-only .revision-editor-pane-preview {
    display: none;
}

.revision-editor-body.revision-editor-layout-preview-only {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.revision-editor-body.revision-editor-layout-preview-only .revision-editor-pane-source {
    display: none;
}

.revision-editor-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-right: 1px solid rgba(167, 139, 250, 0.12);
}

.revision-editor-pane:last-child {
    border-right: none;
}

.revision-editor-pane-header--source {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
    padding: 5.5px 14px;
    background: linear-gradient(180deg, rgba(124, 58, 237, 0.1) 0%, transparent 100%);
    border-bottom: 1px solid rgba(167, 139, 250, 0.1);
}

.revision-editor-pane-title {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--purple-mid);
    min-width: 0;
}

.revision-editor-pane-label {
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--purple-mid);
    padding: 10px 14px;
    background: linear-gradient(180deg, rgba(124, 58, 237, 0.1) 0%, transparent 100%);
    border-bottom: 1px solid rgba(167, 139, 250, 0.1);
}

.revision-editor-pane-inner {
    flex: 1;
    min-height: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.revision-editor-textarea {
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 16px 18px;
    border: none;
    border-radius: 0;
    resize: none;
    background: var(--editor-textarea-bg);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.65;
    box-shadow: none;
}

.revision-editor-textarea:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(124, 58, 237, 0.35);
}

.revision-editor-preview-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 16px 20px 24px;
    background: var(--bg-color);
}

/* Preview uses .note-section-content so typography matches the reader */
.revision-editor-preview-scroll .note-section-content {
    max-width: 52rem;
    margin: 0 auto;
}

@media (max-width: 960px) {
    .revision-editor-body.revision-editor-layout-split {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(220px, 1fr) minmax(220px, 1fr);
    }

    .revision-editor-pane {
        border-right: none;
        border-bottom: 1px solid rgba(167, 139, 250, 0.12);
    }

    .revision-editor-pane:last-of-type {
        border-bottom: none;
    }
}

.note-section-header {
    margin-bottom: 10px;
}

.note-section-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.note-section-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: rgba(124, 58, 237, 0.1);
    color: var(--purple-mid);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid rgba(167, 139, 250, 0.2);
}

.note-section-action-btn:hover {
    background: rgba(124, 58, 237, 0.2);
    color: var(--purple-pale);
    border-color: rgba(167, 139, 250, 0.4);
}

.note-section-action-btn.note-section-delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--rose-text);
    border-color: rgba(239, 68, 68, 0.2);
}

.note-section-action-btn.copied {
    color: var(--purple-mid);
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25);
}

.note-section-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Modal Styles */
.note-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease-out;
}

.note-modal-card {
    width: 75%;
    max-width: 450px;
    background: var(--surface-1);
    border-radius: 16px;
    padding: 30px;
    box-shadow: var(--card-shadow), 0 0 0 1px var(--border-dim);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.note-modal-card h3 {
    margin: 0;
    color: var(--purple-pale);
    font-size: 1.25rem;
    text-align: center;
}

.note-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.note-field label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--purple-mid);
}

.note-field input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-mid);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 1rem;
}

.note-field input:focus {
    outline: none;
    border-color: var(--purple-deep);
    box-shadow: 0 0 0 2px var(--selection-bg);
}

.question-edit-card {
    max-width: 560px;
}
.question-edit-card .note-field input,
.question-edit-card .note-field textarea {
    background: var(--editor-textarea-bg);
    color: var(--text-primary);
}
.question-edit-card .note-field textarea,
.question-edit-card #q-edit-text {
    min-height: 120px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.95rem;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-mid);
    resize: vertical;
}
.question-edit-card #q-edit-opt-a,
.question-edit-card #q-edit-opt-b,
.question-edit-card #q-edit-opt-c,
.question-edit-card #q-edit-opt-d {
    margin-bottom: 8px;
}
.question-edit-card .note-field:last-of-type input {
    margin-bottom: 0;
}

.note-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--purple-deep) 0%, var(--purple-mid) 100%);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.note-add-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Confirm dialog — themed variant of modal */
.note-confirm-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2500;
    animation: fadeIn 0.2s ease-out;
}

.note-confirm-card {
    width: 75%;
    max-width: 420px;
    background: var(--surface-1);
    border-radius: 16px;
    padding: 24px 28px;
    box-shadow: var(--card-shadow), 0 0 0 1px var(--border-dim);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.note-confirm-card .note-confirm-message {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    text-align: center;
}

.note-confirm-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.note-confirm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.18s ease;
}

/* No / Cancel — cross icon, rose */
.note-confirm-btn-no {
    background: rgba(251, 113, 133, 0.12);
    color: var(--rose-text);
    border: 1px solid rgba(251, 113, 133, 0.25);
}

.note-confirm-btn-no:hover {
    background: rgba(251, 113, 133, 0.22);
    color: #fff;
    border-color: rgba(245, 46, 117, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(244, 63, 94, 0.2);
}

/* Yes / Confirm — check icon, green (distinct from No) */
.note-confirm-btn-yes {
    background: rgba(74, 222, 128, 0.15);
    color: var(--green-mid);
    border: 1px solid rgba(74, 222, 128, 0.35);
}

.note-confirm-btn-yes:hover {
    background: linear-gradient(135deg, var(--green-deep) 0%, var(--green-mid) 100%);
    color: #fff;
    border-color: rgba(74, 222, 128, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.3);
}

/* Mobile adjustments for sidebar */
@media (max-width: 1024px) {
    .notes-sidebar,
    .questions-sidebar {
        width: 280px;
        padding-bottom: 40px;
    }
    
    .notes-main-content,
    .questions-main-content {
        margin-left: 0;
        padding: 0 20px 40px;
    }
    
    .sidebar-collapsed .notes-sidebar,
    .questions-layout.sidebar-collapsed .questions-sidebar {
        transform: translateX(-100%);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .notes-header h1 {
        font-size: 1.75rem;
    }
    .section-title {
        font-size: 1.5rem !important;
    }
}
