/* ---------- Fonts (self-hosted; SIL Open Font License, see web/fonts) ---------- */
@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-latin-opsz-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-latin-opsz-italic.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-latin-ext-opsz-normal.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-latin-ext-opsz-italic.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-greek-opsz-normal.woff2) format("woff2-variations");
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap; src: url(/fonts/literata-greek-opsz-italic.woff2) format("woff2-variations");
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: "Geist"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(/fonts/geist-latin-wght-normal.woff2) format("woff2-variations"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(/fonts/geist-mono-latin-wght-normal.woff2) format("woff2-variations"); }

/* ---------- Tokens ----------
   Paper and ink, with two marks borrowed from the printed page:
   rubric red for the paragraph you have open, and a highlighter for the passages an answer drew on. */
:root {
  color-scheme: dark;
  /* One ground. There is no light mode: the reader is dark at every hour. */
  --paper: #0d0c0b;
  --desk: #100f0e;
  --surface: #1a1917;
  --rule: #23221f;
  --rule-strong: #333029;
  --ink: #ebe7de;
  --ink-2: #b4afa5;
  --ink-3: #8d887e;
  --ink-4: #75706a;
  --accent: #ef7658;
  --accent-ink: #f48b70;
  --accent-soft: #3a211a;
  --mark: #3a3012;
  --mark-wash: #221e14;
  --mark-ink: #f0cf6a;
  --mark-line: #a8872c;
  --button: #ebe7de;
  --on-button: #0d0c0b;
  --danger: #f08a68;
  --shadow: 0 1px 2px rgb(0 0 0 / .34), 0 8px 24px rgb(0 0 0 / .34);
  --shadow-lg: 0 16px 40px rgb(0 0 0 / .55);
  --font-ui: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-text: "Literata", Charter, Georgia, "Times New Roman", serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --masthead-h: 52px;
  --gutter-num: 76px;

  /* The Machine register: six hues, never more. One per step, so a trace reads
     as a chord. These are splash.js's own night values, promoted to tokens. */
  --hue-1: #ff8a6b;
  --hue-2: #f2c14e;
  --hue-3: #b5d96a;
  --hue-4: #5fd3c6;
  --hue-5: #94b3ff;
  --hue-6: #e59be2;
  --hue-blend: #b7a6ee;
  --lattice: #1a1816;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent-ink); }
h1, h2, h3 { margin: 0; }
label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 550; color: var(--ink-2); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
::selection { background: var(--mark); color: var(--ink); }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; padding: 6px 12px; font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
button:hover { background: var(--desk); border-color: var(--ink-3); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea {
  max-width: 100%; padding: 7px 10px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
kbd { font: 500 11px/1 var(--font-mono); }

/* ---------- Masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 20; height: var(--masthead-h);
  display: flex; align-items: center; gap: 28px; padding: 0 20px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}
button.brand { display: flex; align-items: baseline; gap: 10px; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--ink); white-space: nowrap; }
button.brand:hover { background: transparent; }
button.brand:hover .brand-name { color: var(--accent-ink); }
.brand-name { font: italic 500 21px/1 var(--font-text); letter-spacing: -.01em; transition: color .15s; }
.brand-sub { font-size: 12px; color: var(--ink-3); letter-spacing: .01em; }
.reader-tools { display: flex; align-items: center; gap: 6px; min-width: 0; }

/* The volume picker reads as a title, not a form field. */
.volume { position: relative; display: flex; align-items: center; min-width: 0; }
.volume select {
  appearance: none; -webkit-appearance: none; width: 300px; height: 32px; padding: 0 28px 0 10px;
  border-color: transparent; background: transparent; font-weight: 550; font-size: 13.5px; text-overflow: ellipsis; cursor: pointer;
}
.volume select:hover { background: var(--desk); }
.volume select:focus { border-color: var(--rule-strong); background: var(--surface); box-shadow: none; }
.volume-chevron { position: absolute; right: 10px; color: var(--ink-3); pointer-events: none; }

.lookup { position: relative; display: flex; align-items: center; }
.lookup-prefix { position: absolute; left: 10px; font: 500 12px/1 var(--font-mono); color: var(--ink-3); pointer-events: none; }
.lookup input { width: 150px; height: 32px; padding: 0 28px 0 34px; font: 13px var(--font-mono); background: var(--surface); }
.lookup-key {
  position: absolute; right: 7px; display: grid; place-items: center; width: 18px; height: 18px;
  border: 1px solid var(--rule-strong); border-radius: 4px; color: var(--ink-3); pointer-events: none;
}
.lookup input:focus + .lookup-key, .lookup input:not(:placeholder-shown) + .lookup-key { display: none; }

.masthead-end { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.version { font: 11px/1 var(--font-mono); color: var(--ink-3); white-space: nowrap; }
.version:empty { display: none; }
.account { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.account[hidden] { display: none; }
.account form { margin: 0; }
.signout { padding: 3px 10px; font-size: 12px; color: var(--ink-2); }
.icon-button { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border-color: transparent; background: transparent; color: var(--ink-2); }
.icon-button:hover { background: var(--desk); border-color: transparent; color: var(--ink); }
.icon-button[aria-expanded="true"] { background: var(--desk); color: var(--ink); }

/* ---------- Layout ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 460px; }
.workspace.chat-expanded { grid-template-columns: minmax(320px, 1fr) minmax(460px, 62%); }

/* ---------- Reader: an edition page with CP numbers in the margin ---------- */
.reader { min-width: 0; padding: 40px clamp(20px, 4vw, 56px) 120px; container: reader / inline-size; }
.reader-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, calc(680px + var(--gutter-num))) minmax(0, 1fr); }
.reader.has-toc .reader-layout { grid-template-columns: minmax(28px, 1fr) minmax(0, calc(680px + var(--gutter-num))) minmax(0, 1fr); column-gap: 16px; }
.reader-main { grid-column: 2; min-width: 0; }
#reader-status { margin: 0 0 20px var(--gutter-num); font-size: 13px; color: var(--ink-2); }
#reader-status:empty { display: none; }

#paragraphs article {
  position: relative; display: grid; grid-template-columns: var(--gutter-num) minmax(0, 1fr);
  padding: 14px 0 18px;
  scroll-margin-top: calc(var(--masthead-h) + 24px);
}
/* The margin: CP number, then small state marks (open icon / Source). */
#paragraphs .para-ref { grid-column: 1; align-self: start; display: flex; flex-direction: column; gap: 6px; padding-top: .42em; padding-right: 16px; font: 500 12px/1.2 var(--font-mono); }
#paragraphs .para-ref a { align-self: flex-start; padding: 2px 5px; margin-left: -5px; border-radius: 4px; color: var(--ink-3); text-decoration: none; letter-spacing: -.01em; transition: color .15s, background .15s; }
#paragraphs .para-ref a:hover { color: var(--ink); background: var(--desk); }
.paragraph-state { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; font: 600 10px/1.4 var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.paragraph-state .state-open { display: inline-flex; color: var(--accent-ink); }
#paragraphs article.retrieved .paragraph-state .state-source { color: var(--mark-ink); }
.paragraph-state:empty { display: none; }
.para-body { grid-column: 2; min-width: 0; }
.prose { font: 400 18.5px/1.72 var(--font-text); font-optical-sizing: auto; white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; hanging-punctuation: first; }
.prose a { text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }

/* Rubric: the open paragraph gets a red rule and number in the margin. */
#paragraphs article::before {
  content: ""; position: absolute; left: calc(var(--gutter-num) - 22px); top: 18px; bottom: 22px; width: 2px; border-radius: 1px;
  background: transparent; transition: background .2s;
}
#paragraphs article.selected::before { background: var(--accent); }
#paragraphs article.selected .para-ref a { color: var(--accent-ink); font-weight: 650; }
/* Highlighter: passages the selected answer drew on. */
#paragraphs article.retrieved .prose { background: linear-gradient(var(--mark-wash), var(--mark-wash)); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
#paragraphs article.retrieved .para-ref a { background: var(--mark); color: var(--mark-ink); }

#paragraphs details { margin-top: 12px; }
#paragraphs summary { width: fit-content; cursor: pointer; font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
#paragraphs summary:hover { color: var(--ink); }
.footnote { margin-top: 10px; padding-left: 14px; border-left: 1px solid var(--rule-strong); font: 15px/1.6 var(--font-text); color: var(--ink-2); white-space: pre-wrap; }
.footnote strong { display: block; margin-bottom: 2px; font: 500 11.5px var(--font-mono); color: var(--ink-3); }

.page-edge {
  display: flex; align-items: center; gap: 14px; width: calc(100% - var(--gutter-num)); margin: 20px 0 20px var(--gutter-num); padding: 6px 0;
  border: 0; background: transparent; color: var(--ink-3); font-size: 12.5px;
}
.page-edge::before, .page-edge::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
.page-edge:hover { background: transparent; color: var(--ink); }
.page-edge[hidden] { display: none; }
#sentinel { height: 1px; }
.chat-expanded .reader { padding-inline: 24px; }
.chat-expanded .prose { font-size: 17px; }

/* ---------- Volume contents: hairline rail, titles on hover ---------- */
.toc {
  --rail-x: 12px;
  grid-column: 1; grid-row: 1; justify-self: start; align-self: start; z-index: 6;
  position: sticky; top: calc(var(--masthead-h) + 28px);
  width: 28px; height: calc(100dvh - var(--masthead-h) - 56px); max-height: 1100px;
}
.toc[hidden] { display: none; }
.toc-rail { position: absolute; left: var(--rail-x); top: 0; bottom: 0; width: 1px; background: var(--rule-strong); cursor: pointer; }
.toc-rail::before { content: ""; position: absolute; inset: 0 -12px; }
.toc-progress { position: absolute; left: -0.5px; top: 0; width: 2px; height: 0; background: var(--ink-3); border-radius: 1px; }
.toc-tick { position: absolute; left: -2px; width: 5px; height: 1px; background: var(--rule-strong); transform: translateY(-.5px); }
.toc-tick-chapter { left: -3px; width: 7px; }
.toc-tick-book { left: -4px; width: 9px; height: 2px; background: var(--ink-3); }
.toc-tick.passed { background: var(--ink-3); }
.toc-tick.active { left: -4px; width: 9px; height: 2px; background: var(--ink); }
.toc-mark { position: absolute; left: -2.5px; width: 6px; height: 6px; margin-top: 2px; border-radius: 50%; background: var(--mark-line); box-shadow: 0 0 0 2px var(--paper); }
.toc-mark-open { background: var(--accent); margin-top: 9px; }

.toc-panel {
  position: absolute; left: calc(var(--rail-x) + 10px); top: -8px; width: 290px; max-height: calc(100% + 16px);
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 12px 6px 12px 0;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  font-size: 12.5px; line-height: 1.35;
  opacity: 0; visibility: hidden; transform: translateX(-6px);
  /* Linger briefly on the way out so crossing the gap from rail to panel doesn't close it. */
  transition: opacity .2s ease .12s, transform .2s ease .12s, visibility 0s linear .32s;
}
.toc:hover .toc-panel, .toc:focus-within .toc-panel {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity .18s ease, transform .18s ease, visibility 0s;
}
.toc:hover .toc-rail, .toc:focus-within .toc-rail { background: var(--ink-3); }
.toc-title { display: block; width: 100%; margin: 0 0 8px; padding: 0 14px; border: 0; background: none; text-align: left; font: italic 500 15px/1.3 var(--font-text); color: var(--ink); }
.toc-title:hover { background: none; color: var(--accent-ink); }
.toc ol { margin: 0; padding: 0; list-style: none; }
.toc li { position: relative; border-left: 2px solid transparent; }
.toc a { display: block; padding: 3px 12px; color: var(--ink-3); text-decoration: none; border-radius: 0 4px 4px 0; transition: color .15s, background .15s; }
.toc a:hover { color: var(--ink); background: var(--desk); }
.toc li.passed a { color: var(--ink-2); }
.toc li.active { border-left-color: var(--ink); }
.toc li.active a { color: var(--ink); font-weight: 600; }
.toc .toc-book a { margin-top: 12px; font-size: 10.5px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.toc .toc-chapter a { margin-top: 4px; font-size: 10.5px; font-weight: 550; letter-spacing: .06em; text-transform: uppercase; }
.toc li:first-child a { margin-top: 0; }
.toc .toc-section a { padding-left: 18px; }
.toc li.has-source > a::after, .toc li.has-open > a::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; vertical-align: middle; background: var(--mark-line);
}
.toc li.has-open > a::after { background: var(--accent); }
.toc li.has-open.has-source > a::after { box-shadow: 8px 0 0 var(--mark-line); margin-right: 8px; }
@media (prefers-reduced-motion: reduce) { .toc-panel, .toc:hover .toc-panel { transition: none; } }
@container reader (max-width: 640px) {
  .reader.has-toc .reader-layout { grid-template-columns: minmax(0, 1fr) minmax(0, calc(680px + var(--gutter-num))) minmax(0, 1fr); column-gap: 0; }
  .toc { grid-column: 2; margin-left: -28px; }
}
@container reader (max-width: 400px) { .toc { display: none; } }
.reader:not(.has-toc) .toc { display: none; }

/* ---------- Chat: a research notebook beside the text ---------- */
.chat {
  --gutter: 24px;
  position: sticky; top: var(--masthead-h); height: calc(100dvh - var(--masthead-h)); min-height: 480px;
  display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain;
  background: var(--desk); border-left: 1px solid var(--rule);
}
.chat-expanded .chat { --gutter: max(clamp(24px, 3vw, 48px), calc((100% - 860px) / 2)); }
.chat-header {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px var(--gutter);
  background: color-mix(in srgb, var(--desk) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chat-header h2 { font: italic 500 18px/1 var(--font-text); }
.question-count { font: 11.5px var(--font-mono); color: var(--ink-3); white-space: nowrap; }
.clear-button { padding: 3px 8px; border: 0; background: transparent; font-size: 12px; color: var(--ink-3); }
.clear-button:hover { color: var(--ink); background: var(--paper); }
.question-count[hidden], .clear-button[hidden] { display: none; }
.header-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.header-actions .icon-button:hover, .header-actions .icon-button[aria-expanded="true"] { background: var(--paper); }
.expand-toggle[aria-expanded="true"] svg { transform: scaleX(-1); }
/* Phone-only controls; the layout below 720px shows them. */
.chat-close, .chat-open { display: none; }
.method-picker { position: relative; }
.method-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 300px; padding: 14px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.method-menu[hidden] { display: none; }
.method-menu select { width: 100%; }
.method-menu p { margin: 10px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.method-menu p:empty { display: none; }

.messages { flex: 1 0 auto; padding: 8px var(--gutter) 24px; }
.welcome { padding: 28px 0 8px; }
.welcome h3 { margin: 0 0 10px; font: 500 26px/1.2 var(--font-text); letter-spacing: -.015em; }
.welcome p { max-width: 46ch; margin: 0 0 24px; font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }
.examples { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--rule-strong); }
.examples li { border-bottom: 1px solid var(--rule-strong); }
.example {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 12px 2px;
  border: 0; border-radius: 0; background: transparent; text-align: left; font: 400 15px/1.4 var(--font-text); color: var(--ink);
}
.example::after { content: "→"; font-family: var(--font-ui); color: var(--ink-3); transition: transform .15s, color .15s; }
.example:hover { background: transparent; color: var(--accent-ink); }
.example:hover::after { color: var(--accent-ink); transform: translateX(3px); }

/* ---------- Inquiries ---------- */
.inquiry { position: relative; padding: 22px 0 26px; overflow-wrap: anywhere; }
.inquiry + .inquiry { border-top: 1px solid var(--rule-strong); }
.inquiry-divider { display: none; }
.inquiry.active::before { content: ""; position: absolute; left: calc(var(--gutter) * -1 + 8px); top: 26px; bottom: 30px; width: 3px; border-radius: 2px; background: var(--mark-line); }
.inquiry-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; font-size: 11.5px; color: var(--ink-3); }
.inquiry-number { font: 500 11.5px var(--font-mono); color: var(--ink-3); }
.inquiry-question { margin: 0 0 16px; font: 500 19px/1.35 var(--font-text); letter-spacing: -.01em; white-space: pre-wrap; }
.inquiry.failed .inquiry-meta::after { content: "Failed"; color: var(--danger); font-weight: 600; }
.content { font-size: 14.5px; line-height: 1.65; white-space: pre-wrap; }
.inquiry.failed .content { color: var(--danger); }
.evidence-label { margin-top: 20px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.references { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.references:empty { display: none; }
.references a {
  padding: 3px 7px; border-radius: 4px; font: 500 12px/1.3 var(--font-mono); text-decoration: none;
  color: var(--mark-ink); background: var(--mark); transition: box-shadow .15s;
}
.references a:hover { box-shadow: 0 0 0 1px var(--mark-line); }
.references a[aria-current] { box-shadow: 0 0 0 2px var(--accent); }
.revise { margin-top: 18px; padding: 0; border: 0; background: transparent; font-size: 12.5px; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.revise:hover { background: transparent; color: var(--ink); text-decoration-color: currentColor; }
.chat-expanded .content { font-size: 15.5px; line-height: 1.7; max-width: 72ch; }
.chat-expanded .inquiry-question { font-size: 22px; }

.research-trace { margin-top: 16px; font-size: 12.5px; overflow-wrap: anywhere; }
.research-trace summary { width: fit-content; cursor: pointer; font-weight: 500; color: var(--ink-2); }
.research-trace summary:hover { color: var(--ink); }
.research-trace > p { margin: 8px 0 0; font: 11.5px var(--font-mono); color: var(--ink-3); }
.research-trace ol { margin: 10px 0 0; padding: 0 0 0 14px; list-style: none; border-left: 1px solid var(--rule-strong); }
.research-trace li { margin: 0 0 8px; }
.research-trace p { margin: 4px 0; color: var(--ink-2); }
.research-trace small { font: 11px var(--font-mono); color: var(--ink-3); }

/* ---------- Loading: what is happening, and how long it has taken ---------- */
.inquiry-loader { white-space: normal; }
.loader-status { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; font-size: 12.5px; color: var(--ink-2); }
.loader-time { font: 12px var(--font-mono); color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- Composer ---------- */
.composer { position: sticky; bottom: 0; z-index: 2; padding: 12px var(--gutter) 16px; background: linear-gradient(transparent, var(--desk) 16px); }
#chat-form { padding: 10px 10px 8px 14px; background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
#chat-form:focus-within { border-color: var(--ink-3); }
#chat-form textarea { display: block; width: 100%; min-height: 0; max-height: 200px; padding: 2px 0 8px; border: 0; border-radius: 0; background: transparent; box-shadow: none; resize: none; overflow-y: auto; font-size: 14.5px; line-height: 1.45; }
#send { flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin-left: 4px; padding: 0; border: 0; border-radius: var(--radius); background: var(--button); color: var(--on-button); }
#send:hover:not(:disabled) { background: var(--accent); color: #0d0c0b; }
.composer-meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; line-height: 1.4; color: var(--ink-3); }
.method-current { min-width: 0; margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); }

/* Level-of-effort dial: a three-stop segmented control with signal bars. */
.effort { display: inline-flex; flex: none; padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--desk); }
.effort[hidden] { display: none; }
.effort button {
  position: relative; padding: 2px 8px 2px 19px; border: 0; border-radius: 4px; background: transparent;
  font-size: 11.5px; font-weight: 500; color: var(--ink-3); line-height: 1.5;
}
.effort button:hover { background: transparent; color: var(--ink); }
.effort button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(40 32 20 / .08); }
.effort button::before {
  content: ""; position: absolute; left: 7px; top: 50%; width: 8px; height: 9px; transform: translateY(-50%);
  background: linear-gradient(currentColor, currentColor) 0 100% / 2px 3px no-repeat,
              linear-gradient(currentColor, currentColor) 3px 100% / 2px 6px no-repeat,
              linear-gradient(currentColor, currentColor) 6px 100% / 2px 9px no-repeat;
  opacity: .4;
}
.effort button[data-effort="low"]::before { background: linear-gradient(currentColor, currentColor) 0 100% / 2px 3px no-repeat, linear-gradient(var(--rule-strong), var(--rule-strong)) 3px 100% / 2px 6px no-repeat, linear-gradient(var(--rule-strong), var(--rule-strong)) 6px 100% / 2px 9px no-repeat; }
.effort button[data-effort="medium"]::before { background: linear-gradient(currentColor, currentColor) 0 100% / 2px 3px no-repeat, linear-gradient(currentColor, currentColor) 3px 100% / 2px 6px no-repeat, linear-gradient(var(--rule-strong), var(--rule-strong)) 6px 100% / 2px 9px no-repeat; }
.effort button[aria-checked="true"]::before { opacity: 1; }
.chat-expanded #chat-form textarea { font-size: 15.5px; }

/* ---------- Rendered Markdown in answers ---------- */
.content.markdown { white-space: normal; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 .8em; white-space: pre-line; }
.markdown h3, .markdown h4 { margin: 1.3em 0 .45em; font-family: var(--font-text); font-weight: 600; line-height: 1.3; }
.markdown h3 { font-size: 1.12em; }
.markdown h4 { font-size: 1em; color: var(--ink-2); }
.markdown ul, .markdown ol { margin: 0 0 .8em; padding-left: 1.35em; }
.markdown li { margin: .3em 0; padding-left: .15em; }
.markdown li > ul, .markdown li > ol { margin: .3em 0 0; }
.markdown li::marker { color: var(--ink-3); }
.markdown ol > li::marker { font: 500 .88em var(--font-mono); }
.markdown strong { font-weight: 650; }
.markdown code { padding: .1em .35em; border-radius: 4px; background: var(--paper); border: 1px solid var(--rule); font: .88em var(--font-mono); }
.markdown pre { margin: 0 0 .8em; padding: 10px 12px; overflow-x: auto; border-radius: var(--radius); background: var(--paper); border: 1px solid var(--rule); }
.markdown pre code { padding: 0; border: 0; background: none; white-space: pre; }
/* Quotations from Peirce appear in the text face, like the reader. */
.markdown blockquote { margin: 0 0 .8em; padding: .1em 0 .1em 1em; border-left: 2px solid var(--rule-strong); color: var(--ink-2); font: 1.04em/1.6 var(--font-text); }
.markdown hr { margin: 1.2em 0; border: 0; border-top: 1px solid var(--rule); }
.markdown .table-wrap { margin: 0 0 .8em; overflow-x: auto; }
.markdown table { width: 100%; border-collapse: collapse; font-size: .93em; }
.markdown th, .markdown td { padding: 6px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.markdown th { font-weight: 600; color: var(--ink-2); }
.markdown a[data-ref] { padding: 0 .2em; border-radius: 3px; font: 500 .9em var(--font-mono); color: var(--mark-ink); background: var(--mark); text-decoration: none; }
.markdown a[data-ref]:hover { box-shadow: 0 0 0 1px var(--mark-line); }

/* Retry buttons shown beside error messages. */
.retry { margin-left: 4px; padding: 1px 10px; font-size: 12.5px; vertical-align: baseline; }
.method-current .retry { padding: 0 8px; font-size: 11.5px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 380px; }
  .brand-sub, .version { display: none; }
  .volume select { width: 220px; }
}
@media (max-width: 720px) {
  :root { --gutter-num: 0px; }
  .masthead { position: static; height: auto; flex-wrap: wrap; gap: 10px 16px; padding: 12px 16px; }
  .reader-tools { order: 3; width: 100%; }
  .volume { flex: 1; }
  .volume select { width: 100%; }
  .lookup input { width: 130px; }
  .lookup-key { display: none; }
  .workspace, .workspace.chat-expanded { display: flex; flex-direction: column; }
  .reader { padding: 24px 16px 40px; }
  #paragraphs article { display: block; }
  #paragraphs article::before { left: -10px; top: 14px; }
  #paragraphs .para-ref { flex-direction: row; align-items: baseline; gap: 10px; margin-bottom: 6px; padding: 0; }
  .prose { font-size: 17.5px; }
  .page-edge { width: 100%; }
  .reader { padding-bottom: 104px; }
  .inquiry.active::before { left: -10px; }
  .expand-toggle { display: none; }
  /* The chat is a full-screen panel over the text, opened with the floating Ask button. */
  .chat {
    position: fixed; inset: 0; z-index: 30; height: auto; min-height: 0; border: 0; --gutter: 16px;
    visibility: hidden; transform: translateY(24px); opacity: 0;
    transition: transform .22s ease, opacity .22s ease, visibility 0s linear .22s;
  }
  .chat-mobile-open .chat { visibility: visible; transform: none; opacity: 1; transition: transform .22s ease, opacity .22s ease, visibility 0s; }
  body.chat-mobile-open { overflow: hidden; }
  .chat-header { padding-left: 6px; }
  .chat-close { display: grid; }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  #chat-form textarea { font-size: 16px; } /* 16px keeps iOS from zooming into the field. */
  .chat-open {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 25;
    display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 20px 0 16px;
    border: 0; border-radius: 999px; background: var(--button); color: var(--on-button);
    font-size: 15px; font-weight: 600; box-shadow: var(--shadow-lg);
  }
  .chat-open:hover { background: var(--button); border: 0; }
  .chat-open.has-answer::after { content: ""; width: 7px; height: 7px; margin-left: 2px; border-radius: 50%; background: var(--mark-line); }
  .chat-mobile-open .chat-open { display: none; }
}
@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .chat, .chat-mobile-open .chat { transform: none; transition: none; }
}

/* ---------- Login page ---------- */
.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--paper); }
.login { width: min(380px, 100%); }
.login-brand { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin-bottom: 24px; }
.login-card { padding: 28px 26px 26px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 6px; font: 500 26px/1.2 var(--font-text); letter-spacing: -.015em; }
.login-lede { margin: 0 0 20px; font-size: 13.5px; line-height: 1.55; color: var(--ink-2); }
.login-card label { margin-top: 14px; }
.login-card label .optional { font-weight: 400; color: var(--ink-3); }
.login-card input { width: 100%; height: 40px; }
.login-card button[type="submit"] { width: 100%; height: 40px; margin-top: 22px; border: 0; background: var(--button); color: var(--on-button); font-weight: 600; }
.login-card button[type="submit"]:hover { background: var(--accent); color: #0d0c0b; }
.login-error { margin: 0 0 4px; padding: 9px 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); font-size: 13px; }
.login-version { margin: 14px 0 0; text-align: center; font: 11px var(--font-mono); color: var(--ink-3); }

/* ---------- Opening introduction: letters flow from PEIRCE into the § mark ---------- */
body.splash-open { overflow: hidden; }
.splash {
  position: fixed; inset: 0; width: 100%; max-width: none; height: 100dvh; max-height: none;
  margin: 0; padding: 0; border: 0; overflow: hidden;
  background: linear-gradient(#f5f3ee 0 35%, #0d0c0b 35% 100%);
  color: #ebe7de; font-family: var(--font-ui);
}
.splash::backdrop { background: #0d0c0b; }
.splash-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.splash-caption {
  position: absolute; bottom: calc(clamp(40px, 5vh + 12px, 64px) + env(safe-area-inset-bottom)); left: 20px; right: 20px;
  display: flex; flex-direction: column; align-items: center;
  max-width: 640px; margin-inline: auto; text-align: center;
}
.splash-eyebrow { margin: 0 0 10px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #a39e94; }
.splash-caption h1 { margin: 0; font: italic 500 clamp(30px, 4.6vw, 46px)/1.15 var(--font-text); letter-spacing: -.02em; }
.splash-enter {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 28px; min-height: 48px; padding: 0 22px 0 26px; border: 1px solid #ebe7de; border-radius: var(--radius);
  background: #ebe7de; color: #0d0c0b; font-size: 15px; font-weight: 600;
  transition: background .15s, border-color .15s, transform .15s;
}
.splash-enter-arrow { font-size: 18px; font-weight: 400; line-height: 1; transition: transform .15s; }
.splash-enter:hover { background: #ef7658; border-color: #ef7658; color: #161513; }
.splash-enter:hover .splash-enter-arrow { transform: translateX(3px); }
.splash-enter:active { transform: translateY(1px); }
@media (prefers-reduced-motion: reduce) { .splash-enter, .splash-enter-arrow { transition: none; } .splash-enter:hover .splash-enter-arrow { transform: none; } }
.splash-enter:focus-visible { outline: 2px solid #ef7658; outline-offset: 4px; }
@media (max-height: 550px) {
  .splash-caption { bottom: calc(28px + env(safe-area-inset-bottom)); }
  .splash-eyebrow { display: none; }
  .splash-caption h1 { font-size: 24px; }
  .splash-enter { margin-top: 16px; }
}

/* ---------- The Machine register ----------
   Everything below belongs to the surfaces where you watch the corpus being
   searched, never to the surfaces where you read it. The reader keeps ink,
   rubric and highlighter; these keep the six hues, the lattice and the glow.
   Hues are assigned per manner of answering and per step, so a trace reads
   as a chord rather than a list. */

.manner { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.manner-sig { flex: none; display: block; }
.manner-name {
  font: 500 10.5px/1 var(--font-mono); letter-spacing: .07em; text-transform: uppercase;
  color: var(--manner-hue, var(--ink-2));
}
.manner-meta { font: 10.5px/1 var(--font-mono); color: var(--ink-4); }

/* One hue per manner. Set on the container; the signature inherits it. */
[data-manner="prompt-only"] { --manner-hue: var(--hue-1); }
[data-manner="naive-rag"] { --manner-hue: var(--hue-2); }
[data-manner="citation-rag"] { --manner-hue: var(--hue-3); }
[data-manner="research-agent"] { --manner-hue: var(--hue-4); }
[data-manner="hybrid-research-agent"] { --manner-hue: var(--hue-blend); }

/* The question, set as a paper sets a theorem. */
.inquiry-question {
  padding-left: 14px; border-left: 2px solid var(--rule-strong);
  font: italic 400 19px/1.45 var(--font-text); letter-spacing: 0;
}
.inquiry.active .inquiry-question { border-left-color: var(--mark-line); }

/* ---------- Researching: the sheet of assertion ----------
   A latent space drawn on a canvas: passages as points in depth, grouped into
   topics, the question at the centre with spokes to its nearest passages and
   a sphere around what was retrieved, the camera circling slowly. Decorative
   and aria-hidden: the spoken status still comes from #chat-status. */
.sheet {
  position: relative; height: 240px; margin: 4px 0 14px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: radial-gradient(90% 80% at 50% 45%, #111016 0%, #070707 75%); overflow: hidden;
}
.sheet canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sheet { cursor: crosshair; }
@media (prefers-reduced-motion: reduce) { .sheet { cursor: auto; } }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* While the machine works the page recedes; pointing at it brings it back. */
.reader { transition: opacity .6s ease; }
.workspace.researching .reader { opacity: .42; }
.workspace.researching .reader:hover, .workspace.researching .reader:focus-within { opacity: 1; }

.loader-status { justify-content: flex-start; align-items: center; }
.loader-label { flex: 1; }
.loader-sign { overflow: visible; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--manner-hue, var(--hue-4)) 55%, transparent)); }
.loader-sign path { stroke-dasharray: 1; animation: sign-draw 2.4s ease-in-out infinite; }
.loader-sign polygon { transform-box: fill-box; transform-origin: center; animation: sign-turn 8s linear infinite; }
.loader-sign polygon + polygon { animation-direction: reverse; }
.loader-sign circle { animation: pulse 1.8s ease-in-out infinite; }
@keyframes sign-draw { 0% { stroke-dashoffset: 1; } 55%, 80% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes sign-turn { to { transform: rotate(360deg); } }

/* The trace, set as a derivation: numbered, one hue per kind of step. */
.research-trace ol { counter-reset: step; }
.research-trace li { counter-increment: step; position: relative; padding-left: 22px; }
.research-trace li::before {
  content: counter(step) "."; position: absolute; left: 0; top: 0;
  font: 11px/1.5 var(--font-mono); color: var(--ink-4); font-variant-numeric: tabular-nums;
}
.research-trace .step-line { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: baseline; font: 12px/1.5 var(--font-mono); }
.research-trace .step-line strong {
  font-weight: 500; color: var(--step-hue, var(--ink-2));
  text-shadow: 0 0 10px color-mix(in srgb, var(--step-hue, transparent) 55%, transparent);
}
.research-trace .step-input { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.research-trace .step-line small { color: var(--ink-4); font-variant-numeric: tabular-nums; white-space: nowrap; }
.research-trace .step-line .step-problem { color: var(--danger); }
.research-trace li > :not(.step-line) { font-size: 12px; color: var(--ink-3); }
.research-trace li[data-step="search_corpus"] { --step-hue: var(--hue-4); }
.research-trace li[data-step="lookup_reference"] { --step-hue: var(--hue-2); }
.research-trace li[data-step="read_passage"] { --step-hue: var(--hue-5); }
.research-trace li[data-step="read_context"] { --step-hue: var(--hue-5); }

/* The panel edge catches the light of the machine behind it. Painted as a
   border image rather than a positioned pseudo-element, so the panel keeps
   its sticky positioning and the edge does not scroll with the content. */
.chat {
  border-left-color: transparent;
  border-image: linear-gradient(
    color-mix(in srgb, var(--hue-4) 45%, transparent),
    color-mix(in srgb, var(--hue-5) 45%, transparent) 32%,
    color-mix(in srgb, var(--hue-6) 45%, transparent) 62%,
    var(--rule)) 1;
}

@media (prefers-reduced-motion: reduce) {
  .loader-sign * { animation: none; }
  .loader-sign path { stroke-dashoffset: 0; }
  .reader { transition: none; }
}

@media (max-width: 720px) {
  .sheet { height: 190px; }
  .chat { border-image: none; border-left-color: var(--rule); }
}
