:root {
  --bg: #f7f4ef;
  --surface: #fffdf9;
  --surface-2: #efe9e0;
  --ink: #23201c;
  --ink-2: #5b554d;
  --ink-3: #8f877c;
  --line: #e2dbd0;
  --accent: #b4532a;
  --accent-ink: #fff;
  --accent-soft: #f6e0d3;
  --hl: #ffd978;
  --hl-ink: #23201c;
  --current: #fbf3e4;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 6px 24px rgb(0 0 0 / .06);
  --radius: 12px;
  --serif: "Iowan Old Style", "Charter", "Palatino", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --chat-w: 420px;
  --topbar-h: 52px;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181614;
    --surface: #211e1b;
    --surface-2: #2b2723;
    --ink: #ece6dd;
    --ink-2: #b5ada2;
    --ink-3: #847c71;
    --line: #37322c;
    --accent: #e0794a;
    --accent-ink: #1a1512;
    --accent-soft: #43291c;
    --hl: #d9a93a;
    --hl-ink: #16120c;
    --current: #26221e;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 24px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { height: 100dvh; } /* mobile browsers: exclude the collapsing URL bar */
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, select, textarea, input { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--ink-3); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h); padding: 0 calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l)); flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand svg { width: 24px; height: 24px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; fill: none; }
.crumb { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.crumb::before { content: "/"; margin-right: 12px; color: var(--line); }
.crumb:empty::before { content: none; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-toggle { display: none; }

/* ---------- library ---------- */
.library { max-width: 880px; width: 100%; margin: 0 auto; padding: 40px 16px 80px; overflow-y: auto; }
.library h1 { font: 600 30px/1.2 var(--serif); margin: 0 0 24px; letter-spacing: -.01em; }
.lecture-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.lecture-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 18px; min-height: 120px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit; transition: border-color .15s, transform .15s, box-shadow .15s;
}
.lecture-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.lecture-card > a { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
/* The link covers the whole card, so the facts row stays clickable too… */
.lecture-card > a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.lecture-card h3 { font: 600 17px/1.3 var(--serif); margin: 0; }
/* …except the date, which sits above it. */
.date-btn { position: relative; z-index: 1; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.date-btn:hover { color: var(--accent); }
/* A date nobody vouched for: the day it was transcribed. */
.date-btn.guessed { text-decoration: underline dotted; text-underline-offset: 3px; opacity: .75; }
.lecture-card .facts { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px 12px; white-space: nowrap; color: var(--ink-3); font-size: 13px; }
.empty { padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--ink-2); text-align: center; }
/* Adding a lecture */
.add-lecture { margin-top: 36px; display: flex; flex-direction: column; gap: 14px; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 20px; text-align: center; cursor: pointer;
  color: var(--ink-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface); }
.dropzone p { margin: 0 0 6px; }
.dropzone .big { font: 600 18px/1.3 var(--serif); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.add-form { display: flex; flex-direction: column; gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.add-form input:not([type="checkbox"]), .add-form select {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: var(--bg); font-size: 14.5px; color: var(--ink);
}
.add-form input:focus, .add-form select:focus { outline: none; border-color: var(--accent); }
.add-form .row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.add-form .row.end { justify-content: space-between; align-items: center; }
.add-form label.ctx-toggle { flex-direction: row; align-items: center; gap: 8px; }
.add-form .grow { flex: 1 1 260px; }
.add-form .picked { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.add-form .picked b { overflow-wrap: anywhere; }

.job-list:empty { display: none; }
.job-list { display: flex; flex-direction: column; gap: 10px; }
.job { padding: 14px 16px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); background: var(--surface); }
.job.error { border-left-color: #c0392b; }
.job-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.job-step { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); }
.small { font-size: 12px; }

.howto { margin-top: 48px; color: var(--ink-2); }
.howto h2 { font-size: 15px; color: var(--ink); margin: 0 0 6px; }
.howto pre { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.howto pre code { background: none; padding: 0; }

/* ---------- lecture layout ---------- */
.lecture { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--chat-w); }
.reader { position: relative; min-height: 0; display: flex; flex-direction: column; }
.transcript-scroll { flex: 1; overflow-y: auto; scroll-behavior: auto; }
.transcript { max-width: 760px; margin: 0 auto; padding: 32px 28px 45vh; }
.transcript h1 { font: 600 28px/1.25 var(--serif); margin: 0 0 6px; letter-spacing: -.01em; }
.transcript .sub { color: var(--ink-3); font-size: 13px; margin-bottom: 28px; display: flex; gap: 14px; flex-wrap: wrap; }

.para { position: relative; padding: 10px 14px 12px; margin: 0 -14px 4px; border-radius: 10px; transition: background .25s; }
.para.current { background: var(--current); }
.para-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; font-size: 12.5px; }
.speaker {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; cursor: pointer;
  font-weight: 600; color: var(--ink-2); font-size: 12.5px;
}
.speaker::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--sp, var(--ink-3)); }
.speaker:hover { color: var(--ink); text-decoration: underline dotted; }
.ts-btn { border: 0; background: none; padding: 0; cursor: pointer; color: var(--ink-3); font-family: var(--mono); font-size: 11.5px; }
.ts-btn:hover { color: var(--accent); }
.para p { margin: 0; font: 18px/1.7 var(--serif); }
.w { cursor: pointer; border-radius: 3px; transition: background-color .12s, color .12s; }
.w:hover { text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 3px; }
.para.current .w { color: var(--ink-3); }
.para.current .w.past { color: var(--ink); }
.w.active, .para.current .w.active { background: var(--hl); color: var(--hl-ink); box-shadow: 0 0 0 2px var(--hl); }

/* Silence markers */
.silence {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 6px 0 10px; padding: 8px 12px;
  border: 1px dashed var(--line); border-radius: 10px; background: none; cursor: pointer; text-align: left;
  color: var(--ink-3); font-size: 13px; transition: background .25s, border-color .25s, color .25s;
}
.silence:hover { border-color: var(--ink-3); }
.silence.likely { color: var(--ink-2); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.silence-label { flex: 1; font-style: italic; }
.silence-dur { font: 11.5px var(--mono); }
.silence-wave { display: inline-flex; align-items: center; gap: 2px; height: 14px; }
.silence-wave i { width: 3px; height: 4px; border-radius: 2px; background: currentColor; opacity: .6; }
.silence.current { background: var(--accent-soft); border-style: solid; border-color: var(--accent); color: var(--ink); }
.playing .silence.current .silence-wave i { animation: wave 1.4s ease-in-out infinite; opacity: 1; background: var(--accent); }
.silence-wave i:nth-child(2) { animation-delay: -.3s !important; }
.silence-wave i:nth-child(3) { animation-delay: -.6s !important; }
.silence-wave i:nth-child(4) { animation-delay: -.9s !important; }
.silence-wave i:nth-child(5) { animation-delay: -1.2s !important; }
@keyframes wave { 0%, 100% { height: 4px; } 50% { height: 14px; } }

.pad-btn .slash { display: none; }
.pad-btn.off { color: var(--ink-3); }
.pad-btn.off .slash { display: block; }

.follow-pill, .ask-selection {
  position: absolute; z-index: 5; border: 0; cursor: pointer; font-size: 13px; font-weight: 600;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
}
.follow-pill { left: 50%; transform: translateX(-50%); bottom: 88px; }
.ask-selection { background: var(--accent); color: var(--accent-ink); padding: 6px 12px; }

/* ---------- account ---------- */
.login-page { display: grid; place-items: center; padding: 24px; }
.login { width: min(100%, 380px); display: flex; flex-direction: column; gap: 18px; }
.login .brand { justify-content: center; font-size: 20px; }
.login .brand svg { width: 30px; height: 30px; }
.login .add-form { gap: 14px; }
.login .send-btn { width: 100%; padding: 10px; }
.login .muted { text-align: center; margin: 0; }

.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); flex: none; }
.user-chip b { color: var(--ink); font-weight: 600; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.tag { align-self: flex-start; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.tag.mine { background: var(--accent-soft); color: var(--accent); }

/* ---------- view modes ---------- */
.view-switch { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 9px; flex: none; }
.view-switch button { border: 0; background: none; padding: 4px 11px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.view-switch button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.stage { display: none; min-height: 0; border-bottom: 1px solid var(--line); background: var(--bg); }
.lecture[data-mode="both"] .stage { display: flex; flex: 0 0 60%; }
.lecture[data-mode="visual"] .stage { display: flex; flex: 1; border-bottom: 0; }
.lecture[data-mode="visual"] .transcript-scroll,
.lecture[data-mode="visual"] .follow-pill { display: none !important; }

.stage-main { flex: 1; min-width: 0; display: flex; flex-direction: column; container-type: inline-size; }
.slide-wrap { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 28px 8px; display: flex; touch-action: pan-y; }
.slide.swipe-out-left { animation: swipe-left .18s ease-in forwards; }
.slide.swipe-out-right { animation: swipe-right .18s ease-in forwards; }
@keyframes swipe-left { to { opacity: 0; transform: translateX(-40px); } }
@keyframes swipe-right { to { opacity: 0; transform: translateX(40px); } }
.stage-nav { flex: none; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 2px 0 8px; }
.slide-count { font: 12px var(--mono); color: var(--ink-3); min-width: 56px; text-align: center; }
#slide-regen { margin-left: 10px; opacity: .6; }
#slide-regen:hover { opacity: 1; }

.outline { flex: 0 0 230px; overflow-y: auto; border-left: 1px solid var(--line); padding: 16px 10px 16px 12px; display: flex; flex-direction: column; gap: 1px; }
.outline:empty { display: none; }
.outline h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 8px 8px; }
.outline button {
  text-align: left; border: 0; background: none; cursor: pointer; border-radius: 7px; padding: 5px 8px;
  font-size: 13px; line-height: 1.35; color: var(--ink-2); border-left: 2px solid transparent;
}
.outline button:hover { background: var(--surface-2); }
.outline .lvl1 { font-weight: 600; color: var(--ink); margin-top: 6px; }
.outline .lvl2 { padding-left: 18px; }
.outline .lvl3 { padding-left: 28px; font-size: 12.5px; }
.outline button.current { background: var(--accent-soft); color: var(--ink); border-left-color: var(--accent); border-radius: 0 7px 7px 0; }

/* Empty / generating state */
.stage-empty { margin: auto; max-width: 440px; text-align: center; color: var(--ink-2); padding: 20px; }
.stage-empty p { margin: 0 0 10px; }
.stage-empty .big { font: 600 20px/1.3 var(--serif); color: var(--ink); }
.stage-empty .send-btn { margin-top: 8px; padding: 9px 18px; }
.stage-icon { font-size: 34px; color: var(--accent); margin-bottom: 6px; }
.error-text { color: #c0392b; font-size: 13.5px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 14px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Slides */
.slide {
  margin: auto; width: 100%; max-width: 920px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: calc(clamp(18px, 4cqi, 40px) * var(--fit)) calc(clamp(20px, 5cqi, 52px) * var(--fit));
  animation: slide-in .45s cubic-bezier(.2, .7, .2, 1);
  /* --fit (set by fitSlide() in app.js) shrinks everything so the slide fits its stage */
  --fit: 1;
  --fs: max(12.5px, calc(clamp(15px, 2.1cqi, 21px) * var(--fit))); /* never below a readable size */
}
@keyframes slide-in { from { opacity: 0; transform: translateY(10px) scale(.99); } }
.kicker { font-size: calc(12px * max(var(--fit), .85)); text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.slide-title { font: 600 max(17px, calc(clamp(20px, 3.3cqi, 32px) * var(--fit)))/1.2 var(--serif); margin: 0 0 4px; letter-spacing: -.01em; text-wrap: balance; }
.slide-sub { margin: 0; color: var(--ink-3); font-size: calc(var(--fs) * .8); }
.slide > :is(ul, ol, dl, div):last-child { margin-top: calc(clamp(14px, 2.6cqi, 26px) * var(--fit)); }

/* Items: ghosted until voiced, then revealed; the latest one is emphasised */
.item { cursor: pointer; opacity: .13; filter: blur(3px); transform: translateY(4px);
  transition: opacity .5s, filter .5s, transform .5s, background-color .4s, border-color .4s; }
.item.shown { opacity: 1; filter: none; transform: none; }
.item .detail { display: block; color: var(--ink-3); font-size: .82em; margin-top: 2px; }
.item:hover .txt, .item:hover dd, .item:hover blockquote { text-decoration: underline dotted var(--ink-3); text-underline-offset: 4px; }

.pts { list-style: none; margin: 0; padding: 0; display: grid; gap: .55em; font-size: var(--fs); line-height: 1.4; }
.pts li { position: relative; padding: .25em .5em .25em 1.4em; border-radius: 8px; }
.pts li::before { content: ""; position: absolute; left: .35em; top: .85em; width: .42em; height: .42em; border-radius: 50%; background: var(--ink-3); transition: background .4s; }
.pts li.latest { background: var(--current); }
.pts li.latest::before { background: var(--accent); }

.defs { margin: 0; display: grid; gap: .8em; font-size: var(--fs); }
.defs .item { display: grid; grid-template-columns: minmax(7em, 30%) 1fr; gap: 1em; padding: .5em .7em; border-radius: 10px; border-left: 3px solid var(--line); }
.defs dt { font-weight: 700; font-family: var(--serif); color: var(--accent); }
.defs dd { margin: 0; line-height: 1.4; }
.defs .item.latest { border-left-color: var(--accent); background: var(--current); }

.cmp { display: grid; gap: .45em; font-size: var(--fs); line-height: 1.35; }
.cmp-head, .cmp-row { display: grid; grid-template-columns: 1fr 2.2em 1fr; align-items: center; }
.cmp-head { font: 700 calc(var(--fs) * .95)/1.2 var(--serif); text-align: center; padding-bottom: .4em; border-bottom: 2px solid var(--line); }
.cmp-head > div:first-child { color: var(--ink-2); }
.cmp-head > div:last-child { color: var(--accent); }
.cmp-head .vs { font: italic 400 .75em var(--sans); color: var(--ink-3); }
.cmp-row { padding: .45em .2em; border-radius: 10px; row-gap: .15em; }
.cmp-row .crit { grid-column: 1 / -1; text-align: center; font-size: .72em; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.cmp-row .cell { text-align: center; padding: 0 .3em; }
.cmp-row .vs::before { content: "↔"; color: var(--ink-3); display: block; text-align: center; }
.cmp-row.latest { background: var(--current); }

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .9em 2.2em; font-size: var(--fs); line-height: 1.35; counter-reset: s; }
.steps li { position: relative; flex: 1 1 11em; max-width: 18em; display: flex; flex-direction: column; gap: .35em;
  padding: .8em .9em; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.steps li:not(:last-child)::after { content: "→"; position: absolute; right: -1.6em; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-size: 1.1em; }
.steps .num { width: 1.7em; height: 1.7em; border-radius: 50%; display: grid; place-items: center; font: 700 .8em var(--sans); background: var(--surface-2); color: var(--ink-2); transition: background .4s, color .4s; }
.steps li.shown .num { background: var(--accent); color: var(--accent-ink); }
.steps li.latest { border-color: var(--accent); }
/* Narrow stage: steps wrap onto several rows, where trailing arrows would point
   at nothing — the numbers already give the order. */
@container (max-width: 620px) {
  .steps { column-gap: .8em; }
  .steps li:not(:last-child)::after { display: none; }
}

.timeline { list-style: none; margin: 0; padding: 0 0 0 1.1em; border-left: 2px solid var(--line); display: grid; gap: .7em; font-size: var(--fs); line-height: 1.35; }
.timeline li { position: relative; display: grid; grid-template-columns: minmax(5em, 24%) 1fr; gap: .8em; padding: .2em .4em; border-radius: 8px; }
.timeline li::before { content: ""; position: absolute; left: calc(-1.1em - 7px); top: .55em; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink-3); }
.timeline li.shown::before { background: var(--accent); border-color: var(--accent); }
.timeline .when { font-weight: 700; font-family: var(--serif); color: var(--accent); }
.timeline li.latest { background: var(--current); }

.quotes { display: grid; gap: 1em; }
.quotes figure { margin: 0; padding: .4em 0 .4em 1.1em; border-left: 4px solid var(--accent); }
.quotes blockquote { margin: 0; font: italic calc(var(--fs) * 1.1)/1.45 var(--serif); }
.quotes figcaption { margin-top: .4em; font-size: calc(var(--fs) * .75); color: var(--ink-3); font-weight: 600; }
.quotes figcaption::before { content: "— "; }
.quote-source { font-size: calc(var(--fs) * .75); font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.quote-source::before { content: "Source : "; font-weight: 500; color: var(--ink-3); }
.quotes.many { gap: .55em; }
.quotes.many figure { padding-top: .15em; padding-bottom: .15em; }
.quotes.many blockquote { font-size: var(--fs); }

.qa .q { display: flex; gap: .8em; align-items: flex-start; padding: .8em 1em; border-radius: 12px; background: var(--accent-soft); margin-bottom: 1em; font-size: var(--fs); }
.qa .q p { margin: 0; font: italic calc(var(--fs) * 1.08)/1.4 var(--serif); }
.q-mark { flex: none; width: 1.6em; height: 1.6em; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font: 700 1em var(--serif); }

@media (prefers-reduced-motion: reduce) {
  .slide, .item { animation: none; transition: none; }
}

/* ---------- artifacts ---------- */
.view-switch .short { display: none; }
.badge { display: inline-block; margin-left: 5px; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.badge:empty { display: none; }

.artifacts { display: none; flex-direction: column; min-height: 0; }
.lecture[data-mode="artifacts"] .artifacts { display: flex; flex: 1; }
.lecture[data-mode="artifacts"] .stage,
.lecture[data-mode="artifacts"] .transcript-scroll,
.lecture[data-mode="artifacts"] .follow-pill { display: none !important; }
.artifact-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.artifact-head select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 8px; font-size: 13.5px; cursor: pointer; min-width: 0; }
#artifact-select { flex: 0 1 auto; max-width: 50%; font-weight: 600; }
.artifact-status { flex: 1; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s steps(2) infinite; }
.artifact-head .icon-btn:disabled { opacity: .35; cursor: default; }
.artifact-body { flex: 1; min-height: 0; overflow-y: auto; position: relative; display: flex; flex-direction: column; }
.artifact-frame { flex: 1; width: 100%; border: 0; display: block; background: var(--bg); }

/* Rich text shared by artifacts (.doc) and chat answers */
.doc { width: 100%; max-width: 800px; margin: 0 auto; padding: 28px 28px 80px; font-size: 16px; line-height: 1.65; }
.doc h1 { font: 600 28px/1.25 var(--serif); margin: 0 0 16px; letter-spacing: -.01em; }
.doc h2 { font: 600 22px/1.3 var(--serif); margin: 28px 0 10px; }
.doc h3 { font-size: 17px; margin: 22px 0 8px; }
.doc h4 { font-size: 15px; margin: 18px 0 6px; color: var(--ink-2); }
.doc p, .doc ul, .doc ol, .doc blockquote, .doc pre, .doc .table-wrap { margin: 0 0 14px; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc blockquote { border-left: 3px solid var(--accent); padding: 2px 0 2px 14px; color: var(--ink-2); }
.doc pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.doc pre code { background: none; padding: 0; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.table-wrap { overflow-x: auto; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .93em; }
.table-wrap th, .table-wrap td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table-wrap th { background: var(--surface-2); font-weight: 650; }
.table-wrap tr:last-child td { border-bottom: 0; }
.mermaid-fig { display: flex; justify-content: center; margin: 16px 0; overflow-x: auto; }
.mermaid-fig svg { max-width: 100%; height: auto; }
pre.mermaid-src { white-space: pre-wrap; font: 12.5px/1.5 var(--mono); color: var(--ink-3); background: var(--surface-2); padding: 12px; border-radius: 8px; }
pre.mermaid-error { border-left: 3px solid #c0392b; }

.artifact-card {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 8px 0; padding: 10px 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: inherit; font: inherit; transition: border-color .15s;
}
.artifact-card:hover { border-color: var(--accent); }
.art-icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 16px; }
.art-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.art-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-meta small { color: var(--ink-3); font-size: 12px; }
.art-open { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.artifact-card.live .art-icon { animation: blink 1.2s ease-in-out infinite; }
.artifact-card.gone { cursor: default; opacity: .6; }
.artifact-card.gone .art-icon { background: var(--surface-2); color: var(--ink-3); }

/* ---------- player ---------- */
.player {
  flex: none; border-top: 1px solid var(--line); background: var(--surface);
  padding: 12px calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
}
.player-row { display: flex; align-items: center; gap: 10px; max-width: 900px; margin: 0 auto; }
.play-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.play-btn svg { width: 20px; height: 20px; fill: currentColor; }
.play-btn .i-pause, .playing .play-btn .i-play { display: none; }
.playing .play-btn .i-pause { display: block; }
.time { font: 12.5px var(--mono); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.seek { position: relative; flex: 1; height: 28px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.seek-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }
.seek-hover {
  position: absolute; bottom: 30px; transform: translateX(-50%); pointer-events: none;
  background: var(--ink); color: var(--bg); font: 11.5px var(--mono); padding: 3px 7px; border-radius: 6px; white-space: nowrap;
}
#rate { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 6px; font-size: 13px; cursor: pointer; }

/* ---------- chat ---------- */
.chat { min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--surface); }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.chat-head h2 { font-size: 15px; margin: 0; flex: 1; }
.chat-close { display: none; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--accent-soft); padding: 9px 13px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.user .at { display: block; font-size: 11.5px; color: var(--ink-3); margin-bottom: 2px; }
.msg.assistant { font-size: 14.5px; line-height: 1.6; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p, .msg.assistant ul, .msg.assistant ol, .msg.assistant pre, .msg.assistant blockquote { margin: 0 0 10px; }
.msg.assistant ul, .msg.assistant ol { padding-left: 20px; }
.msg.assistant li { margin: 3px 0; }
.msg.assistant h3, .msg.assistant h4 { font-size: 15px; margin: 14px 0 6px; }
.msg.assistant blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--ink-2); }
.msg.assistant pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.assistant .table-wrap { margin: 0 0 10px; }
.msg.error { color: #c0392b; font-size: 13.5px; background: color-mix(in srgb, #c0392b 10%, transparent); padding: 8px 12px; border-radius: 8px; }
a.ts {
  font: 600 12px var(--mono); color: var(--accent); background: var(--accent-soft);
  padding: 1px 5px; border-radius: 5px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
a.ts:hover { background: var(--accent); color: var(--accent-ink); }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.suggestions p { color: var(--ink-3); font-size: 13px; margin: 0 0 4px; }
.suggestions button {
  text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 12px; cursor: pointer; font-size: 13.5px;
}
.suggestions button:hover { border-color: var(--accent); }

.chat-form { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-form textarea {
  resize: none; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg);
  max-height: 180px; outline: none;
}
.chat-form textarea:focus { border-color: var(--accent); }
.chat-form-row { display: flex; align-items: center; gap: 8px; }
.ctx-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); flex: 1; cursor: pointer; }
.ctx-toggle b { font-family: var(--mono); font-weight: 600; }
.web-toggle { flex: none; }
.tool-steps { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-3); }
.tool-step { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-step.current { color: var(--ink-2); }
.tool-step.current::after { content: "…"; animation: blink 1s steps(2) infinite; }
.msg.assistant a:not(.ts) { color: var(--accent); overflow-wrap: anywhere; }
.send-btn { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 7px 16px; border-radius: 8px; cursor: pointer; }
.send-btn:disabled { opacity: .5; cursor: default; }

/* ---------- medium screens (small laptops, tablets in landscape) ---------- */
@media (min-width: 961px) and (max-width: 1279px) {
  :root { --chat-w: 340px; }
  /* The section title is already shown above each slide: give the slide the room. */
  .lecture[data-mode="both"] .outline { display: none; }
  .outline { flex-basis: 190px; }
}

/* ---------- narrow screens: chat becomes a drawer ---------- */
@media (max-width: 960px) {
  .lecture { grid-template-columns: minmax(0, 1fr); }
  .outline { display: none; }
  .view-switch button { padding: 4px 8px; font-size: 12.5px; }
  .slide-wrap { padding: 12px 12px 4px; }
  .chat-toggle { display: inline-grid; }
  .chat {
    position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: min(100%, 460px); z-index: 20;
    padding-bottom: var(--safe-b); box-shadow: var(--shadow); transform: translateX(100%); transition: transform .2s;
  }
  .chat.open { transform: none; }
  .chat-close { display: inline-grid; }
  .transcript { padding: 24px 16px 45vh; }
  .para { margin: 0 -8px 4px; padding: 8px 8px 10px; }
  .player { padding-top: 10px; padding-bottom: calc(10px + var(--safe-b)); }
  .player-row { gap: 6px; }
  /* Without the outline, let the stage shrink to the slide instead of a fixed share. */
  .lecture[data-mode="both"] .stage { flex: 0 1 auto; max-height: 62%; }
  .lecture[data-mode="both"] .slide-wrap { flex: 0 1 auto; }
}
@media (max-width: 700px) {
  .crumb { display: none; }
  .user-chip b { display: none; }
}
@media (max-width: 600px) {
  #back-btn, #fwd-btn { display: none; }
}
@media (max-width: 560px) {
  .view-switch .long { display: none; }
  .view-switch .short { display: inline; }
}
@media (max-width: 480px) {
  .para p { font-size: 17px; }
  .artifact-head { padding-left: 10px; gap: 4px; }
  #artifact-select { max-width: 60%; }
  .doc { padding: 18px 16px 60px; }
  #duration { display: none; }
  .brand { font-size: 0; gap: 0; } /* logo only: the view switch needs the room */
  .lecture[data-mode="both"] .stage { max-height: 66%; }
}

/* ---------- phones in landscape: side by side, compact chrome ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --topbar-h: 44px; }
  .brand { font-size: 0; gap: 0; }
  .player { padding-top: 6px; padding-bottom: calc(6px + var(--safe-b)); }
  .play-btn { width: 42px; height: 42px; }
  .lecture[data-mode="both"] .reader {
    display: grid; grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); grid-template-rows: minmax(0, 1fr) auto;
  }
  .lecture[data-mode="both"] .stage { grid-area: 1 / 1; max-height: none; border-bottom: 0; border-right: 1px solid var(--line); }
  .lecture[data-mode="both"] .slide-wrap { flex: 1 1 auto; }
  .lecture[data-mode="both"] .transcript-scroll { grid-area: 1 / 2; }
  .lecture[data-mode="both"] .player { grid-area: 2 / 1 / 3 / 3; }
  .lecture[data-mode="both"] .transcript { padding: 12px 14px 45vh; }
  .lecture[data-mode="both"] .para p { font-size: 16px; line-height: 1.6; }
  .lecture[data-mode="both"] .follow-pill { left: 77%; }
  /* No room for a navigation row: swipe the slide instead (see app.js). */
  .stage-nav { display: none !important; }
  .slide-wrap { padding: 8px 10px; }
  .slide { border-radius: 12px; }
  .kicker { margin-bottom: 2px; }
}

/* ---------- touch screens: comfortable hit targets (≥ 44px) ---------- */
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .view-switch button { min-height: 38px; padding-inline: 12px; }
  #rate { min-height: 40px; }
  .ts-btn { padding: 12px 8px; margin: -12px -8px; } /* bigger hit area, same look */
  .speaker { padding: 10px 0; margin: -10px 0; }
  .silence { min-height: 44px; }
  .outline button { padding-top: 10px; padding-bottom: 10px; }
  .suggestions button { padding: 12px; }
  .ctx-toggle input { width: 20px; height: 20px; }
  .send-btn { min-height: 40px; }
  .w:hover { text-decoration: none; } /* no sticky hover underline after a tap */
}
@media (pointer: coarse) and (max-width: 480px) {
  .view-switch button { padding-inline: 8px; }
}
