/* Engram — design tokens
   Palette semantics follow memory strength: teal = strong, amber = fading, coral = forgotten.
   Everything else stays neutral ink so the memory colors always mean something. */

@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/atkinson-400i.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("../fonts/space-grotesk.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #e8edf5;
  --line: #dce3ee;
  --line-strong: #c4cfdf;
  --ink: #13213b;
  --ink-2: #46546e;
  --ink-3: #6f7c93;
  --on-ink: #ffffff;
  --btn-hover: #22355b;

  --trace: #0e8f86;
  --trace-ink: #0a6d66;
  --trace-soft: rgba(14, 143, 134, 0.12);
  --ok: #4aa79a;
  --fade: #d98a1c;
  --fade-ink: #925705;
  --fade-soft: rgba(217, 138, 28, 0.13);
  --miss: #d64535;
  --miss-ink: #ad2f22;
  --miss-soft: rgba(214, 69, 53, 0.1);
  --select: #e3ebff;
  --select-line: #6d8fe0;
  --focus: #3b6fe0;

  --heat-0: #e3e9f2;
  --heat-1: #b7e2dc;
  --heat-2: #6cc2b7;
  --heat-3: #22988d;
  --heat-4: #0b6b63;

  --log-bg: #0f1a2e;
  --log-ink: #c6d3ea;

  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-pop: 0 18px 50px -12px rgba(19, 33, 59, 0.35);
  --side: 236px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1524; --surface: #142036; --surface-2: #192740; --surface-3: #20304d;
    --line: #253556; --line-strong: #34476d;
    --ink: #e8edf6; --ink-2: #aab6cb; --ink-3: #8592ab; --on-ink: #0d1524; --btn-hover: #ffffff;
    --trace: #2cc3b4; --trace-ink: #59d8cb; --trace-soft: rgba(44, 195, 180, 0.14); --ok: #5fb9ab;
    --fade: #f0a93b; --fade-ink: #f6c477; --fade-soft: rgba(240, 169, 59, 0.14);
    --miss: #f06a5d; --miss-ink: #ff9a8f; --miss-soft: rgba(240, 106, 93, 0.13);
    --select: #1f3462; --select-line: #7d9df0; --focus: #8eabff;
    --heat-0: #1c2a45; --heat-1: #1d4d52; --heat-2: #1f7a73; --heat-3: #2ab0a2; --heat-4: #6fe0d2;
    --log-bg: #0a111e; --log-ink: #c6d3ea;
    --shadow-pop: 0 18px 50px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1524; --surface: #142036; --surface-2: #192740; --surface-3: #20304d;
  --line: #253556; --line-strong: #34476d;
  --ink: #e8edf6; --ink-2: #aab6cb; --ink-3: #8592ab; --on-ink: #0d1524; --btn-hover: #ffffff;
  --trace: #2cc3b4; --trace-ink: #59d8cb; --trace-soft: rgba(44, 195, 180, 0.14); --ok: #5fb9ab;
  --fade: #f0a93b; --fade-ink: #f6c477; --fade-soft: rgba(240, 169, 59, 0.14);
  --miss: #f06a5d; --miss-ink: #ff9a8f; --miss-soft: rgba(240, 106, 93, 0.13);
  --select: #1f3462; --select-line: #7d9df0; --focus: #8eabff;
  --heat-0: #1c2a45; --heat-1: #1d4d52; --heat-2: #1f7a73; --heat-3: #2ab0a2; --heat-4: #6fe0d2;
  --log-bg: #0a111e; --log-ink: #c6d3ea;
  --shadow-pop: 0 18px 50px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.8rem, 1.2rem + 2vw, 2.5rem); letter-spacing: -0.025em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; }
a { color: inherit; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.8rem; }
.mono { font-family: var(--mono); font-size: 0.82em; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.icon { display: inline-flex; flex: none; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 24px; }
.mt-sm { margin-top: 12px; }

/* ---------- Shell ---------- */

.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.app.bare { grid-template-columns: 1fr; }
.app.bare .side, .app.bare .tabbar { display: none; }

.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 22px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-family: var(--display); font-weight: 600; font-size: 1.3rem; letter-spacing: -0.02em; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-md);
  color: var(--ink-2); text-decoration: none; font-weight: 700; font-size: 0.97rem;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link[aria-current="page"] { background: var(--surface-3); color: var(--ink); }
.nav-link .badge { margin-left: auto; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.side-profile { padding: 12px; border-radius: var(--r-md); background: var(--surface-2); font-size: 0.85rem; color: var(--ink-2); }

.main { min-width: 0; padding: 36px clamp(18px, 4vw, 48px) 80px; }
.page { max-width: 1040px; margin: 0 auto; }
.page-narrow { max-width: 720px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head p { margin: 8px 0 0; color: var(--ink-2); max-width: 60ch; }

.tabbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 22px 16px 104px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 0.72rem; font-weight: 700; color: var(--ink-3); text-decoration: none; border-radius: 10px; }
  .tabbar a[aria-current="page"] { color: var(--ink); background: var(--surface-3); }
  .page-head { margin-bottom: 20px; }
}

/* ---------- Controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 700; font-size: 0.97rem; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, transform .08s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover:not(:disabled) { background: var(--btn-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-danger { background: var(--miss); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.05); }
.btn-trace { background: var(--trace); color: #fff; }
.btn-trace:hover:not(:disabled) { filter: brightness(1.06); }
.btn-lg { min-height: 54px; padding: 0 26px; font-size: 1.05rem; border-radius: 14px; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.87rem; border-radius: 10px; gap: 6px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 700; font-size: 0.92rem; }
.hint { font-size: 0.85rem; color: var(--ink-3); }
.input, .textarea, .select {
  width: 100%; min-height: 46px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--select-line); box-shadow: 0 0 0 3px var(--select); }

.switch { display: flex; align-items: flex-start; gap: 14px; cursor: pointer; padding: 6px 0; }
.switch input { appearance: none; flex: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--trace); }
.switch input:checked::after { transform: translateX(18px); }
.switch .switch-text { display: flex; flex-direction: column; gap: 2px; }

.seg { display: inline-flex; width: fit-content; max-width: 100%; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface-3); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 700; color: var(--ink-2); cursor: pointer; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(19,33,59,.12); }

input[type="range"] { width: 100%; accent-color: var(--trace); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 99px; background: var(--surface-3); color: var(--ink-2); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.pill-trace { background: var(--trace-soft); color: var(--trace-ink); }
.pill-fade { background: var(--fade-soft); color: var(--fade-ink); }
.pill-miss { background: var(--miss-soft); color: var(--miss-ink); }
.badge { min-width: 24px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--fade); color: #1b1203; font-size: 0.78rem; font-weight: 700; display: inline-grid; place-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; }
.panel-tight { padding: 16px; }
.panel h2 + p, .panel h3 + p { margin-top: 6px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.callout { display: flex; gap: 14px; padding: 16px 18px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.callout.warn { background: var(--fade-soft); border-color: transparent; }
.callout.bad { background: var(--miss-soft); border-color: transparent; }
.callout .icon { margin-top: 2px; }

.empty { text-align: center; padding: 48px 20px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg); }
.empty h3 { margin-bottom: 8px; }
.empty .btn { margin-top: 12px; }

/* ---------- Toasts & dialogs ---------- */

.toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); }
@media (max-width: 860px) { .toasts { bottom: 92px; } }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out; font-size: 0.95rem; }
.toast-error .icon { color: #ff9a8f; }
.toast-success .icon { color: #5ee0d2; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .25s; }
.toast-action { margin-left: auto; border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.modal { border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); width: min(94vw, 560px); max-height: 88vh; box-shadow: var(--shadow-pop); }
.modal-wide { width: min(94vw, 820px); }
.modal::backdrop { background: rgba(9, 15, 28, 0.55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 18px 0 24px; }
.modal-body { padding: 16px 24px 8px; overflow: auto; max-height: calc(88vh - 140px); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px 22px; flex-wrap: wrap; }

/* ---------- Onboarding ---------- */

.onboard { min-height: 100vh; display: grid; place-items: start center; padding: clamp(24px, 6vh, 72px) 18px 48px; }
.onboard-card { width: min(100%, 760px); }
.onboard-steps { display: flex; gap: 8px; margin-bottom: 28px; }
.onboard-steps span { height: 5px; flex: 1; border-radius: 99px; background: var(--line); }
.onboard-steps span.on { background: var(--ink); }
.onboard h1 { margin-bottom: 10px; }
.onboard .lede { font-size: 1.1rem; color: var(--ink-2); max-width: 54ch; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin: 26px 0; }
.choice-grid.wide { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 16px; min-height: 64px; border-radius: var(--r-md); text-align: left;
  border: 1.5px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 700; font-size: 1.05rem;
}
.choice small { font-weight: 400; color: var(--ink-3); font-size: 0.82rem; }
.choice:hover { border-color: var(--ink-3); }
.choice[aria-pressed="true"] { border-color: var(--ink); background: var(--select); box-shadow: inset 0 0 0 1px var(--ink); }
.onboard-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }

.periods { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; margin: 24px 0; }
.period { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--line); text-align: left; background: transparent; border-left: 0; border-right: 0; border-bottom: 0; cursor: pointer; width: 100%; }
.period:first-child { border-top: 0; }
.period:hover { background: var(--surface-2); }
.period-num { font-family: var(--display); font-weight: 600; font-size: 0.95rem; color: var(--ink-3); }
.period-name { font-weight: 700; }
.period-name.unset { color: var(--ink-3); font-weight: 400; }
.period .dept-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }

.picker-search { position: sticky; top: 0; background: var(--surface); padding-bottom: 12px; z-index: 2; display: flex; flex-direction: column; gap: 10px; }
.dept-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.dept-tabs button { flex: none; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-weight: 700; font-size: 0.85rem; cursor: pointer; color: var(--ink-2); }
.dept-tabs button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.course-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.course-opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; font-size: 0.95rem; }
.course-opt:hover { border-color: var(--ink-3); background: var(--surface-2); }
.course-opt[aria-pressed="true"] { border-color: var(--ink); background: var(--select); }
.course-group { margin: 14px 0 8px; font-family: var(--display); font-size: 0.95rem; color: var(--ink-2); }

/* ---------- Today (dashboard) ---------- */

.today-hero { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 960px) { .today-hero { grid-template-columns: 1fr; } }
.hero-memory .big { font-family: var(--display); font-size: clamp(3rem, 2rem + 4vw, 4.6rem); font-weight: 600; line-height: 1; letter-spacing: -0.04em; }
.hero-memory .big small { font-size: 0.4em; color: var(--ink-3); letter-spacing: 0; margin-left: 4px; }
.hero-memory .sentence { font-size: 1.05rem; color: var(--ink-2); margin: 10px 0 4px; max-width: 46ch; }
.hero-cta { display: flex; flex-direction: column; justify-content: space-between; gap: 18px; background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.hero-cta .muted { color: color-mix(in srgb, var(--on-ink) 72%, transparent); }
.hero-cta .count { font-family: var(--display); font-size: 3rem; font-weight: 600; line-height: 1; letter-spacing: -0.03em; }
.hero-cta .btn-primary { background: var(--on-ink); color: var(--ink); }
.hero-cta .btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--on-ink) 88%, var(--trace)); }
.hero-cta .btn-ghost { color: var(--on-ink); }
.hero-cta .btn-ghost:hover { background: rgba(255,255,255,.1); color: var(--on-ink); }
.hero-cta .split { display: flex; gap: 22px; flex-wrap: wrap; }
.hero-cta .split div { display: flex; flex-direction: column; }
.hero-cta .split strong { font-family: var(--display); font-size: 1.4rem; }

.schedule { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.sched-row { display: grid; grid-template-columns: 56px minmax(0, 1.4fr) minmax(120px, 1fr) 90px 28px; align-items: center; gap: 16px; padding: 14px 18px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.sched-row:first-child { border-top: 0; }
a.sched-row:hover { background: var(--surface-2); }
.sched-row.muted-row { color: var(--ink-3); }
.sched-row .p { font-family: var(--display); color: var(--ink-3); font-weight: 600; }
.sched-row .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-row .sub { font-size: 0.85rem; color: var(--ink-3); }
.sched-row .due { text-align: right; font-size: 0.9rem; font-weight: 700; color: var(--fade-ink); }
.sched-row .due.zero { color: var(--ink-3); font-weight: 400; }
@media (max-width: 640px) {
  .sched-row { grid-template-columns: 40px 1fr 70px; row-gap: 6px; }
  .sched-row .strength { grid-column: 2 / 4; grid-row: 2; }
  .sched-row .chev { display: none; }
}

.strength { display: flex; align-items: center; gap: 10px; min-width: 0; }
.strength-track { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.strength-fill { height: 100%; border-radius: 99px; background: var(--ink-3); }
.strength-num { font-size: 0.85rem; font-weight: 700; width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.s-strong .strength-fill { background: var(--trace); }
.s-ok .strength-fill { background: var(--ok); }
.s-fading .strength-fill { background: var(--fade); }
.s-weak .strength-fill { background: var(--miss); }
.s-none .strength-num { color: var(--ink-3); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat strong { font-family: var(--display); font-size: 1.8rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat span { color: var(--ink-2); font-size: 0.9rem; }

/* ---------- Charts ---------- */

.chart { position: relative; margin: 0; width: 100%; }
.chart svg { display: block; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font: 500 11.5px var(--font); }
.chart .value { fill: var(--ink); font: 700 12.5px var(--font); }
.chart .target { stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart .target-label { fill: var(--ink-2); }
.chart .trace-line { fill: none; stroke: var(--trace); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .trace-area { fill: var(--trace-soft); }
.chart .trace-dot { fill: var(--trace); stroke: var(--surface); stroke-width: 2; }
.chart .trace-cross { fill: var(--fade); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .bar { fill: var(--trace); }
.chart .bar-today { fill: var(--fade); }
.chart .heat { stroke: none; }
.chart .heat-0 { fill: var(--heat-0); } .chart .heat-1 { fill: var(--heat-1); } .chart .heat-2 { fill: var(--heat-2); }
.chart .heat-3 { fill: var(--heat-3); } .chart .heat-4 { fill: var(--heat-4); }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; padding: 8px 11px; border-radius: 10px; background: var(--ink); color: var(--on-ink); font-size: 0.85rem; line-height: 1.35; white-space: nowrap; box-shadow: var(--shadow-pop); }
.chart-tip span { opacity: 0.75; }
@media (prefers-reduced-motion: no-preference) {
  .chart-recall.draw-in .trace-line { stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: draw 1.6s cubic-bezier(.3,.6,.2,1) .15s forwards; }
  .chart-recall.draw-in .trace-area { opacity: 0; animation: fade-in .8s ease 1.1s forwards; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { to { opacity: 1; } }

/* ---------- Build ---------- */

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center;
  min-height: 210px; padding: 28px; border-radius: var(--r-lg);
  border: 2px dashed var(--line-strong); background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--trace); background: var(--trace-soft); }
.drop .icon { color: var(--trace-ink); }
.drop strong { font-family: var(--display); font-size: 1.25rem; }
.file-list { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.file-row .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .meta { font-size: 0.82rem; color: var(--ink-3); }
.class-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.class-chip { border: 1.5px solid var(--line-strong); background: var(--surface); border-radius: 12px; padding: 9px 14px; cursor: pointer; font-weight: 700; font-size: 0.93rem; text-align: left; }
.class-chip small { display: block; font-weight: 400; color: var(--ink-3); font-size: 0.78rem; }
.class-chip[aria-pressed="true"] { border-color: var(--ink); background: var(--select); }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .options-grid { grid-template-columns: 1fr; } }
.depth-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.depth-opt { padding: 12px; border-radius: var(--r-md); border: 1.5px solid var(--line-strong); background: var(--surface); text-align: left; cursor: pointer; }
.depth-opt strong { display: block; font-family: var(--display); }
.depth-opt small { color: var(--ink-3); font-size: 0.78rem; display: block; line-height: 1.35; margin-top: 2px; }
.depth-opt[aria-pressed="true"] { border-color: var(--ink); background: var(--select); }

.run { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .run { grid-template-columns: 1fr; } }
.stages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.stage { display: grid; grid-template-columns: 30px 1fr; gap: 12px; padding: 12px 0; position: relative; }
.stage::before { content: ""; position: absolute; left: 14px; top: 42px; bottom: -4px; width: 2px; background: var(--line); }
.stage:last-child::before { display: none; }
.stage-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 0.85rem; font-weight: 600; background: var(--surface-3); color: var(--ink-3); position: relative; z-index: 1; }
.stage.active .stage-dot { background: var(--ink); color: var(--on-ink); }
.stage.active .stage-dot::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--trace); border-top-color: transparent; animation: spin 1s linear infinite; }
.stage.done .stage-dot { background: var(--trace); color: #fff; }
.stage.skipped .stage-dot { background: var(--surface-3); color: var(--ink-3); }
.stage.error .stage-dot { background: var(--miss); color: #fff; }
.stage-label { font-weight: 700; }
.stage.pending .stage-label { color: var(--ink-3); font-weight: 400; }
.stage-detail { font-size: 0.85rem; color: var(--ink-3); }
.stage-bar { height: 4px; border-radius: 99px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.stage-bar div { height: 100%; background: var(--trace); transition: width .3s; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .stage.active .stage-dot::after { animation: none; } }

.log { background: var(--log-bg); color: var(--log-ink); border-radius: var(--r-lg); padding: 16px 18px; height: min(62vh, 560px); overflow-y: auto; font: 500 12.5px/1.6 var(--mono); }
.log-line { margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; }
.log-line .tag { display: inline-block; min-width: 74px; color: #7f8db0; }
.log-line.thinking { color: #9fb0d0; }
.log-line.search { color: #8de5da; }
.log-line.source { color: #8a98b6; }
.log-line.warn { color: #f6c477; }
.log-line.note { color: #e6ecf7; }
.log-line.done { color: #8de5da; }
.log-head { display: flex; align-items: center; justify-content: space-between; color: #8a98b6; font-family: var(--font); font-size: 0.85rem; margin-bottom: 10px; position: sticky; top: -16px; background: var(--log-bg); padding: 4px 0; }

/* ---------- Study ---------- */

.study { max-width: 760px; margin: 0 auto; }
.study-top { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.study-progress { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.study-progress div { height: 100%; background: var(--trace); border-radius: 99px; transition: width .3s ease; }
.study-meta { font-size: 0.9rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: clamp(20px, 4vw, 34px); }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.stem { font-size: clamp(1.18rem, 1rem + 0.7vw, 1.42rem); line-height: 1.5; font-weight: 400; margin: 0 0 22px; }
.stem .blank { display: inline-block; min-width: 90px; border-bottom: 2.5px solid var(--ink); margin: 0 4px; }
.recall-box { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: var(--r-md); background: var(--surface-2); margin-bottom: 18px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line-strong);
  background: var(--surface); text-align: left; cursor: pointer; font-size: 1.04rem; line-height: 1.4; min-height: 58px;
}
.opt:hover:not(:disabled) { border-color: var(--ink-3); }
.opt .key { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); font-family: var(--display); font-weight: 600; font-size: 0.9rem; }
.opt.selected { border-color: var(--select-line); background: var(--select); }
.opt.selected .key { background: var(--select-line); color: #fff; }
.opt.right { border-color: var(--trace); background: var(--trace-soft); }
.opt.right .key { background: var(--trace); color: #fff; }
.opt.wrong { border-color: var(--miss); background: var(--miss-soft); }
.opt.wrong .key { background: var(--miss); color: #fff; }
.opt:disabled { cursor: default; }
.opt .why { grid-column: 2 / 4; font-size: 0.92rem; color: var(--ink-2); margin-top: 2px; }
.conf { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.conf-q { font-weight: 700; margin-bottom: 10px; }
.conf-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.conf-btns button { min-height: 56px; border-radius: 12px; border: 1.5px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.conf-btns button small { font-weight: 400; color: var(--ink-3); font-size: 0.75rem; }
.conf-btns button:hover { border-color: var(--ink); }
.answer-input { font-size: 1.1rem; }
.verdict { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; margin: 18px 0 14px; font-weight: 700; }
.verdict.good { background: var(--trace-soft); color: var(--trace-ink); }
.verdict.part { background: var(--fade-soft); color: var(--fade-ink); }
.verdict.bad { background: var(--miss-soft); color: var(--miss-ink); }
.verdict .sub { display: block; font-weight: 400; color: var(--ink-2); font-size: 0.92rem; }
.feedback { display: flex; flex-direction: column; gap: 14px; }
.fb-block { padding: 14px 16px; border-radius: 14px; background: var(--surface-2); }
.fb-block h4 { font-family: var(--font); font-weight: 700; font-size: 0.86rem; color: var(--ink-2); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.fb-block p:last-child { margin-bottom: 0; }
.fb-quote { border-left: 3px solid var(--line-strong); padding-left: 12px; color: var(--ink-2); font-style: italic; }
.fb-next { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: space-between; margin-top: 6px; }
.study-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line-strong); font-size: 0.75rem; color: var(--ink-3); font-family: var(--display); }
.tutor { padding: 16px 18px; border-radius: 14px; border: 1px solid var(--line); }
.tutor p { margin-bottom: 0.6em; }
.tutor ul, .tutor ol { margin: 0.4em 0 0.6em; padding-left: 1.3em; }
.hc-flag { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--fade-soft); color: var(--ink); font-size: 0.95rem; }
.timer { font-family: var(--display); font-weight: 600; font-variant-numeric: tabular-nums; }

.summary-hero { text-align: center; padding: 18px 0 8px; }
.summary-hero .big { font-family: var(--display); font-size: 4rem; font-weight: 600; letter-spacing: -0.04em; line-height: 1; }
.review-list { display: flex; flex-direction: column; gap: 8px; }
.review-item { display: grid; grid-template-columns: 24px 1fr auto; gap: 12px; align-items: start; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: 0.95rem; }
.review-item .ok { color: var(--trace-ink); }
.review-item .no { color: var(--miss-ink); }

/* ---------- Library ---------- */

.deck-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.deck-row { display: grid; grid-template-columns: 1fr minmax(120px, 200px) 80px 24px; gap: 16px; align-items: center; padding: 16px 18px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.deck-row:first-child { border-top: 0; }
.deck-row:hover { background: var(--surface-2); }
.deck-row .title { font-weight: 700; }
.deck-row .sub { font-size: 0.85rem; color: var(--ink-3); }
@media (max-width: 640px) { .deck-row { grid-template-columns: 1fr 64px; } .deck-row .strength { grid-column: 1 / -1; } .deck-row .chev { display: none; } }
.class-group { margin-bottom: 28px; }
.class-group > h2 { margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; }
.class-group > h2 small { font-family: var(--font); font-weight: 400; font-size: 0.9rem; color: var(--ink-3); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 22px 0 18px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 700; color: var(--ink-3); cursor: pointer; border-bottom: 2.5px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.topic { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); margin-bottom: 12px; overflow: hidden; }
.topic > summary { list-style: none; cursor: pointer; padding: 16px 18px; display: grid; grid-template-columns: 1fr minmax(120px, 200px) 20px; gap: 16px; align-items: center; }
.topic > summary::-webkit-details-marker { display: none; }
.topic[open] > summary .icon { transform: rotate(90deg); }
.topic > summary .icon { transition: transform .15s; }
.concept { display: grid; grid-template-columns: 1fr minmax(100px, 180px); gap: 16px; padding: 14px 18px; border-top: 1px solid var(--line); align-items: start; }
.concept .facts { margin: 6px 0 0; padding-left: 1.1em; color: var(--ink-2); font-size: 0.92rem; }
.concept .misc { font-size: 0.86rem; color: var(--fade-ink); margin-top: 6px; }
@media (max-width: 640px) { .topic > summary, .concept { grid-template-columns: 1fr; } }
.item-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: center; cursor: pointer; }
.item-row:hover { background: var(--surface-2); }
.item-row .stem-line { font-size: 0.95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-row .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.prose { max-width: 70ch; }
.prose p, .prose li { color: var(--ink); }
.prose h4 { margin: 1.2em 0 0.4em; font-size: 1rem; }
.source-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.source-list a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); text-decoration: none; }
.source-list a:hover { background: var(--surface-3); }
.source-list .host { font-size: 0.8rem; color: var(--ink-3); }

/* ---------- Settings & science ---------- */

.settings-section { padding: 24px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section > div:first-child p { color: var(--ink-3); font-size: 0.9rem; margin-top: 6px; }
@media (max-width: 760px) { .settings-section { grid-template-columns: 1fr; gap: 12px; } }
.science-item { padding: 22px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
.science-item:first-of-type { border-top: 0; }
.science-item h3 { font-size: 1.15rem; }
.science-item .how { margin-top: 8px; padding: 12px 14px; border-radius: 12px; background: var(--trace-soft); color: var(--ink); font-size: 0.95rem; }
.science-item .cite { font-size: 0.82rem; color: var(--ink-3); margin-top: 8px; }
@media (max-width: 760px) { .science-item { grid-template-columns: 1fr; gap: 8px; } }

.loading { display: grid; place-items: center; min-height: 50vh; color: var(--ink-3); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
