/* ============================================================================
   The Weirwood Network — component styles. Reads ONLY the custom properties in
   theme/tokens.css (swap the whole look by editing that one file). No colours,
   fonts, or sizes are hard-coded here.
   ========================================================================== */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(130% 100% at 50% -10%, var(--c-bg) 38%, var(--c-bg-deep) 100%);
  color: var(--c-text);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-prose);
  display: flex;
  flex-direction: column;
}

/* ---- Weirwood backdrop: token-controlled, low-contrast, behind everything --- */
.weirwood-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  opacity: var(--weirwood-opacity);
  mix-blend-mode: var(--weirwood-blend);
  /* Fuller toward the bottom, fading the top edge so it clears the header. */
  -webkit-mask-image: linear-gradient(to top, #000 0%, #000 88%, transparent 100%);
  mask-image: linear-gradient(to top, #000 0%, #000 88%, transparent 100%);
}
.weirwood-bg svg { width: min(1100px, 120vw); height: 100%; }

/* Lift real content above the backdrop. */
.site-head, .intro, .stage, .site-foot { position: relative; z-index: 1; }

/* ---- Header --------------------------------------------------------------- */
.site-head {
  border-bottom: 1px solid var(--c-border-soft);
  background: color-mix(in srgb, var(--c-bg-deep) 72%, transparent);
  backdrop-filter: blur(6px);
}
.head-inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); }
.brand-text { display: flex; flex-direction: row; align-items: baseline; gap: var(--sp-3); line-height: 1.1; }
.brand-text h1 {
  font-family: var(--font-prose);
  font-weight: 500;
  font-size: var(--fs-h1);
  letter-spacing: 0.01em;
  margin: 0;
}
.tagline {
  font-family: var(--font-prose);
  font-style: italic;
  color: var(--c-accent-soft);
  font-size: var(--fs-small);
  margin: 0;
}
/* The plain what-this-is descriptor beside the tagline. */
.site-desc {
  font-family: var(--font-ui);
  color: var(--c-text-faint);
  font-size: var(--fs-cite);
  letter-spacing: 0.02em;
  margin: 0;
}
/* Narrow screens: the header row is already tight — the descriptor is in the
   <title> too, so it drops rather than wraps the brand awkwardly. */
@media (max-width: 640px) {
  .site-desc { display: none; }
}
.head-actions { display: flex; align-items: center; gap: var(--sp-2); }
.about-toggle,
.save-toggle {
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--c-text-dim);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  transition: var(--transition);
}
.about-toggle:hover,
.save-toggle:hover:not(:disabled) { color: var(--c-text); }
.save-toggle:disabled { opacity: 0.5; cursor: not-allowed; }
.save-toggle[hidden] { display: none; }

/* ---- About view (toggled; the page itself opens straight to the chat) ----- */
.about-view {
  position: relative; z-index: 1;
  max-width: 46rem;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-7);
}
/* The header "About" button toggles `body.about-open`: swap chat for the about
   view. Driven by the body class (not [hidden]) so it beats .stage's display:grid. */
body.about-open .stage { display: none; }
body.about-open .about-view { display: block; }
.about-title {
  font-family: var(--font-prose); font-weight: 500; font-size: 1.4rem;
  color: var(--c-text); text-align: center; margin: 0 0 var(--sp-5);
}
.about-back {
  font-family: var(--font-ui); font-size: var(--fs-small); color: var(--c-text-dim);
  background: transparent; border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3); cursor: pointer; transition: var(--transition);
  margin-bottom: var(--sp-5);
}
.about-back:hover { color: var(--c-text); border-color: var(--c-accent); }

/* ---- Intro / framing (inner copy, reused inside .about-view) --------------- */
.intro {
  max-width: 60rem;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-2);
}
.intro-lead {
  /* Same size as the body paragraphs below (Matt: one font size on About). */
  font-size: var(--fs-body);
  color: var(--c-text-dim);
  margin: 0 auto;
  max-width: 46rem;
  /* Left-aligned to match the body paragraphs below — one consistent reading
     column under the centred heading (Matt: about page needs consistent formatting). */
  text-align: left;
}
.intro-lead em { font-style: italic; color: var(--c-text); }
.intro-lead strong { color: var(--c-text); font-weight: 500; }
.intro-more { max-width: 46rem; margin: var(--sp-4) auto 0; }
.intro-more summary {
  cursor: pointer;
  color: var(--c-accent-soft);
  font-size: var(--fs-small);
  text-align: center;
  list-style: none;
}
.intro-more summary::-webkit-details-marker { display: none; }
.intro-more summary::before { content: "› "; }
.intro-more[open] summary::before { content: "⌄ "; }
.intro-body {
  margin-top: var(--sp-4);
  color: var(--c-text-dim);
  /* Same size as the lead (Matt: one font size on About). */
  font-size: var(--fs-body);
}
.intro-body p { margin: 0 0 var(--sp-3); }
.intro-body strong { color: var(--c-text); font-weight: 500; }
.intro-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--c-accent-soft);
}
/* The builder's contact line — small, quiet, at the foot of the About copy. */
.about-contact {
  margin-top: var(--sp-5);
  font-size: var(--fs-small);
  color: var(--c-text-faint);
}
.about-contact a { color: var(--c-accent-soft); text-underline-offset: 3px; }
.about-contact a:hover { color: var(--c-text); }

/* ---- Stage: thread + receipts grid ---------------------------------------- */
.stage {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-7);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
  gap: var(--sp-4) var(--sp-6);
  align-items: start;
}
.thread-col { grid-column: 1; }
.receipts-col { grid-column: 2; }

/* Landing (before the first question): line the composer up with the chain-walked
   box — same top, same height — and vertically centre the input row within it. The
   `landing` class is dropped on the first question, so chat mode keeps the composer
   sticky at the bottom. */
body.landing .stage { align-content: start; align-items: stretch; }
body.landing .thread-col { gap: 0; }
body.landing .composer {
  margin-top: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
/* The note is empty until a question is asked — drop it so the input row itself
   (not the row + empty note) centres against the chain box. */
body.landing .composer-note { display: none; }
@media (max-width: 860px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .thread-col, .receipts-col { grid-column: 1; }
  /* Prose first on every screen (Matt): the conversation leads, the chain follows below it. */
  .thread-col { order: -1; }
  .receipts-col { order: 1; }
}

/* ---- Thread column -------------------------------------------------------- */
.thread-col { min-width: 0; display: flex; flex-direction: column; gap: var(--sp-4); }
.thread { display: flex; flex-direction: column; gap: var(--sp-5); }

.msg { max-width: var(--maxw-reading); }
.msg-role {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
  letter-spacing: 0.04em;
  margin-bottom: var(--sp-2);
}
.msg.user { align-self: flex-end; max-width: 38rem; }
.msg.user .bubble {
  background: var(--c-bubble-user);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  color: var(--c-text);
}
.msg.user .msg-role { text-align: right; }

/* Bloodraven speaks on the ground itself — serif prose, no bubble chrome. */
.msg.bot .bubble {
  background: var(--c-bubble-bot);
  font-family: var(--font-prose);
  font-size: 1.32rem;   /* tuned in the font lab for Spectral */
  line-height: 1.72;
  color: var(--c-text);
  padding: 0 var(--sp-1);
  white-space: pre-wrap;
}
.msg.bot .bubble blockquote {
  margin: var(--sp-3) 0;
  padding: var(--sp-2) var(--sp-4);
  border-left: 2px solid var(--c-accent-deep);
  color: var(--c-text-dim);
  font-style: italic;
}
.msg.bot.streaming .bubble::after {
  content: "▏";
  color: var(--c-accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- Composer ------------------------------------------------------------- */
.composer {
  position: sticky;
  bottom: var(--sp-4);
  margin-top: var(--sp-2);
  /* Near-opaque so streamed prose never bleeds through the chip box behind it. */
  background: color-mix(in srgb, var(--c-bg) 97%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3);
  box-shadow: var(--shadow);
}
.examples { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.chip {
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--c-accent-soft);
  background: var(--c-accent-faint);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  transition: var(--transition);
}
.chip:hover { border-color: var(--c-accent); color: var(--c-text); }
/* Persona switch — pick the answer voice (loremaster default / bloodraven). */
.persona-switch { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-2); }
.persona-label {
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint);
  letter-spacing: 0.05em; text-transform: uppercase;
}
.persona-opt {
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-dim);
  background: transparent; border: 1px solid var(--c-border); border-radius: var(--radius-pill, 999px);
  padding: 2px var(--sp-2); cursor: pointer; transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.persona-opt:hover { color: var(--c-text); border-color: var(--c-accent); }
.persona-opt.is-active {
  color: var(--c-bg); background: var(--c-accent); border-color: var(--c-accent);
}
.persona-opt:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* Theory toggle — opt into the fan-theory layer (default OFF). A pill switch +
   a quiet spoiler note, styled to sit unobtrusively above the composer row. */
.theory-switch { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin: 0 0 var(--sp-2); }
.theory-toggle {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  background: transparent; border: none; padding: 0; cursor: pointer;
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-dim);
}
.theory-track {
  position: relative; flex: none; width: 30px; height: 16px;
  background: var(--c-border); border-radius: 999px; transition: background 0.15s;
}
.theory-knob {
  position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  background: var(--c-bg); border-radius: 50%; transition: transform 0.15s, background 0.15s;
}
.theory-toggle.is-on .theory-track { background: var(--c-accent); }
.theory-toggle.is-on .theory-knob { transform: translateX(14px); }
.theory-toggle:hover { color: var(--c-text); }
.theory-toggle:hover .theory-track { border-color: var(--c-accent); }
.theory-toggle.is-on .theory-label { color: var(--c-text); }
.theory-toggle:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; border-radius: var(--radius); }
.theory-note {
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint);
  font-style: italic;
}

.composer-row { display: flex; gap: var(--sp-2); align-items: flex-end; }
.input {
  flex: 1;
  resize: none;
  max-height: 9rem;
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  transition: var(--transition);
}
.input:focus { outline: none; border-color: var(--c-accent); box-shadow: var(--ring); }
.input::placeholder { color: var(--c-text-faint); }
.send {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  font-weight: 500;
  color: var(--c-bg-deep);
  background: var(--c-accent);
  border: none;
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-5);
  cursor: pointer;
  transition: var(--transition);
}
.send:hover { background: var(--c-accent-soft); }
.send:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-note { margin: var(--sp-2) 0 0; min-height: 1.1em; font-size: var(--fs-cite); color: var(--c-text-faint); }

/* ---- Receipts panel ------------------------------------------------------- */
.receipts-col {
  position: sticky;
  top: var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  /* The rail itself scrolls (S194) — a receipt-heavy turn stays within the
     viewport instead of pushing the sticky panel far past it. */
  max-height: calc(100vh - var(--sp-4) * 2);
  overflow-y: auto;
}
.receipts-col:has(.receipts:empty) { display: none; } /* nothing to show → no empty panel */
/* Stacked below the prose on small screens, the rail joins the page's own
   scroll — no sticky, no inner scrollbox (the desktop rail-scroll would
   double-scroll here). Sits AFTER the base rule above so it wins the cascade. */
@media (max-width: 860px) {
  .receipts-col { position: static; max-height: none; overflow: visible; }
}
.receipts { display: flex; flex-direction: column; gap: var(--sp-3); }
.receipts-empty { color: var(--c-text-faint); font-style: italic; font-family: var(--font-prose); font-size: var(--fs-small); }

/* The rail header — names the panel once, and carries the ONE global
   affordance hint (every node name in every card below opens its dossier). */
.rail-head {
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--c-border-soft);
}
.rail-title {
  display: block;
  font-family: var(--font-prose);
  font-weight: 500;
  font-size: 1.02rem;
  color: var(--c-text);
}
.rail-sub {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-accent-soft);
  letter-spacing: 0.03em;
}

/* A receipt card. */
.card {
  background: var(--c-bg);
  border: 1px solid var(--c-border-soft);
  border-radius: var(--radius);
  padding: var(--sp-3);
}
.card-kind {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}
.card-kind .ti, .card-kind .glyph { color: var(--c-accent-soft); }
.card-kind .kind-count { margin-left: auto; text-transform: none; color: var(--c-text-faint); }
.card-title { font-family: var(--font-prose); font-size: 1rem; color: var(--c-text); }
.card-type {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
}
.card-identity { color: var(--c-text-dim); font-size: var(--fs-small); margin-top: var(--sp-2); }
.card-more {
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
}

/* ---- The node chip: the ONE clickable-node atom (S194) --------------------
   Shared by the search/list/theme/neighbors/resolve cards. The dotted accent
   underline is the "this opens a record" signal, everywhere the same. */
.node-chip {
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--c-text);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 2px var(--sp-2);
  line-height: 1.35;
  cursor: pointer;
  text-decoration: underline dotted var(--c-accent-soft);
  text-underline-offset: 3px;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.node-chip:hover, .node-chip:focus-visible {
  border-color: var(--c-accent);
  background: var(--c-surface-2);
  text-decoration-style: solid;
  outline: none;
}
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* resolve trace — a thin chip line. */
.resolve-line { font-size: var(--fs-small); color: var(--c-text-dim); }
.resolve-line + .resolve-line { margin-top: var(--sp-1); }
.resolve-line code { font-family: var(--font-mono); color: var(--c-accent-soft); font-size: 0.85em; }
.resolve-phrase { font-family: var(--font-prose); font-style: italic; color: var(--c-text-dim); margin-bottom: var(--sp-2); }
.resolve-meta { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); }

/* ---- Passages consulted (search_quotes receipts) --------------------------- */
.search-hit { margin-top: var(--sp-3); }
.search-hit:first-of-type { margin-top: var(--sp-2); }
.search-hit-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); }
.search-hit .bookquote { margin-top: var(--sp-1); }
.search-blurb {
  margin: var(--sp-1) 0 0;
  color: var(--c-text-dim);
  font-size: var(--fs-small);
  line-height: 1.55;
}

/* ===== The family tree — a generational ladder of the lineage ============== */
.ft-card { background: var(--c-surface); border-color: var(--c-border); }
.ft-root-label {
  font-family: var(--font-prose);
  font-size: var(--fs-body);
  color: var(--c-text);
  margin-bottom: var(--sp-3);
}
.ft-count { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); }

/* Each generation is a labelled band; a hairline down the left ties the bands
   into one descending ladder. */
.ft-gen {
  position: relative;
  padding: 0 0 var(--sp-3) var(--sp-4);
  border-left: 1px solid var(--c-border);
}
.ft-gen:last-child { padding-bottom: 0; }
.ft-gen::before {
  content: "";
  position: absolute;
  left: -3px; top: 0.55em;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--c-border);
}
.ft-gen-label {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
  letter-spacing: 0.04em;
  margin-bottom: var(--sp-2);
}
.ft-gen-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }

/* A person: a chip. A node opens a dossier (button); a bare name the graph
   holds no node for renders as dimmed plain text. */
.ft-node {
  font-family: var(--font-ui);
  font-size: var(--fs-small);
  color: var(--c-text);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 3px var(--sp-2);
  line-height: 1.3;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
button.ft-node:hover, button.ft-node:focus-visible {
  border-color: var(--c-accent);
  background: var(--c-surface-2);
  outline: none;
}
.ft-node.hub {
  border-color: var(--c-accent);
  background: var(--c-accent-faint);
  color: var(--c-text);
  font-weight: 600;
}
.ft-node.no-node {
  color: var(--c-text-faint);
  background: transparent;
  border-style: dashed;
  cursor: default;
}
/* A married couple, joined by the ⚭ glyph. */
.ft-couple { display: inline-flex; align-items: center; gap: var(--sp-1); }
.ft-marr { color: var(--c-accent-soft); font-size: 0.85em; padding: 0 1px; }

/* ===== The family-tree DIAGRAM — an SVG descendant chart, in the chat ====== */
.ft-diagram-wrap {
  margin: 0 0 var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  overflow: hidden;
}
.ft-diagram-cap {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-dim);
  letter-spacing: 0.03em;
  padding: var(--sp-3) var(--sp-3) 0;
}
.ft-diagram-sub { color: var(--c-text-faint); }
.ft-diagram-cap { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1); }
.ft-diagram-scroll { overflow: auto; padding: var(--sp-3); max-height: 62vh; }
.ft-diagram { display: block; }

.ft-expand-btn {
  margin-left: auto;
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint);
  background: transparent; border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  padding: 1px var(--sp-2); cursor: pointer; transition: var(--transition);
}
.ft-expand-btn:hover, .ft-expand-btn:focus-visible { color: var(--c-text); border-color: var(--c-accent); outline: none; }

/* --- Family-tree modal: the inline chart, popped out full-size --- */
/* Below the node dossier (20) so clicking a name inside the tree modal opens the
   dossier ON TOP of it. Uses the #id so it beats the later `.dossier-overlay`
   z-index:20 rule (equal-specificity source order would otherwise win). */
#tree-modal { z-index: 19; }
body.tree-modal-open { overflow: hidden; }
.ft-modal-card {
  position: relative;
  width: min(92vw, 1200px); max-height: 90vh;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.ft-modal-card .ft-diagram-cap { padding: 0; padding-right: var(--sp-5); }
.ft-modal-scroll { overflow: auto; flex: 1 1 auto; min-height: 0; }

.ft-link { stroke: var(--c-border); stroke-width: 1.5; }

.ft-dnode .ft-dnode-box {
  fill: var(--c-bg);
  stroke: var(--c-border);
  stroke-width: 1;
  transition: fill var(--transition), stroke var(--transition);
}
/* Prominence tiers (ported from web/dev/family-tree-fixture.html). Marquee kin
   read first; minor historical filler recedes. tier-* is set in buildTreeSVG
   from prominence = degree + 4*quoteCount. The .hub root rule below wins over
   these (equal specificity, later in source) so the queried person always pops. */
.ft-dnode.tier-major .ft-dnode-box {
  fill: var(--c-accent-faint);
  stroke: var(--c-accent);
  stroke-width: 1.75;
}
.ft-dnode.tier-major .ft-dnode-text .ln1 { font-weight: 700; fill: var(--c-text); }
.ft-dnode.tier-notable .ft-dnode-box {
  fill: var(--c-surface-2);
  stroke: var(--c-accent-deep);
}
.ft-dnode.tier-minor .ft-dnode-box { fill: var(--c-bg); stroke: var(--c-border-soft); }
.ft-dnode.tier-minor .ft-dnode-text { fill: var(--c-text-faint); }
.ft-prom-dot { fill: var(--c-accent); }

.ft-dnode[role="button"] { cursor: pointer; }
.ft-dnode[role="button"]:hover .ft-dnode-box,
.ft-dnode[role="button"]:focus-visible .ft-dnode-box {
  stroke: var(--c-accent);
  fill: var(--c-surface-2);
  outline: none;
}
.ft-dnode.hub .ft-dnode-box { stroke: var(--c-accent); fill: var(--c-accent-faint); stroke-width: 1.5; }
.ft-dnode.no-node .ft-dnode-box { stroke-dasharray: 3 3; }
.ft-dnode-text {
  font-family: var(--font-ui);
  fill: var(--c-text);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
.ft-dnode-text .ln1 { font-size: 12px; }
.ft-dnode-text .ln2 { font-size: 10px; fill: var(--c-text-dim); }
.ft-dnode.hub .ft-dnode-text .ln1 { font-weight: 600; }
.ft-dnode.no-node .ft-dnode-text { fill: var(--c-text-faint); }

/* When a diagram leads the answer, the persona prose collapses to a thin
   caption underneath (a lineage query wants the chart, not the narration). */
.msg.bot.has-diagram .bubble {
  font-size: var(--fs-small);
  color: var(--c-text-dim);
}

/* ===== "The chain walked" — one deduped, annotated, vertical spine ========= */

.chain-header { margin-bottom: var(--sp-2); }
.chain-title { font-family: var(--font-prose); font-weight: 500; font-size: 1.15rem; margin: 0; }
.chain-sub { font-size: var(--fs-cite); color: var(--c-text-faint); margin: 2px 0 0; }
/* (The per-card "click any node" hint retired S194 — the rail header carries it.) */

.chain-card { background: var(--c-bg); }

/* The two story-time sections — antecedents then consequences — each labelled so a
   downstream consequence never reads as a cause (S185). */
.chain-section { margin-top: var(--sp-3); }
.chain-section + .chain-section { margin-top: var(--sp-4); }
.chain-section-label {
  font-family: var(--font-mono); font-size: var(--fs-cite); letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--c-text-faint); margin: 0 0 var(--sp-1);
}
/* Inside a section the flow's own top margin is redundant with the label gap. */
.chain-section .chain-flow.spine { margin-top: var(--sp-1); }

.chain-flow.spine {
  display: flex; flex-direction: column; gap: 2px; margin-top: var(--sp-3);
  /* bounded — a long chain scrolls inside the card, never runs far past the chat */
  max-height: 62vh; overflow-y: auto;
}

/* node = a clickable card showing its name + type (+ degree badge). The whole
   node is a button → opens its dossier; reset the native button chrome. */
.spine-node {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: var(--sp-2) var(--sp-3);
  cursor: pointer; transition: var(--transition);
}
.spine-node:hover, .spine-node:focus-visible { border-color: var(--c-accent); background: var(--c-surface-2); outline: none; }
.node-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-2); }
.spine-node .node-name {
  font-family: var(--font-prose); font-size: var(--fs-body); color: var(--c-text); line-height: 1.25;
  /* Same "this opens a record" signal the node chips carry (S194 affordance). */
  text-decoration: underline dotted var(--c-accent-soft);
  text-underline-offset: 3px;
}
.spine-node:hover .node-name, .spine-node:focus-visible .node-name { text-decoration-style: solid; }
.node-type { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); letter-spacing: 0.03em; }
.node-degree { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-accent-soft); }
.spine-node.hub { border-color: var(--c-accent); background: var(--c-surface-2); }
.spine-node.terminal { border-left: 3px solid var(--c-accent); }
/* a node already shown above collapses to a slim back-reference (still clickable) */
.spine-node.repeat {
  background: transparent; border: none; border-left: 2px solid var(--c-border);
  border-radius: 0; padding: var(--sp-1) 0 var(--sp-1) var(--sp-3); opacity: 0.75;
}
.spine-node.repeat:hover { opacity: 1; border-left-color: var(--c-accent); }
.spine-node.repeat .node-name { font-family: var(--font-ui); font-size: var(--fs-small); color: var(--c-text-dim); }

/* edge = a left-accent block with the evidence quote + cite always visible */
.spine-edge {
  border-left: 2px solid var(--et-color, var(--c-edge-default));
  margin-left: var(--sp-4); padding: var(--sp-2) 0 var(--sp-2) var(--sp-3);
  transition: opacity var(--transition);
}
.spine-edge-head { display: flex; align-items: center; gap: var(--sp-2); }
.tier-inline { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); }
.spine-quote {
  font-family: var(--font-prose); font-style: italic; color: var(--c-text-dim);
  font-size: var(--fs-small); line-height: 1.5; margin: var(--sp-2) 0 var(--sp-1);
}
.spine-cite { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); }

/* Hover-peek: a node hover lights the edges it touches and dims the rest. */
.chain-flow.spine.has-hot .spine-edge:not(.hot) { opacity: 0.3; }
.chain-flow.spine .spine-edge.hot { border-left-width: 4px; }
.spine-node.hot { border-color: var(--c-accent); box-shadow: var(--ring); }

/* --- Preconditions: the ENABLES web behind one progressive-disclosure toggle --- */
.pre-wrap { margin-top: var(--sp-3); padding-top: var(--sp-2); border-top: 1px solid var(--c-border-soft); }
.pre-toggle {
  font-family: var(--font-mono); font-size: var(--fs-cite); letter-spacing: 0.03em;
  color: var(--c-edge-enables); background: transparent;
  border: 1px dashed color-mix(in srgb, var(--c-edge-enables) 60%, transparent);
  border-radius: 999px; padding: var(--sp-1) var(--sp-3); cursor: pointer; transition: var(--transition);
}
.pre-toggle:hover { color: var(--c-text); border-color: var(--c-edge-enables); }
.pre-list { margin-top: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); opacity: 0.82; }
.pre-row { border-left: 2px solid var(--c-edge-enables); padding-left: var(--sp-3); margin-left: var(--sp-1); }
.pre-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); }
.pre-node {
  font: inherit; font-family: var(--font-prose); font-size: var(--fs-small); color: var(--c-text-dim);
  background: transparent; border: none; border-bottom: 1px dotted var(--c-border); padding: 0; cursor: pointer;
  transition: var(--transition);
}
.pre-node:hover { color: var(--c-text); border-bottom-color: var(--c-accent); }
.pre-quote {
  font-family: var(--font-prose); font-style: italic; color: var(--c-text-faint);
  font-size: var(--fs-small); line-height: 1.5; margin: var(--sp-2) 0 var(--sp-1);
}

/* --- Node dossier: a live /api/node lookup, in a modal over the page --- */
.dossier-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: var(--sp-5);
  background: color-mix(in srgb, var(--c-bg-deep) 90%, transparent);
  backdrop-filter: blur(5px);
}
/* The class sets display:flex, which would otherwise beat the UA [hidden] rule —
   keep the overlay truly gone (no stray backdrop dimming the page) until opened. */
.dossier-overlay[hidden] { display: none; }
body.dossier-open { overflow: hidden; }
.dossier-card {
  position: relative;
  width: min(34rem, 100%); max-height: 82vh; overflow-y: auto;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: var(--sp-5);
}
.dossier-close {
  position: absolute; top: var(--sp-3); right: var(--sp-3);
  font-family: var(--font-ui); font-size: var(--fs-small); line-height: 1;
  color: var(--c-text-faint); background: transparent; border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); padding: var(--sp-1) var(--sp-2); cursor: pointer; transition: var(--transition);
}
.dossier-close:hover { color: var(--c-text); border-color: var(--c-accent); }
.dossier-body { padding-right: var(--sp-4); }
.dossier-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.dossier-head h3 { font-family: var(--font-prose); font-weight: 500; font-size: 1.3rem; color: var(--c-text); margin: 0; }
.dossier-type { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); letter-spacing: 0.03em; }
.dossier-slug { font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint); }
.dossier-identity { color: var(--c-text-dim); font-size: var(--fs-small); line-height: 1.6; margin: 0 0 var(--sp-4); }
/* Wiki-sourced identity prose, labelled so its provenance is explicit (characters
   are from the books; this reference blurb is from the wiki). */
.dossier-wiki { margin-bottom: var(--sp-3); }
.dossier-wiki .dossier-identity {
  margin: 0; padding-left: var(--sp-3);
  border-left: 2px solid var(--c-border);
  font-style: italic;
}
.dossier-sub {
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint);
  letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: var(--sp-1);
}
.dossier-loading, .dossier-empty { color: var(--c-text-faint); font-style: italic; font-family: var(--font-prose); font-size: var(--fs-small); margin: 0; }
.node-name { color: var(--c-text); font-size: var(--fs-small); }
.edge-label {
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  letter-spacing: 0.05em;
  color: var(--et-color, var(--c-edge-default));
  border: 1px solid var(--et-color, var(--c-edge-default));
  border-radius: 999px;
  padding: 1px var(--sp-2);
}
.cite {
  display: inline-block;
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
}

/* node-quote container inside a read_node / dossier card */
.quotes { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-3); }

/* Narrative-arc + extra body-section prose in the dossier (fetched from the
   per-node static asset; absent when the node has none — see node.ts, and
   app.js narrativeArcSection/proseSection). */
.dossier-arc { margin-top: var(--sp-4); }
.dossier-arc .arc-text + .arc-text { margin-top: var(--sp-2); }
.arc-block { margin-top: var(--sp-2); }
.arc-heading {
  font-family: var(--font-mono); font-size: var(--fs-cite); color: var(--c-text-faint);
  letter-spacing: 0.03em; margin-bottom: var(--sp-1);
}
.arc-text { color: var(--c-text-dim); font-size: var(--fs-small); line-height: 1.6; margin: 0; }

/* ---- The unified book-quote — used EVERYWHERE (Bloodraven's answer prose, the
   dossier, chain edges, preconditions, neighbours) so a quote looks the same
   wherever it appears: an italic serif line, then "— speaker, ASOS Arya 11". --- */
.bookquote { display: block; margin: var(--sp-2) 0 0; }
.bookquote .bq-text { font-family: var(--font-prose); font-style: italic; color: var(--c-text-dim); font-size: var(--fs-small); line-height: 1.55; }
.bookquote .bq-attr { display: block; margin-top: var(--sp-1); font-family: var(--font-ui); font-style: normal; font-size: var(--fs-cite); color: var(--c-text-faint); }
/* dossier + search-hit cards carry the accent rail (the old quote-row look) */
.quotes .bookquote, .search-hit .bookquote { border-left: 2px solid var(--c-accent-deep); padding-left: var(--sp-3); }
/* In Bloodraven's answer the quote is a pull-quote — its own line, brighter, larger. */
.msg.bot .bubble .bookquote {
  border-left: 2px solid var(--c-accent-deep);
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-4);
  margin: var(--sp-3) 0;
}
.msg.bot .bubble .bookquote .bq-text { font-size: 1.02rem; color: var(--c-text); font-style: italic; }

/* ---- Prose entity links (S194 tier 1) — a tool-surfaced name in the answer
   opens its dossier. Styled as marked-up TEXT, not a button: the prose keeps
   its reading rhythm, the dotted accent underline is the shared signal. */
.prose-link {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted var(--c-accent-soft);
  text-underline-offset: 3px;
  transition: color var(--transition);
}
.prose-link:hover, .prose-link:focus-visible {
  color: var(--c-accent-soft);
  text-decoration-style: solid;
  outline: none;
}

/* ---- Connections (neighbors) — unified on the chip + visible-evidence
   pattern (S194; the ▶ disclosure rows are retired). Each row: the connected
   node as a dossier chip, evidence beneath it exactly as the spine shows it. */
/* Bounded like the chain spine — a well-connected node (100+ edges) scrolls
   inside its card instead of swallowing the whole rail. */
.neigh-card { max-height: 62vh; overflow-y: auto; }
.neigh-card .neigh-group { margin-top: var(--sp-3); }
.neigh-group > .edge-label { margin-bottom: var(--sp-1); }
.neigh-rows { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-2); }
.neigh-row {
  border-left: 2px solid var(--et-color, var(--c-edge-default));
  padding: var(--sp-1) 0 var(--sp-1) var(--sp-3);
  margin-left: var(--sp-1);
}
.neigh-row-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); }
.neigh-row .bookquote { margin-top: var(--sp-1); }

/* ---- Status / failure-mode lines ------------------------------------------ */
.status-line {
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-small);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-dim);
}
.status-line.warn { border-color: var(--c-edge-triggers); }
.status-line.error { border-color: var(--c-accent-deep); color: var(--c-text); }
.status-line .status-head { font-weight: 500; color: var(--c-text); display: block; margin-bottom: 2px; }

/* ---- Footer --------------------------------------------------------------- */
.site-foot {
  text-align: center;
  padding: var(--sp-5);
  font-size: var(--fs-cite);
  color: var(--c-text-faint);
  border-top: 1px solid var(--c-border-soft);
}

/* ---- Edge-type colour mapping (set as --et-color on the link) ------------- */
.et-causes    { --et-color: var(--c-edge-causes); }
.et-triggers  { --et-color: var(--c-edge-triggers); }
.et-motivates { --et-color: var(--c-edge-motivates); }
.et-enables   { --et-color: var(--c-edge-enables); }
.et-default   { --et-color: var(--c-edge-default); }

/* inline edge-type tags used in the intro copy */
.et { font-family: var(--font-mono); font-size: 0.82em; padding: 0 4px; border-radius: 3px; }
.et.et-causes    { color: var(--c-edge-causes); }
.et.et-triggers  { color: var(--c-edge-triggers); }
.et.et-motivates { color: var(--c-edge-motivates); }
.et.et-enables   { color: var(--c-edge-enables); }
