/* Locker — IBM Plex identity, phone-first, light+dark */
:root {
  --paper: #FBFBF8; --card: #FFFFFF; --ink: #22303F; --muted: #5D6B7A;
  --line: #E3E4DD; --chip: #F1F2EC; --accent: #2E5AAC; --accent-ink: #FFFFFF;
  --gold: #A87E22; --flag: #C0392B; --ok: #2E7D4F; --shadow: 0 1px 3px rgba(30,40,60,.07), 0 8px 24px rgba(30,40,60,.05);
  --sans: "IBM Plex Sans", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A21; --card: #1C232C; --ink: #E6EBF1; --muted: #98A5B3;
    --line: #2A323D; --chip: #232B35; --accent: #82A9E8; --accent-ink: #10151C;
    --gold: #D2AC5A; --flag: #E06A5B; --ok: #6FBF8F; --shadow: 0 1px 3px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --paper: #141A21; --card: #1C232C; --ink: #E6EBF1; --muted: #98A5B3;
  --line: #2A323D; --chip: #232B35; --accent: #82A9E8; --accent-ink: #10151C;
  --gold: #D2AC5A; --flag: #E06A5B; --ok: #6FBF8F; --shadow: 0 1px 3px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font: inherit; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

#app { min-height: 100dvh; }

/* ---------- shell layout ---------- */
.shell { padding: calc(var(--sat) + 8px) 16px calc(var(--sab) + 84px); max-width: 640px; margin: 0 auto; }
@media (min-width: 900px) {
  .shell { max-width: 720px; padding-left: 96px; padding-bottom: 40px; }
}
/* bottom nav (left rail on desktop) */
.nav {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(var(--sab) + 6px);
}
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 10.5px; font-weight: 500; letter-spacing: .02em; min-width: 56px; padding: 4px 6px; border-radius: 10px; }
.nav button svg { width: 22px; height: 22px; }
.nav button.on { color: var(--accent); }
.nav .fab {
  background: var(--accent); color: var(--accent-ink); border-radius: 16px;
  width: 52px; height: 40px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); min-width: 52px;
}
.nav .fab svg { width: 24px; height: 24px; }
@media (min-width: 900px) {
  .nav { left: 0; right: auto; top: 0; bottom: 0; flex-direction: column; justify-content: center; gap: 10px; border-top: 0; border-right: 1px solid var(--line); padding: 16px 12px; }
}

/* ---------- primitives ---------- */
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .13em; text-transform: uppercase; color: var(--gold); }
h1.page { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; margin: 2px 0 4px; text-wrap: balance; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.section-h h2 { font-family: var(--serif); font-weight: 600; font-size: 18px; margin: 0; }
.section-h .more { font-size: 13px; color: var(--accent); font-weight: 500; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.row + .row { border-top: 1px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chipbar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chipbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 13.5px; font-weight: 500; padding: 7px 13px; border-radius: 999px;
  background: var(--chip); border: 1px solid var(--line); color: var(--ink); transition: background .15s, color .15s;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { font-family: var(--mono); font-size: 12px; opacity: .75; margin-left: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
  border-radius: 12px; padding: 12px 18px; transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--chip); color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 7px 12px; font-size: 13.5px; border-radius: 9px; }
.btn.danger { background: var(--flag); color: #fff; }
/* Destructive but not shouting — delete sits at the bottom of an edit sheet. */
.btn.ghost.danger { background: transparent; color: var(--flag); border: 1px solid color-mix(in srgb, var(--flag) 40%, transparent); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.badge { font-family: var(--mono); font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.warn { background: color-mix(in srgb, var(--flag) 14%, transparent); color: var(--flag); }
.badge.gold { background: color-mix(in srgb, var(--gold) 15%, transparent); color: var(--gold); }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 34px 20px; font-size: 14.5px; }
.empty .big { font-size: 26px; display: block; margin-bottom: 8px; }

input.field, select.field, textarea.field {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font-size: 16px;
}
input.field:focus, select.field:focus, textarea.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label.lbl { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 12px 0 5px; letter-spacing: .02em; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 360px; padding: 32px 28px; text-align: center; }
.login .mark { font-family: var(--serif); font-size: 34px; font-weight: 600; }
.login .mark .dot { color: var(--gold); }
.login .sub { margin-bottom: 22px; }
.login .err { color: var(--flag); font-size: 13.5px; min-height: 20px; margin: 10px 0 2px; }

/* ---------- home ---------- */
.today-line { display: flex; align-items: baseline; justify-content: space-between; }
.sync-dot { font-family: var(--mono); font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync-dot .spin { width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.due-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
.due-row + .due-row { border-top: 1px solid var(--line); }
.tick { width: 24px; height: 24px; flex: none; border: 2px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: transparent; transition: all .15s; }
.tick.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.due-row .when { font-family: var(--mono); font-size: 12px; color: var(--muted); flex: none; text-align: right; }
.due-row .when.urgent { color: var(--flag); font-weight: 500; }
.due-row .cdot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.due-title { font-weight: 500; font-size: 14.5px; }
.due-sub { font-size: 12.5px; color: var(--muted); }

/* Tapping the middle of a row opens its editor; the tick and the date stay
   their own targets. */
.due-row .tap { cursor: pointer; border-radius: 8px; margin: -4px 0; padding: 4px 0; transition: opacity .12s; }
.due-row .tap:active { opacity: .55; }

/* Prep tasks are derived work, not deadlines — quieter, and marked. */
.due-row.prep .due-title { font-weight: 400; }
.due-row.prep .prep-tag { color: var(--gold); margin-right: 5px; vertical-align: -1px; display: inline-flex; }

/* The single most time-critical thing left today, given its own weight at the
   top of the page. Everything else is a list; this is the answer. */
.nextup {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--flag);
  border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; margin: 14px 0 4px;
  cursor: pointer; transition: transform .12s;
}
.nextup:active { transform: scale(.99); }
.nextup-when {
  font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--flag);
  flex: none; min-width: 62px;
}
.nextup-title { font-weight: 600; font-size: 15.5px; line-height: 1.25; }
.nextup-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.missed-card { border-left: 3px solid var(--flag); }

/* Due earlier today and still open — not yet "overdue" by date, but gone. */
.due-row.passed .due-title { color: var(--flag); }
.due-row.passed .when { color: var(--flag); font-weight: 500; }

.confirm-card { border-left: 3px solid var(--gold); }

.class-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.class-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 13px 14px 12px; text-align: left; position: relative; overflow: hidden; transition: transform .12s;
}
.class-card:active { transform: scale(.98); }
.class-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--cc, var(--accent)); }
.class-card .code { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.class-card .cname { font-weight: 600; font-size: 14.5px; line-height: 1.25; margin: 3px 0 8px; min-height: 36px; }
.class-card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.class-card .meta b { color: var(--ink); font-weight: 600; }

/* ---------- class view ---------- */
.class-head { border-radius: 16px; padding: 18px 16px 14px; color: #fff; position: relative; overflow: hidden; background: var(--cc, var(--accent)); box-shadow: var(--shadow); }
.class-head::after { content: ""; position: absolute; inset: 0; background: linear-gradient(155deg, rgba(0,0,0,.05), rgba(0,0,0,.28)); }
.class-head > * { position: relative; z-index: 1; }
.class-head .code { font-family: var(--mono); font-size: 12px; opacity: .9; letter-spacing: .06em; }
.class-head h1 { font-family: var(--serif); font-size: 24px; margin: 2px 0 2px; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.2); }
.class-head .prof { font-size: 13px; opacity: .92; }
.back { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13.5px; font-weight: 500; margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 14px -16px 16px; padding: 0 16px 2px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; padding: 9px 13px; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--cc, var(--accent)); }
.tabs button .n { font-family: var(--mono); font-size: 11px; margin-left: 3px; color: var(--gold); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.stat .k { font-size: 11.5px; color: var(--muted); }

.lec-row { display: block; width: 100%; text-align: left; padding: 12px 14px; }
.lec-row + .lec-row { border-top: 1px solid var(--line); }
.lec-row .t { font-weight: 500; font-size: 14.5px; }
.lec-row .d { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; }

.note-card { padding: 12px 14px; }
.note-card + .note-card { border-top: 1px solid var(--line); }
.note-card .prev { font-size: 13px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

button.note-card { display: block; width: 100%; text-align: left; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chips .chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--chip); border: 1px solid var(--line); color: var(--muted); }

.flag-item { display: flex; gap: 10px; padding: 11px 14px; align-items: flex-start; }
.flag-item + .flag-item { border-top: 1px solid var(--line); }
.flag-item .star { color: var(--flag); flex: none; margin-top: 1px; }
.flag-item .topic { font-size: 12.5px; color: var(--muted); }
.flag-item .fctx { font-size: 13px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.flag-item .frow { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- note page: his paper, set in type ---------- */
/* The page keeps its own texture: every worked line is its own line, his
   numbering is his, and the red marks stay red and stay where he put them. */
.paper {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px 18px 20px; margin-top: 14px;
  font-size: 15px; line-height: 1.55; overflow-wrap: break-word;
}
.paper h3, .paper h4, .paper h5, .paper h6 { font-family: var(--serif); margin: 16px 0 6px; font-size: 16.5px; }
.paper h3:first-child, .paper h4:first-child { margin-top: 0; }
.paper .ln { padding: 1px 0; }
.paper .lnum { font-family: var(--mono); font-size: 13px; color: var(--gold); font-weight: 500; margin-right: 2px; }
.paper .nsp { height: 12px; }
.paper ul { margin: 2px 0; padding-left: 22px; }
.paper blockquote { margin: 6px 0; padding: 6px 12px; border-left: 3px solid var(--gold); background: var(--chip); border-radius: 0 8px 8px 0; font-size: 14px; color: var(--muted); }
.paper code { font-family: var(--mono); font-size: 13.5px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.paper hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.paper b { font-weight: 600; }
/* the red mark, live on the page */
.fmark {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; margin-left: 5px; padding: 0 5px;
  border-radius: 999px; color: var(--flag); font-size: 13px; vertical-align: -3px;
  background: color-mix(in srgb, var(--flag) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--flag) 35%, transparent);
}
.fmark:active { transform: scale(.92); }

.note-flagbar {
  display: flex; align-items: center; gap: 10px; margin: 12px 0 0;
  padding: 10px 14px; border-radius: 12px; font-size: 13.5px;
  background: color-mix(in srgb, var(--flag) 8%, var(--card));
  border: 1px solid color-mix(in srgb, var(--flag) 30%, transparent);
}
.note-flagbar .star { color: var(--flag); flex: none; }

/* the ask bar — present but quiet; it should read as an invitation, not a
   feature competing with the day's work */
.askbar {
  display: flex; align-items: center; gap: 9px; width: 100%;
  margin: 12px 0 4px; padding: 11px 14px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--line);
  color: var(--muted); font-size: 14.5px; text-align: left;
  transition: border-color .15s, color .15s;
}
.askbar svg { width: 17px; height: 17px; flex: none; color: var(--gold); }
.askbar:active { border-color: var(--accent); color: var(--ink); }
.askbar.in-sheet { margin: 0 0 6px; }

.ask-done {
  display: flex; gap: 9px; align-items: flex-start; margin-top: 16px;
  padding: 12px 14px; border-radius: 12px; font-size: 15px; line-height: 1.45;
  background: color-mix(in srgb, var(--ok) 12%, var(--card));
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
}
.ask-done svg { width: 18px; height: 18px; flex: none; color: var(--ok); margin-top: 1px; }
.ask-done.warn { background: color-mix(in srgb, var(--gold) 12%, var(--card)); border-color: color-mix(in srgb, var(--gold) 38%, transparent); }
.ask-done.warn svg { color: var(--gold); }
.ask-undo-row { display: flex; justify-content: flex-end; margin-top: 10px; }
.linkbtn { font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 6px 2px; }
.linkbtn:active { color: var(--ink); }
.chg { display: flex; gap: 10px; align-items: baseline; padding: 10px 14px; font-size: 14px; }
.chg + .chg { border-top: 1px solid var(--line); }
.chg-op { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--gold); flex: none; }

.rrule { display: flex; gap: 10px; align-items: center; padding: 11px 14px; }
.rrule + .rrule { border-top: 1px solid var(--line); }
.rrule .days { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ---------- the drawn page ---------- */
/* Real paper: white in both themes, because this is a copy of a physical page
   and dark-mode notes read as a screenshot of an app, not as his notebook.
   Ink colors are the page's own, so they're fixed values, not theme tokens. */
.drawn {
  --ink-black: #1B2430; --ink-blue: #1D4ED8; --ink-red: #C0392B;
  --ink-green: #15803D; --ink-pencil: #6B7280;
  background: #fff; color: var(--ink-black);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 20px 18px 24px; margin-top: 14px;
  font-family: "Caveat", "Bradley Hand", "Segoe Print", var(--sans);
  font-size: 21px; line-height: 1.5; overflow-x: auto;
}
.drawn.grid {
  background-image: linear-gradient(#EEF1F5 1px, transparent 1px), linear-gradient(90deg, #EEF1F5 1px, transparent 1px);
  background-size: 22px 22px;
}
.drawn.ruled { background-image: linear-gradient(#EEF1F5 1px, transparent 1px); background-size: 100% 26px; }
.drow { display: block; }
.drow.split { display: flex; gap: 18px; align-items: flex-start; }
.drow.split .dcol { flex: 1 1 0; min-width: 0; }
.blk { padding: 1px 0; position: relative; }
.blk-heading { font-weight: 700; font-size: 1.12em; margin-top: 10px; text-decoration: underline; text-underline-offset: 3px; }
.drow:first-child .blk-heading { margin-top: 0; }
.blk-label { font-size: .8em; opacity: .8; font-style: italic; }
.blk-margin { font-size: .85em; padding-left: 10px; border-left: 2px solid currentColor; margin: 4px 0; }
.blk-diagram { font-size: .8em; font-style: italic; opacity: .75; border: 1px dashed currentColor; border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-family: var(--sans); }
.blk-divider { border-top: 1.5px solid #C9D1DA; margin: 12px 0; height: 0; padding: 0; }
.blk.boxed > .blk-body { display: inline-block; border: 1.7px solid currentColor; border-radius: 7px; padding: 3px 10px; margin: 3px 0; }
.blk.struck > .blk-body { text-decoration: line-through; opacity: .55; }
.blk .tex-raw { font-family: var(--mono); font-size: .72em; }
/* KaTeX inherits the block's ink so a blue step renders blue */
.drawn .katex { font-size: 1em; color: inherit; }
/* displayMode gives full-size fractions, but its centering and big margins are
   wrong for a notes page — pull it back to a left-aligned line. */
.drawn .katex-display { display: block; text-align: left; margin: 2px 0; }
/* Never wrap an equation mid-expression — "= x +" on one line and "1," on the
   next is unreadable. A long line scrolls inside its own block instead. */
.drawn .katex-display > .katex { display: inline-block; text-align: left; white-space: nowrap; }
.blk-math > .blk-body { display: block; max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.blk.boxed > .blk-body { max-width: 100%; }
.blk.boxed > .blk-body .katex-display { margin: 0; }
.drawn .blk-math { font-family: var(--sans); }
/* a drawing cut straight out of the photo — it keeps the paper it was on, so
   it sits on a plain card rather than pretending to be typeset */
.blk-clip { margin: 10px 0; }
.clip { margin: 0; }
.clip canvas {
  display: block; width: 100%; height: auto; border-radius: 9px;
  border: 1px solid #D9DEE5; background: #fff;
}
.clip figcaption {
  font-family: var(--sans); font-size: 11.5px; line-height: 1.4;
  color: #6B7280; margin-top: 5px; display: flex; align-items: baseline; gap: 6px;
}
.clip-failed canvas { min-height: 60px; }
.clip-failed figcaption::before { content: "couldn't cut this from the photo — "; }
.clip-turn { display: block; margin: 8px 0 0 auto; }

.drawn .fmark { vertical-align: 1px; margin-left: 7px; min-width: 20px; height: 20px; font-size: 12px; flex: none; }

/* A phone cannot hold two columns of mathematics side by side — stack them,
   keeping their order, rather than cutting the right one off the screen. */
@media (max-width: 620px) {
  .drawn { font-size: 19px; padding: 16px 13px 20px; }
  .drow.split { display: block; }
  .drow.split .dcol + .dcol { margin-top: 6px; }
}
.blk-margin { display: flex; align-items: baseline; gap: 2px; }
.blk-margin > .blk-body { flex: 1 1 auto; }

/* the redrawn page — white paper regardless of theme, it IS the artifact */
.clean-page {
  margin-top: 14px; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow); background: #fff;
}
.clean-page img { display: block; width: 100%; }
.clean-note { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.clean-note.drawing { display: flex; align-items: center; gap: 8px; padding: 12px 2px; font-size: 13.5px; }
.clean-note .spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; flex: none; }

details.orig { margin-top: 16px; }
details.orig summary { font-weight: 600; cursor: pointer; padding: 10px 0; }
details.orig img { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); }

.fq { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--flag); background: var(--chip); border-radius: 0 8px 8px 0; font-size: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

/* ---------- lecture detail ---------- */
.digest h3 { font-family: var(--serif); font-size: 16px; margin: 18px 0 8px; }
.kc { padding: 10px 14px; }
.kc + .kc { border-top: 1px solid var(--line); }
.kc b { display: block; font-size: 14px; }
.kc span { font-size: 13.5px; color: var(--muted); }
details.transcript { margin-top: 18px; }
details.transcript summary { font-weight: 600; cursor: pointer; padding: 10px 0; }
details.transcript pre { white-space: pre-wrap; font-family: var(--sans); font-size: 14px; color: var(--muted); line-height: 1.6; }

/* ---------- sheet (capture etc) ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(10,14,20,.45); z-index: 60; opacity: 0; transition: opacity .2s; }
.sheet-back.show { opacity: 1; }
.sheet {
  position: fixed; z-index: 61; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 18px 18px 0 0; padding: 10px 18px calc(var(--sab) + 20px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.3,.9,.3,1);
  max-width: 640px; margin: 0 auto;
}
.sheet.show { transform: none; }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 4px; }
.cap-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 4px; }
.cap-btn { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.cap-btn svg { width: 26px; height: 26px; color: var(--accent); }
.up-item { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 14px; }
.up-item .bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 5px; }
.up-item .bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

/* ---------- study / flashcards ---------- */
.fc-stage { perspective: 1200px; margin: 14px 0; }
.fc {
  position: relative; min-height: 250px; border-radius: 18px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); width: 100%; text-align: center;
  display: flex; align-items: center; justify-content: center; padding: 28px 22px;
  font-size: 18px; line-height: 1.45; transition: transform .15s;
}
.fc:active { transform: scale(.99); }
.fc .cls { position: absolute; top: 12px; left: 14px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.fc .side { position: absolute; top: 12px; right: 14px; font-family: var(--mono); font-size: 11px; color: var(--gold); }
.fc-grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.fc-grades button { border-radius: 12px; padding: 12px 4px; font-weight: 600; font-size: 14px; background: var(--chip); border: 1px solid var(--line); }
.fc-grades .g0 { color: var(--flag); } .fc-grades .g3 { color: var(--ok); }
.fc-progress { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: center; margin-top: 12px; }

/* ---------- grades ---------- */
.grade-big { font-family: var(--mono); font-size: 38px; font-weight: 500; }
.gcat { display: flex; justify-content: space-between; padding: 9px 14px; font-size: 14px; }
.gcat + .gcat { border-top: 1px solid var(--line); }
.gcat .avg { font-family: var(--mono); }

/* ---------- tutor chat ---------- */
.chat-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
#chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 90px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5; overflow-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.bubble.tutor { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.tutor p { margin: 0 0 8px; } .bubble.tutor p:last-child { margin: 0; }
.bubble.tutor ul, .bubble.tutor ol { margin: 0 0 8px; padding-left: 20px; }
.bubble.tutor h4 { margin: 4px 0 6px; font-size: 14.5px; }
.bubble.tutor code { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.bubble.thinking { display: flex; gap: 5px; padding: 14px 16px; }
.bubble.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: think 1.2s infinite; }
.bubble.thinking span:nth-child(2) { animation-delay: .2s; }
.bubble.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes think { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--sab) + 66px); z-index: 30;
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  max-width: 640px; margin: 0 auto;
}
.chat-bar textarea { resize: none; max-height: 140px; border-radius: 14px; }
.chat-bar .btn { border-radius: 12px; padding: 11px 16px; font-size: 18px; line-height: 1; }
@media (min-width: 900px) { .chat-bar { bottom: 0; padding-left: 96px; max-width: 720px; } }

/* the notes peek — his page, one tap away without leaving the answer.
   Sticky rather than fixed: it rides the chat's own scroller, so it is in the
   corner wherever he has scrolled to, and it cannot drift the way a fixed
   element does over iOS's collapsing toolbar. */
.peek { position: sticky; top: calc(var(--sat) + 4px); z-index: 25; display: flex; justify-content: flex-end; margin: -4px 0 6px; }
.peek-tab {
  display: inline-flex; align-items: center; gap: 6px; max-width: 62%;
  padding: 7px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500;
  color: var(--muted); background: color-mix(in srgb, var(--card) 97%, transparent);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.peek-tab .peek-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peek-tab .peek-ico { flex: none; opacity: .75; display: flex; }
.peek-tab .peek-chev { flex: none; font-size: 10px; transition: transform .18s; }
.peek.on .peek-tab { color: var(--ink); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.peek.on .peek-chev { transform: rotate(180deg); }
.peek-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  width: min(560px, calc(100vw - 32px)); max-height: 62dvh; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(10, 14, 20, .22); padding: 12px 12px 14px;
}
.peek-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13.5px; }
.peek-head b { flex: 1; font-weight: 600; line-height: 1.3; }
.peek-body .paper { margin-top: 0; border: 0; box-shadow: none; padding: 0; background: none; }
.peek-body .drawn { margin-top: 0; }
.peek-body .fmark { opacity: .55; }
.peek-switch { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.peek-switch .chip { font-size: 11.5px; }

/* typeset math in the tutor's answers — same renderer as the drawn page */
.bubble.tutor .katex { font-size: 1.03em; color: inherit; }
.bubble.tutor .mathline { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }
.bubble.tutor .katex-display { margin: 0; text-align: left; }
.bubble.tutor .katex-display > .katex { text-align: left; }
.bubble.tutor .tex-raw { font-family: var(--mono); font-size: 12.5px; }

/* ---------- practice ---------- */
.prac { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14.5px; }
.prac-q { line-height: 1.5; }
.prac-steps { white-space: pre-wrap; color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* ---------- toast ---------- */
#toasts { position: fixed; z-index: 100; left: 0; right: 0; bottom: calc(var(--sab) + 92px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--paper); font-size: 14px; font-weight: 500;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); max-width: 88vw;
  animation: toast-in .25s cubic-bezier(.3,.9,.3,1);
}
.toast.warn { background: var(--flag); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.skel { border-radius: 12px; background: linear-gradient(90deg, var(--chip) 25%, var(--line) 50%, var(--chip) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.seg { display: flex; background: var(--chip); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* Phone: the PAGE does not scroll — the shell inside it does.
 *
 * A `position: fixed` bottom bar over a scrolling body drifts on iOS: Safari
 * resizes the visual viewport as its own toolbar collapses and re-lays fixed
 * elements out at the end of a momentum scroll, so the nav visibly rides up
 * and down with the content. Nothing about the nav's own CSS causes it and no
 * amount of layer-promotion fixes it. Taking the scroll off <body> does: the
 * toolbar never collapses, the viewport never resizes, and the bar is nailed
 * down. It also fixes .chat-bar, which had the same drift.
 *
 * Desktop keeps body scrolling — the nav is a left rail there and no toolbar
 * moves — so this is scoped below the rail breakpoint.
 */
@media (max-width: 899px) {
  html, body { height: 100%; overflow: hidden; }
  #app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  .shell {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain; padding-bottom: calc(var(--sab) + 20px); width: 100%;
  }
  /* in flow now, so it cannot move; it still owns the same strip of screen,
     which is why .chat-bar's bottom offset is unchanged */
  .nav { position: static; flex: none; }
  .login { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
}
