/* humandatacollective.org — whitepaper stylesheet
   Layout: single-page book viewer (center) + right sidebar (TOC + comments)
   Animations: CSS 3-D perspective page-flip on navigation
*/

:root {
  --ink:        #1a1a1a;
  --ink-soft:   #2a2a2a;
  --muted:      #6a6a6a;
  --rule:       #e2dfd6;
  --rule-soft:  #ececec;
  --bg:         #f5f2ea;
  --paper:      #ffffff;
  --accent:     #1f6b45;
  --accent-2:   #185539;
  --accent-soft:#e8efe9;
  --warn:       #b04a2a;
  --highlight:  rgba(255, 222, 102, 0.55);
  --highlight-active: rgba(255, 196, 0, 0.70);
  --link:       #1f4d7a;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.04), 0 1px 1px rgba(0,0,0,0.03);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-page:0 8px 40px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.05);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Hoefler Text",
           "Apple Garamond", Georgia, serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
           "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --doc-width:    720px;
  --toc-w:        232px;
  --sidebar-w:    312px;
  --doc-pad-x:    62px;
  --doc-pad-y:    1.6rem;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.paper-body {
  /* Normal document flow: navbar (sticky), the paper layout sized to
     fill the visible viewport, then the footer below — so users can
     scroll past the page viewer down to the footer. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: auto;
  overflow: visible;
}
body.paper-body > .layout {
  height: calc(100vh - 3.2rem);
  flex: 0 0 auto;
}

a { color: var(--link); text-decoration: none; border-bottom: 1px solid rgba(31,77,122,0.25); }
a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ======================================================================
   Top bar
   ====================================================================== */

.appbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(245, 242, 234, 0.96);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
.appbar-inner {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 1.1rem;
  max-width: calc(var(--doc-width) + var(--sidebar-w) + 6rem);
  margin: 0 auto;
  font-size: 0.84rem;
}
.appbar .brand {
  font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--accent);
  border-bottom: none; font-size: 0.88rem; flex-shrink: 0;
}
.appbar .doctitle {
  color: var(--ink-soft);
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 0.82rem;
}
.appbar .doctitle small { color: var(--muted); margin-left: 0.35rem; }
.appbar nav a {
  margin-left: 0.75rem;
  border-bottom: none;
  color: var(--muted); font-family: var(--sans); font-size: 0.82rem;
}
.appbar nav a:hover { color: var(--ink); }
.appbar .status {
  font-size: 0.72rem; color: var(--muted); flex-shrink: 0;
}
.appbar .status .dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-right: 0.25rem; vertical-align: middle;
}

/* ======================================================================
   Master layout: 2-column grid (page + sidebar) inside body's middle row
   ====================================================================== */

.layout {
  /* Lives in body's 1fr row, so its height is whatever's left after
     navbar + footer-bar.  min-height:0 lets the inner grid shrink. */
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, var(--doc-width)) var(--sidebar-w);
  grid-template-rows: 1fr;
  gap: 0 1.5rem;
  width: 100%;
  max-width: calc(var(--toc-w) + var(--doc-width) + var(--sidebar-w) + 5rem);
  margin: 0 auto;
  padding: 0.6rem 1rem 0;
}

/* ======================================================================
   Page viewer (center column)
   ====================================================================== */

.page-viewer {
  position: relative;
  overflow: hidden;
  min-height: 0;
  /* fills its grid cell automatically (grid-template-rows: 1fr)         */
}

/* Navigation arrows */
.page-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--rule);
  border-radius: 50%;
  width: 2.4rem; height: 2.4rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, box-shadow 0.15s, opacity 0.15s;
  color: var(--ink-soft);
}
.page-nav svg { width: 1.1rem; height: 1.1rem; }
.page-nav:hover { background: #fff; box-shadow: var(--shadow-md); color: var(--accent); }
.page-nav:disabled { opacity: 0; pointer-events: none; }
.page-nav-prev { left: 0.5rem; }
.page-nav-next { right: 0.5rem; }

/* ======================================================================
   The article / doc container
   ====================================================================== */

.doc {
  /* NOT positioned — we want .page (absolute) to position against .page-viewer */
  width: 100%;
  height: 100%;
}

.doc::selection, .doc *::selection {
  background: var(--highlight);
  color: var(--ink);
}

/* ======================================================================
   Single page cards — book animation
   ====================================================================== */

.page {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow-page);
  overflow: hidden;
  padding: var(--doc-pad-y) var(--doc-pad-x);
  display: flex;
  flex-direction: column;
  visibility: hidden;
  will-change: transform;
}

.page.page-visible {
  visibility: visible;
  transform: translateX(0);
}

.page-body {
  flex: 1;
  min-height: 0;
  overflow: hidden; /* content is paginated to fit, never scroll */
}

/* ---- PDF.js page rendering ----------------------------------------- */
.page:has(.pdf-page) {
  /* The visible "paper" is the PDF wrap itself, not the .page card, so
     the white sheet exactly matches the PDF aspect ratio and is centred. */
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}
.page:has(.pdf-page) .page-foot {
  display: none;             /* PDF already has its own page footer */
}
.page-body.pdf-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}
.pdf-page-wrap {
  position: relative;
  display: block;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow-page);
  overflow: hidden;
}
.pdf-canvas {
  display: block;
  user-select: none;
}
.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0.999;          /* selection works without showing glyphs */
  line-height: 1;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  z-index: 2;
}
.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
}
.textLayer ::selection {
  background: var(--highlight);
  color: transparent;
}
.textLayer .highlight {
  background: var(--highlight);
  border-radius: 2px;
}

.page-foot {
  flex-shrink: 0;
  margin-top: 0.6rem;
  padding-top: 0.4rem;
  text-align: center;
  font-family: var(--sans); font-size: 0.76rem;
  letter-spacing: 0.08em; color: var(--muted);
  pointer-events: none;
}
.page-foot::before { content: "\2014\2009"; }
.page-foot::after  { content: "\2009\2014"; }

/* ======================================================================
   Document typography (mirrors LaTeX article class)
   ====================================================================== */

.doc h1, .doc h2, .doc h3, .doc h4 {
  font-family: var(--serif); font-weight: 600;
  color: var(--ink); line-height: 1.22;
  scroll-margin-top: 4rem;
  letter-spacing: -0.005em;
}
.doc h1 {
  font-size: 1.7rem;
  margin: 0 0 0.9rem;
  font-weight: 700;
  letter-spacing: -0.012em;
}
.doc h2 {
  font-size: 1.18rem; margin: 1.6rem 0 0.5rem;
  padding-bottom: 0.22rem; border-bottom: 1px solid var(--rule);
}
.doc h3 { font-size: 1.02rem; margin: 1.2rem 0 0.35rem; }
.doc h4 { font-size: 0.96rem; margin: 0.95rem 0 0.25rem; font-style: italic; font-weight: 500; }
.doc p  { margin: 0 0 0.85em; text-align: justify; hyphens: auto; }
.doc p + p { text-indent: 1.4em; margin-top: -0.1em; }
.doc h1 + p, .doc h2 + p, .doc h3 + p, .doc h4 + p, .doc blockquote + p,
.doc figure + p, .doc pre + p, .doc table + p, .doc ul + p, .doc ol + p,
.doc hr + p { text-indent: 0; }
.doc blockquote {
  /* TeX \begin{quote} — indented, italic, no border */
  margin: 1.2rem 2.8rem;
  padding: 0;
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.97em;
  line-height: 1.58;
  text-align: justify;
  hyphens: auto;
}
.doc ul, .doc ol { margin: 0 0 1em 1.4rem; padding: 0; }
.doc li  { margin-bottom: 0.3rem; }
.doc hr  { border: none; border-top: 1px solid var(--rule); margin: 2rem auto; width: 44%; }
.doc code {
  font-family: var(--mono); font-size: 0.88em;
  background: #f6f3ec; padding: 0.05em 0.3em; border-radius: 3px;
}
.doc pre {
  font-family: var(--mono); font-size: 0.84em;
  background: #faf8f1; padding: 0.75rem 1rem;
  border: 1px solid var(--rule-soft); border-radius: 4px;
  overflow-x: auto;
}
.doc table {
  border-collapse: collapse; margin: 1.2rem 0; width: 100%; font-size: 0.94em;
}
.doc th, .doc td {
  border: 1px solid var(--rule); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top;
}
.doc th { background: #faf8f1; font-weight: 600; }
.doc img { max-width: 100%; }
.doc sup { font-size: 0.7em; }
.doc a { border-bottom: 1px solid rgba(31,77,122,0.22); }

/* anchored highlights */
.doc mark.cm-mark {
  background: var(--highlight); padding: 0.05em 0; border-radius: 2px;
  cursor: pointer; transition: background 0.15s;
}
.doc mark.cm-mark.active,
.doc mark.cm-mark:hover { background: var(--highlight-active); }
.doc [data-bid] { position: relative; }

/* ======================================================================
/* ======================================================================
   Sidebars (TOC left, comments right)
   ====================================================================== */

.sidebar-left,
.sidebar-right {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  scrollbar-width: thin;
  padding-bottom: 0.5rem;
}
.sidebar-left { padding-right: 0.25rem; }

/* ======================================================================
   TOC
   ====================================================================== */

.toc {
  font-family: var(--sans);
  font-size: 0.78rem;
}
.toc-inner {
  border-left: 1px solid var(--rule);
  padding: 0.25rem 0 0.6rem 0.7rem;
}
.toc-head {
  font-size: 0.62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.11em;
  color: var(--muted); margin-bottom: 0.5rem;
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { margin: 0; }
.toc-skel { color: var(--muted); font-style: italic; padding: 0.2rem 0.4rem; }
.toc-list .toc-link {
  display: flex; align-items: baseline; justify-content: space-between;
  width: 100%; text-align: left;
  font: inherit; color: var(--ink-soft);
  background: transparent; border: none;
  padding: 0.18rem 0.5rem 0.18rem 0.4rem;
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
  cursor: pointer; line-height: 1.28;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  gap: 0.5rem;
  letter-spacing: -0.005em;
}
.toc-list .toc-link:hover {
  color: var(--accent); background: rgba(31,107,69,0.05);
}
.toc-list .toc-link.active {
  color: var(--accent-2); font-weight: 600;
  border-left-color: var(--accent); background: rgba(31,107,69,0.09);
}
.toc-list .lvl-1 {
  font-weight: 600;
  margin-top: 0.55rem;
  color: var(--ink);
  font-size: 0.78rem;
}
.toc-list .lvl-1:first-child { margin-top: 0; }
.toc-list .lvl-2 { padding-left: 1rem; }
.toc-list .lvl-3 { padding-left: 1.7rem; color: var(--muted); font-size: 0.95em; }
.toc-pg {
  font-size: 0.66rem; color: var(--muted); flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
/* TOC for the paper mirrors the printed "Contents" list shape:
   group labels as plain rows, then numbered/lettered items. */
.toc-group {
  padding: 0.52rem 0.5rem 0.18rem 0.4rem;
  margin-top: 0.35rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.toc-main {
  display: inline-flex;
  align-items: baseline;
  gap: 0.38rem;
  min-width: 0;
  flex: 1;
}
.toc-idx {
  width: 1.2rem;
  flex-shrink: 0;
  text-align: right;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.toc-link.toc-major {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-soft);
  padding-left: 0.4rem;
}
.toc-link.toc-major:hover .toc-idx,
.toc-link.toc-major.active .toc-idx {
  color: var(--accent);
}
.toc-tx {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ghost-btn {
  font: inherit; font-family: var(--sans); font-size: 0.78rem;
  background: transparent; border: 1px solid var(--rule);
  color: var(--muted); padding: 0.2rem 0.55rem;
  border-radius: 3px; cursor: pointer; margin-right: 0.3rem;
  display: none;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink); }

/* ======================================================================
   Gutter (comment threads in sidebar)
   ====================================================================== */

.gutter {
  font-family: var(--sans);
  font-size: 0.86rem;
  min-height: 4rem;
}
.gutter-head {
  font-family: var(--sans);
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted); margin-bottom: 0.45rem;
}
.gutter-inner {
  border-left: 1px solid var(--rule);
  padding-left: 0.85rem;
}

.thread {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.6rem 0.75rem 0.65rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.65rem;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.thread:hover { box-shadow: var(--shadow-md); }
.thread.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31,107,69,0.15), var(--shadow-md);
}

.thread .quote {
  font-family: var(--serif); font-style: italic;
  color: var(--ink-soft); font-size: 0.8rem; line-height: 1.4;
  border-left: 2px solid var(--accent);
  padding: 0.05rem 0 0.05rem 0.5rem;
  margin-bottom: 0.45rem;
  /* show full quoted text; let it wrap naturally */
  word-break: break-word;
  white-space: pre-wrap;
}
.thread .comment {
  padding: 0.35rem 0; border-top: 1px dashed var(--rule-soft);
  overflow-wrap: break-word; word-break: break-word;
}
.thread .comment:first-of-type { border-top: none; padding-top: 0; }
.thread .who {
  font-weight: 600; color: var(--ink); font-size: 0.8rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread .who .aff { font-weight: 400; color: var(--muted); }
.thread .when { color: var(--muted); font-size: 0.68rem; margin-left: 0.35rem; }
.thread .who { display: flex; align-items: center; gap: 0.2rem; }
.thread .comment-del {
  margin-left: auto;
  background: transparent; border: 0;
  color: var(--muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 0.25rem;
  border-radius: 4px;
  opacity: 0; transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.thread .comment:hover .comment-del,
.thread.active .comment-del { opacity: 1; }
.thread .comment-del:hover {
  color: #b03a3a;
  background: rgba(176,58,58,0.08);
}
.thread .body {
  margin: 0.2rem 0 0;
  font-family: var(--serif); font-size: 0.9rem; line-height: 1.5;
  white-space: pre-wrap; color: var(--ink);
  overflow-wrap: break-word; word-break: break-word;
  max-width: 100%;
}

.thread .actions {
  margin-top: 0.4rem; display: flex; gap: 0.55rem; flex-wrap: wrap;
  font-size: 0.76rem; color: var(--muted);
}
.thread .actions button {
  font: inherit; color: inherit; border: none; background: transparent;
  padding: 0; cursor: pointer;
}
.thread .actions button:hover { color: var(--accent); }

.thread .reply,
.thread .composer {
  display: grid; gap: 0.32rem;
  margin-top: 0.5rem; padding-top: 0.5rem;
  border-top: 1px solid var(--rule-soft);
}
.thread .reply.collapsed { display: none; }

/* All form inputs inside threads: no overflow, full width */
.thread input,
.thread textarea {
  font: inherit; font-family: var(--sans); font-size: 0.83rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--rule); border-radius: 3px;
  background: #fcfaf6; color: var(--ink);
  width: 100%; min-width: 0; box-sizing: border-box;
  overflow: hidden; text-overflow: ellipsis;
}
.thread textarea {
  min-height: 6.5em; resize: vertical;
  overflow: auto; text-overflow: clip;
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.5;
}
.thread input::placeholder,
.thread textarea::placeholder { color: var(--muted); opacity: 1; font-size: 0.82rem; }
.thread input:focus,
.thread textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; background: #fff;
}
.thread .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.32rem; }
.thread .submit-row {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
}
.thread button.primary {
  font: inherit; font-family: var(--sans); font-size: 0.8rem;
  padding: 0.3rem 0.8rem;
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent); border-radius: 3px; cursor: pointer; flex-shrink: 0;
}
.thread button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.thread button.ghost {
  font: inherit; font-family: var(--sans); font-size: 0.8rem;
  padding: 0.3rem 0.55rem; background: transparent;
  border: 1px solid var(--rule); border-radius: 3px; cursor: pointer; color: var(--muted);
}
.thread button.ghost:hover { color: var(--ink); border-color: var(--ink); }
.thread .status { font-size: 0.73rem; color: var(--accent); min-height: 1em; min-width: 0; }
.thread .status.error { color: var(--warn); }

/* ======================================================================
   Floating "Comment" pill on selection
   ====================================================================== */

.float-pill {
  position: absolute; z-index: 100;
  background: var(--ink); color: #fff;
  font-family: var(--sans); font-size: 0.76rem; font-weight: 600;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  box-shadow: var(--shadow-md); cursor: pointer;
  white-space: nowrap; transform: translate(-50%, -120%);
  user-select: none; display: none; border: none;
}
.float-pill::after {
  content: ""; position: absolute; left: 50%; bottom: -5px;
  transform: translateX(-50%); width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 5px solid var(--ink);
}
.float-pill.show { display: block; }
.float-pill svg { width: 0.82em; height: 0.82em; vertical-align: -0.1em; margin-right: 0.22em; }

/* ======================================================================
   Empty / loading states
   ====================================================================== */

.gutter-empty {
  font-family: var(--sans); color: var(--muted); font-size: 0.8rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--rule); border-radius: 4px;
  background: rgba(255,255,255,0.5);
  line-height: 1.5;
}
.gutter-empty a { color: var(--muted); }

.skeleton {
  font-family: var(--sans); color: var(--muted); padding: 4rem 0; text-align: center;
}
.anon { font-style: italic; color: var(--muted); }

/* ======================================================================
   Per-page tools (Summarize button)
   ====================================================================== */

.page-tools {
  position: absolute;
  top: 0.6rem; right: 0.9rem;
  display: flex; gap: 0.4rem; font-family: var(--sans);
  z-index: 4;
}
.page-summarize {
  font: inherit; font-size: 0.72rem; color: var(--ink-soft);
  background: rgba(255,255,255,0.92); border: 1px solid var(--rule);
  border-radius: 999px; padding: 0.22rem 0.75rem;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  backdrop-filter: blur(4px);
  transition: color 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.page-summarize:hover { color: var(--accent); border-color: var(--accent); background: rgba(31,107,69,0.06); }
.page-summarize[disabled] { opacity: 0.6; cursor: progress; }

.page-summary {
  margin: 1.2rem 0 0.4rem;
  padding: 0.9rem 1rem 0.8rem;
  background: linear-gradient(180deg, #fbf6e6 0%, #f8f1d8 100%);
  border: 1px solid #e8d28a; border-radius: 5px;
  font-family: var(--sans); font-size: 0.86rem; line-height: 1.58;
  color: #3a2f10; white-space: pre-wrap; position: relative;
}
.page-summary::before {
  content: "AI Summary";
  position: absolute; top: -0.6rem; left: 0.8rem;
  background: #f5e8b5; border: 1px solid #e8d28a;
  border-radius: 999px; padding: 0.04rem 0.55rem;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: #6a5018;
}
.page-summary.error { background: #fdecea; border-color: #f3b8b1; color: #7d2421; }
.page-summary.error::before { background: #f9d4cf; border-color: #f3b8b1; color: #7d2421; content: "Error"; }

/* ======================================================================
   Diagrams (interactive SVG)
   ====================================================================== */

figure.diagram {
  margin: 1.8rem auto;
  padding: 1rem 0.5rem 0.8rem;
  text-align: center;
  border: 1px solid var(--rule-soft);
  background: #fcfaf3;
  border-radius: 6px;
  overflow: hidden;
}
figure.diagram .diagram-mount {
  display: block; width: 100%; max-width: 100%; overflow: visible;
}
figure.diagram svg.diagram-svg {
  display: block; width: 100%; height: auto; max-width: 720px; margin: 0 auto;
}
figure.diagram figcaption {
  font-family: var(--sans); font-size: 0.77rem; color: var(--muted);
  max-width: 580px; margin: 0.5rem auto 0; padding: 0 1rem;
  line-height: 1.48; text-align: justify;
}

/* Bubbles & boxes: enter animation */
figure.diagram .bubble,
figure.diagram .box {
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transform-origin: center;
  transition:
    opacity 0.5s ease var(--enter-delay, 0ms),
    transform 0.5s cubic-bezier(.2,.8,.2,1) var(--enter-delay, 0ms),
    filter 0.18s, stroke-width 0.18s;
}
figure.diagram.in-view .bubble,
figure.diagram.in-view .box { opacity: 1; transform: translateY(0) scale(1); }

figure.diagram .edge {
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  transition: stroke-dashoffset 0.85s ease 0.25s, stroke-width 0.18s, stroke 0.18s, opacity 0.18s;
  opacity: 0.85;
}
figure.diagram.in-view .edge { stroke-dashoffset: 0; }
figure.diagram .edge.return {
  stroke-dasharray: 5 4; stroke-dashoffset: 0;
  opacity: 0; transition: opacity 0.55s ease 0.9s;
}
figure.diagram.in-view .edge.return { opacity: 1; }

figure.diagram .edge-label {
  pointer-events: none; opacity: 0; transition: opacity 0.4s ease 0.65s;
}
figure.diagram.in-view .edge-label { opacity: 1; }
figure.diagram text { pointer-events: none; }

figure.diagram .bubble { cursor: default; }
figure.diagram .bubble:hover ellipse,
figure.diagram .bubble.active ellipse {
  filter: drop-shadow(0 2px 7px rgba(0,0,0,0.13)); stroke-width: 2.5;
}
figure.diagram .edge.active { stroke: var(--accent); stroke-width: 2.5; opacity: 1; }
figure.diagram .box rect { transition: filter 0.18s, stroke-width 0.18s; }
figure.diagram .box:hover rect { filter: drop-shadow(0 2px 6px rgba(0,0,0,0.10)); stroke-width: 2; }

/* ======================================================================
   Compact footer bar (always visible at bottom of app-body)
   ====================================================================== */

.docfoot-bar {
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.3rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1;
}
.docfoot-bar a { color: var(--muted); border-bottom: none; }
.docfoot-bar a:hover { color: var(--ink); }
.docfoot-bar .sep { color: var(--rule); }

/* ======================================================================
   Subscribe block (used on /updates page)
   ====================================================================== */

.subscribe {
  max-width: var(--doc-width);
  margin: 3.5rem auto 0;
  background: var(--paper);
  border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: var(--shadow-sm); padding: 1.5rem 1.7rem 1.3rem;
}
.subscribe-inner { display: grid; gap: 1rem; }
.subscribe-copy h2 {
  margin: 0 0 0.3rem; font-family: var(--serif); font-size: 1.18rem; color: var(--ink);
}
.subscribe-copy p { margin: 0; color: var(--ink-soft); font-size: 0.94rem; line-height: 1.55; }
.subscribe-form { display: grid; gap: 0.42rem; font-family: var(--sans); }
.subscribe-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.42rem; }
.subscribe-form input,
.subscribe-form textarea {
  font: inherit; font-family: var(--sans); font-size: 0.89rem;
  padding: 0.43rem 0.58rem; border: 1px solid var(--rule);
  border-radius: 3px; background: #fcfaf6; color: var(--ink); width: 100%;
}
.subscribe-form textarea { min-height: 4.2em; resize: vertical; }
.subscribe-form input::placeholder,
.subscribe-form textarea::placeholder { color: var(--muted); }
.subscribe-form input:focus,
.subscribe-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: #fff; }
.subscribe-actions { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.2rem; }
.subscribe-form button.primary {
  font: inherit; font-family: var(--sans); font-size: 0.88rem;
  padding: 0.42rem 1.1rem; background: var(--accent); color: #fff;
  border: 1px solid var(--accent); border-radius: 3px; cursor: pointer;
}
.subscribe-form button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.subscribe-status { font-size: 0.82rem; color: var(--accent); }
.subscribe-status.error { color: var(--warn); }

/* ======================================================================
   Footer
   ====================================================================== */

.docfoot {
  max-width: calc(var(--doc-width) + var(--sidebar-w) + 5rem);
  margin: 3.5rem auto 0;
  padding: 1.2rem 1.1rem;
  font-family: var(--sans); font-size: 0.76rem; color: var(--muted);
  border-top: 1px solid var(--rule);
}
.docfoot-inner { display: flex; flex-direction: column; gap: 0.45rem; }
.docfoot-copy, .docfoot-links, .docfoot-attest { line-height: 1.6; }
.docfoot a { color: var(--muted); border-bottom-color: rgba(0,0,0,0.12); }
.docfoot a:hover { color: var(--ink); }
.attest-badge {
  display: inline-block;
  background: #f7f3e8; border: 1px solid var(--rule-soft);
  border-radius: 3px; padding: 0.15rem 0.5rem;
  font-size: 0.72rem; color: var(--muted);
}
.attest-badge code { font-size: 0.9em; background: none; padding: 0; }

/* ======================================================================
   Responsive
   ====================================================================== */

/* Below 1100px: drop right sidebar into overlay; keep TOC inline */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: var(--toc-w) minmax(0, 1fr);
  }
  .sidebar-right {
    position: fixed; top: 3.2rem; right: 0; bottom: 2rem;
    width: 300px; background: var(--paper);
    border-left: 1px solid var(--rule); box-shadow: var(--shadow-md);
    padding: 0.8rem 0.7rem 1rem;
    transform: translateX(105%);
    transition: transform 0.18s ease;
    z-index: 60;
  }
  .sidebar-right.open { transform: translateX(0); }
  .ghost-btn { display: inline-block; }
}

/* Below 900px: drop TOC into overlay too */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar-left {
    position: fixed; top: 3.2rem; left: 0; bottom: 2rem;
    width: 260px; background: var(--paper);
    border-right: 1px solid var(--rule); box-shadow: var(--shadow-md);
    padding: 0.8rem 0.7rem 1rem;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    z-index: 60;
  }
  .sidebar-left.open { transform: translateX(0); }
  .page-nav-prev { left: 0.4rem; }
  .page-nav-next { right: 0.4rem; }
}

@media (max-width: 900px) {
  :root { --doc-pad-x: 1.5rem; --doc-pad-y: 1.2rem; }
  .page-nav { display: none; }
  .doc { font-size: 16.5px; }
  .doc h1 { font-size: 1.55rem; }
  .doc h2 { font-size: 1.18rem; }
  .appbar nav a:not(.always) { display: none; }
}

@media (max-width: 600px) {
  :root { --doc-pad-x: 1.3rem; --doc-pad-y: 1.5rem; }
  .subscribe { margin: 2.2rem 0.3rem 0; padding: 1.1rem 1rem; }
  .subscribe-form .row2 { grid-template-columns: 1fr; }
  figure.diagram svg.diagram-svg { max-width: 100%; }
  .thread .row2 { grid-template-columns: 1fr; }
}

/* Mobile comment drawer */
.mobile-thread-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: var(--paper); border-top: 1px solid var(--rule);
  box-shadow: 0 -4px 18px rgba(0,0,0,0.10);
  padding: 0.75rem 1rem 1rem;
  max-height: 70vh; overflow-y: auto;
  font-family: var(--sans); font-size: 0.9rem;
  transform: translateY(110%); transition: transform 0.2s ease;
  display: none;
}
.mobile-thread-drawer.open { transform: translateY(0); }
.mobile-thread-drawer .closebar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.5rem;
}
.mobile-thread-drawer .closebar button {
  font: inherit; background: transparent; border: 1px solid var(--rule);
  border-radius: 3px; padding: 0.2rem 0.6rem; color: var(--muted); cursor: pointer;
}

@media (max-width: 900px) {
  .mobile-thread-drawer { display: block; }
  .gutter { display: none; }
}

/* ======================================================================
   Footnotes
   ====================================================================== */

.doc sup.footnote-ref {
  font-size: 0.62em;
  vertical-align: super;
  margin-left: 0.1em;
}
.doc sup.footnote-ref a,
.doc a.footnote-ref {
  color: var(--accent);
  border-bottom: none;
  font-weight: 600;
  font-family: var(--sans);
  font-feature-settings: "tnum";
  padding: 0 0.15em;
}
.doc sup.footnote-ref a:hover,
.doc a.footnote-ref:hover { color: var(--accent-2); text-decoration: underline; }

.doc section.footnotes,
.doc .footnotes {
  margin-top: 2.2rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  font-size: 0.83em;
  line-height: 1.5;
  color: var(--ink-soft);
}
.doc section.footnotes ol,
.doc .footnotes ol {
  margin: 0; padding-left: 1.6rem;
}
.doc section.footnotes li,
.doc .footnotes li { margin-bottom: 0.45rem; }
.doc a.footnote-backref { font-family: var(--sans); margin-left: 0.25rem; text-decoration: none; border: none; }

/* ======================================================================
   Summarize modal
   ====================================================================== */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  opacity: 0;
  transition: opacity 0.18s ease;
}
.modal-backdrop.open {
  display: flex;
  opacity: 1;
}
.modal-card {
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28), 0 4px 16px rgba(0,0,0,0.12);
  max-width: 620px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(8px) scale(0.985);
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.25, 1);
}
.modal-backdrop.open .modal-card { transform: translateY(0) scale(1); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem 0.7rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}
.modal-head .modal-title {
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--accent-2);
}
.modal-head .modal-title::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent);
}
.modal-head .modal-page {
  font-size: 0.74rem; color: var(--muted); font-feature-settings: "tnum";
}
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 1.1rem; color: var(--muted);
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.modal-close:hover { background: rgba(0,0,0,0.05); color: var(--ink); }

.modal-body {
  padding: 1.1rem 1.2rem 1.3rem;
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink-soft);
  white-space: pre-wrap;
}
.modal-body.loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 6rem; color: var(--muted); font-style: italic;
}
.modal-body.error { color: #7d2421; }

.modal-foot {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 0.6rem 1.1rem 0.9rem;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--sans);
}
.modal-foot button {
  font: inherit; font-size: 0.78rem;
  background: transparent; border: 1px solid var(--rule);
  color: var(--ink-soft); padding: 0.3rem 0.85rem;
  border-radius: 999px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.modal-foot button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.modal-foot button:hover { color: var(--accent); border-color: var(--accent); }
.modal-foot button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* ======================================================================
   Diagram polish
   ====================================================================== */

figure.diagram {
  margin: 1.4rem auto;
  text-align: center;
}
figure.diagram .diagram-mount {
  display: inline-block;
  max-width: 100%;
}
figure.diagram svg.diagram-svg {
  max-width: 100%;
  height: auto;
}
figure.diagram figcaption {
  margin-top: 0.5rem;
  font-family: var(--sans); font-size: 0.78rem;
  color: var(--muted); line-height: 1.5;
  max-width: 92%; margin-left: auto; margin-right: auto;
  text-align: center;
}

/* ================================================================== */
/*  Open Questions page (v=21 redesign)                                */
/* ================================================================== */

body.qa-body {
  /* Match the rest of the site (paper-body / site-body) so the background
     is consistent on About, Read the paper, Threads, and Updates. */
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  height: auto;
}
body.qa-body .layout { display: block; overflow: visible; padding: 0; }
body.qa-body > main { flex: 1 0 auto; }
body.qa-body > .docfoot { flex-shrink: 0; margin-top: auto; }

.qa-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.4rem 5rem;
}

/* hero */
.qa-hero {
  padding: 2.6rem 0 1.6rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2rem;
}
.qa-hero-inner { max-width: 720px; }
.qa-eyebrow {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.9rem;
}
.qa-hero h1 {
  font-family: var(--serif);
  font-size: 2.6rem;
  font-weight: 700;
  margin: 0 0 0.7rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.qa-lede {
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 0 0 1.5rem;
  max-width: 640px;
}
.qa-stats {
  display: flex;
  gap: 1.6rem;
  font-family: var(--sans);
}
.qa-stat strong {
  display: block;
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.qa-stat span {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.3rem;
}

/* layout */
.qa-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2.2rem;
  align-items: start;
}
@media (max-width: 820px) {
  .qa-grid { grid-template-columns: 1fr; gap: 1.4rem; }
  .qa-side { position: static !important; }
}

/* sidebar */
.qa-side {
  position: sticky;
  top: 5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-family: var(--sans);
}
.qa-newbtn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(31,107,69,0.18);
  transition: background 0.15s, transform 0.05s, box-shadow 0.2s;
}
.qa-newbtn:hover { background: var(--accent-2); box-shadow: 0 8px 22px rgba(31,107,69,0.24); }
.qa-newbtn:active { transform: translateY(1px); }

.qa-side-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.85rem 0.95rem;
  box-shadow: var(--shadow-sm);
}
.qa-side-card h3 {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 0.55rem;
}
.qa-side-text {
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
}
.qa-sort {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.qa-sort-btn {
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  background: transparent;
  color: var(--ink-soft);
  border: 0;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.qa-sort-btn:hover { background: var(--accent-soft); color: var(--accent); }
.qa-sort-btn.active {
  background: var(--accent);
  color: #fff;
}
.qa-side input[type="search"] {
  width: 100%;
  font: inherit;
  font-size: 0.88rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fafaf6;
  color: var(--ink);
}
.qa-side input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

/* feed */
.qa-feed { min-width: 0; }
.qa-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.qa-empty {
  text-align: center;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.92rem;
  padding: 3rem 1rem;
  background: #fff;
  border: 1px dashed var(--rule);
  border-radius: 12px;
}

/* card */
.qa-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.1rem 1.25rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.qa-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #d6d2c5;
}
.qa-card-head {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.65rem;
}
.qa-card-headtext { flex: 1; min-width: 0; }
.qa-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.25rem;
  line-height: 1.35;
  color: var(--ink);
  margin: 0 0 0.35rem;
  letter-spacing: -0.005em;
}
.qa-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
}
.qa-meta .qa-author { color: var(--ink-soft); font-weight: 500; }
.qa-meta .qa-aff    { color: var(--muted); }
.qa-meta .qa-dot    { color: #c9c4b6; }
.qa-pill {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
}

p.qa-body, .qa-card > .qa-body, .qa-reply > .qa-body {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.8rem;
}
.qa-reply .qa-body { font-size: 0.94rem; line-height: 1.55; margin-bottom: 0.4rem; }

.qa-actions {
  display: flex;
  gap: 0.4rem;
  font-family: var(--sans);
  font-size: 0.8rem;
}
.qa-link {
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  font: inherit;
  transition: color 0.12s, background 0.12s;
}
.qa-link:hover { color: var(--accent); background: var(--accent-soft); }
.qa-link.qa-del { color: var(--muted); }
.qa-link.qa-del:hover { color: #b03a3a; background: rgba(176,58,58,0.08); }

/* avatar */
.qa-avatar {
  width: var(--av-size, 28px);
  height: var(--av-size, 28px);
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--av-bg, var(--accent));
  color: #fff;
  font-family: var(--sans);
  font-size: calc(var(--av-size, 28px) * 0.36);
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

/* replies */
.qa-replies {
  margin-top: 0.9rem;
  padding-left: 1rem;
  border-left: 2px solid var(--accent-soft);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.qa-reply {
  padding: 0.55rem 0.7rem 0.5rem;
  background: #fbfaf6;
  border-radius: 8px;
  border: 1px solid var(--rule-soft);
}
.qa-reply .qa-meta { font-size: 0.74rem; margin-bottom: 0.3rem; }
.qa-reply .qa-actions { font-size: 0.74rem; }
.qa-reply .qa-link { padding: 0.15rem 0.4rem; }

/* reply form */
.qa-reply-form {
  display: none;
  margin-top: 0.7rem;
  padding: 0.85rem 0.95rem;
  background: var(--accent-soft);
  border: 1px solid #d2e3d8;
  border-radius: 10px;
}
.qa-reply-form.open { display: block; }
.qa-reply-form textarea,
.qa-reply-form input {
  width: 100%;
  font: inherit;
  font-family: var(--serif);
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  margin-bottom: 0.5rem;
}
.qa-reply-form textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
.qa-reply-form input { font-family: var(--sans); font-size: 0.85rem; }
.qa-reply-form .qa-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0;
}
.qa-reply-form .qa-field-row input { margin-bottom: 0; }
.qa-reply-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.55rem;
}
.qa-reply-foot .qa-status { font-size: 0.78rem; color: var(--muted); margin-right: auto; }
.qa-reply-foot .qa-status.error { color: #b03a3a; }

/* shared buttons */
.qa-btn {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.84rem;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.qa-btn.primary {
  background: var(--accent);
  color: #fff;
}
.qa-btn.primary:hover { background: var(--accent-2); }
.qa-btn.primary.danger { background: #b03a3a; }
.qa-btn.primary.danger:hover { background: #8a2c2c; }
.qa-btn.primary[disabled] { opacity: 0.6; cursor: progress; }
.qa-btn.ghost {
  background: transparent;
  color: var(--ink-soft);
}
.qa-btn.ghost:hover { color: var(--ink); background: rgba(0,0,0,0.04); }

/* ================== modal (composer + dialog) ================== */
.qa-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.qa-modal[hidden] { display: none; }
.qa-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,18,22,0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.2s;
}
.qa-modal.open .qa-modal-backdrop { opacity: 1; }
.qa-modal-card {
  position: relative;
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 3rem);
  overflow: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,0.25), 0 6px 18px rgba(0,0,0,0.10);
  transform: translateY(8px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.qa-modal.open .qa-modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.qa-modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem 0.8rem;
  border-bottom: 1px solid var(--rule);
}
.qa-modal-card header h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}
.qa-x {
  background: transparent;
  border: 0;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}
.qa-x:hover { color: var(--ink); background: rgba(0,0,0,0.05); }

.qa-modal-card form { padding: 1rem 1.2rem 1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.qa-field { display: flex; flex-direction: column; gap: 0.3rem; }
.qa-field > span {
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.qa-field > span em { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; color: #b3aea0; margin-left: 0.25rem; }
.qa-field input,
.qa-field textarea {
  font: inherit;
  font-family: var(--serif);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fafaf6;
  color: var(--ink);
}
.qa-field input { font-family: var(--sans); font-size: 0.92rem; }
.qa-field textarea { min-height: 130px; resize: vertical; line-height: 1.55; }
.qa-field input:focus,
.qa-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.qa-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.qa-modal-card footer {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.85rem 1.2rem 1.05rem;
  border-top: 1px solid var(--rule);
}
.qa-modal-card form footer { padding-top: 0; border-top: 0; padding-bottom: 0; padding-left: 0; padding-right: 0; }
.qa-status { font-family: var(--sans); font-size: 0.82rem; color: var(--muted); margin-right: auto; }
.qa-status.error { color: #b03a3a; }

.qa-dialog-card { max-width: 460px; }
.qa-dialog-body {
  padding: 1rem 1.2rem 0.5rem;
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
}
.qa-dialog-input-wrap { padding: 0 1.2rem 0.5rem; }
.qa-dialog-input-wrap input {
  width: 100%;
  font: inherit;
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fafaf6;
}
.qa-dialog-input-wrap input:focus {
  outline: none; border-color: var(--accent); background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

body.qa-modal-open { overflow: hidden; }

/* toasts */
.qa-toasts {
  position: fixed;
  bottom: 1.4rem;
  right: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 300;
  pointer-events: none;
}
.qa-toast {
  font-family: var(--sans);
  font-size: 0.86rem;
  background: #2a2a2a;
  color: #fff;
  padding: 0.6rem 0.95rem;
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.18);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s, transform 0.22s;
}
.qa-toast.in  { opacity: 1; transform: translateY(0); }
.qa-toast.out { opacity: 0; transform: translateY(8px); }
.qa-toast-success { background: var(--accent); }
.qa-toast-error   { background: #b03a3a; }

/* ================================================================== */
/*  Threads list — clickable card link & thread detail                */
/* ================================================================== */

.qa-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border: 0;
  padding: 0;
  margin: 0 0 0.5rem;
}
.qa-card-link:hover { color: inherit; }
.qa-card-link:hover .qa-title { color: var(--accent); }
.qa-body-preview {
  font-family: var(--serif);
  font-size: 0.96rem;
  line-height: 1.55;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.4rem;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
a.qa-link {
  text-decoration: none;
  border-bottom: 0;
}

/* Thread detail page */
.qa-thread-page { max-width: 820px; }
.qa-back {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.84rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 0;
  margin: 1.6rem 0 1rem;
}
.qa-back:hover { color: var(--accent); }

.qa-thread-top {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.4rem 1.6rem 1.2rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.4rem;
}
.qa-thread-head {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}
.qa-thread-head-text { flex: 1; min-width: 0; }
.qa-thread-title {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 0.4rem;
}
.qa-thread-body {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.9rem;
}

/* Reddit-style nested replies */
.qa-tree { display: flex; flex-direction: column; gap: 0.6rem; }
.qa-node {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.85rem 1rem 0.7rem;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.qa-node-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.qa-node-body {
  font-family: var(--serif);
  font-size: 0.97rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.5rem;
}
.qa-node-children {
  margin-top: 0.7rem;
  margin-left: 0.6rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--accent-soft);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.qa-node.depth-2 { background: #fbfaf6; }
.qa-node.depth-3 { background: #faf8f1; }
.qa-node.depth-4,
.qa-node.depth-5,
.qa-node.depth-6 { background: #f7f4ec; }

/* ================================================================== */
/*  Sticky footer for non-paper pages                                 */
/* ================================================================== */
body.site-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: auto;
  overflow: auto;
}
body.site-body > main { flex: 1 0 auto; }
body.site-body > .docfoot { flex-shrink: 0; margin-top: auto; }

/* On article-style pages (about, updates), don't inherit the paper grid */
body.site-body .layout {
  display: block;
  grid-template-columns: none;
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.2rem 3rem;
  overflow: visible;
  min-height: 0;
}

/* Paper page no longer needs to override the dark site footer. */
body.paper-body > .docfoot:not(.site-footer) {
  margin: 0 auto;
  width: 100%;
  max-width: none;
  padding: 0.7rem 1.1rem 0.8rem;
  font-size: 0.74rem;
}
body.paper-body > .docfoot:not(.site-footer) .docfoot-inner {
  max-width: calc(var(--doc-width) + var(--sidebar-w) + 5rem);
  margin: 0 auto;
}

/* ================================================================== */
/*  PDF toolbar (zoom, search, define)                                */
/* ================================================================== */
.pdf-toolbar {
  position: absolute;
  top: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--rule);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  font-family: var(--sans);
  font-size: 0.78rem;
  backdrop-filter: blur(6px) saturate(140%);
  -webkit-backdrop-filter: blur(6px) saturate(140%);
}
.pdf-tool-group { display: flex; align-items: center; gap: 0.15rem; }
.pdf-tool-group + .pdf-tool-group { padding-left: 0.5rem; border-left: 1px solid var(--rule-soft); }
.pdf-tool-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.pdf-tool-btn:hover { background: var(--accent-soft, #ece8dc); color: var(--accent); }
.pdf-tool-num { min-width: 3.2rem; font-variant-numeric: tabular-nums; }
.pdf-tool-search input {
  appearance: none;
  border: 1px solid var(--rule);
  background: #fff;
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  font: inherit;
  width: 12rem;
  color: var(--ink);
}
.pdf-tool-search input:focus { outline: none; border-color: var(--accent); }
.pdf-search-count { font-size: 0.72rem; color: var(--muted); min-width: 2.5rem; }

/* Make room below the toolbar inside the viewer */
.page-viewer { padding-top: 2.2rem; }
.page-viewer.zoomed { overflow: auto; }

/* Annotation/link layer over PDF canvas */
.linkLayer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.linkLayer a {
  position: absolute;
  display: block;
  pointer-events: auto;
  border: 0;
  border-bottom: 1px dashed rgba(31, 77, 122, 0.45);
  background: rgba(31, 77, 122, 0.04);
  border-radius: 2px;
  transition: background 0.15s, border-color 0.15s;
}
.linkLayer a:hover {
  background: rgba(31, 77, 122, 0.14);
  border-bottom-color: var(--accent);
}

/* Search highlights inside text layer */
.textLayer .search-hit {
  background: rgba(255, 213, 79, 0.55);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(180, 130, 0, 0.35);
}
.textLayer .search-hit-active {
  background: rgba(255, 152, 0, 0.7);
}

/* ======================================================================
   PDF toolbar: search results dropdown + define popover (v=25)
   ====================================================================== */

.pdf-tool-search { position: relative; }

.pdf-search-results {
  position: absolute;
  top: 100%; left: 0; right: 0;
  margin-top: 6px;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.14);
  max-height: 360px;
  overflow: auto;
  z-index: 50;
  padding: 0.4rem;
  font-family: var(--sans);
  font-size: 0.78rem;
}
.pdf-search-page {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0.5rem 0.5rem 0.2rem;
  border-top: 1px solid var(--rule-soft, #ece8dc);
}
.pdf-search-page:first-child { border-top: 0; padding-top: 0.2rem; }
.pdf-search-hit {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
  line-height: 1.4;
  font: inherit;
}
.pdf-search-hit:hover, .pdf-search-hit:focus-visible {
  background: #f4f1e9;
  outline: none;
}
.pdf-search-hit mark {
  background: rgba(255, 213, 79, 0.55);
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
.pdf-search-more, .pdf-search-empty {
  padding: 0.3rem 0.5rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-style: italic;
}

/* Define popover (auto on single-word selection) */
.define-popover {
  position: absolute;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
  padding: 0.7rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink);
  max-width: 340px;
  line-height: 1.4;
}
.def-head { font-size: 0.95rem; margin-bottom: 0.2rem; }
.def-phon { color: var(--muted); font-size: 0.78rem; margin-left: 0.3rem; font-style: italic; }
.def-loading { color: var(--muted); font-style: italic; font-size: 0.75rem; margin-left: 0.3rem; }
.def-pos {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent, #8a5a00);
  margin-top: 0.45rem;
  margin-bottom: 0.1rem;
}
.def-def { margin: 0.1rem 0; }
.def-def.def-empty { color: var(--muted); font-style: italic; }
.def-foot { margin-top: 0.55rem; font-size: 0.74rem; }
.def-foot a { color: var(--muted); border-bottom-color: rgba(0,0,0,0.12); }
.def-foot a:hover { color: var(--ink); }

/* Threads/Q&A footer: match the unified site background. */
body.qa-body > .docfoot {
  background: var(--bg);
  border-top-color: rgba(0, 0, 0, 0.08);
}

/* ======================================================================
   Zoom: when zoomed in, the page should grow with content and the
   viewer should scroll. (v=26 fix for content cut off at bottom.)
   ====================================================================== */
.page-viewer.zoomed {
  overflow: auto;
  padding: 0.6rem;
}
.page-viewer.zoomed .page {
  position: relative;
  inset: auto;
  height: auto;
  min-height: calc(100% - 1.2rem);
  overflow: visible;
  margin: 0 auto;
  width: max-content;
  max-width: none;
  visibility: visible;
  transform: none;
}
.page-viewer.zoomed .page:not(.page-visible) { display: none; }
.page-viewer.zoomed .pdf-page-wrap { margin: 0 auto; }
/* When the user zooms beyond the default fit, let the centre column claim
   any unused horizontal space so the larger paper has room to breathe
   before it has to scroll. The TOC and sidebar widths are pinned, so the
   surrounding layout doesn't shift. */
body.zoom-expand .layout {
  grid-template-columns: var(--toc-w) minmax(0, 1fr) var(--sidebar-w);
  max-width: none;
  padding-left: 1rem;
  padding-right: 1rem;
}
/* When zoomed, the viewer becomes the scroll container and any
   absolutely-positioned children (toolbar, nav arrows) would scroll
   away with the content. Pin them to the viewport instead — JS sets
   the explicit top/left/right values so they track the viewer's bbox. */
.page-viewer.zoomed .pdf-toolbar,
.page-viewer.zoomed .page-nav {
  position: fixed;
}

/* Threads aside: ensure sticky pin works (parent scroll context = html). */
html { scroll-behavior: smooth; }
body.qa-body .qa-side { align-self: start; }

/* Lower the comments-column breakpoint so the gutter only collapses on
   true mobile widths, not when DevTools is open. */

/* ======================================================================
   Site footer (v=30) — same paper background as the rest of the site,
   separated only by a hairline rule. Light, calm, ignorable.
   ====================================================================== */
.site-footer.docfoot {
  background: var(--bg);
  color: var(--ink-soft, var(--muted));
  font-family: var(--sans);
  font-size: 0.86rem;
  line-height: 1.55;
  padding: 0;
  margin: 3.2rem 0 0;
  max-width: none;
  border-top: 1px solid var(--rule);
}
body.qa-body > .site-footer.docfoot,
body.site-body > .site-footer.docfoot,
body.paper-body > .site-footer.docfoot {
  background: var(--bg);
  border-top: 1px solid var(--rule);
}
.site-footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.4rem 1.6rem 1.6rem;
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) 2.4fr;
  gap: 2.6rem;
}
.site-footer-brand { display: flex; flex-direction: column; gap: 0.6rem; }
.site-footer-logo {
  font-family: var(--serif, Georgia, serif);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 0;
  width: max-content;
}
.site-footer-logo:hover { color: var(--accent); }
.site-footer-tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  max-width: 32ch;
  line-height: 1.55;
}
.site-footer-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.8rem;
}
.site-footer-col h4 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink);
  margin: 0 0 0.7rem;
}
.site-footer-col ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.site-footer-col a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 0;
  transition: color 0.12s ease;
}
.site-footer-col a:hover { color: var(--accent); }
.site-footer-bottom {
  border-top: 1px solid var(--rule);
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.9rem 1.6rem 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.74rem;
  color: var(--muted);
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .site-footer-inner {
    grid-template-columns: 1fr;
    gap: 1.6rem;
    padding: 2rem 1.2rem 1.2rem;
  }
  .site-footer-cols { gap: 1.4rem; }
  .site-footer-bottom { padding: 0.8rem 1.2rem 1rem; }
}

body.paper-body > .site-footer.docfoot,
body.qa-body > .site-footer.docfoot,
body.site-body > .site-footer.docfoot {
  border-top: 1px solid var(--rule);
}

/* ======================================================================
   Threads page redesign (v=28)
   ====================================================================== */
.threads-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 2.6rem 1.4rem 3rem;
}
.threads-hero { margin-bottom: 2rem; }
.threads-eyebrow {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent, #1f6b45);
  margin-bottom: 0.7rem;
}
.threads-hero h1 {
  font-family: var(--serif, Georgia, serif);
  font-size: 2.2rem;
  margin: 0 0 0.7rem;
  line-height: 1.15;
  color: var(--ink);
}
.threads-lede {
  margin: 0 0 1.4rem;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink-soft, #514d42);
  max-width: 60ch;
  line-height: 1.6;
}
.threads-stats {
  display: flex;
  gap: 1.6rem;
  margin-top: 1.2rem;
}
.threads-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-family: var(--sans);
}
.threads-stat strong {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.threads-stat span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.threads-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.threads-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.threads-sort {
  display: inline-flex;
  background: #f4f1e9;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.threads-sort .qa-sort-btn {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.82rem;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.threads-sort .qa-sort-btn:hover { color: var(--ink); }
.threads-sort .qa-sort-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.threads-search input[type="search"] {
  font: inherit;
  font-family: var(--sans);
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  color: var(--ink);
  width: 200px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.threads-search input[type="search"]:focus {
  outline: none;
  border-color: var(--accent, #1f6b45);
  box-shadow: 0 0 0 3px rgba(31,107,69,0.12);
}

@media (max-width: 600px) {
  .threads-page { padding: 1.6rem 1rem 2rem; }
  .threads-hero h1 { font-size: 1.7rem; }
  .threads-toolbar { flex-direction: column; align-items: stretch; }
  .threads-toolbar-right { justify-content: space-between; }
  .threads-search input[type="search"] { width: 100%; }
}

/* ======================================================================
   Thread → GitHub handoff (v=29)
   ====================================================================== */
.qa-handoff {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin: 0.9rem 0 0.4rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.85rem;
}
.qa-handoff-label {
  color: var(--muted);
  font-size: 0.78rem;
  margin-right: 0.3rem;
}
.qa-handoff-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #1c1a16;
  color: #fff;
  border: 0;
  border-bottom: 0;
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s ease, transform 0.05s ease;
}
.qa-handoff-btn:hover { background: #36322a; color: #fff; border-bottom: 0; }
.qa-handoff-btn:active { transform: translateY(1px); }
.qa-handoff-btn svg { flex: 0 0 auto; }

/* ======================================================================
   GitHub tracker (Updates page) — v=34
   ====================================================================== */
.gh-track {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
.gh-track-head h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  margin: 0 0 0.4rem;
  color: var(--ink);
}
.gh-track-head p {
  margin: 0 0 1.2rem;
  color: var(--ink-soft, var(--muted));
  font-size: 0.95rem;
  line-height: 1.55;
}
.gh-track-actions {
  display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.gh-btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 500;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.gh-btn:hover { border-color: var(--accent); color: var(--accent); }
.gh-btn.primary {
  background: #1c1a16; color: #fff; border-color: #1c1a16;
}
.gh-btn.primary:hover { background: #36322a; color: #fff; border-color: #36322a; }
.gh-count {
  display: inline-block; min-width: 1.8em; text-align: center;
  padding: 0.05rem 0.45rem; border-radius: 999px;
  background: rgba(0,0,0,0.08); font-size: 0.78rem; font-weight: 600;
  color: inherit;
}
.gh-btn.primary .gh-count { background: rgba(255,255,255,0.18); }
.gh-track-feed {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.6rem;
}
@media (max-width: 720px) { .gh-track-feed { grid-template-columns: 1fr; } }
.gh-feed-col h3 {
  font-family: var(--sans);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 0.6rem;
}
.gh-feed-col ul { list-style: none; margin: 0; padding: 0; }
.gh-feed-col li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.86rem;
  line-height: 1.5;
}
.gh-feed-col li:last-child { border-bottom: 0; }
.gh-feed-col a { color: var(--ink); border-bottom: 0; }
.gh-feed-col a:hover { color: var(--accent); }

/* ======================================================================
   Mobile gate (v=37)
   The interactive paper experience is desktop-only. On narrow viewports
   we hide the layout entirely and show a full-screen splash directing
   readers to the PDF or to come back on a larger screen.
   ====================================================================== */
.mobile-gate { display: none; }

@media (max-width: 820px) {
  body.paper-body > .layout,
  body.paper-body > .site-footer,
  body.paper-body > .mobile-thread-drawer,
  body.paper-body > #summaryModal,
  body.paper-body > #definePopover { display: none !important; }

  body.paper-body { overflow: hidden; height: 100vh; }

  .mobile-gate {
    display: flex;
    position: fixed;
    inset: 3.2rem 0 0;
    background: var(--bg);
    z-index: 40;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1.4rem 2rem;
    text-align: center;
    overflow-y: auto;
  }
  .mobile-gate-inner {
    max-width: 28rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
  }
  .mobile-gate h1 {
    font-family: var(--serif);
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    line-height: 1.25;
  }
  .mobile-gate p {
    font-family: var(--sans);
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--ink-soft);
    margin: 0;
  }
  .mobile-gate-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
    margin-top: 0.6rem;
  }
  .mobile-gate-btn {
    display: inline-block;
    font-family: var(--sans);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
  }
  .mobile-gate-btn.ghost {
    background: transparent;
    color: var(--accent-2);
    border-color: var(--rule);
  }
  .mobile-gate-foot {
    margin-top: 0.4rem;
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--muted);
  }
  .mobile-gate-foot a { color: var(--muted); }
}


/* ======================================================================
   Glossary & Index page (gx-*) and Contributors page (contrib-*)
   ====================================================================== */

.gx-doc { font-family: var(--serif); }
.gx-doc h1 { font-size: 2.1rem; margin-bottom: 0.3rem; }
.gx-doc h2 {
  font-size: 1.18rem; margin: 2rem 0 0.7rem;
  padding-bottom: 0.25rem; border-bottom: 1px solid var(--rule);
}
.gx-lede {
  font-size: 1rem; color: var(--ink-soft); line-height: 1.6;
  margin: 0.4rem 0 1.4rem; max-width: 64ch;
}
.gx-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #faf8f1;
  margin: 0.6rem 0 1.6rem;
  font-family: var(--sans);
  position: sticky; top: 3.2rem; z-index: 5;
  backdrop-filter: blur(6px);
}
.gx-toolbar input[type="search"] {
  flex: 1 1 220px; min-width: 180px;
  font: inherit; font-size: 0.92rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 4px; background: #fff; color: var(--ink);
}
.gx-toolbar input[type="search"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31,107,69,0.15);
}
.gx-tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.gx-tab {
  font: inherit; font-family: var(--sans); font-size: 0.82rem;
  background: transparent; color: var(--muted);
  border: 1px solid var(--rule); border-radius: 4px;
  padding: 0.35rem 0.7rem; cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.gx-tab:hover { color: var(--ink); border-color: var(--ink-soft); }
.gx-tab.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.gx-count {
  font-family: var(--sans); font-size: 0.78rem; color: var(--muted);
  margin-left: auto;
}

.gx-section { margin: 1.4rem 0 2.2rem; }
.gx-list { margin: 0; padding: 0; list-style: none; }

/* Glossary terms (definition list) */
dl.gx-list { display: block; }
dl.gx-list .gx-entry {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule-soft);
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: 0.4rem 1.2rem;
  align-items: baseline;
}
dl.gx-list .gx-entry:last-child { border-bottom: none; }
dl.gx-list dt {
  font-family: var(--serif); font-weight: 700;
  color: var(--ink); font-size: 1rem;
}
dl.gx-list dd {
  margin: 0; color: var(--ink-soft); line-height: 1.55; font-size: 0.96rem;
}

/* People / orgs lists */
.gx-people-list { display: flex; flex-direction: column; }
.gx-people-list .gx-entry {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule-soft);
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  grid-template-areas:
    "name desc"
    "name links";
  gap: 0.25rem 1.2rem;
  align-items: baseline;
}
.gx-people-list .gx-entry:last-child { border-bottom: none; }
.gx-people-list .gx-entry > strong {
  grid-area: name;
  font-family: var(--serif); font-weight: 700;
  color: var(--ink); font-size: 1rem;
}
.gx-people-list .gx-entry > span:not(.gx-links) {
  grid-area: desc;
  color: var(--ink-soft); line-height: 1.55; font-size: 0.96rem;
}
.gx-people-list .gx-entry > .gx-links {
  grid-area: links;
  display: flex; flex-wrap: wrap; gap: 0.45rem 0.95rem;
  font-family: var(--sans); font-size: 0.8rem;
  margin-top: 0.25rem;
}
.gx-people-list .gx-entry > .gx-links a {
  border-bottom: 1px dotted rgba(31,77,122,0.4);
  color: var(--link);
}
.gx-people-list .gx-entry > .gx-links a:hover {
  color: var(--accent); border-bottom-color: var(--accent);
}

.gx-foot {
  margin-top: 2.6rem; padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans); font-size: 0.86rem; color: var(--muted);
}

/* Contributors page */
.contrib-stats {
  display: flex; gap: 1.5rem; flex-wrap: wrap;
  margin: 0.4rem 0 1.4rem;
  padding: 0.9rem 1.1rem;
  background: #faf8f1;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-family: var(--sans);
}
.contrib-stat { display: flex; flex-direction: column; }
.contrib-stat strong {
  font-family: var(--serif); font-size: 1.7rem; color: var(--ink);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.contrib-stat span {
  font-size: 0.74rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-top: 0.25rem;
}
.contrib-sub {
  font-family: var(--sans); font-size: 0.88rem; color: var(--muted);
  margin: -0.3rem 0 0.9rem;
}
.contrib-list { margin: 0; padding: 0; list-style: none; }
.contrib-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--sans);
}
.contrib-row:last-child { border-bottom: none; }
.contrib-row.is-anon .contrib-name code {
  font-size: 0.88rem; padding: 0.1em 0.4em;
  background: #f1ede2; border-radius: 3px; color: var(--ink-soft);
}
.contrib-id { display: flex; flex-direction: column; min-width: 0; }
.contrib-name {
  font-family: var(--serif); font-weight: 600; color: var(--ink); font-size: 1rem;
}
.contrib-aff { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.contrib-meta {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 0.8rem; color: var(--muted); white-space: nowrap;
}
.contrib-bits { color: var(--ink-soft); }
.contrib-when { font-size: 0.74rem; margin-top: 0.15rem; }

.contrib-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.7rem; margin: 0; padding: 0; list-style: none;
}
.contrib-card {
  border: 1px solid var(--rule);
  border-radius: 6px; background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.contrib-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.contrib-card-link {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 0.85rem;
  font-family: var(--sans); color: var(--ink);
  border-bottom: none;
}
.contrib-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--rule-soft); flex-shrink: 0;
}
.contrib-login { font-weight: 600; font-size: 0.92rem; }
.contrib-commits { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

.contrib-empty {
  padding: 1.4rem 0; color: var(--muted);
  font-family: var(--sans); font-style: italic; font-size: 0.92rem;
}

@media (max-width: 720px) {
  dl.gx-list .gx-entry,
  .gx-people-list .gx-entry {
    grid-template-columns: 1fr;
    grid-template-areas: "name" "desc" "links";
  }
  .contrib-row { flex-direction: column; align-items: flex-start; }
  .contrib-meta { align-items: flex-start; }
}
