:root {
  /* Infographic colours: a strong shade for text and marks, and a soft one for backgrounds. */
  --ig-0: #2563a8; --ig-0-soft: #dfe8f1;
  --ig-1: #0f7a6c; --ig-1-soft: #d8ebe6;
  --ig-2: #a8541a; --ig-2-soft: #f1e2d3;
  --ig-3: #75479e; --ig-3-soft: #e7deef;
  /* Soft, slightly warm greys rather than bright white, so long reading sessions are easier on the eyes. */
  --bg: #e4e2dd;
  --surface: #efede8;
  --text: #22272f;
  --muted: #5f6672;
  --border: #d3d0c8;
  --accent: #2f343c;
  --accent-hover: #1f2329;
  --accent-soft: #dcd9d2;
  --on-accent: #ffffff;
  --user-bubble: #2f343c;
  --user-text: #ffffff;
  --ok: #157f3b;
  --ok-soft: #e7f6ec;
  --warn: #9a6100;
  --warn-soft: #fff4dc;
  --danger: #c4320a;
  --danger-soft: #fdecea;
  --code-bg: #e2dfd8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ig-0: #7fb4ee; --ig-0-soft: #1f2d3f;
    --ig-1: #5fcdb9; --ig-1-soft: #17312d;
    --ig-2: #eda76e; --ig-2-soft: #3a2a1c;
    --ig-3: #c3a0e8; --ig-3-soft: #2e2439;
    --bg: #15171c;
    --surface: #1e2128;
    --text: #e3e6ec;
    --muted: #98a1b3;
    --border: #323743;
    --accent: #e3e6ec;
    --accent-hover: #ffffff;
    --accent-soft: #2c3039;
    --on-accent: #15171c;
    --user-bubble: #3a3f4a;
    --user-text: #ffffff;
    --ok: #5fd08a;
    --ok-soft: #173224;
    --warn: #f0b94d;
    --warn-soft: #3a2e14;
    --danger: #ff8a73;
    --danger-soft: #3d1e19;
    --code-bg: #262a33;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); }
/* The tabs share the whole bar, each as wide as the others. */
.topbar nav { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.topbar nav a { padding: 6px 14px; border-radius: 6px; color: var(--muted); text-align: center; font-weight: 500; }
.topbar nav a.active, .topbar nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

.banner { padding: 10px 24px; border-bottom: 1px solid var(--border); }
.banner.error { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-head p { margin: 4px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 20px;
}
.card > input, .card > textarea, .card > select, .card label { display: block; width: 100%; margin-bottom: 10px; }
.card label { font-weight: 600; font-size: 13px; }
.card label input, .card label select, .card label textarea { display: block; width: 100%; margin-top: 4px; font-weight: normal; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .card { margin-bottom: 20px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; gap: 0; } }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 6px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
form { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: 0.7; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.block { display: flex; width: 100%; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.large { width: 32px; height: 32px; border-width: 3px; color: var(--accent); }

.busy-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
                padding: 16px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(2px); }
.busy-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px 32px;
              text-align: center; max-width: 360px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.15); }
.busy-panel p { margin: 4px 0; }
.busy-panel .busy-message { font-weight: 600; margin-top: 14px; }
.busy-time { font-variant-numeric: tabular-nums; }

/* --- Markdown content ----------------------------------------------------- */
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose pre { background: var(--code-bg); padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 13px; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose h1, .prose h2, .prose h3 { font-size: 1.05em; margin: 1em 0 0.4em; }
/* Infographics (drawn by infographics.py). Everything wraps or stacks, as a lecture column can be narrow. */
.msg.assistant:has(.infographic), .msg.assistant:has(.flashcards) { width: 100%; }
.infographic { margin: 12px 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.flashcard .infographic { margin: 0 12px 10px 28px; }
.infographic figcaption { font-weight: 600; margin-bottom: 10px; }
.infographic strong { display: block; }
.infographic span { color: var(--muted); font-size: 13px; }
.ig-c0 { --ig: var(--ig-0); --ig-soft: var(--ig-0-soft); }
.ig-c1 { --ig: var(--ig-1); --ig-soft: var(--ig-1-soft); }
.ig-c2 { --ig: var(--ig-2); --ig-soft: var(--ig-2-soft); }
.ig-c3 { --ig: var(--ig-3); --ig-soft: var(--ig-3-soft); }
.ig-steps { list-style: none; margin: 0; padding: 0; }
.ig-steps li { display: flex; gap: 10px; padding-bottom: 12px; position: relative; margin: 0; }
.ig-steps li:last-child { padding-bottom: 0; }
.ig-steps li:not(:last-child)::before { content: ""; position: absolute; left: 12px; top: 26px; bottom: 0; width: 2px; background: var(--border); }
.ig-badge { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ig); color: var(--bg); font-size: 13px; }
.ig-loop { margin: 8px 0 0 36px; color: var(--muted); font-size: 13px; }
.ig-columns, .ig-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.ig-columns section { background: var(--ig-soft); border-top: 3px solid var(--ig); border-radius: 6px; padding: 8px 10px; }
.ig-columns h4 { margin: 0 0 6px; color: var(--ig); font-size: 14px; }
.ig-columns ul { margin: 0; padding-left: 16px; }
.ig-layers { display: flex; flex-direction: column; gap: 4px; }
.ig-layers > div, .ig-tiles > div { background: var(--ig-soft); border-left: 3px solid var(--ig); border-radius: 6px; padding: 7px 10px; }
.ig-center { width: fit-content; max-width: 100%; margin: 0 auto 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; text-align: center; }
.ig-bars { display: flex; flex-direction: column; gap: 8px; }
.ig-bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: baseline; }
.ig-bar b { font-size: 13px; color: var(--ig); }
.ig-track { grid-column: 1 / -1; grid-row: 2; height: 10px; border-radius: 5px; background: var(--ig-soft); overflow: hidden; }
.ig-track i { display: block; height: 100%; background: var(--ig); }
.ig-decisions { display: flex; flex-direction: column; gap: 6px; }
.ig-decisions > div { background: var(--ig-soft); border-left: 3px solid var(--ig); border-radius: 6px; padding: 7px 10px; }
.ig-decisions span { display: block; }
.ig-decisions strong { color: var(--ig); }
.ig-fact { background: var(--ig-soft); border-left: 4px solid var(--ig); border-radius: 6px; padding: 10px 12px;
  font-size: 16px; font-weight: 600; }
.ig-points { margin: 8px 0 0; padding-left: 18px; }

/* Collapsible sections in a lecture reply (made from its headings in app.js). */
.lecture-section > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 6px; }
.lecture-section > summary::-webkit-details-marker { display: none; }
.lecture-section > summary::before { content: "▾"; color: var(--muted); font-size: 0.9em; width: 1em; flex: none; }
.lecture-section:not([open]) > summary::before { content: "▸"; }
.lecture-section > summary > :is(h1, h2, h3, h4) { margin: 0; }
.lecture-section > summary:hover > :is(h1, h2, h3, h4) { color: var(--accent); }
.lecture-section { margin: 1em 0 0.4em; }
.lecture-section > div { padding-left: calc(1em + 6px); }
.lecture-section > div > :first-child { margin-top: 0.4em; }
.prose blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }

/* --- Lecture ------------------------------------------------------------------ */
/* The Lecture page fills the window: header and banners on top, chat takes the rest. */
body:has(main.ask-layout) { height: 100vh; display: flex; flex-direction: column; }
main.ask-layout {
  max-width: none;
  width: 100%;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 40px;
  gap: 20px;
  flex: 1;
  min-height: 0;
  padding: 20px 24px;
}
.sidebar { overflow-y: auto; }
/* Lecture list: folding groups, each lecture under a thin rail, the open one marked with an accent edge. */
.convo-groups { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.convo-group > summary { display: flex; align-items: flex-start; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer;
                         list-style: none; font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--text); }
.convo-group > summary::-webkit-details-marker { display: none; }
.convo-group > summary::before { content: "▾"; color: var(--muted); font-size: 11px; width: 12px; flex: none; margin-top: 2px; }
.convo-group:not([open]) > summary::before { content: "▸"; }
.convo-group > summary:hover { background: var(--surface); }
.convo-group-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.convo-count { flex: none; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--border); color: var(--muted);
               text-align: center; font-size: 11px; line-height: 18px; font-variant-numeric: tabular-nums; }
.convo-group-link { flex: none; width: 20px; text-align: center; border-radius: 4px; color: var(--muted); font-weight: 400; }
.convo-group-link:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.convo-list { list-style: none; margin: 4px 0 0 11px; padding: 0 0 0 8px; border-left: 1px solid var(--border);
              display: flex; flex-direction: column; gap: 2px; }
.convo-item a { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.convo-item a:hover { background: var(--surface); text-decoration: none; }
.convo-item.active a { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent), 0 1px 2px rgb(0 0 0 / 0.06); }
.convo-item.active .convo-title { color: var(--accent); font-weight: 600; }
.convo-title { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
               overflow: hidden; overflow-wrap: anywhere; }
.convo-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-live { color: var(--warn); font-weight: 600; }
.convo-group.completed { padding-top: 12px; border-top: 1px solid var(--border); }
.convo-group.completed > summary { color: var(--ok); }
.convo-group.completed .convo-count { background: var(--ok-soft); color: var(--ok); }
.convo-group.completed .convo-title { color: var(--muted); }
.convo-group.completed .convo-item.active .convo-title { color: var(--accent); }
.convo-empty { padding: 0 4px; }

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: none;   /* as wide as the column the page gives it, between the list and the side panel */
  width: 100%;
  margin: 0 auto;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.chat-head h1 { flex: 1; min-width: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.chat-tools form { margin: 0; }
/* Hiding the lecture list, with its toggle at the bottom left (desktop only; on a phone it's a drawer already). */
@media (min-width: 761px) {
  .sidebar { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
  .sidebar .convo-drawer { flex: 1; min-height: 0; overflow-y: auto; }
  main.ask-layout.sidebar-collapsed { grid-template-columns: 40px minmax(0, 1fr) 40px; }
  main.ask-layout.sidebar-collapsed.quick-open { grid-template-columns: 40px minmax(0, 1fr) clamp(320px, 30vw, 560px); }
  main.ask-layout.sidebar-collapsed .sidebar > :not(.side-tab) { display: none; }

}
.messages { flex: 1; overflow-y: auto; padding: 4px 0 12px 4px; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; max-width: 100%; }
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--user-bubble); color: var(--user-text); border-color: transparent; white-space: pre-wrap; }
.fallback-note { margin-bottom: 4px; }
.error-text { color: var(--danger); }

.empty-chat { margin: auto; text-align: center; max-width: 560px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.composer { display: flex; gap: 8px; align-items: flex-end; padding-top: 12px; }
.composer textarea { flex: 1; min-height: 48px; max-height: 200px; }
/* Lecture: room for a paragraph, growing with what you type (see autoGrow in app.js) up to 40% of the window. */
#composer textarea { min-height: 110px; max-height: 40vh; resize: none; line-height: 1.5; }
/* Quiz answer: three lines to start, growing with what you type (see the quiz answer code in app.js) up to 40% of the window. */
.composer textarea[name=answer] { max-height: 40vh; resize: none; }

@media (max-width: 760px) {
  main.ask-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding: 16px; }
  .sidebar { max-height: 140px; }
  .msg { max-width: 95%; }
}

/* --- Knowledge ------------------------------------------------------------ */
.filter { margin-bottom: 16px; }
.filter input { flex: 1; min-width: 160px; }
.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { padding: 12px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.note-list li:first-child { border-top: none; }
.note-list .title { font-weight: 600; }
.snippet { color: var(--muted); font-size: 14px; white-space: pre-line; max-height: 4.5em; overflow: hidden; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 999px; font-size: 12px; }
.tag:hover { text-decoration: none; filter: brightness(0.95); }
.mastery { font-size: 12px; color: var(--muted); }

.dropzone {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 24px 12px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  font-weight: normal !important;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone input { width: 100%; max-width: 320px; margin-bottom: 6px; }

/* --- Quiz ----------------------------------------------------------------- */
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 8px 0; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; }
ul.plain li:first-child { border-top: none; }

.progress { height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 20px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transition: width 0.3s; }

.quiz-thread { display: flex; flex-direction: column; gap: 22px; margin-bottom: 20px; }
.qa { display: flex; flex-direction: column; gap: 10px; scroll-margin-top: 16px; }
/* Code in a quiz answer wraps instead of running off the edge of its box, where a long line looked cut off mid-word and
   the sideways scroll bar was easy to miss. (Lectures keep the scroll bar: their code has Run and Edit buttons.) */
.qa .prose pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.question { font-weight: 600; font-size: 16px; margin-top: 4px; }
.verdict { font-weight: 700; margin-bottom: 6px; }
.verdict-correct { border-color: var(--ok); background: var(--ok-soft); }
.verdict-correct .verdict { color: var(--ok); }
.verdict-partial { border-color: var(--warn); background: var(--warn-soft); }
.verdict-partial .verdict { color: var(--warn); }
.verdict-incorrect { border-color: var(--danger); background: var(--danger-soft); }
.verdict-incorrect .verdict { color: var(--danger); }
.summary h2 { font-size: 20px; }

/* --- Curriculum ----------------------------------------------------------- */
.grid-2.tight { gap: 12px; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
ul.plain li { align-items: center; }
.progress.slim { height: 4px; margin: 6px 0 0; max-width: 360px; }
.up-next .progress { margin: 8px 0 0; max-width: 480px; }
.done-badge { color: var(--ok); font-weight: 600; }

.module h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.module-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  flex: none;
}
.module-summary { margin: 0 0 8px 36px; font-size: 14px; }

.topic-list { list-style: none; margin: 0; padding: 0; }
.topic { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.topic:first-child { border-top: none; }
.topic .btn { margin-top: 1px; }
.checkbox {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.checkbox:hover { border-color: var(--ok); }
.status-done .checkbox { background: var(--ok); border-color: var(--ok); }
.status-done .topic-title { text-decoration: line-through; color: var(--muted); }
.topic details summary { cursor: pointer; list-style: none; }
.topic details summary::-webkit-details-marker { display: none; }
.topic-title { font-weight: 600; }
.topic-summary { display: block; }
.key-points { margin: 8px 0 0; padding-left: 20px; font-size: 14px; }
.pill { font-size: 11px; font-weight: 600; background: var(--warn-soft); color: var(--warn); padding: 1px 8px; border-radius: 999px; margin-left: 6px; }

.wrap-up { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
           margin-top: 10px; padding: 10px 14px; border: 1px solid var(--ok); border-radius: 8px;
           background: var(--ok-soft); }
.wrap-up-text strong { color: var(--ok); }
.wrap-up form { margin: 0; }

.topic-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--accent-soft);
  border-radius: 8px;
}

/* Flashcards made from an Lecture reply */
.flashcards { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 0 6px; max-width: none; }
.flashcard { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; background: var(--surface); }
.flashcard summary { cursor: pointer; padding: 8px 10px; font-weight: 500; display: flex; align-items: flex-start; gap: 8px; list-style: none; }
.flashcard summary::-webkit-details-marker { display: none; }
.flashcard summary::before { content: "▸"; color: var(--muted); }
.flashcard[open] summary::before { content: "▾"; }
.flashcard summary .btn { margin-left: auto; padding: 0 6px; opacity: 0.5; }
.flashcard summary .btn:hover { opacity: 1; }
.flashcard .prose { padding: 0 12px 10px 28px; }
.composer-side { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* Quick questions under the lecture composer: a one-line box, and short answers above it. */
/* The quick question panel is a third column beside the lecture, so it never covers the conversation. */
/* The gap between the lecture text and the side panel should look as wide as the page's left margin (24px): the
   lecture's scroll bar sits in that gap, so the panel moves 2px closer. */
.quick-pop { margin-left: -2px; }
main.ask-layout.quick-open { grid-template-columns: 270px minmax(0, 1fr) clamp(320px, 30vw, 560px); }
.quick-pop { display: flex; flex-direction: column; min-height: 0; background: var(--surface);
             border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.quick-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.quick-pop.collapsed .quick-body { display: none; }
.quick-pop:not(.collapsed) .quick-tab { display: none; }
/* Folded away, all that's left is one small button at the top to bring it back. */
.quick-pop.collapsed { background: none; border: none; border-radius: 0; overflow: visible; }
.quick-tab { flex: none; width: 40px; height: 40px; padding: 0; }
.quick-tab:hover { border-color: var(--accent); background: var(--accent-soft); }
.quick-tab-icon { display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%;
                  background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 700; }
.quick-form { display: flex; gap: 8px; align-items: flex-end; }
/* Starts one line high and grows with the question (see growQuick in app.js). */
.quick-form textarea { flex: 1; width: auto; min-width: 0; min-height: 36px; max-height: 35%; max-height: 30vh;
                       resize: none; overflow-y: auto; font-size: 14px; line-height: 1.45; padding: 7px 10px; }
.quick-form .btn { min-height: 36px; }
/* The panel is split in two, one above the other: quick questions on top, the learner's own notes below. */
.quick-pane, .notes-pane { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
/* Two boxes of the same size, each scrolling inside itself. */
.quick-pane, .notes-pane { flex: 1 1 0; }
.pane-divider { flex: none; height: 1px; background: var(--border); }
.pane-title { font-weight: 600; display: flex; align-items: center; gap: 8px; min-height: 28px; }
.pane-title .btn { margin-left: auto; font-size: 16px; line-height: 1; padding: 4px 9px; }
.pane-title .muted { font-weight: 400; }
.notes-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.note-sec { border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 6px 6px 0; padding: 6px 10px; }
.note-head { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.note-head:focus-visible { outline: 2px solid var(--accent); }
.note-head .note-preview { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.note-sec.has-corrections:not(.open) > .note-head::after { content: '· corrections'; color: var(--accent); font-weight: 600; flex: none; }
.note-body { display: none; }
.note-sec.open .note-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* The page being written fills the rest of the Notes box; older pages are one line each above it. */
.notes-list { flex: 1; }
/* An open page is as tall as the whole Notes box (the list scrolls to the folded pages above it). */
.note-sec.open { flex: 0 0 100%; min-height: 0; display: flex; flex-direction: column; }
.note-sec { flex: none; }
.note-chevron::before { content: '▸'; display: inline-block; width: 1em; }
.note-sec.open .note-chevron::before { content: '▾'; }
.note-sec.open .note-preview { color: var(--muted); }
.note-text { flex: 1; width: 100%; margin-top: 6px; min-height: 96px; resize: none; }
.note-feedback { max-height: 40%; overflow-y: auto; }
.note-status:empty { display: none; }
.note-feedback:empty { display: none; }
.note-feedback { margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: var(--surface); }
.quick-answers { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.quick-answers:empty { display: none; }
.quick-entry { border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 6px 6px 0;
               padding: 6px 10px; font-size: 14px; }
.quick-q { font-weight: 600; margin-bottom: 2px; }
.quick-cards-status { margin-top: 4px; }
.quick-entry .flashcards { margin-top: 6px; }

/* Threads: side conversations branching off one reply */
.thread-btn {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  margin: 6px 0 0 6px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); background: var(--surface);
  font-size: 13px; font-weight: 600;
}
.thread-btn:hover { background: var(--accent); color: var(--on-accent); text-decoration: none; }
button.thread-btn { font-family: inherit; cursor: pointer; }
.flashcard form { padding: 0 12px 10px 22px; }
.flashcard .card-answer textarea { width: 100%; resize: none; overflow-y: auto; min-height: 56px; max-height: 40vh;
                                  line-height: 1.5; margin-bottom: 6px; }
.flashcard .card-result { margin: 0 12px 10px 22px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.flashcard .card-result p { margin: 0; }
.flashcard .card-back .prose { padding-top: 0; }
.flashcard form .thread-btn { margin: 0; }
.threads { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 2px 10px; margin: 6px 0 0 6px;
           padding-left: 10px; border-left: 2px solid var(--border); }
.threads a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.thread-banner { padding: 8px 12px; margin-bottom: 10px; background: var(--accent-soft); border-radius: 8px; }
.thread-banner summary { cursor: pointer; }
.thread-banner .prose { margin-top: 8px; max-height: 240px; overflow-y: auto; }

/* Quiz topic picker: tick one or more topics */
.topic-picker { border: none; padding: 0; margin: 0 0 12px; }
.topic-picker legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.card .topic-chip { display: inline-flex; width: auto; align-items: center; gap: 4px; margin: 0 6px 6px 0; padding: 3px 10px;
              border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-weight: normal; }
.card .topic-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.card .topic-chip:has(input:indeterminate) { border-color: var(--accent); border-style: dashed; color: var(--accent); }
.card .topic-chip input { margin: 0; width: auto; }
.topic-group { display: flex; flex-wrap: wrap; align-items: center; column-gap: 4px; margin-bottom: 4px; }
.topic-group .topic-chip { margin-bottom: 4px; }
.topic-group > .muted.small { margin-bottom: 4px; }
.subtopic-toggle { width: 24px; height: 24px; flex: none; margin-bottom: 4px; padding: 0; border: none; background: none;
                   color: var(--muted); font-size: 14px; cursor: pointer; }
button.subtopic-toggle:hover { color: var(--accent); }
.topic-group .subtopics { flex-basis: 100%; margin: 0 0 6px 11px; padding-left: 17px; border-left: 2px solid var(--border); }
.topic-group .subtopics[hidden] { display: none; }

/* Quiz: random questions from past conversations */
.next-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.verdict-text-correct { color: var(--ok); }
.verdict-text-partial { color: var(--warn); }
.verdict-text-incorrect { color: var(--danger); }

/* Quiz game: player card, round progress and XP feedback */
.banner.levelup { background: var(--accent-soft); color: var(--accent); font-weight: 600; text-align: center; animation: pop 0.5s ease-out; }
.player-top { display: flex; gap: 14px; align-items: center; }
.level-badge {
  flex: none; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; font-weight: 800; color: var(--on-accent); background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.xp-bar, .goal-bar { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 6px 0 4px; }
.xp-bar div, .goal-bar div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.6s ease-out; }
.player-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.stat { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 8px; background: var(--bg); min-width: 0; }
.stat-value { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat.hot .stat-value, .stat-pill.hot { color: var(--warn); }
.stat.goal .goal-bar { height: 6px; margin: 4px 0 0; }
.stat.goal.met .goal-bar div { background: var(--ok); }
.stat.goal.met .stat-value { color: var(--ok); }
@media (max-width: 600px) { .player-stats { grid-template-columns: repeat(2, 1fr); } }

.round-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.round-head h1 { font-size: 20px; }
.round-dots { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border); }
.dot-correct { background: var(--ok); }
.dot-partial { background: var(--warn); }
.dot-incorrect { background: var(--danger); }
.dot-current { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.round-stats { display: flex; gap: 8px; }
.stat-pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px;
             background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: 13px; }
.xp-text { color: var(--accent); }
.q-source { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 2px; }
.kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 1px 8px; border-radius: 999px; }
.kind-flashcard { background: var(--accent-soft); color: var(--accent); }
.kind-note { background: var(--ok-soft); color: var(--ok); }
.kind-chat { background: var(--warn-soft); color: var(--warn); }
/* Whether a question is one to revisit or new: outlined, so it sits quietly beside the kind badge */
.q-mix { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 0 7px; border-radius: 999px;
       border: 1px solid currentColor; cursor: help; }
.q-mix-revisit { color: var(--warn); }
.q-mix-new { color: var(--ok); }
.q-mix-note { margin: 0 0 12px; }
.xp-pop, .combo-pop { display: inline-block; margin-left: 8px; padding: 1px 10px; border-radius: 999px; font-size: 13px; animation: pop 0.5s ease-out; }
.xp-pop { background: var(--accent); color: var(--on-accent); }
.combo-pop { background: var(--warn-soft); color: var(--warn); }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .xp-pop, .combo-pop, .banner.levelup { animation: none; } }
.end-round { display: flex; justify-content: center; margin-top: 8px; }

.round-result { text-align: center; }
.round-result h1 { font-size: 28px; margin: 6px 0 14px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 520px; margin: 0 auto 16px; }
.result-stats .stat { align-items: center; }
.result-stats .stat-value { font-size: 26px; }
.round-result .row { justify-content: center; }

/* Curriculum: what's next after finishing, and adding modules */
.whats-next { border-color: var(--ok); }
.whats-next h2 { margin: 0; }
.suggestions-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.suggestion { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.suggestion .col { align-items: stretch; }
.suggestion .small { margin-top: 3px; }
.card.extend .row select { flex: none; }
.card-mark { font-weight: 700; min-width: 1em; }
.card-mark:empty { display: none; }

/* Quiz follow-ups: smaller dots, and their own badge colour */
.dot-followup { width: 9px; height: 9px; align-self: center; }
.kind-followup { background: var(--danger-soft); color: var(--danger); }
.follow-up-hint { margin: 8px 0 0; }

/* --- Phones ------------------------------------------------------------------
   The nav becomes a bottom tab bar, tap targets grow to at least 44px, and text boxes use 16px text so
   iPhones don't zoom in when you tap one. */
.convo-drawer > summary { display: none; }
@media (max-width: 760px) {
  body { font-size: 15px; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .topbar { height: 50px; padding: 0 16px; }
  .topbar nav {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; gap: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }
  .topbar nav a { display: grid; place-items: center; min-height: 46px; padding: 4px 2px; font-size: 13px; font-weight: 600; text-align: center; }
  .banner { padding: 10px 16px; }

  input, select, textarea { font-size: 16px; }
  .btn { min-height: 44px; padding: 10px 16px; white-space: normal; text-align: center; justify-content: center; }
  .btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
  .page-head { margin-bottom: 12px; }
  h1 { font-size: 22px; }

  /* Lecture: chat fills the screen above the tab bar; the conversation list is a collapsible drawer. */
  body:has(main.ask-layout) { height: 100dvh; }
  main.ask-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 10px;
                    padding: 10px 12px calc(72px + env(safe-area-inset-bottom)); }
  .sidebar { max-height: none; overflow: visible; display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
  .sidebar-top .btn.block { width: auto; }
  .convo-drawer { flex: 1; min-width: 0; }
  .convo-drawer > summary { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border: 1px solid var(--border);
                            border-radius: 6px; background: var(--surface); font-weight: 600; cursor: pointer; }
  .convo-drawer[open] .convo-groups { max-height: 45dvh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
                                    border-radius: 8px; padding: 4px; margin-top: 6px; }
  .convo-item a { padding: 10px 10px 10px 9px; }
  .chat-head h1 { font-size: 16px; }
  .sidebar-toggle, .side-tab { display: none; }
  .sidebar-top { flex: none; }
  /* On a phone the quick question panel sits below the lecture instead of beside it. */
  main.ask-layout, main.ask-layout.quick-open { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
  .quick-pop { max-height: 34dvh; margin-left: 0; }
  .quick-body { overflow-y: auto; }
  /* Short descriptions go on a phone so the lecture keeps its room above the panel. */
  .pane-title .muted { display: none; }
  .quick-pane, .notes-pane { flex: none; }
  .quick-answers, .notes-list { overflow: visible; }
  .msg { max-width: 100%; }
  .composer { padding-top: 8px; gap: 6px; }
  #composer textarea { min-height: 64px; max-height: 30dvh; }
  .composer textarea[name=answer] { max-height: 30dvh; }
  .flashcard summary { padding: 10px; }
  .thread-btn { padding: 8px 14px; }

  /* Lists and cards: let long titles and buttons wrap instead of pushing the page wider. */
  ul.plain li { flex-wrap: wrap; }
  .up-next .row form, .up-next .row .btn { width: 100%; }
  .topic { flex-wrap: wrap; }
  .card { padding: 14px; }
  .checkbox { width: 32px; height: 32px; }
  .flashcard summary .btn { min-width: 36px; min-height: 36px; opacity: 0.7; }
  .tag { display: inline-block; padding: 5px 10px; }
  .note-list .row { gap: 6px; }
}


/* Quiz: throwing out a bad question */
.remove-q { display: flex; gap: 6px; margin-top: 4px; }
.remove-q .btn { color: var(--muted); }
.remove-q .btn:hover { color: var(--danger); }

/* Usage page */
.usage-ranges { display: flex; gap: 6px; flex-wrap: wrap; }
.usage-ranges .chip { text-decoration: none; }
.usage-ranges .chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.usage-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.usage-card { overflow-x: auto; padding: 0; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.usage-table th, .usage-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.usage-table thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
.usage-table tfoot th { border-bottom: none; }
.usage-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.usage-table .share-col { width: 22%; min-width: 80px; }
.share-bar { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.share-bar div { height: 100%; background: var(--accent); border-radius: 4px; }
.composer[hidden] { display: none; }

/* Usage charts. Series colors are a validated categorical palette (biggest task first), stepped for each mode. */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4;
  --series-other: #a3a9b4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
    --series-other: #5d6472;
  }
}
.usage-chart-card h2 { margin: 0; }
.usage-chart-card > p, .chart-head p { margin: 2px 0 10px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 4px 0 8px; padding: 0;
                font-size: 13px; color: var(--muted); }
.chart-legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; flex: none; }
.chart-legend .swatch { margin: 0; }
.chart { position: relative; width: 100%; min-height: 260px; }
.chart-small { min-height: 180px; }
.chart svg { display: block; overflow: visible; }
.chart-grid line { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.chart-grid text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-col path { transition: opacity .12s; }
.chart-col.dim path { opacity: .35; }
.chart-tip { position: absolute; pointer-events: none; z-index: 2; min-width: 170px; padding: 8px 10px; font-size: 12px;
             background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
             box-shadow: 0 4px 16px rgba(0, 0, 0, .12); }
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 2px; line-height: 1.6; }
.tip-row span:last-child { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.tip-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 2px; font-weight: 600; }
.usage-grid { margin-bottom: 14px; }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.hbars li { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; align-items: center; gap: 10px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: block; height: 10px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.hbar { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.5em; text-align: right; }
.token-mix { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.mix-top { display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 14px; }
.mix-share { font-variant-numeric: tabular-nums; }
.mix-item .hbar-track { margin-bottom: 4px; }
.table-title { margin: 14px 16px 4px; }
.usage-chart-card, .usage-card { margin-bottom: 14px; }

/* Curriculum stats */
.overview { padding: 14px; }
.overview-stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin: 0; }
.overview-stats .stat { gap: 2px; }
.stat-of { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }
.overview-stats .progress.slim { margin: 4px 0 0; max-width: none; }
.verdict-bar { display: flex; gap: 2px; height: 6px; margin: 4px 0 2px; border-radius: 3px; overflow: hidden; }
.verdict-bar span { min-width: 0; }
.v-correct { background: var(--ok); }
.v-partial { background: var(--warn); }
.v-incorrect { background: var(--danger); }
.curriculum-meta { display: block; margin-top: 4px; }
.curriculum-pct { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.module-count { font-weight: 500; font-variant-numeric: tabular-nums; }
.module-complete .module-num { background: var(--ok-soft); color: var(--ok); }
.module-progress { margin: 0 0 8px 36px; max-width: 240px; }

/* Lecture: the topic bar is the page's first row, across the list, the lecture and the quick panel. */
main.ask-layout:has(> .topic-banner) { grid-template-rows: auto minmax(0, 1fr); }
main.ask-layout > .topic-banner { grid-column: 1 / -1; margin: 0; padding: 10px 16px; font-size: 14px; }
main.ask-layout > .topic-banner .small { font-size: 14px; }
.crumb-sep { color: var(--muted); margin: 0 4px; }
@media (max-width: 760px) {
  main.ask-layout:has(> .topic-banner), main.ask-layout.quick-open:has(> .topic-banner) {
    grid-template-rows: auto auto minmax(0, 1fr) auto; }
  main.ask-layout > .topic-banner { padding: 8px 12px; }
}
/* Thin scrollbars that sit on the page background instead of a white strip. */
.convo-drawer, .messages, .quick-answers { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* Lecture list: "+ New lecture" with the hide button beside it; hidden, a tab on the left edge brings it back. */
.sidebar-top { display: flex; gap: 6px; }
.sidebar-top .btn.block { flex: 1; width: auto; }
.sidebar-toggle { flex: none; width: 40px; padding: 0; color: var(--muted); }
.sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
/* Hidden, all that's left is one small button at the top to bring the list back. */
.side-tab { display: none; }
main.ask-layout.sidebar-collapsed .side-tab { display: inline-flex; }
.sidebar .side-tab { flex: none; width: 40px; height: 40px; padding: 0; justify-content: center; color: var(--muted); }
.sidebar .side-tab:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* --- Colourful text in lectures, quiz feedback and flashcards ------------------------------------------------
   Only code blocks and tables get colour: code is syntax highlighted (Pygments: "default" theme in light mode,
   "github-dark" in dark mode) and tables have a tinted header and striped rows. Inline names like terraform-deploy stay plain. */
:root { --prose-heading: #15181d; --prose-strong: #0f1115; --prose-em: #4b5563;
        --marker: #6b7280; --quote-bar: #cfd4db; --th-bg: #dae3ee; --th-text: #1d5fae; --row-alt: #e8e6e0;
        --table-key: #0f6b4f; --code-edge: #2a78d6; }
@media (prefers-color-scheme: dark) {
  :root { --prose-heading: #f4f6f9; --prose-strong: #ffffff; --prose-em: #c3c9d3;
          --marker: #9aa3b2; --quote-bar: #4a515e; --th-bg: #1d3352; --th-text: #9cc6ff; --row-alt: #1a1f29;
          --table-key: #6fd8ad; --code-edge: #3987e5; }
}
.prose :is(h1, h2, h3, h4) { color: var(--prose-heading); }
.prose strong { color: var(--prose-strong); }
.prose em { color: var(--prose-em); }
.prose li::marker { color: var(--marker); font-weight: 700; }
.prose blockquote { border-left-color: var(--quote-bar); }
.prose th { background: var(--th-bg); color: var(--th-text); }
/* The first column usually names the row, so it gets its own colour. */
.prose tbody td:first-child { color: var(--table-key); font-weight: 600; }
/* Links are the same grey as the text, so they are underlined. */
.prose a { text-decoration: underline; text-underline-offset: 2px; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
/* Your own messages are on the dark bubble: keep them white. */
.msg.user .prose :is(strong, em) { color: inherit; }
.codehilite { margin: 0.6em 0; }
.prose .codehilite pre { border-left: 3px solid var(--code-edge); }
.codehilite pre { margin: 0; }
.code-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.code-editor, .prose .code-output { width: 100%; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.45; border-radius: 6px; }
.code-editor { display: block; padding: 12px; color: var(--text); background: var(--code-bg); border: 1px solid var(--code-edge); resize: none; overflow-x: auto; white-space: pre; tab-size: 4; }
.prose .code-output { margin: 6px 0 0; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--border); }
.code-output:empty { display: none; }
.code-error { color: var(--danger); white-space: pre-wrap; overflow-wrap: anywhere; }
.code-editor[hidden], .codehilite pre[hidden], .code-tools [hidden] { display: none; }
.codehilite .c { color: #3D7B7B; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #F00 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #666 } /* Operator */
.codehilite .ch { color: #3D7B7B; font-style: italic } /* Comment.Hashbang */
.codehilite .cm { color: #3D7B7B; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #9C6500 } /* Comment.Preproc */
.codehilite .cpf { color: #3D7B7B; font-style: italic } /* Comment.PreprocFile */
.codehilite .c1 { color: #3D7B7B; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #3D7B7B; font-style: italic } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.codehilite .gr { color: #E40000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #008400 } /* Generic.Inserted */
.codehilite .go { color: #717171 } /* Generic.Output */
.codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #04D } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #008000 } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #B00040 } /* Keyword.Type */
.codehilite .m { color: #666 } /* Literal.Number */
.codehilite .s { color: #BA2121 } /* Literal.String */
.codehilite .na { color: #687822 } /* Name.Attribute */
.codehilite .nb { color: #008000 } /* Name.Builtin */
.codehilite .nc { color: #00F; font-weight: bold } /* Name.Class */
.codehilite .no { color: #800 } /* Name.Constant */
.codehilite .nd { color: #A2F } /* Name.Decorator */
.codehilite .ni { color: #717171; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #CB3F38; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #00F } /* Name.Function */
.codehilite .nl { color: #767600 } /* Name.Label */
.codehilite .nn { color: #00F; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #19177C } /* Name.Variable */
.codehilite .ow { color: #A2F; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #BBB } /* Text.Whitespace */
.codehilite .mb { color: #666 } /* Literal.Number.Bin */
.codehilite .mf { color: #666 } /* Literal.Number.Float */
.codehilite .mh { color: #666 } /* Literal.Number.Hex */
.codehilite .mi { color: #666 } /* Literal.Number.Integer */
.codehilite .mo { color: #666 } /* Literal.Number.Oct */
.codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
.codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
.codehilite .sc { color: #BA2121 } /* Literal.String.Char */
.codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
.codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
.codehilite .se { color: #AA5D1F; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
.codehilite .si { color: #A45A77; font-weight: bold } /* Literal.String.Interpol */
.codehilite .sx { color: #008000 } /* Literal.String.Other */
.codehilite .sr { color: #A45A77 } /* Literal.String.Regex */
.codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
.codehilite .ss { color: #19177C } /* Literal.String.Symbol */
.codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
.codehilite .fm { color: #00F } /* Name.Function.Magic */
.codehilite .vc { color: #19177C } /* Name.Variable.Class */
.codehilite .vg { color: #19177C } /* Name.Variable.Global */
.codehilite .vi { color: #19177C } /* Name.Variable.Instance */
.codehilite .vm { color: #19177C } /* Name.Variable.Magic */
.codehilite .il { color: #666 } /* Literal.Number.Integer.Long */
@media (prefers-color-scheme: dark) {
  .codehilite .c { color: #8B949E; font-style: italic } /* Comment */
  .codehilite .err { color: #F85149 } /* Error */
  .codehilite .esc { color: #E6EDF3 } /* Escape */
  .codehilite .g { color: #E6EDF3 } /* Generic */
  .codehilite .k { color: #FF7B72 } /* Keyword */
  .codehilite .l { color: #A5D6FF } /* Literal */
  .codehilite .n { color: #E6EDF3 } /* Name */
  .codehilite .o { color: #FF7B72; font-weight: bold } /* Operator */
  .codehilite .x { color: #E6EDF3 } /* Other */
  .codehilite .p { color: #E6EDF3 } /* Punctuation */
  .codehilite .ch { color: #8B949E; font-style: italic } /* Comment.Hashbang */
  .codehilite .cm { color: #8B949E; font-style: italic } /* Comment.Multiline */
  .codehilite .cp { color: #8B949E; font-weight: bold; font-style: italic } /* Comment.Preproc */
  .codehilite .cpf { color: #8B949E; font-style: italic } /* Comment.PreprocFile */
  .codehilite .c1 { color: #8B949E; font-style: italic } /* Comment.Single */
  .codehilite .cs { color: #8B949E; font-weight: bold; font-style: italic } /* Comment.Special */
  .codehilite .gd { color: #FFA198; background-color: #490202 } /* Generic.Deleted */
  .codehilite .ge { color: #E6EDF3; font-style: italic } /* Generic.Emph */
  .codehilite .ges { color: #E6EDF3; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
  .codehilite .gr { color: #FFA198 } /* Generic.Error */
  .codehilite .gh { color: #79C0FF; font-weight: bold } /* Generic.Heading */
  .codehilite .gi { color: #56D364; background-color: #0F5323 } /* Generic.Inserted */
  .codehilite .go { color: #8B949E } /* Generic.Output */
  .codehilite .gp { color: #8B949E } /* Generic.Prompt */
  .codehilite .gs { color: #E6EDF3; font-weight: bold } /* Generic.Strong */
  .codehilite .gu { color: #79C0FF } /* Generic.Subheading */
  .codehilite .gt { color: #FF7B72 } /* Generic.Traceback */
  .codehilite .g-Underline { color: #E6EDF3; text-decoration: underline } /* Generic.Underline */
  .codehilite .kc { color: #79C0FF } /* Keyword.Constant */
  .codehilite .kd { color: #FF7B72 } /* Keyword.Declaration */
  .codehilite .kn { color: #FF7B72 } /* Keyword.Namespace */
  .codehilite .kp { color: #79C0FF } /* Keyword.Pseudo */
  .codehilite .kr { color: #FF7B72 } /* Keyword.Reserved */
  .codehilite .kt { color: #FF7B72 } /* Keyword.Type */
  .codehilite .ld { color: #79C0FF } /* Literal.Date */
  .codehilite .m { color: #A5D6FF } /* Literal.Number */
  .codehilite .s { color: #A5D6FF } /* Literal.String */
  .codehilite .na { color: #E6EDF3 } /* Name.Attribute */
  .codehilite .nb { color: #E6EDF3 } /* Name.Builtin */
  .codehilite .nc { color: #F0883E; font-weight: bold } /* Name.Class */
  .codehilite .no { color: #79C0FF; font-weight: bold } /* Name.Constant */
  .codehilite .nd { color: #D2A8FF; font-weight: bold } /* Name.Decorator */
  .codehilite .ni { color: #FFA657 } /* Name.Entity */
  .codehilite .ne { color: #F0883E; font-weight: bold } /* Name.Exception */
  .codehilite .nf { color: #D2A8FF; font-weight: bold } /* Name.Function */
  .codehilite .nl { color: #79C0FF; font-weight: bold } /* Name.Label */
  .codehilite .nn { color: #FF7B72 } /* Name.Namespace */
  .codehilite .nx { color: #E6EDF3 } /* Name.Other */
  .codehilite .py { color: #79C0FF } /* Name.Property */
  .codehilite .nt { color: #7EE787 } /* Name.Tag */
  .codehilite .nv { color: #79C0FF } /* Name.Variable */
  .codehilite .ow { color: #FF7B72; font-weight: bold } /* Operator.Word */
  .codehilite .pm { color: #E6EDF3 } /* Punctuation.Marker */
  .codehilite .w { color: #6E7681 } /* Text.Whitespace */
  .codehilite .mb { color: #A5D6FF } /* Literal.Number.Bin */
  .codehilite .mf { color: #A5D6FF } /* Literal.Number.Float */
  .codehilite .mh { color: #A5D6FF } /* Literal.Number.Hex */
  .codehilite .mi { color: #A5D6FF } /* Literal.Number.Integer */
  .codehilite .mo { color: #A5D6FF } /* Literal.Number.Oct */
  .codehilite .sa { color: #79C0FF } /* Literal.String.Affix */
  .codehilite .sb { color: #A5D6FF } /* Literal.String.Backtick */
  .codehilite .sc { color: #A5D6FF } /* Literal.String.Char */
  .codehilite .dl { color: #79C0FF } /* Literal.String.Delimiter */
  .codehilite .sd { color: #A5D6FF } /* Literal.String.Doc */
  .codehilite .s2 { color: #A5D6FF } /* Literal.String.Double */
  .codehilite .se { color: #79C0FF } /* Literal.String.Escape */
  .codehilite .sh { color: #79C0FF } /* Literal.String.Heredoc */
  .codehilite .si { color: #A5D6FF } /* Literal.String.Interpol */
  .codehilite .sx { color: #A5D6FF } /* Literal.String.Other */
  .codehilite .sr { color: #79C0FF } /* Literal.String.Regex */
  .codehilite .s1 { color: #A5D6FF } /* Literal.String.Single */
  .codehilite .ss { color: #A5D6FF } /* Literal.String.Symbol */
  .codehilite .bp { color: #E6EDF3 } /* Name.Builtin.Pseudo */
  .codehilite .fm { color: #D2A8FF; font-weight: bold } /* Name.Function.Magic */
  .codehilite .vc { color: #79C0FF } /* Name.Variable.Class */
  .codehilite .vg { color: #79C0FF } /* Name.Variable.Global */
  .codehilite .vi { color: #79C0FF } /* Name.Variable.Instance */
  .codehilite .vm { color: #79C0FF } /* Name.Variable.Magic */
  .codehilite .il { color: #A5D6FF } /* Literal.Number.Integer.Long */
}
.prose tbody tr:nth-child(even) td { background: var(--row-alt); }
/* Table cells wrap between words, never inside one; a table too wide for the reply scrolls sideways. */
.prose :is(td, th) { overflow-wrap: normal; word-break: normal; }
.prose td code { white-space: nowrap; }
