/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #f6f5f2;
  --panel: #fffefb;
  --ink: #1b1a17;
  --ink-soft: #5c5850;
  --muted: #8a857c;
  --line: #e2ddd2;
  --accent: #9a3412;
  --accent-soft: #fdf0e7;
  --mark: #ffe9a8;
  --shadow: 0 1px 2px rgba(24, 20, 12, .06), 0 8px 24px rgba(24, 20, 12, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --topbar-h: 56px;
}

:root[data-theme="dark"] {
  --bg: #14140f;
  --panel: #1c1c17;
  --ink: #ece7dc;
  --ink-soft: #b9b2a4;
  --muted: #8b8579;
  --line: #2e2d26;
  --accent: #f0a26a;
  --accent-soft: #2a211a;
  --mark: #5c4a12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14140f;
    --panel: #1c1c17;
    --ink: #ece7dc;
    --ink-soft: #b9b2a4;
    --muted: #8b8579;
    --line: #2e2d26;
    --accent: #f0a26a;
    --accent-soft: #2a211a;
    --mark: #5c4a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

.muted { color: var(--muted); }

/* ================================================================ chat app */
.chat-page { height: 100%; overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  grid-template-rows: 100vh;      /* a fixed row so the columns can overflow */
  height: 100vh;
  overflow: hidden;
}

.app.no-rail { grid-template-columns: 0 minmax(0, 1fr); }
.app.no-rail .rail { display: none; }
.app.sourcing { grid-template-columns: 264px minmax(0, 1fr) minmax(380px, 46%); }
.app.sourcing.no-rail { grid-template-columns: 0 minmax(0, 1fr) minmax(380px, 46%); }

/* ----------------------------------------------------------------- rail */
.rail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  background: color-mix(in srgb, var(--panel) 70%, var(--bg));
  border-right: 1px solid var(--line);
}

.rail-new {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.rail-new:hover { border-color: var(--accent); color: var(--accent); }

.rail-section {
  margin: 18px 4px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; }

.chat-list button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list button:hover { background: var(--accent-soft); color: var(--ink); }
.chat-list button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.rail-foot { border-top: 1px solid var(--line); padding-top: 10px; }
.rail-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }

.rail-foot select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 12.5px;
}

.rail-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}

.rail-link:hover { color: var(--accent); }
.rail-status { margin-top: 8px; font-size: 11px; color: var(--muted); }
.rail-status.bad { color: var(--accent); }

/* ----------------------------------------------------------------- chat */
/* min-height:0 is what lets .thread scroll: without it a flex/grid child
   refuses to shrink below its content, so the column grows past the viewport
   and the overflow never engages. */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--bg);
}

.chat-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}

.chat-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* the streaming bubble is rewritten on every token; scroll anchoring
     reacts to that by shifting the viewport under the reader's hands */
  overflow-anchor: none;
  padding: 26px 20px 10px;
  scroll-behavior: smooth;
}

.welcome { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.welcome h1 { margin: 0 0 10px; font-size: 27px; letter-spacing: -.02em; }
.welcome p { margin: 0 auto 26px; max-width: 56ch; font-size: 14.5px; line-height: 1.6; color: var(--muted); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.cards button {
  padding: 13px 15px;
  text-align: left;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-soft);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.cards button:hover { border-color: var(--accent); color: var(--accent); }

.msg { max-width: 760px; margin: 0 auto 26px; }
.msg .who { font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }

.msg.user .body {
  padding: 11px 15px;
  font-size: 14.5px;
  line-height: 1.55;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.msg.bot .body {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.68;
}

.msg.bot .body p { margin: 0 0 .85em; }
.msg.bot .body ul, .msg.bot .body ol { margin: 0 0 .9em; padding-left: 1.25em; }
.msg.bot .body li { margin-bottom: .35em; }
.msg.bot .body li::marker { color: var(--accent); }
.msg.bot .body h3 { font-family: var(--sans); font-size: 15px; margin: 1.2em 0 .4em; }
.msg.bot .body code { font-size: .9em; background: var(--accent-soft); padding: 1px 4px; border-radius: 4px; }

.cite {
  display: inline-block;
  min-width: 18px;
  margin: 0 1px;
  padding: 0 5px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  vertical-align: 1px;
}

.cite:hover { background: var(--accent); color: var(--panel); }

.sources { margin-top: 14px; }

.sources-head {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 10px;
  border-top: 1px solid var(--line);
  margin-bottom: 4px;
}

.source {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}

.source:last-child { border-bottom: 0; }
.source img { width: 60px; height: 60px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); background: #fff; }
.source .n { font-size: 11px; font-weight: 700; color: var(--accent); }
.source button.open { display: block; padding: 0; font: inherit; font-size: 12.5px;
  color: var(--ink); background: none; border: 0; text-align: left; cursor: pointer; }
.source button.open:hover { color: var(--accent); }
.source .snip { font-size: 11.5px; color: var(--muted); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.pending::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.msg-error {
  margin-top: 8px;
  padding: 9px 12px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.msg-error code { background: none; }

/* ------------------------------------------------------------- composer */
.composer { padding: 10px 20px 16px; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 8px 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.composer-box:focus-within { border-color: var(--accent); }

.composer textarea {
  flex: 1;
  max-height: 190px;
  padding: 8px 0;
  color: var(--ink);
  background: none;
  border: 0;
  outline: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
}

.composer button {
  width: 34px;
  height: 34px;
  font-size: 15px;
  color: var(--panel);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.composer button:disabled { opacity: .4; cursor: default; }

.composer-note {
  max-width: 760px;
  margin: 7px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

/* ---------------------------------------------------------- source pane */
.source-pane { display: flex; flex-direction: column; min-width: 0;
  min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
.source-pane[hidden] { display: none; }

.source-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.source-head .rail-link { margin: 0 0 0 auto; text-transform: none; letter-spacing: 0; }
.source-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 16px 18px 40px;
  background: var(--bg);
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.62;
}

.source-meta {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.source-body p { margin: 0 0 .8em; }
.source-body h4 { font-family: var(--sans); font-size: 14px; margin: 1.2em 0 .4em; }
.source-body ul { margin: 0 0 .8em; padding-left: 1.2em; }
.source-body li { margin-bottom: .3em; }
.source-body figure { margin: 1.1em 0; text-align: center; }
.source-body figure img { max-width: 100%; height: auto; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; }
.source-body figcaption { margin-top: 7px; font-size: 12.5px; color: var(--ink-soft); text-align: left; }
.source-body .page-caption { font-size: 12.5px; color: var(--ink-soft);
  border-left: 2px solid var(--line); padding-left: 10px; }
.source-body .page-callout { margin: 1em 0; padding: 10px 12px; font-size: 13.5px;
  background: var(--accent-soft); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 8px; }
.source-loading { padding: 20px 0; font-family: var(--sans); font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  .app, .app.sourcing { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .app.sourcing .chat { display: none; }
  .cards { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
  max-width: 26ch;
}

.brand select {
  max-width: 26ch;
  height: 26px;
  padding: 0 4px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.brand select:hover { border-color: var(--line); background: var(--bg); }

.brand span { font-size: 11px; }

.icon-btn {
  flex: none;
  height: 34px;
  min-width: 34px;
  padding: 0 9px;
  font-size: 15px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}

.icon-btn:hover { background: var(--accent-soft); border-color: var(--line); }

/* ---------------------------------------------------------------- search */
.search-wrap { position: relative; flex: 1; max-width: 620px; margin-left: auto; }

input[type="search"], input[type="number"] {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
}

input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.results .hit {
  display: block;
  width: 100%;
  padding: 9px 11px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.results .hit:hover, .results .hit[aria-selected="true"] { background: var(--accent-soft); }
.results .hit b { color: var(--accent); }

.results .hit .where {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.results .hit .snippet {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.results .empty { padding: 12px; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- pager */
.pager { display: flex; align-items: center; gap: 4px; }
.pager input { width: 68px; text-align: center; }
.pager span { font-size: 12px; }

/* ---------------------------------------------------------------- layout */
.shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: calc(100vh - var(--topbar-h));
}

.shell.collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.shell.collapsed .sidebar { display: none; }

.sidebar {
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-head input { margin-top: 8px; height: 32px; }

.outline { padding: 8px; }

.outline details { margin-bottom: 2px; }

.outline summary {
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}

.outline summary::-webkit-details-marker { display: none; }
.outline summary:hover { background: var(--accent-soft); }
.outline summary .pages { float: right; font-size: 11px; color: var(--muted); font-weight: 400; }

.outline a {
  display: block;
  padding: 5px 10px 5px 22px;
  color: var(--ink-soft);
  font-size: 12.5px;
  text-decoration: none;
  border-radius: 7px;
  border-left: 2px solid transparent;
}

.outline a.lv3 { padding-left: 32px; font-size: 12px; color: var(--muted); }
.outline a:hover { background: var(--accent-soft); color: var(--ink); }
.outline a.current { border-left-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------------------------------------------------------------- reader */
.reader { overflow-y: auto; scroll-behavior: smooth; padding: 26px 20px 60vh; }
.loading { text-align: center; padding: 60px; color: var(--muted); }

.page {
  max-width: 860px;
  margin: 0 auto 22px;
  padding: 34px 46px 40px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-head .folio { font-weight: 700; color: var(--ink-soft); }

.page h2, .page h3, .page h4 {
  font-family: var(--sans);
  line-height: 1.25;
  margin: 1.7em 0 .5em;
}

.page h2 { font-size: 23px; letter-spacing: -.01em; }
.page h3 { font-size: 18px; }
.page h4 { font-size: 14.5px; color: var(--ink-soft); }
.page > :first-child { margin-top: 0; }

.page p {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.66;
  margin: 0 0 1em;
  hyphens: auto;
}

.page p .lead { font-weight: 700; font-style: italic; }
.page p.cont::before { content: "…"; color: var(--muted); margin-right: .3em; }

.page ul {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.6;
  margin: 0 0 1.1em;
  padding-left: 1.3em;
}

.page li { margin-bottom: .35em; }
.page li::marker { color: var(--accent); }

.callout {
  margin: 1.4em 0;
  padding: 16px 18px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}

.callout .label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}

.callout p { font-size: 14.5px; margin: 0; }

figure {
  margin: 1.8em 0;
  text-align: center;
}

figure img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: zoom-in;
}

figure figcaption {
  margin-top: 9px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: left;
}

figure figcaption .label { font-weight: 700; color: var(--accent); }

.orphan-caption {
  font-size: 13px;
  color: var(--ink-soft);
  border-left: 2px solid var(--line);
  padding-left: 12px;
  margin: 1em 0;
}

mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

.sentinel { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- ask panel */
.shell.asking { grid-template-columns: 300px minmax(0, 1fr) minmax(340px, 420px); }
.shell.asking.collapsed { grid-template-columns: 0 minmax(0, 1fr) minmax(340px, 420px); }

.ask {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.ask[hidden] { display: none; }

.ask-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.ask-head select {
  margin-left: auto;
  max-width: 170px;
  height: 28px;
  padding: 0 6px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

.ask-log { flex: 1; overflow-y: auto; padding: 14px; }

.ask-intro p { margin: 0 0 12px; font-size: 13px; line-height: 1.55; color: var(--muted); }
.ask-examples { display: flex; flex-direction: column; gap: 6px; }

.ask-examples button {
  padding: 9px 11px;
  text-align: left;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

.ask-examples button:hover { border-color: var(--accent); color: var(--accent); }

.turn { margin-bottom: 18px; }
.turn.you { text-align: right; }

.turn.you .bubble {
  display: inline-block;
  max-width: 92%;
  padding: 8px 12px;
  text-align: left;
  font-size: 13.5px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 12px 12px 3px 12px;
}

.turn.bot .bubble {
  font-size: 14px;
  line-height: 1.62;
  font-family: var(--serif);
}

.turn.bot .bubble p { margin: 0 0 .75em; }
.turn.bot .bubble ul { margin: 0 0 .75em; padding-left: 1.15em; }
.turn.bot .bubble li { margin-bottom: .3em; }
.turn.bot .bubble strong { font-weight: 700; }

.cite {
  display: inline-block;
  min-width: 17px;
  margin: 0 1px;
  padding: 0 4px;
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  vertical-align: 1px;
}

.cite:hover { background: var(--accent); color: var(--panel); }

.sources { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }

.sources summary {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.source {
  display: flex;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}

.source:last-child { border-bottom: 0; }
.source img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.source .n { font-size: 10.5px; font-weight: 700; color: var(--accent); }
.source a { display: block; font-size: 12px; color: var(--ink); text-decoration: none; }
.source a:hover { color: var(--accent); }
.source .snip { font-size: 11.5px; color: var(--muted); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.ask-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

.ask-form textarea {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13.5px;
  resize: vertical;
}

.ask-form button {
  align-self: flex-end;
  height: 42px;
  padding: 0 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--panel);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.ask-form button:disabled { opacity: .5; cursor: default; }

.ask-note { font-size: 12px; color: var(--muted); padding: 6px 0; }
.ask-error { font-size: 12.5px; color: var(--accent); padding: 6px 0; }

.thinking::after {
  content: "▍";
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(10, 9, 6, .88);
}

.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-height: 100%; overflow: auto; }

.lightbox img {
  max-width: min(1200px, 92vw);
  max-height: 82vh;
  border-radius: 8px;
  background: #fff;
}

.lightbox figcaption {
  max-width: min(1200px, 92vw);
  margin-top: 12px;
  color: #e8e2d6;
  font-size: 13.5px;
  line-height: 1.5;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  color: #fff;
  font-size: 20px;
}

/* ---------------------------------------------------------------- small screens */
@media (max-width: 900px) {
  .brand, .pager span { display: none; }
  .shell { grid-template-columns: 0 minmax(0, 1fr); }
  .shell .sidebar { display: none; }

  .shell.mobile-open {
    grid-template-columns: minmax(0, 1fr);
  }

  .shell.mobile-open .sidebar { display: block; border-right: 0; }
  .shell.mobile-open .reader { display: none; }
  .page { padding: 24px 20px 28px; }
  .page p, .page ul { font-size: 16px; }
}
