/* ============================================================
   M171 Study Hub — stylesheet
   Tokens first (light), then dark overrides, then components.
   ============================================================ */
:root {
  --bg: #F6F8FB;
  --grid: rgba(43, 85, 184, 0.05);
  --surface: #FFFFFF;
  --surface-2: #EEF2F7;
  --surface-3: #E2E8F0;
  --border: #D8DFEA;
  --border-strong: #B6C1D2;
  --ink: #131C2E;
  --ink-2: #364258;
  --muted: #64718A;
  --accent: #2B55B8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E4EBFA;
  --accent-line: #9DB4EA;
  --gold: #A8841A;
  --gold-soft: #FBF2D5;
  --good: #1F8A5B;
  --good-soft: #DFF4E8;
  --bad: #C43E3E;
  --bad-soft: #FBE4E4;
  --warn: #B26B10;
  --warn-soft: #FDEFD9;
  --lab: #6F45B0;
  --lab-soft: #EDE5FA;
  --shadow: 0 10px 30px rgba(19, 28, 46, 0.10);
  --shadow-sm: 0 2px 8px rgba(19, 28, 46, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-display: "STIX Two Text", "Times New Roman", Georgia, serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1420; --grid: rgba(124, 163, 255, 0.06);
    --surface: #151D2B; --surface-2: #1B2534; --surface-3: #243043;
    --border: #283548; --border-strong: #3B4A61;
    --ink: #E7EDF6; --ink-2: #C3CDDB; --muted: #8C9AB0;
    --accent: #7CA3FF; --accent-ink: #0B1424; --accent-soft: #1B2C4F; --accent-line: #3D5A9A;
    --gold: #E2BE4E; --gold-soft: #3A3013;
    --good: #4CC38A; --good-soft: #12331F;
    --bad: #F07373; --bad-soft: #3D1A1A;
    --warn: #E5A44A; --warn-soft: #3B2A10;
    --lab: #B08CE8; --lab-soft: #2B2140;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45); --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1420; --grid: rgba(124, 163, 255, 0.06);
  --surface: #151D2B; --surface-2: #1B2534; --surface-3: #243043;
  --border: #283548; --border-strong: #3B4A61;
  --ink: #E7EDF6; --ink-2: #C3CDDB; --muted: #8C9AB0;
  --accent: #7CA3FF; --accent-ink: #0B1424; --accent-soft: #1B2C4F; --accent-line: #3D5A9A;
  --gold: #E2BE4E; --gold-soft: #3A3013;
  --good: #4CC38A; --good-soft: #12331F;
  --bad: #F07373; --bad-soft: #3D1A1A;
  --warn: #E5A44A; --warn-soft: #3B2A10;
  --lab: #B08CE8; --lab-soft: #2B2140;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45); --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-body); font-size: 15px; line-height: 1.55; color: var(--ink);
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; color: var(--ink); }
h1 { font-size: 30px; } h2 { font-size: 22px; } h3 { font-size: 18px; } h4 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
mjx-container[display="true"] { margin: 10px 0 !important; }
.qmath mjx-container[display="true"] { margin: 8px 0 2px !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- app frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.nav-backdrop { display: none; position: fixed; inset: 0; background: rgba(8, 12, 20, 0.4); z-index: 40; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px 14px; gap: 6px;
}
.brand { display: flex; align-items: baseline; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.brand-code { font-family: var(--font-display); font-style: italic; font-size: 30px; font-weight: 600; letter-spacing: -0.5px; color: var(--accent); }
.brand-name { font-size: 13px; line-height: 1.25; color: var(--ink-2); }
.brand-name small { display: block; color: var(--muted); font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase; }
.nav-label { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 14px; font-weight: 500; transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.pomo { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }
.pomo-time { font-family: var(--font-mono); font-size: 22px; font-weight: 500; letter-spacing: 0.02em; min-width: 72px; color: var(--ink); font-variant-numeric: tabular-nums; }
.pomo-mode { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.pomo-btns { display: flex; gap: 4px; margin-left: auto; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--ink); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
.exam-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.exam-chip b { font-family: var(--font-mono); font-weight: 600; }
.search-btn { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer; }
.search-btn svg { width: 15px; height: 15px; }
.search-btn:hover { color: var(--ink); background: var(--surface-2); }
.kbd { font-family: var(--font-mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); }
.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: 26px 28px 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.page-title { font-size: 28px; }
.page-sub { color: var(--muted); margin-top: 4px; max-width: 70ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- layout helpers ---------- */
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.gap-sm { gap: 6px; } .gap-lg { gap: 16px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.prose { max-width: 72ch; }
.prose p + p { margin-top: 10px; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.panel.flat { background: transparent; border-style: dashed; }
.panel.lift { box-shadow: var(--shadow); border-color: var(--accent-line); }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-title svg { width: 18px; height: 18px; color: var(--accent); }
.eyebrow { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* ---------- buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background 0.12s, border-color 0.12s; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.xs { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.input, .select, textarea.input { width: 100%; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font-size: 14px; }
.input.mono { font-family: var(--font-mono); }
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.input.invalid { border-color: var(--bad); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid transparent; white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.lab { background: var(--lab-soft); color: var(--lab); }
.chip.outline { background: transparent; border-color: var(--border-strong); }
.chip.toggle { cursor: pointer; user-select: none; }
.chip.toggle:hover { border-color: var(--border-strong); }
.chip.toggle.on { background: var(--accent); color: var(--accent-ink); }
.chip.exam { background: var(--gold-soft); color: var(--gold); }
.chip.lecture { background: var(--accent-soft); color: var(--accent); }
.chip.holiday { background: var(--surface-3); color: var(--muted); }
.chip.admin { background: var(--warn-soft); color: var(--warn); }
.chip.review { background: var(--good-soft); color: var(--good); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-family: var(--font-mono); }
.table.compact th, .table.compact td { padding: 5px 8px; }
.table tr.hl td { background: var(--accent-soft); }

/* ---------- stats / bars ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-family: var(--font-mono); font-size: 26px; font-weight: 500; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s; }
.bar-fill.good { background: var(--good); } .bar-fill.warn { background: var(--warn); } .bar-fill.bad { background: var(--bad); } .bar-fill.gold { background: var(--gold); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px; }
.bar-row .bar { grid-column: 1 / -1; }

/* ---------- callouts / lists ---------- */
.callout { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); font-size: 14px; }
.callout.tip { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 30%, transparent); }
.callout.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.callout.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.callout .eyebrow { margin-bottom: 4px; }
.list { margin: 0; padding-left: 20px; }
.list li { margin: 6px 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: 0; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; cursor: pointer; }
.check input { margin-top: 3px; flex: none; }
.check.done span { color: var(--muted); text-decoration: line-through; }
.card-link { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none; transition: border-color 0.12s, transform 0.12s; }
.card-link:hover { border-color: var(--accent-line); text-decoration: none; transform: translateY(-1px); }
.card-link .eyebrow { margin-bottom: 4px; }
.card-link h4 { font-size: 15px; }
.card-link p { font-size: 13px; color: var(--muted); margin-top: 3px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 12px; border: 0; background: transparent; color: var(--muted); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.empty { color: var(--muted); font-size: 14px; padding: 14px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius-sm); }

/* ---------- dashboard ---------- */
.hero-exam { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; }
.countdown { text-align: center; padding: 8px 18px; border-right: 1px solid var(--border); }
.countdown-num { font-family: var(--font-display); font-size: 64px; line-height: 1; font-weight: 600; color: var(--gold); font-variant-numeric: tabular-nums; }
.countdown-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 4px; }
.today-ev { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.today-ev:last-child { border-bottom: 0; }
.today-ev .when { font-family: var(--font-mono); font-size: 12px; color: var(--muted); min-width: 64px; }
.week-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.week-day { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; min-height: 84px; background: var(--surface); font-size: 12.5px; }
.week-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.week-day.past { opacity: 0.6; }
.week-day .d { font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; }
.week-day .d span { font-family: var(--font-mono); color: var(--muted); font-weight: 500; }
.week-day .ev { padding: 2px 0; color: var(--ink-2); line-height: 1.3; }
.week-day .ev.exam { color: var(--gold); font-weight: 600; }
.week-day .ev.lab { color: var(--lab); }
.week-day .ev.holiday { color: var(--muted); font-style: italic; }
.week-day .ev.admin { color: var(--warn); }

/* ---------- calendar ---------- */
.cal-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.cal-week { display: grid; grid-template-columns: 70px repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 6px; }
.cal-wk { font-size: 12px; color: var(--muted); padding-top: 10px; font-family: var(--font-mono); }
.cal-day { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 9px; min-height: 76px; background: var(--surface); font-size: 13px; }
.cal-day.past { opacity: 0.55; }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); opacity: 1; }
.cal-day.exam-day { background: var(--gold-soft); }
.cal-date { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-family: var(--font-mono); }
.cal-date b { color: var(--ink); font-family: var(--font-body); }
.cal-ev { line-height: 1.3; padding: 2px 0; }
.cal-ev.exam { color: var(--gold); font-weight: 600; }
.cal-ev.lab { color: var(--lab); }
.cal-ev.holiday { color: var(--muted); font-style: italic; }
.cal-ev.admin { color: var(--warn); font-weight: 600; }
.cal-ev.review { color: var(--good); }
.cal-head { display: grid; grid-template-columns: 70px repeat(5, minmax(0, 1fr)); gap: 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin-bottom: 6px; padding: 0 9px; }

/* ---------- notes ---------- */
.notes-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.sec-nav { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow-y: auto; }
.sec-nav .nav-label { padding: 10px 8px 4px; }
.sec-link { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--ink-2); font-size: 13.5px; cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; }
.sec-link:hover { background: var(--surface-2); text-decoration: none; }
.sec-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sec-link .num { font-family: var(--font-mono); font-size: 12px; color: var(--muted); min-width: 28px; }
.sec-link.active .num { color: var(--accent); }
.note-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.note-num { font-family: var(--font-mono); color: var(--accent); font-size: 14px; }
.note-title { font-size: 26px; }
.note-block { margin-top: 18px; }
.note-block h4 { font-size: 12px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); font-family: var(--font-body); margin-bottom: 8px; }
.formula-row { display: grid; grid-template-columns: 170px 1fr; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.formula-row:last-child { border-bottom: 0; }
.formula-row .name { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.formula-row .tex { overflow-x: auto; }
.reveal { display: none; }
.reveal.open { display: block; }

/* ---------- formula sheet ---------- */
.fs-group { break-inside: avoid; }
.fs-group h3 { font-size: 16px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); margin-bottom: 4px; }
.fs-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.fs-row:last-child { border-bottom: 0; }
.fs-row .name { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.fs-row .tex { overflow-x: auto; }

/* ---------- flashcards ---------- */
.fc-stage { perspective: 1200px; }
.fc-card { position: relative; width: 100%; min-height: 260px; cursor: pointer; transition: transform 0.45s; transform-style: preserve-3d; }
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 28px 32px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); backface-visibility: hidden; -webkit-backface-visibility: hidden; font-size: 18px; box-shadow: var(--shadow-sm); }
.fc-face .eyebrow { position: absolute; top: 14px; left: 18px; }
.fc-face .sec { position: absolute; top: 12px; right: 16px; }
.fc-front { font-family: var(--font-display); font-size: 22px; }
.fc-back { transform: rotateY(180deg); background: var(--accent-soft); border-color: var(--accent-line); font-size: 17px; line-height: 1.5; }
.fc-hint { position: absolute; bottom: 12px; left: 0; right: 0; font-size: 12px; color: var(--muted); }
.fc-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* ---------- practice ---------- */
.q-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 18px 20px; }
.q-card.correct { border-color: var(--good); }
.q-card.wrong { border-color: var(--bad); }
.q-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.q-num { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.q-prompt { font-size: 15.5px; line-height: 1.6; }
.q-opts { display: grid; gap: 8px; margin-top: 14px; }
.q-opt { display: flex; align-items: flex-start; gap: 10px; text-align: left; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: 14.5px; line-height: 1.5; transition: border-color 0.12s, background 0.12s; }
.q-opt:hover:not(:disabled) { border-color: var(--accent-line); background: var(--accent-soft); }
.q-opt:disabled { cursor: default; }
.q-opt .letter { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 3px; min-width: 14px; }
.q-opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.q-opt.correct { border-color: var(--good); background: var(--good-soft); }
.q-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-numrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.q-numrow .input { max-width: 220px; }
.q-feedback { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; }
.q-feedback.ok { background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.q-feedback.no { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.q-feedback b.res { display: block; margin-bottom: 4px; }
.q-hint { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); background: var(--gold-soft); padding: 8px 12px; border-radius: var(--radius-sm); }
.score-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.timer { font-family: var(--font-mono); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }

/* ---------- grapher / labs ---------- */
.graph-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.graph-wrap { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
canvas.graph { display: block; width: 100%; height: 460px; touch-action: none; cursor: crosshair; }
.graph-legend { position: absolute; top: 10px; left: 12px; display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.graph-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.readout { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.readout .k { color: var(--muted); font-family: var(--font-body); }
.readout .v { text-align: right; }
canvas.riemann { display: block; width: 100%; height: 300px; }
.slider-row { display: grid; grid-template-columns: 1fr 76px; gap: 8px; align-items: center; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- scratchpad ---------- */
.pad-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border-strong); cursor: pointer; padding: 0; }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
canvas.pad { display: block; width: 100%; height: 540px; touch-action: none; cursor: crosshair; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
canvas.pad.grid { background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
.sizes { display: flex; gap: 4px; }
.size-btn { width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.size-btn.on { border-color: var(--accent); background: var(--accent-soft); }
.size-btn i { display: block; border-radius: 50%; background: var(--ink); }

/* ---------- grades ---------- */
.grade-letter { font-family: var(--font-display); font-size: 56px; font-weight: 600; line-height: 1; color: var(--accent); }
.grade-row td .input { max-width: 110px; }

/* ---------- modal / search / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 20, 0.5); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px; }
.modal { width: 100%; max-width: 640px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.search-input { width: 100%; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--ink); font-size: 16px; }
.search-input:focus { outline: none; }
.search-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.search-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.search-item:hover, .search-item.active { background: var(--accent-soft); }
.search-item .type { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); min-width: 64px; }
.search-item .t { color: var(--ink); }
.search-item .s { color: var(--muted); font-size: 12.5px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.search-foot { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); display: flex; gap: 12px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 70; box-shadow: var(--shadow); }

/* ---------- textbook ---------- */
.pdf-frame { width: 100%; height: 720px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .graph-layout { grid-template-columns: 1fr; }
  .notes-layout { grid-template-columns: 220px 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 50; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .nav-backdrop { display: block; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .page { padding: 18px 16px 50px; }
  .notes-layout { grid-template-columns: 1fr; }
  .sec-nav { position: static; max-height: none; }
  .hero-exam { grid-template-columns: 1fr; }
  .countdown { border-right: 0; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
  .search-btn span { display: none; }
  .exam-chip span { display: none; }
}
@media (max-width: 640px) {
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .page-title { font-size: 24px; }
  .week-strip { grid-template-columns: 1fr; }
  .cal-week { grid-template-columns: 1fr; }
  .cal-head { display: none; }
  .cal-wk { padding-top: 0; }
  .formula-row, .fs-row { grid-template-columns: 1fr; gap: 2px; }
  .slider-row { grid-template-columns: 1fr; }
  canvas.graph { height: 340px; }
  canvas.pad { height: 420px; }
  .countdown-num { font-size: 48px; }
}

/* ---------- print ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 12px; }
  .sidebar, .topbar, .no-print, .nav-backdrop { display: none !important; }
  .app { display: block; }
  .page { max-width: none; padding: 0; }
  .panel { border: 0; padding: 0; box-shadow: none; break-inside: avoid; }
  .grid { display: block; }
  .fs-group { margin-bottom: 14px; }
  .reveal { display: block !important; }
  a { color: inherit; }
}
