/* MathStudio — application shell, solver, notes, settings.
   Colour is defined once as tokens and redefined for dark mode, so every
   component follows the theme without knowing anything about it. */

:root {
  /* Surfaces */
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f7f8fa;
  --surface-3:   #eef0f4;

  /* The sidebar keeps its own dark palette in both themes: it anchors the
     layout and stops the page reading as one undifferentiated sheet. */
  --sidebar-bg:        #14181f;
  --sidebar-fg:        #9aa4b2;
  --sidebar-fg-strong: #f3f5f8;
  --sidebar-hover:     #1e242e;
  --sidebar-active:    #243043;

  --border:      #dfe3e9;
  --border-soft: #ecedf1;

  --text:        #10151c;
  --text-muted:  #59616e;
  --text-faint:  #8b93a1;

  --accent:      #3563e9;
  --accent-hover:#2b53cc;
  --accent-soft: #eaf0fe;
  --accent-text: #ffffff;

  --ok:   #0b7a4b;  --ok-soft:   #e4f6ec;
  --warn: #9a6400;  --warn-soft: #fdf2d9;
  --bad:  #b32318;  --bad-soft:  #fdebe9;
  --info: #5344b8;  --info-soft: #eeecfb;

  --radius:    10px;
  --radius-sm: 7px;
  --radius-xs: 5px;

  --shadow-sm: 0 1px 2px rgba(16,21,28,.05);
  --shadow:    0 1px 3px rgba(16,21,28,.06), 0 6px 16px -6px rgba(16,21,28,.10);
  --shadow-lg: 0 12px 44px -8px rgba(16,21,28,.26);

  --sidebar-w: 236px;
  --topbar-h:  62px;

  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas, ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg:          #0f1319;
    --surface:     #161b23;
    --surface-2:   #1c222b;
    --surface-3:   #252c37;
    --sidebar-bg:  #0b0e13;
    --sidebar-fg:  #8b95a5;
    --sidebar-fg-strong: #eef1f6;
    --sidebar-hover:  #161c25;
    --sidebar-active: #1d2938;
    --border:      #2a323d;
    --border-soft: #202731;
    --text:        #e9edf3;
    --text-muted:  #a3adbb;
    --text-faint:  #78828f;
    --accent:      #5b87f5;
    --accent-hover:#6f96f7;
    --accent-soft: #17243c;
    --ok:   #45c489;  --ok-soft:   #112b1f;
    --warn: #dcae4b;  --warn-soft: #2e2510;
    --bad:  #ef8a82;  --bad-soft:  #331917;
    --info: #a494f2;  --info-soft: #211d38;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow:    0 1px 3px rgba(0,0,0,.45), 0 6px 18px -6px rgba(0,0,0,.5);
    --shadow-lg: 0 14px 48px -8px rgba(0,0,0,.66);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #0f1319;
  --surface:     #161b23;
  --surface-2:   #1c222b;
  --surface-3:   #252c37;
  --sidebar-bg:  #0b0e13;
  --sidebar-fg:  #8b95a5;
  --sidebar-fg-strong: #eef1f6;
  --sidebar-hover:  #161c25;
  --sidebar-active: #1d2938;
  --border:      #2a323d;
  --border-soft: #202731;
  --text:        #e9edf3;
  --text-muted:  #a3adbb;
  --text-faint:  #78828f;
  --accent:      #5b87f5;
  --accent-hover:#6f96f7;
  --accent-soft: #17243c;
  --ok:   #45c489;  --ok-soft:   #112b1f;
  --warn: #dcae4b;  --warn-soft: #2e2510;
  --bad:  #ef8a82;  --bad-soft:  #331917;
  --info: #a494f2;  --info-soft: #211d38;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 1px 3px rgba(0,0,0,.45), 0 6px 18px -6px rgba(0,0,0,.5);
  --shadow-lg: 0 14px 48px -8px rgba(0,0,0,.66);
}

:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* The `hidden` attribute is a UA rule of the lowest specificity, so any
   component that sets `display` beats it and hidden panels stay visible.
   This is the fix for the symbol palette, the find bar and the sheet list. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

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

/* ══════════════════════════════ SHELL ══════════════════════════════ */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100%;
  transition: grid-template-columns .18s cubic-bezier(.4,0,.2,1);
}
.shell.is-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

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

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 14px 0 18px;
  flex-shrink: 0;
}
.brand-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #7aa2ff);
  color: #fff; border-radius: 8px;
  font-size: 17px; font-weight: 600; line-height: 1;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.brand-name {
  color: var(--sidebar-fg-strong);
  font-weight: 620; font-size: 14.5px;
  letter-spacing: -.01em; white-space: nowrap;
}
.brand-sub {
  font-size: 10.5px; color: var(--sidebar-fg);
  opacity: .72; white-space: nowrap;
}

.sidebar-collapse {
  background: none; border: 0; padding: 5px;
  color: var(--sidebar-fg); cursor: pointer;
  border-radius: var(--radius-xs);
  display: grid; place-items: center;
}
.sidebar-collapse:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }

.sidebar-nav {
  flex: 1; overflow-y: auto;
  padding: 6px 10px 14px;
  display: flex; flex-direction: column; gap: 1px;
}

.nav-group-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--sidebar-fg); opacity: .55;
  padding: 14px 8px 6px; white-space: nowrap;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 8px 10px;
  border: 0; background: none;
  color: var(--sidebar-fg);
  font: inherit; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; position: relative;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }
.nav-item.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-fg-strong);
  font-weight: 560;
}
.nav-item.is-active::before {
  content: "";
  position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-icon { width: 19px; height: 19px; flex-shrink: 0; opacity: .92; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-key {
  font-family: var(--mono); font-size: 10px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(255,255,255,.07);
  color: var(--sidebar-fg);
  opacity: 0; transition: opacity .12s;
}
.nav-item:hover .nav-key, .nav-item.is-active .nav-key { opacity: .8; }

.nav-divider { height: 1px; background: rgba(255,255,255,.07); margin: 12px 8px 0; }

.sidebar-foot {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.ai-chip {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.03);
  color: var(--sidebar-fg);
  border-radius: var(--radius-sm);
  font: inherit; font-size: 12px;
  cursor: pointer; min-width: 0;
  transition: background .12s;
}
.ai-chip:hover { background: rgba(255,255,255,.07); color: var(--sidebar-fg-strong); }
.ai-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint); flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(255,255,255,.05);
}
.ai-chip.on  .ai-dot { background: #37d39b; box-shadow: 0 0 0 3px rgba(55,211,155,.16); }
.ai-chip.off .ai-dot { background: #e0a33c; box-shadow: 0 0 0 3px rgba(224,163,60,.16); }
.ai-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.theme-button {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.03);
  color: var(--sidebar-fg);
  border-radius: var(--radius-sm);
  cursor: pointer; flex-shrink: 0;
}
.theme-button:hover { background: rgba(255,255,255,.07); color: var(--sidebar-fg-strong); }

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

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 {
  margin: 0; font-size: 16px; font-weight: 620;
  letter-spacing: -.012em; white-space: nowrap;
}
.topbar-title p {
  margin: 1px 0 0; font-size: 12.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 7px; align-items: center; }

.sidebar-open {
  display: none; width: 34px; height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  border-radius: var(--radius-sm); cursor: pointer;
}
.shell.is-collapsed .sidebar-open { display: grid; }

#workspace { flex: 1; position: relative; overflow: hidden; }
.view { display: none; height: 100%; overflow: hidden; }
.view.is-active { display: block; }

.centred-scroll {
  height: 100%; overflow-y: auto;
  padding: 22px; max-width: 1000px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}
/* Flex children shrink by default, so in a scrolling column every panel gets
   squashed to fit the viewport and its content is clipped rather than
   scrolled. Panels must keep their natural height and let the column scroll. */
.centred-scroll > * { flex: 0 0 auto; }
.centred-scroll.narrow { max-width: 760px; }

/* ══════════════════════════ PRIMITIVES ══════════════════════════ */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 15px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.panel-head h2 {
  margin: 0; font-size: 12px; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-muted); flex: 1;
}
.panel-head-actions { display: flex; gap: 6px; }
.panel-body { padding: 15px; }
.panel-intro { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); font-weight: 560;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet { background: transparent; color: var(--text-muted); }
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 9px; font-size: 11.5px; }
.btn-icon { padding: 8px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-glyph { font-size: 13px; opacity: .75; }
.btn-solve { min-width: 96px; padding-inline: 20px; }

.input, .select {
  font: inherit; font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  max-width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .problem-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.wide { flex: 1; min-width: 0; }
.input.mono { font-family: var(--mono); font-size: 12.5px; }
.select { padding-right: 26px; cursor: pointer; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 32px; height: 18px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border);
  position: relative; flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform .15s cubic-bezier(.4,0,.2,1);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-label { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.switch.small .switch-track { width: 28px; height: 16px; }
.switch.small .switch-thumb { width: 10px; height: 10px; }
.switch.small input:checked + .switch-track .switch-thumb { transform: translateX(12px); }

.field-label {
  font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint); font-weight: 650;
}
.option-spacer { flex: 1; }
.muted { color: var(--text-muted); }
.link { color: var(--accent); text-decoration: none; font-size: 12.5px; }
.link:hover { text-decoration: underline; }

.status-badge {
  font-size: 11px; font-weight: 620;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted);
}
.status-badge.on  { background: var(--ok-soft);   color: var(--ok); }
.status-badge.off { background: var(--warn-soft); color: var(--warn); }

/* ══════════════════════════ SOLVER ══════════════════════════ */

.solver-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; height: 100%; }
.solver-main { overflow-y: auto; padding: 22px; }
.solver-side {
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--bg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}

.problem-card { max-width: 900px; margin: 0 auto 18px; padding: 16px; }
.problem-input-row { display: flex; gap: 10px; align-items: stretch; }
.problem-input {
  flex: 1;
  font-family: var(--mono); font-size: 14.5px; line-height: 1.6;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  resize: vertical; min-height: 52px;
}
.problem-input::placeholder { color: var(--text-faint); }

.math-preview {
  margin-top: 11px; padding: 9px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 15px; color: var(--text-muted); overflow-x: auto;
}
.math-preview:empty { display: none; }

.problem-options, .problem-tools {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 13px; padding-top: 13px;
  border-top: 1px solid var(--border-soft);
}
.problem-tools { margin-top: 10px; padding-top: 10px; }

.symbol-palette {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 11px; padding-top: 11px;
  border-top: 1px solid var(--border-soft);
}
.symbol-palette button {
  min-width: 36px; padding: 6px 9px; font-size: 14.5px;
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  border-radius: var(--radius-xs); cursor: pointer;
}
.symbol-palette button:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.solution-area { max-width: 900px; margin: 0 auto; }

.empty-state { text-align: center; padding: 44px 20px; }
.empty-mark {
  width: 52px; height: 52px; margin: 0 auto 18px;
  display: grid; place-items: center;
  font-size: 26px; color: var(--accent);
  background: var(--accent-soft); border-radius: 14px;
}
.empty-title { font-size: 17px; font-weight: 620; margin: 0 0 8px; letter-spacing: -.01em; }
.empty-body { max-width: 540px; margin: 0 auto 26px; color: var(--text-muted); font-size: 13.5px; }
.example-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 620px; margin: 0 auto; }
.example {
  font: inherit; font-size: 13px; padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  border-radius: 999px; cursor: pointer; transition: all .12s;
}
.example:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.solution {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden; margin-bottom: 16px;
}
.solution-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  background: var(--surface-2);
}
.solution-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  font-size: 11px; font-weight: 560;
  padding: 3px 8px; border-radius: 5px;
  background: var(--surface-3); color: var(--text-muted);
}
.tag.domain { background: var(--info-soft); color: var(--info); }
.tag.timing { background: transparent; color: var(--text-faint); }
.confidence {
  font-size: 10.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .05em;
}
.confidence.high   { background: var(--ok-soft);   color: var(--ok); }
.confidence.medium { background: var(--warn-soft); color: var(--warn); }
.confidence.low    { background: var(--bad-soft);  color: var(--bad); }
.confidence.unsolved { background: var(--surface-3); color: var(--text-muted); }
.solution-actions { margin-left: auto; display: flex; gap: 6px; }

.answer-block {
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--accent-soft), transparent);
  border-bottom: 1px solid var(--border-soft);
  text-align: center; overflow-x: auto;
}
.answer-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted); font-weight: 700; margin-bottom: 9px;
}
.answer-math { font-size: 21px; }
.answer-decimal { margin-top: 9px; font-size: 12.5px; color: var(--text-muted); font-family: var(--mono); }

.note-line {
  padding: 9px 16px; font-size: 12.5px;
  background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid var(--border-soft);
}

.steps { padding: 4px 0; }
.step { padding: 13px 16px; border-bottom: 1px solid var(--border-soft); }
.step:last-child { border-bottom: 0; }
.step.nested {
  margin: 0 0 0 16px;
  border-left: 2px solid var(--border);
  background: var(--surface-2);
  border-bottom: 0; padding: 11px 14px;
}
.step-head { display: flex; gap: 9px; align-items: baseline; flex-wrap: wrap; }
.step-number { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); min-width: 22px; font-weight: 600; }
.step-title { font-weight: 570; flex: 1; min-width: 200px; font-size: 13.5px; }

.badge {
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 4px;
  white-space: nowrap; cursor: help;
}
.badge.exact          { background: var(--ok-soft);   color: var(--ok); }
.badge.numeric        { background: var(--info-soft); color: var(--info); }
.badge.not_applicable { background: var(--surface-3); color: var(--text-faint); }
.badge.unchecked      { background: var(--warn-soft); color: var(--warn); }
.badge.failed         { background: var(--bad-soft);  color: var(--bad); }

.step-detail { margin: 7px 0 0; color: var(--text-muted); font-size: 13px; }
.step-detail p { margin: 0 0 6px; }
.step-math {
  margin-top: 9px; padding: 10px 13px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  overflow-x: auto; font-size: 14.5px;
}
.step-arrow { color: var(--text-faint); margin: 0 11px; }
.step-subs { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px; }
.sub-chip { background: var(--surface-3); padding: 2px 8px; border-radius: var(--radius-xs); font-size: 12px; }
.citation {
  margin-top: 8px; font-size: 12px;
  color: var(--info); background: var(--info-soft);
  padding: 6px 10px; border-radius: var(--radius-xs);
}
.narrative { padding: 16px; font-size: 14px; line-height: 1.68; }
.narrative code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.solution-footer {
  padding: 10px 16px; border-top: 1px solid var(--border-soft);
  font-size: 12px; color: var(--text-faint);
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}

.error-card {
  background: var(--bad-soft);
  border: 1px solid color-mix(in srgb, var(--bad) 34%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
}
.error-card h3 { margin: 0 0 5px; font-size: 14px; color: var(--bad); font-weight: 620; }
.error-card p { margin: 0; color: var(--text-muted); font-size: 13px; }

.note-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  padding: 13px 16px; margin-bottom: 16px;
  font-size: 13px; color: var(--text-muted);
}
.note-card strong { color: var(--text); display: block; margin-bottom: 3px; }

.failure-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12.5px; max-height: 250px; overflow-y: auto; }
.failure-list li { padding: 4px 0; border-top: 1px solid color-mix(in srgb, var(--bad) 18%, transparent); }
.failure-list code { font-family: var(--mono); font-size: 12px; color: var(--text); }
.failure-reason { color: var(--text-muted); }

.physics-form, .plot-form { display: flex; flex-direction: column; gap: 9px; }
.given-list { display: flex; flex-direction: column; gap: 6px; }
.given-row { display: grid; grid-template-columns: 1fr 1.25fr auto; gap: 5px; }
.given-row .input { min-width: 0; }
.given-row button { border: 0; background: none; color: var(--text-faint); cursor: pointer; font-size: 15px; padding: 0 4px; }
.given-row button:hover { color: var(--bad); }
.range-row { display: flex; align-items: center; gap: 7px; }
.range-row .input { width: 100%; min-width: 0; }
.range-sep { color: var(--text-faint); font-size: 12px; }
.plot-output { padding: 0 15px 15px; overflow-x: auto; }
.plot-output svg { display: block; margin: 0 auto; }

.formula-browser { font-size: 12.5px; margin-top: 4px; }
.formula-browser summary { cursor: pointer; color: var(--text-muted); padding: 5px 0; }
.formula-item { padding: 8px 0; border-top: 1px solid var(--border-soft); cursor: pointer; }
.formula-item:hover .formula-name { color: var(--accent); }
.formula-name { font-weight: 570; font-size: 12.5px; }
.formula-math { font-size: 13px; margin-top: 3px; overflow-x: auto; }
.formula-conditions { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.history-list, .notebook-list, .document-list, .outline-list,
.comment-list, .page-thumbs, .notes-list { list-style: none; margin: 0; padding: 0; }
.history-list li { padding: 9px 15px; border-bottom: 1px solid var(--border-soft); cursor: pointer; }
.history-list li:hover { background: var(--surface-2); }
.history-problem { font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }

/* ══════════════════════ PROBLEM SHEETS ══════════════════════ */

.sheet-panel { max-width: 900px; margin: 0 auto 18px; }
.sheet-warnings { padding: 0 15px; }
.sheet-warning {
  margin: 12px 0 0; padding: 9px 12px;
  background: var(--warn-soft); color: var(--warn);
  border-radius: var(--radius-sm); font-size: 12.5px;
}
.sheet-warning.error { background: var(--bad-soft); color: var(--bad); }
.sheet-list { margin: 10px 0 0; }
.sheet-stem { padding: 11px 15px 4px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.sheet-item {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 10px 15px; border-top: 1px solid var(--border-soft);
}
.sheet-item.is-prose { opacity: .58; }
.sheet-label { font-family: var(--mono); font-size: 11.5px; font-weight: 700; color: var(--text-faint); min-width: 42px; padding-top: 4px; }
.sheet-body { flex: 1; min-width: 0; }
.sheet-text {
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  padding: 4px 8px; border: 1px solid transparent;
  border-radius: var(--radius-xs); outline: none;
  white-space: pre-wrap; word-break: break-word;
}
.sheet-text:hover { border-color: var(--border); }
.sheet-text:focus { border-color: var(--accent); background: var(--surface-2); }
.sheet-reason { font-size: 11px; color: var(--text-faint); padding: 3px 8px 0; }
.sheet-actions { display: flex; align-items: center; gap: 7px; padding-top: 2px; }
.sheet-page { font-size: 10.5px; color: var(--text-faint); }

/* ══════════════════════════ NOTES ══════════════════════════ */

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px; text-align: center;
  color: var(--text-muted);
  display: flex; flex-direction: column; gap: 5px;
  transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--text); font-size: 14px; }
.dropzone span { font-size: 12.5px; }
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }

.notes-search { display: flex; gap: 8px; }
.notes-body { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
.notes-list li {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 9px; background: var(--surface);
}
.note-title { font-weight: 570; font-size: 13.5px; }
.note-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.note-actions { margin-top: 8px; display: flex; gap: 6px; }
.notes-results .hit {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 10px;
}
.hit-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.hit-title { font-weight: 570; font-size: 13px; }
.hit-score { margin-left: auto; font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.hit-text {
  font-size: 12.5px; color: var(--text-muted);
  white-space: pre-wrap; max-height: 180px; overflow-y: auto;
  margin: 0; font-family: var(--font);
}

/* ══════════════════════════ SETTINGS ══════════════════════════ */

.key-row { display: flex; gap: 8px; align-items: stretch; }
.key-actions { display: flex; gap: 8px; align-items: center; margin-top: 11px; flex-wrap: wrap; }
.key-note {
  margin-top: 13px; padding: 10px 13px;
  border-radius: var(--radius-sm); font-size: 12.5px;
  background: var(--surface-2); color: var(--text-muted);
  border-left: 3px solid var(--border);
}
.key-note.ok  { background: var(--ok-soft);  color: var(--ok);  border-left-color: var(--ok); }
.key-note.bad { background: var(--bad-soft); color: var(--bad); border-left-color: var(--bad); }

.callout {
  margin-top: 16px; padding: 13px 15px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 12.5px; color: var(--text-muted);
}
.callout strong { display: block; color: var(--text); margin-bottom: 4px; }
.callout code {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--surface-3); padding: 1px 5px;
  border-radius: 4px; word-break: break-all;
}

.facts { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 9px 18px; font-size: 13px; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; color: var(--text); }
.facts dd code { font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
.facts .yes { color: var(--ok); font-weight: 560; }
.facts .no  { color: var(--warn); font-weight: 560; }

.badge-key, .shortcut-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.badge-key li, .shortcut-list li { padding: 5px 0; display: flex; gap: 10px; align-items: baseline; }
kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}

/* ══════════════════════════ FEEDBACK ══════════════════════════ */

.toast-stack {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 300; pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  box-shadow: var(--shadow-lg);
  font-size: 13px; max-width: 380px;
  pointer-events: auto;
  animation: toast-in .2s cubic-bezier(.2,.8,.3,1);
}
.toast.error { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--ok); }
.toast strong { display: block; margin-bottom: 2px; font-weight: 570; }
.toast .detail { color: var(--text-muted); font-size: 12px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0; max-width: 560px; width: calc(100% - 40px);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(8,11,16,.55); }
.modal-body { padding: 22px 24px; }
.modal-body h2 { margin: 0 0 14px; font-size: 18px; font-weight: 620; }
.modal-body h3 {
  margin: 18px 0 8px; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}

.scrim { position: fixed; inset: 0; background: rgba(8,11,16,.45); z-index: 90; }

.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg) } }
.thinking { padding: 30px; text-align: center; color: var(--text-muted); }

/* ══════════════════════════ RESPONSIVE ══════════════════════════ */

@media (max-width: 1180px) {
  .solver-layout { grid-template-columns: 1fr; }
  .solver-side { border-left: 0; border-top: 1px solid var(--border); }
  .notes-body { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  /* One column, not "0 + rest". Making the sidebar `position: fixed` takes it
     out of the grid flow, so `.main` becomes the first in-flow item and is
     auto-placed into column 1 -- which at zero width collapsed the entire
     application to a blank page. */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w); z-index: 100;
    transform: translateX(-100%);
    transition: transform .2s cubic-bezier(.4,0,.2,1);
  }
  .shell.is-open .sidebar { transform: none; }
  .sidebar-open { display: grid; }
  .topbar { padding: 0 16px; }
  .topbar-title p { display: none; }
  .solver-main, .centred-scroll { padding: 14px; }
}

/* ── Account form (Settings → Your login) ───────────────────────────────── */
/* `.input.wide` is `flex: 1`, which does nothing outside a flex container,
   so the form is one. Fields stack full width with their labels above. */
#account-form {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#account-form .field-label { margin-top: 10px; }
#account-form .field-label:first-child { margin-top: 0; }
#account-form .input { width: 100%; }
#account-form .key-actions { margin-top: 14px; }

/* ── Learn: guided practice ─────────────────────────────────────────────── */

.learn-progress { display: flex; align-items: center; gap: 12px; }
.learn-progress-track {
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--border-soft); overflow: hidden;
}
.learn-progress-bar {
  height: 100%; width: 0;
  background: var(--accent);
  transition: width .35s ease;
}
.learn-progress-text {
  font-size: 12px; color: var(--text-muted); white-space: nowrap;
}

.learn-question {
  margin: 0 0 12px; font-size: 15px; font-weight: 600;
  color: var(--text);
}
.learn-from {
  padding: 12px 14px; margin-bottom: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
#learn-answer { margin-bottom: 12px; }
.learn-attempts { font-size: 12px; }

/* Feedback on an attempt. Green and red do the work, but the text carries
   the meaning: colour alone is unreadable to a good number of students. */
.learn-feedback {
  margin-top: 14px; padding: 12px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  font-size: 13.5px;
}
.learn-feedback.good { background: var(--ok-soft); border-left-color: var(--ok); }
.learn-feedback.bad  { background: var(--bad-soft); border-left-color: var(--bad); }
.learn-feedback-message { font-weight: 600; }
.learn-feedback.good .learn-feedback-message { color: var(--ok); }
.learn-feedback.bad  .learn-feedback-message { color: var(--bad); }
.learn-read {
  margin-top: 8px; font-size: 12.5px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.learn-diagnosis {
  margin-top: 8px; font-size: 13px; color: var(--text);
  line-height: 1.6;
}

/* The hint ladder. Each rung looks slightly heavier than the last, so it is
   visible that you are working down towards the answer. */
.learn-hints { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.learn-hint {
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.learn-hint.kind-notes    { border-left-color: var(--ok); }
.learn-hint.kind-answer   { border-left-color: var(--bad); }
.learn-hint-kind {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 650; color: var(--text-faint); margin-bottom: 5px;
}
.learn-hint-text { font-size: 13.5px; line-height: 1.6; }
.learn-math { margin: 10px 0 2px; overflow-x: auto; }

/* A passage from the student's own notes. */
.learn-citations { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.learn-citation {
  padding: 9px 11px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-soft);
}
.learn-citation-title {
  font-size: 12px; font-weight: 640; color: var(--text);
}
.learn-citation-text {
  margin-top: 3px; font-size: 12px; color: var(--text-muted); line-height: 1.55;
}

/* Working so far. */
.learn-history { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.learn-done {
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
}
.learn-done.correct  { border-left-color: var(--ok); }
.learn-done.revealed { border-left-color: var(--warn); }
.learn-done-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.learn-done-title { font-size: 13.5px; font-weight: 620; }
.learn-tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 650; color: var(--text-faint); white-space: nowrap;
}
.learn-tag.correct { color: var(--ok); }
.learn-detail { margin-top: 6px; font-size: 13px; color: var(--text-muted); line-height: 1.6; }

/* The end. Three counts, never one score. */
.learn-answer-final { margin: 6px 0 18px; }
.learn-answer-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 650; color: var(--text-faint);
}
.learn-tally { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.learn-tally-cell {
  flex: 1 1 110px; padding: 13px;
  border-radius: var(--radius-sm); text-align: center;
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.learn-tally-cell.good { background: var(--ok-soft); }
.learn-tally-cell.bad  { background: var(--bad-soft); }
.learn-tally-number { font-size: 22px; font-weight: 680; line-height: 1.1; }
.learn-tally-label { margin-top: 3px; font-size: 11.5px; color: var(--text-muted); }
.learn-review { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.learn-review-item {
  padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.learn-review-title { font-size: 13px; font-weight: 620; }

#learn-problem { min-height: 70px; resize: vertical; margin-bottom: 12px; }
