/* ============================================================
   SQE1 Lex Prep — Design System
   Vibrant palette + dual-font hierarchy + dark mode
   ============================================================ */

:root {
    /* Warm cream/brown light mode */
    --bg: #f5f0e8;
    --bg-subtle: #ebe5d9;
    --card: #faf7f2;
    --card-hover: #f7f3ec;
    --surface-raised: #faf7f2;
    --border: rgba(120,90,50,0.10);
    --border-light: rgba(120,90,50,0.06);
    --border-strong: rgba(120,90,50,0.18);
    --accent: #7c3aed;
    --accent-light: rgba(124,58,237,0.10);
    --accent-soft: rgba(124,58,237,0.05);
    --accent-hover: #6d28d9;
    --accent-strong: #5b21b6;
    --sidebar-active-bg: rgba(124,58,237,0.10);
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1);
    --text: #2c2417;
    --text-secondary: rgba(44,36,23,0.6);
    --text-muted: rgba(44,36,23,0.4);
    --text-inverse: #faf7f2;
    --green: #059669;
    --green-dark: #047857;
    --green-bg: rgba(5,150,105,0.08);
    --green-gradient: linear-gradient(135deg, #10b981, #059669);
    --amber: #d97706;
    --amber-bg: rgba(217,119,6,0.08);
    --amber-dark: #b45309;
    --pink: #db2777;
    --pink-bg: rgba(219,39,119,0.08);
    --red: #dc2626;
    --red-bg: rgba(220,38,38,0.08);
    --red-dark: #b91c1c;
    --blue: #2563eb;
    --blue-bg: rgba(37,99,235,0.08);
    --blue-dark: #1d4ed8;
    --teal: #0d9488;
    --teal-bg: rgba(13,148,136,0.08);
    --purple: #7c3aed;
    --purple-bg: rgba(124,58,237,0.08);
    --orange: #ea580c;
    --orange-bg: rgba(234,88,12,0.08);
    --sidebar-bg: #ebe5d9;
    --sidebar-w: 260px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 3px rgba(80,60,30,0.06);
    --shadow: 0 1px 3px rgba(80,60,30,0.08), 0 1px 2px rgba(80,60,30,0.04);
    --shadow-md: 0 4px 12px rgba(80,60,30,0.08), 0 2px 4px rgba(80,60,30,0.04);
    --shadow-lg: 0 12px 28px rgba(80,60,30,0.10), 0 4px 10px rgba(80,60,30,0.04);
    --shadow-glow: 0 0 0 4px rgba(124,58,237,0.12);
    --card-hover-lift: translateY(-2px);
    --section-gap: 32px;
    --callout-bg: rgba(124,58,237,0.04);
    --blockquote-border: rgba(120,90,50,0.15);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --leading-tight: 1.3;
    --leading-snug: 1.45;
    --leading-normal: 1.55;
    --leading-relaxed: 1.7;
    --measure-short: 52ch;
    --measure-reading: 68ch;
    --measure-wide: 84ch;
    --color-focus: #7c3aed;
    color-scheme: light;
}

/* ── Dark mode (system preference) ────────────────────────── */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #13111a;
        --bg-subtle: #17151f;
        --card: rgba(255,255,255,0.03);
        --card-hover: rgba(255,255,255,0.05);
        --surface-raised: rgba(255,255,255,0.05);
        --border: rgba(255,255,255,0.06);
        --border-light: rgba(255,255,255,0.04);
        --border-strong: rgba(255,255,255,0.12);
        --accent: #8b5cf6;
        --accent-light: rgba(139,92,246,0.15);
        --accent-soft: rgba(139,92,246,0.08);
        --accent-hover: #a78bfa;
        --accent-strong: #c4b5fd;
        --sidebar-active-bg: rgba(139,92,246,0.15);
        --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1);
        --text: #f0f0f5;
        --text-secondary: rgba(255,255,255,0.5);
        --text-muted: rgba(255,255,255,0.3);
        --text-inverse: #13111a;
        --green: #34d399;
        --green-dark: #10b981;
        --green-bg: rgba(16,185,129,0.15);
        --green-gradient: linear-gradient(135deg, #10b981, #34d399);
        --amber: #fbbf24;
        --amber-bg: rgba(245,158,11,0.15);
        --amber-dark: #f59e0b;
        --pink: #f472b6;
        --pink-bg: rgba(236,72,153,0.15);
        --red: #f87171;
        --red-bg: rgba(248,113,113,0.12);
        --red-dark: #fca5a5;
        --blue: #60a5fa;
        --blue-bg: rgba(96,165,250,0.12);
        --blue-dark: #93c5fd;
        --teal: #2dd4bf;
        --teal-bg: rgba(45,212,191,0.12);
        --purple: #a78bfa;
        --purple-bg: rgba(167,139,250,0.12);
        --orange: #fb923c;
        --orange-bg: rgba(251,146,60,0.12);
        --sidebar-bg: #15131d;
        --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
        --shadow: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
        --shadow-md: 0 4px 10px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
        --shadow-lg: 0 14px 30px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
        --shadow-glow: 0 0 0 4px rgba(139,92,246,0.25);
        --card-hover-lift: translateY(-2px);
        --callout-bg: rgba(255,255,255,0.035);
        --blockquote-border: rgba(255,255,255,0.1);
        --color-focus: #8b5cf6;
        color-scheme: dark;
    }
}

/* ── Light mode (manual toggle) ───────────────────────────── */
/* D05/A1b: explicit anchor block. Light tokens are still defined on :root,
   but having an `[data-theme="light"]` selector means the cascade always has
   a deterministic specificity-equal counterweight to [data-theme="dark"].
   Most importantly, the FOUC guard in <head> sets this attribute on the
   very first paint, and the @media (prefers-color-scheme: dark) rule above
   intentionally excludes :root[data-theme="light"]. So a user with system
   dark preference but theme="light" stored will paint light immediately. */
[data-theme="light"] {
    color-scheme: light;
}

/* ── Dark mode (manual toggle) ────────────────────────────── */

[data-theme="dark"] {
    --bg: #13111a;
    --bg-subtle: #17151f;
    --card: rgba(255,255,255,0.03);
    --card-hover: rgba(255,255,255,0.05);
    --surface-raised: rgba(255,255,255,0.05);
    --border: rgba(255,255,255,0.06);
    --border-light: rgba(255,255,255,0.04);
    --border-strong: rgba(255,255,255,0.12);
    --accent: #8b5cf6;
    --accent-light: rgba(139,92,246,0.15);
    --accent-soft: rgba(139,92,246,0.08);
    --accent-hover: #a78bfa;
    --accent-strong: #c4b5fd;
    --sidebar-active-bg: rgba(139,92,246,0.15);
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1);
    --text: #f0f0f5;
    --text-secondary: rgba(255,255,255,0.5);
    --text-muted: rgba(255,255,255,0.3);
    --text-inverse: #13111a;
    --green: #34d399;
    --green-dark: #10b981;
    --green-bg: rgba(16,185,129,0.15);
    --green-gradient: linear-gradient(135deg, #10b981, #34d399);
    --amber: #fbbf24;
    --amber-bg: rgba(245,158,11,0.15);
    --amber-dark: #f59e0b;
    --pink: #f472b6;
    --pink-bg: rgba(236,72,153,0.15);
    --red: #f87171;
    --red-bg: rgba(248,113,113,0.12);
    --red-dark: #fca5a5;
    --blue: #60a5fa;
    --blue-bg: rgba(96,165,250,0.12);
    --blue-dark: #93c5fd;
    --teal: #2dd4bf;
    --teal-bg: rgba(45,212,191,0.12);
    --purple: #a78bfa;
    --purple-bg: rgba(167,139,250,0.12);
    --orange: #fb923c;
    --orange-bg: rgba(251,146,60,0.12);
    --sidebar-bg: #15131d;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
    --shadow: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 10px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 14px 30px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 0 4px rgba(139,92,246,0.25);
    --card-hover-lift: translateY(-2px);
    --callout-bg: rgba(255,255,255,0.035);
    --blockquote-border: rgba(255,255,255,0.1);
    --color-focus: #8b5cf6;
    color-scheme: dark;
}

/* ── Dark mode specific overrides ─────────────────────────── */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) #sidebar {
        background: linear-gradient(180deg, #1a1726 0%, #15131d 100%);
    }
    :root:not([data-theme="light"]) .card:hover,
    :root:not([data-theme="light"]) .stat-card:hover,
    :root:not([data-theme="light"]) .grid-card:hover {
        box-shadow: var(--shadow-lg), 0 0 20px rgba(139,92,246,0.08);
    }
    :root:not([data-theme="light"]) .btn-primary {
        box-shadow: 0 2px 8px rgba(139,92,246,0.3);
    }
    :root:not([data-theme="light"]) .source-badge.study_notes_src {
        background: rgba(16,185,129,0.15);
        color: #34d399;
    }
}

[data-theme="dark"] #sidebar {
    background: linear-gradient(180deg, #1a1726 0%, #15131d 100%);
}

[data-theme="dark"] .card:hover,
[data-theme="dark"] .stat-card:hover,
[data-theme="dark"] .grid-card:hover {
    box-shadow: var(--shadow-lg), 0 0 20px rgba(139,92,246,0.08);
}

[data-theme="dark"] .btn-primary {
    box-shadow: 0 2px 8px rgba(139,92,246,0.3);
}

[data-theme="dark"] .countdown-gradient {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

[data-theme="dark"] .grid-card-icon-circle {
    opacity: 0.9;
}

[data-theme="dark"] .source-badge.study_notes_src {
    background: rgba(16,185,129,0.15);
    color: #34d399;
}

[data-theme="dark"] .subject-selector-list {
    background: #1e1b2e;
    border-color: rgba(139,92,246,0.2);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .subject-selector-list {
        background: #1e1b2e;
        border-color: rgba(139,92,246,0.2);
        box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.3);
    }
}

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

html, body {
    font-family: 'Urbanist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'ss01', 'cv11';
}

body {
    display: flex;
    line-height: 1.55;
}

::selection {
    background: var(--accent-light);
    color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Sidebar ─────────────────────────────────────────────── */

#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 1px 0 0 var(--border-light);
    position: relative;
}

/* Scroll-overflow affordance — gradient fade at bottom so users know
   more nav items live below the fold (Revision Timetable, AI Tutor). */
#nav {
    position: relative;
    padding-bottom: 24px;
}
#nav::after {
    content: '';
    display: block;
    position: sticky;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 28px;
    margin-top: -28px;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent, var(--sidebar-bg));
}

.sidebar-header {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    left: 20px;
    right: 20px;
    bottom: -1px;
    height: 2px;
    background: linear-gradient(90deg, var(--accent) 0%, transparent 70%);
    border-radius: 2px;
}

.sidebar-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-family: 'Baloo 2', cursive;
    font-size: 24px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.logo-sub {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

/* ── Theme toggle ────────────────────────────────────────── */

.theme-toggle {
    /* P9 fix C9: 44×44 touch target for WCAG 2.5.5 AAA. The icon stays 16px;
       padding fills the rest. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.18s var(--ease-out),
                border-color 0.18s var(--ease-out),
                color 0.18s var(--ease-out),
                transform 0.12s var(--ease-out);
    flex-shrink: 0;
    padding: 0;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
    transform: translateY(-1px);
}

.theme-toggle:active { transform: translateY(0); }

.theme-toggle:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

/* Show sun in dark mode (click to go light), moon in light mode */
.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun { display: none; }

[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
}

#nav {
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* ── Subject selector ────────────────────────────────────── */

.subject-selector {
    padding: 0 12px;
    margin: 12px 0 8px;
    position: relative;
}

.subject-selector-btn {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent-gradient);
    color: white;
    cursor: pointer;
    position: relative;
    box-shadow: 0 4px 16px rgba(139,92,246,0.25);
    transition: box-shadow 0.2s ease, transform 0.1s ease;
    font-family: inherit;
    text-align: left;
}

.subject-selector-btn:hover {
    box-shadow: 0 6px 20px rgba(139,92,246,0.35);
}

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

.subject-selector-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.7;
    margin-bottom: 2px;
    font-weight: 600;
}

.subject-selector-value {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 24px);
}

.subject-selector-chevron {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.subject-selector-btn[aria-expanded="true"] .subject-selector-chevron {
    transform: translateY(-50%) rotate(180deg);
}

.subject-selector-list {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 12px;
    right: 12px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
    list-style: none;
}

.subject-selector-list.open {
    display: block;
}

.subject-option {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-family: inherit;
}

.subject-option:hover {
    background: var(--accent-light);
    color: var(--text);
}

.subject-option.selected {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.subject-option-header {
    padding: 10px 14px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    cursor: default;
    user-select: none;
}

.subject-option-header:not(:first-child) {
    margin-top: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* ── Nav group labels ────────────────────────────────────── */

.nav-group-label {
    padding: 12px 14px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    user-select: none;
}

.nav-item {
    /* P9 fix C8: 44px min-height meets WCAG 2.5.5 AAA touch target on every
       viewport — previously 38px on desktop, sub-44 on mobile. */
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    transition: background 0.18s var(--ease-out),
                color 0.18s var(--ease-out);
    min-height: 44px;
}

.nav-item:hover {
    background: var(--bg-subtle);
    color: var(--text);
    padding-left: 16px;
}
.nav-item:active {
    background: var(--accent-soft);
    transition-duration: 0.06s;
}

.nav-item:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

.nav-item.active {
    background: var(--sidebar-active-bg, var(--accent-soft));
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 2px;
    background: var(--accent);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.8;
    transition: opacity 0.18s var(--ease-out);
}

.nav-item:hover svg,
.nav-item.active svg {
    opacity: 1;
}

/* ── Main ────────────────────────────────────────────────── */

#main {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 32px 40px;
}

#view-container {
    max-width: 1440px;
    margin: 0 auto;
}

@media (min-width: 1680px) {
    #main { padding: 32px 56px; }
    #view-container { max-width: 1560px; }
}

@media (max-width: 900px) {
    #main { padding: 20px 16px; }
}

/* Utility: narrow column for body copy, briefs, long prose — keeps reading measure sane */
.reading-narrow { max-width: var(--measure-reading); }
.reading-wide   { max-width: var(--measure-wide); }

/* ── Typography ──────────────────────────────────────────── */

h1 { font-family: 'Baloo 2', cursive; font-size: 32px; font-weight: 800; letter-spacing: -0.6px; line-height: var(--leading-tight); color: var(--text); max-width: var(--measure-wide); }
h2 { font-family: 'Baloo 2', cursive; font-size: 24px; font-weight: 700; letter-spacing: -0.3px; line-height: var(--leading-tight); color: var(--text); }
h3 { font-size: 17px; font-weight: 600; line-height: var(--leading-tight); color: var(--text); }
h4 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); }

@media (max-width: 640px) {
    h1 { font-size: 26px; letter-spacing: -0.4px; }
    h2 { font-size: 20px; }
}

/* Accessible focus ring — visible on every interactive element */
:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.page-header {
    background: linear-gradient(135deg, var(--accent-soft) 0%, transparent 55%);
    margin: -32px -32px 28px;
    padding: 36px 32px 26px;
    border-bottom: 1px solid var(--border);
}

.page-header h1 {
    margin-bottom: 6px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: var(--leading-normal);
    max-width: var(--measure-reading);
}

/* ── Utility ─────────────────────────────────────────────── */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }

.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

/* ── Grid ────────────────────────────────────────────────── */

.grid {
    display: grid;
    gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (min-width: 1280px) {
    .grid-3 { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.005em;
    cursor: pointer;
    transition: background 0.18s var(--ease-out),
                border-color 0.18s var(--ease-out),
                color 0.18s var(--ease-out),
                box-shadow 0.2s var(--ease-out),
                transform 0.12s var(--ease-out);
    text-decoration: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn:hover {
    border-color: var(--border-strong);
    background: var(--card-hover);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0) scale(0.97);
    box-shadow: none;
    transition-duration: 0.08s;
}

.btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.btn[disabled],
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: transparent;
    box-shadow: 0 1px 2px rgba(84,72,217,0.25),
                0 4px 12px rgba(84,72,217,0.18);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: transparent;
    box-shadow: 0 2px 4px rgba(84,72,217,0.3),
                0 8px 18px rgba(84,72,217,0.22);
    transform: translateY(-1px);
}

.btn-primary:active {
    background: var(--accent-strong);
    box-shadow: 0 1px 2px rgba(84,72,217,0.35);
    transform: translateY(0) scale(0.97);
    transition-duration: 0.08s;
}

.btn-primary:focus-visible {
    box-shadow: var(--shadow-glow),
                0 4px 12px rgba(84,72,217,0.22);
}

.btn-secondary {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

.btn-secondary:hover {
    background: var(--accent-light);
    border-color: transparent;
    color: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-subtle);
    border-color: transparent;
    color: var(--text);
    box-shadow: none;
    transform: none;
}

.btn-sm {
    padding: 6px 12px;
    min-height: 32px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-lg {
    padding: 12px 22px;
    min-height: 46px;
    font-size: 15px;
    border-radius: 12px;
}

.btn-danger {
    background: var(--card);
    color: var(--red);
    border-color: var(--border);
}

.btn-danger:hover {
    background: var(--red-bg);
    border-color: var(--red);
    color: var(--red);
}

.btn-success {
    background: var(--green);
    color: var(--text-inverse);
    border-color: transparent;
    box-shadow: 0 1px 2px rgba(16,164,95,0.25),
                0 4px 12px rgba(16,164,95,0.15);
}

.btn-success:hover {
    background: var(--green-dark);
    box-shadow: 0 2px 4px rgba(16,164,95,0.3),
                0 8px 18px rgba(16,164,95,0.22);
}

.btn-block { display: flex; width: 100%; }

/* ── Inputs ──────────────────────────────────────────────── */

input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
    padding: 10px 14px;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.18s var(--ease-out),
                background 0.18s var(--ease-out),
                box-shadow 0.2s var(--ease-out);
    width: 100%;
    max-width: 100%;
}

input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
}

input:hover:not(:focus),
select:hover:not(:focus),
textarea:hover:not(:focus) {
    border-color: var(--border-strong);
    background: var(--card-hover);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238A8891' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
select option {
    background: var(--bg);
    color: var(--text);
}

[data-theme="dark"] select,
[data-theme="dark"] input[type="search"]::-webkit-search-cancel-button {
    color-scheme: dark;
}

/* ── Loading ─────────────────────────────────────────────── */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 12px;
}

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

/* ── Empty state ─────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--text-muted);
}

/* Hidden by default — shown only on mobile via @media query */
.notes-mobile-back {
    display: none;
}

/* ── Scrollbar ───────────────────────────────────────────── */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border: 2px solid var(--bg);
    border-radius: 999px;
    transition: background 0.18s var(--ease-out);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }

/* ── Content rendering ───────────────────────────────────── */

.rendered-content h1 { font-size: 22px; margin: 20px 0 8px; }
.rendered-content h2 { font-size: 18px; margin: 16px 0 6px; border-bottom: 2px solid var(--border); padding-bottom: 6px; margin-top: 24px; margin-bottom: 12px; }
.rendered-content h3 { font-size: 15px; margin: 14px 0 4px; border-left: 3px solid var(--accent); padding-left: 10px; margin-top: 20px; margin-bottom: 8px; }

.rendered-content ul,
.rendered-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.rendered-content li {
    margin-bottom: 4px;
    line-height: 1.6;
}

.rendered-content li::marker {
    color: var(--accent);
}

.rendered-content p {
    margin-bottom: 10px;
    line-height: 1.7;
}

.rendered-content .statute-ref {
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-light);
    padding: 2px 6px;
    border-radius: 4px;
}

.rendered-content .case-ref {
    font-style: italic;
    font-weight: 500;
    background: var(--green-bg);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--green-dark);
}

/* ── Rich content: dividers, blockquotes, callouts ────────── */

.content-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.content-blockquote {
    border-left: 3px solid var(--blockquote-border);
    padding-left: 16px;
    margin: 16px 0;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.7;
}

.callout {
    border-radius: 8px;
    padding: 16px;
    border-left: 4px solid var(--accent);
    background: var(--callout-bg);
    margin: 16px 0;
}

.callout-title {
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.callout-body {
    font-size: inherit;
    line-height: 1.7;
}

.callout-rule { border-left-color: var(--accent); background: var(--accent-light); }
.callout-rule .callout-title { color: var(--accent); }
.callout-note { border-left-color: var(--blue); background: var(--blue-bg); }
.callout-note .callout-title { color: var(--blue); }
.callout-important { border-left-color: var(--amber); background: var(--amber-bg); }
.callout-important .callout-title { color: var(--amber); }
.callout-warning { border-left-color: var(--red); background: var(--red-bg); }
.callout-warning .callout-title { color: var(--red); }
.callout-example { border-left-color: var(--green-dark); background: var(--green-bg); }
.callout-example .callout-title { color: var(--green-dark); }
.callout-definition { border-left-color: var(--purple); background: var(--purple-bg); }
.callout-definition .callout-title { color: var(--purple); }

.inline-code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.9em;
}

.rendered-content dl {
    margin: 12px 0;
}

.rendered-content dt {
    font-weight: 700;
    color: var(--text);
    margin-top: 8px;
}

.rendered-content dd {
    margin-left: 16px;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* ── Priority legend ─────────────────────────────────────── */

.priority-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 20px;
}

.priority-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.priority-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Quick actions ─────────────────────────────────────── */

.quick-actions {
    display: flex;
    gap: 12px;
    margin-bottom: var(--section-gap);
}

.quick-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow);
}

.quick-action-btn:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.quick-action-btn .qa-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.quick-action-btn .qa-icon.quiz { background: var(--blue-bg); }
.quick-action-btn .qa-icon.flashcards { background: var(--green-bg); }
.quick-action-btn .qa-icon.notes { background: var(--amber-bg); }

/* ── Focus card ────────────────────────────────────────── */

.focus-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--red);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: var(--section-gap);
    box-shadow: var(--shadow);
}

.focus-card h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.focus-card .focus-subject {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.focus-card .focus-reason {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── Progress bar (inline) ─────────────────────────────── */

.progress-bar-inline {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar-inline .progress-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--accent);
    transition: width 0.5s ease;
}

.progress-bar-lg {
    height: 12px;
    border-radius: 6px;
}

/* ── Mastery (Phase 7) ────────────────────────────────── */

.mastery-heatmap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.mastery-tile {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: var(--border);
    display: inline-block;
    cursor: help;
    transition: transform 160ms var(--ease-out, ease), box-shadow 160ms var(--ease-out, ease);
}
.mastery-tile:hover {
    transform: scale(1.25);
    box-shadow: 0 2px 6px rgba(17,17,20,0.25);
    z-index: 2;
    position: relative;
}
.mastery-tile.mastery-green  { background: var(--green); }
.mastery-tile.mastery-amber  { background: var(--amber); }
.mastery-tile.mastery-red    { background: var(--red); }
.mastery-tile.mastery-unknown { background: var(--border); opacity: .55; }

.mastery-carousel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.mastery-card {
    padding: 18px 18px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    border-left: 4px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: transform 160ms var(--ease-out, ease), box-shadow 200ms var(--ease-out, ease), border-color 160ms var(--ease-out, ease);
}
.mastery-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.mastery-card.mastery-green { border-left-color: var(--green); }
.mastery-card.mastery-amber { border-left-color: var(--amber); }
.mastery-card.mastery-red   { border-left-color: var(--red); }

.progress-fill.mastery-green { background: var(--green); }
.progress-fill.mastery-amber { background: var(--amber); }
.progress-fill.mastery-red   { background: var(--red); }

/* Mastery header — formula as inline legend chip */
.mastery-header {
    position: relative;
}
.mastery-header .mastery-subtitle {
    max-width: var(--measure-reading);
    color: var(--text-secondary);
    font-size: 15px;
    line-height: var(--leading-snug);
    margin-bottom: 14px;
}
.mastery-formula {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}
.mastery-formula-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    padding-right: 8px;
    border-right: 1px solid var(--border);
}
.mastery-formula-part {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    text-transform: lowercase;
    letter-spacing: 0.02em;
}
.mastery-formula-part .mastery-weight {
    font-family: 'Baloo 2', cursive;
    font-size: 14px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.01em;
}
.mastery-formula-dot {
    color: var(--text-muted);
    font-weight: 700;
}

/* Filter-bar label */
.filter-bar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-right: 4px;
}

/* Mastery vitals — one row of primary stats */
.mastery-vitals {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr;
    align-items: stretch;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 8px;
    box-shadow: var(--shadow-sm);
}
.mastery-vital {
    padding: 4px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mastery-vital-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.mastery-vital-value {
    font-family: 'Baloo 2', cursive;
    font-size: 30px;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.mastery-vital-value.is-good { color: var(--green); }
.mastery-vital-value.is-warn { color: var(--amber); }
.mastery-vital-suffix {
    font-family: 'Urbanist', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 4px;
    letter-spacing: 0;
}
.mastery-vital-hint {
    font-size: 12px;
    color: var(--text-muted);
}
.mastery-vital-divider {
    width: 1px;
    background: var(--border);
    margin: 8px 0;
}
@media (max-width: 900px) {
    .mastery-vitals {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 14px;
    }
    .mastery-vital-divider { display: none; }
    .mastery-vital { border-bottom: 1px solid var(--border); padding: 10px 12px; }
    .mastery-vital:nth-last-child(-n+2) { border-bottom: none; }
}

/* Mastery section header — h2 with meta */
.mastery-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin: 24px 0 14px;
}
.mastery-section-title {
    font-family: 'Baloo 2', cursive;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0;
}
.mastery-section-meta {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Mastery card — review carousel */
.mastery-card-eyebrow {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.mastery-card-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text);
    margin: 0 0 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mastery-card-score {
    font-family: 'Baloo 2', cursive;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1;
    margin-bottom: 10px;
    font-variant-numeric: tabular-nums;
}
.mastery-card-breakdown {
    display: flex;
    gap: 14px;
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}
.mastery-card-breakdown span {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
}
.mastery-card-breakdown em {
    font-style: normal;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

/* Mastery subject grid */
.mastery-subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.mastery-subject-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 160ms var(--ease-out, ease), box-shadow 200ms var(--ease-out, ease);
}
.mastery-subject-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.mastery-subject-name {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text);
    margin: 0 0 4px;
}
.mastery-subject-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.mastery-subject-score {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-top: 8px;
}
.mastery-subject-pct {
    font-family: 'Baloo 2', cursive;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.mastery-subject-band {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 3px 8px;
    border-radius: 999px;
}
.mastery-subject-band.band-green { background: var(--green-bg); color: var(--green-dark); }
.mastery-subject-band.band-amber { background: var(--amber-bg); color: var(--amber-dark); }
.mastery-subject-band.band-red   { background: var(--red-bg); color: var(--red-dark); }
.mastery-subject-band.band-unknown { background: var(--bg-subtle); color: var(--text-muted); }

/* Mastery legend */
.mastery-legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 14px;
    font-size: 11.5px;
    color: var(--text-secondary);
}
.mastery-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.mastery-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--border);
}
.mastery-legend-swatch.mastery-green  { background: var(--green); }
.mastery-legend-swatch.mastery-amber  { background: var(--amber); }
.mastery-legend-swatch.mastery-red    { background: var(--red); }
.mastery-legend-swatch.mastery-unknown { background: var(--border); opacity: .55; }

/* ── Chips, inputs, two-pane (Phase 8) ────────────────── */

.chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--card-bg, var(--bg));
    color: var(--text-muted);
    line-height: 1.4;
    vertical-align: middle;
    margin-left: 4px;
}
.chip-amber { background: rgba(245, 158, 11, .15); color: #b45309; border-color: rgba(245, 158, 11, .35); }
.chip-green { background: rgba(34, 197, 94, .15); color: #15803d; border-color: rgba(34, 197, 94, .35); }
.chip-red   { background: rgba(239, 68, 68, .15); color: #b91c1c; border-color: rgba(239, 68, 68, .35); }

.search-input,
.select-input {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--input-bg, var(--bg));
    color: var(--text);
    font-size: 14px;
    min-height: 40px;
}
.search-input { min-width: 260px; flex: 1 1 240px; max-width: 420px; }

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

.two-pane {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 2fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 900px) {
    .two-pane { grid-template-columns: 1fr; }
}

.pane-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 70vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    background: var(--card-bg, var(--bg));
}

.pane-list-item {
    text-align: left;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    width: 100%;
}
.pane-list-item:hover { background: var(--hover-bg, rgba(0,0,0,.04)); }
.pane-list-item.active {
    background: var(--accent-bg, rgba(59, 130, 246, .1));
    border-color: var(--accent);
}
.pane-item-title { font-weight: 600; font-size: 14px; }
.pane-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.pane-detail {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg, var(--bg));
    min-height: 320px;
}

.case-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.case-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.case-field { margin-bottom: 12px; }
.case-field-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}
.case-field-value {
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
}
.case-field-input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--input-bg, var(--bg));
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
}

/* Statute tree */
.statute-tree { display: flex; flex-direction: column; gap: 8px; }
.statute-act {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-bg, var(--bg));
}
.statute-act-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}
.statute-act-header:hover { background: var(--hover-bg, rgba(0,0,0,.03)); }
.statute-act.open .statute-act-header { background: var(--hover-bg, rgba(0,0,0,.03)); border-bottom: 1px solid var(--border); }
.statute-act-chevron { display: inline-block; margin-right: 8px; color: var(--text-muted); transition: transform 120ms ease; }
.statute-act.open .statute-act-chevron { transform: rotate(90deg); }
.statute-act-meta { font-size: 12px; color: var(--text-muted); font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.statute-act-meta .chip { font-size: 10px; padding: 2px 6px; }
.statute-sections { padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.statute-sections[hidden] { display: none !important; }
.statute-section {
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
}
.statute-section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}
.statute-section-body {
    font-size: 13px;
    color: var(--text);
    line-height: 1.5;
    white-space: pre-wrap;
}
.statute-section-meta { margin-top: 6px; }
.statute-ext-link { margin-bottom: 8px; font-size: 13px; }
.statute-ext-link a { color: var(--accent); text-decoration: none; }
.statute-ext-link a:hover { text-decoration: underline; }
.link, .link-small { color: var(--accent); text-decoration: none; font-size: 13px; }
.link:hover, .link-small:hover { text-decoration: underline; }

/* ── Palette + Shortcuts (Phase 9) ────────────────────── */

.palette-backdrop,
.shortcuts-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 998;
}

.palette {
    position: fixed;
    top: 12vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(640px, 92vw);
    max-height: 70vh;
    background: var(--card-bg, var(--bg));
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.palette-input {
    width: 100%;
    padding: 16px 20px;
    border: none;
    outline: none;
    font-size: 16px;
    background: transparent;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.palette-hint {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.palette-hint kbd {
    background: var(--bg);
    padding: 1px 5px;
    margin: 0 2px;
    border-radius: 3px;
    border: 1px solid var(--border);
    font-size: 10px;
}

.palette-results {
    overflow-y: auto;
    max-height: 50vh;
    padding: 4px;
}

.palette-result {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
}

/* C4: hover gets a soft surface highlight only — no border ring. */
.palette-result:hover {
    background: var(--card-hover);
}

/* C4: only the keyboard-active row shows the focus ring. We use both the
   .is-active class (set by the renderer) and the legacy .active class for
   backwards compatibility with any stale markup. */
.palette-result.is-active,
.palette-result.active,
.palette-result[aria-selected="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

/* C4: merged-results badge — surfaces "(+N similar)" so the user knows
   results were folded together. */
.palette-merged {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    padding: 1px 7px;
    border-radius: 999px;
    white-space: nowrap;
}

.palette-kind {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .05em;
    background: var(--border);
    color: var(--text-muted);
    min-width: 62px;
    text-align: center;
    font-weight: 600;
}

.palette-title { flex: 1; font-weight: 500; }
.palette-subtitle { color: var(--text-muted); font-size: 12px; }
.palette-empty { padding: 16px 20px; color: var(--text-muted); font-size: 13px; }

.palette-group { margin-bottom: 4px; }
.palette-group-label {
    padding: 6px 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--surface-2, rgba(0,0,0,0.02));
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Shortcuts modal */
.shortcuts {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, 92vw);
    background: var(--card-bg, var(--bg));
    border: 1px solid var(--border);
    border-radius: 12px;
    z-index: 999;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.shortcuts-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.shortcuts-head h2 { margin: 0; font-size: 18px; }
.shortcuts-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.shortcuts-close:hover { background: var(--border); }
.shortcuts-table { width: 100%; border-collapse: collapse; }
.shortcuts-table td { padding: 6px 0; font-size: 13px; }
.shortcuts-table td:first-child { width: 90px; }
.shortcuts-table kbd {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── Design polish (Phase 9) + A11y (Phase 10) ──────── */

.skip-link {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--accent, #3b82f6);
    color: #fff;
    padding: 10px 16px;
    border-radius: 0 0 8px 0;
    font-weight: 600;
    text-decoration: none;
    transform: translateY(-120%);
    transition: transform 0.15s ease;
    z-index: 1000;
}
.skip-link:focus {
    transform: translateY(0);
    outline: 2px solid #fff;
    outline-offset: -4px;
}

:focus-visible {
    outline: 2px solid var(--accent, #3b82f6);
    outline-offset: 2px;
    border-radius: 3px;
}

@media (prefers-contrast: more) {
    :focus-visible {
        outline-width: 3px;
        outline-offset: 3px;
    }
    .chip, .filter-chip {
        border-width: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Reading measure for note bodies */
.note-body, .note-content, .tutor-section-notes {
    max-width: 68ch;
    line-height: 1.6;
}

.btn, .nav-item, .filter-chip {
    min-height: 40px;
}

/* ── Breadcrumbs ───────────────────────────────────────── */

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.breadcrumbs a {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.breadcrumbs a:hover {
    text-decoration: underline;
}

.breadcrumbs .separator {
    color: var(--text-muted);
}

/* ── Streak counter ────────────────────────────────────── */

.streak-counter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--green-bg);
    color: var(--green-dark);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

/* ── Card type icons ───────────────────────────────────── */

.card-type-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ── Hamburger menu button ────────────────────────────── */

.hamburger-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 998;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: background 0.15s, box-shadow 0.15s;
}

.hamburger-btn:hover {
    background: var(--border);
    box-shadow: var(--shadow-lg);
}

/* ── Sidebar overlay (backdrop) ──────────────────────── */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* ── Animations ────────────────────────────────────────── */

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes correctPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); box-shadow: 0 0 0 4px var(--green-bg), 0 0 16px rgba(21,217,11,0.15); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes drawCircle {
    from { stroke-dashoffset: var(--circumference); }
    to { stroke-dashoffset: var(--final-offset); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.page-header {
    animation: fadeInUp 0.4s ease-out;
}

/* ── Per-view page header tints ──────────────────────────── */
.page-header-notes     { background: linear-gradient(135deg, var(--purple-bg) 0%, transparent 60%); }
.page-header-quiz      { background: linear-gradient(135deg, var(--blue-bg) 0%, transparent 60%); }
.page-header-flashcards { background: linear-gradient(135deg, var(--pink-bg) 0%, var(--green-bg) 60%, transparent 100%); }
.page-header-slides    { background: linear-gradient(135deg, var(--teal-bg) 0%, transparent 60%); }
.page-header-analytics { background: linear-gradient(135deg, var(--accent-light) 0%, transparent 60%); }
.page-header-rules     { background: linear-gradient(135deg, rgba(71,85,105,0.08) 0%, transparent 60%); }
.page-header-studyplanner { background: linear-gradient(135deg, var(--orange-bg) 0%, transparent 60%); }
.page-header-favourites { background: linear-gradient(135deg, var(--amber-bg) 0%, transparent 60%); }
.page-header-dashboard { background: linear-gradient(135deg, var(--accent-light) 0%, transparent 60%); }

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Note read progress ───────────────────────────────── */

.read-progress {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--border-light);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: auto;
    white-space: nowrap;
}

.read-progress-bar {
    padding: 8px 12px 4px;
}

.wrong-mcq-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.wrong-mcq-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.wrong-mcq-select-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ── Responsive ────────────────────────────────────────── */

/* Tablet: max-width 1024px (must come before 768px for desktop-first) */
@media (max-width: 1024px) {
    .notes-layout {
        grid-template-columns: 1fr 1fr;
        height: auto;
    }

    /* Hide subjects panel, show topics + content side by side */
    .notes-panel:first-child {
        display: none;
    }

    .notes-panel:nth-child(2) {
        display: block;
        border-right: 1px solid var(--border);
    }

    .notes-panel:last-child {
        display: block;
    }
}

/* Mobile: max-width 768px */
@media (max-width: 768px) {
    /* Show hamburger button */
    .hamburger-btn {
        display: flex;
    }

    /* Hide sidebar by default, slide in when .open */
    #sidebar {
        display: none;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        min-width: 280px;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
        transition: transform 0.3s ease;
    }

    #sidebar.open {
        display: flex;
    }

    #main {
        padding: 16px;
        padding-top: 68px; /* space for hamburger button */
    }

    .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .quick-actions {
        flex-direction: column;
    }

    .notes-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    /* On mobile, show all notes panels stacked */
    .notes-panel:first-child {
        display: block;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }

    .notes-panel:nth-child(2) {
        display: block;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }

    .notes-panel:last-child {
        display: block;
    }

    .flashcard-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .quiz-card {
        margin: 0 -8px;
    }

    /* Quiz question grid: scroll on mobile for large grids */
    .question-grid-container {
        max-height: 180px;
        overflow-y: auto;
    }

    /* Notes: add mobile "Back" button support */
    .notes-mobile-back {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 4px 10px;
        font-size: 13px;
        color: var(--accent);
        cursor: pointer;
        background: none;
        border: none;
    }

    .page-header {
        margin: -16px -16px 20px;
        padding: 16px 16px 16px;
    }

    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
}
