/* PLAIT.tech — the PLAIT viewer (marketing/DESIGN_CONTRACT.md §2.5; FLAGSHIP_SITE_MODEL.md §6; RESOURCE_MODEL.md §6–§7).
   One stylesheet for everything the viewer module (src/utils/viewerHtml.js) draws: the overlay frame, the standalone page,
   full screen, the shelf view, the side sheet and the drawer, and the document surface whose body is the shared block
   renderer's output (src/utils/blocksHtml.js). Tokens only, on --unit. Shared with the app: import it wherever the same
   markup is mounted.

   The anatomy (the viewer restructured, MD-34 ruled 2026-09-30): the BAR is ← Back · the KIND (icon + word, the title under
   it, the set as a quiet control that opens the drawer) · the kind's one primary action · More · Full screen · Close, with a
   hairline progress line under it; the BODY is the Resource at its measure (the only scroll in the overlay) and, when the
   document has enough headings, the On this page rail (pinned, collapsible). Related and Previous · Next follow the document.
   No boxes: rails are text on the surface. A Template reads on a sheet; a Prompt opens on its copy block. */

/* ── The frame (OVERLAY): a dialog above the page, on the canvas width, below the header ── */
body.viewer-open { overflow: hidden; }
.viewer { --viewer-bar-h: calc(56 * var(--unit)); position: fixed; inset: var(--header-h) 0 0; z-index: var(--z-content-overlay); display: grid; grid-template-columns: minmax(var(--gutter), 1fr) minmax(0, var(--canvas-w)) minmax(var(--gutter), 1fr); align-items: stretch; padding: var(--space-4) 0; background: var(--scrim); }
.viewer-panel { grid-column: 2; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-layer); overflow: hidden; }

/* ── The bar, ONE row: ← Back · kind · title · set · primary · More · Full screen · Close (round forty-three: the two-row ident read as a second header) ── */
.viewer-bar { position: relative; flex: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-4); padding: var(--space-1) var(--space-3) var(--space-1) var(--space-3); border-bottom: 1px solid var(--line); min-height: var(--viewer-bar-h); }
.viewer-back { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control); padding: 0 var(--space-3) 0 var(--space-2); border-radius: var(--radius-full); font-size: var(--text-small); font-weight: 600; color: var(--ink-muted); text-decoration: none; white-space: nowrap; }
.viewer-back:hover { color: var(--brand-dark); background: var(--surface-soft); }
.viewer-back .back-arrow { color: var(--brand); }
.viewer-ident { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.viewer-kind { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-label); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--brand); white-space: nowrap; }
.viewer-kind .kind-icon { display: inline-flex; width: calc(16 * var(--unit)); height: calc(16 * var(--unit)); }
.viewer-kind .kind-icon svg { width: 100%; height: 100%; }
.viewer-kind .kind-type { color: var(--ink-faint); font-weight: 500; }
.viewer-set { flex: none; display: inline-flex; align-items: center; gap: var(--space-1); min-height: 24px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-full); background: transparent; font: inherit; font-size: var(--text-label); font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-muted); white-space: nowrap; cursor: pointer; }
.viewer-set::after { content: '▾'; color: var(--ink-faint); }
.viewer-set:hover { color: var(--brand-dark); background: var(--surface-soft); }
.viewer-set .muted { color: var(--ink-faint); }
.viewer-title { flex: 0 1 auto; min-width: 0; display: block; font-size: var(--text-small); font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-nav { display: flex; align-items: center; gap: var(--space-1); }
.viewer-nav a, .viewer-nav button, .viewer-nav summary { display: inline-flex; align-items: center; gap: var(--space-2); min-height: calc(36 * var(--unit)); padding: 0 var(--space-3); border-radius: var(--radius-full); border: 1px solid transparent; background: transparent; font: inherit; font-size: var(--text-small); font-weight: 600; color: var(--ink-muted); white-space: nowrap; text-decoration: none; cursor: pointer; transition: color var(--dur-hover) ease, background-color var(--dur-hover) ease; list-style: none; }
.viewer-nav a:hover, .viewer-nav button:hover, .viewer-nav summary:hover { color: var(--brand-dark); background: var(--surface-soft); }
.viewer-nav .viewer-action.primary { color: var(--white); background: var(--brand); border-color: var(--brand); }
.viewer-nav .viewer-action.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--white); }
.viewer-nav .viewer-prev::before { content: '←'; color: var(--brand); }
.viewer-nav .viewer-next::after { content: '→'; color: var(--brand); }
.viewer-more { position: relative; }
.viewer-more > summary::-webkit-details-marker { display: none; }
.viewer-more > summary::after { content: '▾'; color: var(--ink-faint); }
.viewer-more[open] > summary { color: var(--ink); background: var(--surface-soft); }
.more-menu { position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: var(--z-popover); min-width: calc(220 * var(--unit)); display: flex; flex-direction: column; padding: var(--space-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-layer); }
.more-item { display: flex; align-items: center; min-height: var(--control); padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; font: inherit; font-size: var(--text-small); font-weight: 500; color: var(--ink); text-align: left; text-decoration: none; cursor: pointer; }
.more-item:hover { background: var(--surface-soft); color: var(--brand-dark); }
.viewer-nav .viewer-full, .viewer-nav .viewer-close, .sheet-head .viewer-close { width: var(--control); height: var(--control); min-height: var(--control); padding: 0; justify-content: center; border: 1px solid var(--line); border-radius: var(--radius-full); color: var(--ink); background: transparent; text-decoration: none; display: inline-flex; align-items: center; flex: none; }
.viewer-nav .viewer-full { border-color: transparent; color: var(--ink-muted); }
.viewer-nav .viewer-full[aria-pressed="true"] { color: var(--brand-dark); background: var(--surface-soft); }
.viewer-nav .viewer-close { margin-left: var(--space-2); }
.viewer-nav .viewer-full svg, .viewer-nav .viewer-close svg, .sheet-head .viewer-close svg { width: calc(16 * var(--unit)); height: calc(16 * var(--unit)); }
.viewer-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--brand); transform-origin: 0 50%; transform: scaleX(var(--p, 0)); pointer-events: none; }
.viewer-body { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: var(--space-6) var(--space-6) var(--space-8); }

/* ── FULL SCREEN: the frame takes the viewport; the rail hides; the bar keeps its controls ── */
.viewer.is-full { inset: 0; padding: 0; background: var(--surface); }
.viewer.is-full .viewer-panel { border: 0; border-radius: 0; box-shadow: none; }
.viewer.is-full .surface-aside { display: none; }
.viewer.is-full .surface-grid.has-aside { grid-template-columns: minmax(0, 1fr); }

/* ── The shelf view: a context's documents inside the frame ── */
.shelf-view { max-width: var(--measure-doc); margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-4); }
.shelf-head { display: flex; flex-direction: column; gap: var(--space-2); }
.shelf-head .lede { max-width: none; }
.shelf-contexts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.shelf-contexts .chip { text-decoration: none; }
.shelf-rows { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.shelf-rows .developing { margin-top: var(--space-4); }
.shelf-foot { padding-top: var(--space-2); }
.shelf-foot a { font-weight: 600; }

/* ── Rows — one shape everywhere a shelf is listed (the sheet, the drawer, the shelf view) ── */
.resource-row {
  display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); align-items: start;
  width: 100%; min-height: calc(56 * var(--unit)); padding: var(--space-4) var(--space-2); border-bottom: 1px solid var(--line);
  color: inherit; text-align: left; background: transparent; border-left: 0; border-right: 0; border-top: 0;
}
a.resource-row:hover { background: var(--surface-soft); color: inherit; }
a.resource-row[aria-current="page"] { background: var(--tint-brand-8, var(--surface-soft)); box-shadow: inset 2px 0 0 var(--brand); }
.resource-row .type { display: block; font-size: var(--text-label); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--brand); margin-bottom: var(--space-1); }
.resource-row b { display: block; font-size: var(--text-h4); font-weight: 600; margin-bottom: var(--space-1); }
.resource-row p { font-size: var(--text-small); color: var(--ink-muted); line-height: 1.5; }
.resource-row .access { display: block; margin-top: var(--space-1); font-size: var(--text-label); text-transform: none; letter-spacing: 0; color: var(--ink-faint); font-weight: 500; }
.resource-row .arrow { color: var(--ink-muted); padding-top: var(--space-2); font-size: var(--text-label); font-weight: 600; }
.activity-row { cursor: default; }
.activity-row .btn { align-self: center; }
.activity-row .access { text-transform: capitalize; }

/* ── The side sheet (the Resources door on a stage) and the DRAWER (the set, over a document) ── */
.viewer.viewer-sheet { grid-template-columns: 1fr; justify-items: end; padding: 0; }
.viewer-sheet .viewer-panel { width: var(--drawer-w); height: 100%; border-radius: 0; border: 0; border-left: 1px solid var(--line); animation: sheet-in var(--dur-drawer) var(--ease-out); }
.viewer.viewer-drawer { z-index: var(--z-dialog); inset: 0; }
@keyframes sheet-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: var(--text-h3); font-weight: 600; margin: var(--space-2) 0 var(--space-1); }
.sheet-head .viewer-close { margin-left: 0; }
.sheet-contexts { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--line); }
.sheet-contexts .chip { text-decoration: none; }
.sheet-list { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: var(--space-2) var(--space-3) var(--space-5); }
.sheet-list .developing { margin: var(--space-3) var(--space-2) 0; }
.sheet-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); }
.sheet-foot .small { display: block; line-height: 1.4; }

/* ── The document surface: the main region (the only scroll in the overlay) · the On this page rail (pinned, collapsible) ── */
.viewer[data-viewer-kind="document"] .viewer-body { display: flex; overflow: hidden; padding: 0; }
.surface-grid { flex: 1; min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
.surface-grid.has-aside { grid-template-columns: minmax(0, 1fr) calc(248 * var(--unit)); }
.surface-aside { min-height: 0; overflow-y: auto; scrollbar-width: thin; display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-6) var(--space-5) var(--space-8) var(--space-3); }
.page-toc > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-2); min-height: 24px; padding-left: calc(var(--space-3) + 2px); }
.page-toc > summary::-webkit-details-marker { display: none; }
.page-toc > summary::after { content: '▾'; color: var(--ink-faint); font-size: var(--text-small); }
.page-toc:not([open]) > summary::after { content: '▸'; }
.surface-main { min-height: 0; min-width: 0; overflow-y: auto; scrollbar-width: thin; padding: var(--space-6) var(--space-8) var(--space-12); }
.surface-document { max-width: var(--measure-doc); margin: 0 auto; }
.index-list { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-direction: column; }
.index-list a { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: calc(36 * var(--unit)); padding: var(--space-2) var(--space-3); border-left: 2px solid transparent; font-size: var(--text-small); font-weight: 500; line-height: 1.35; color: var(--ink-muted); text-decoration: none; transition: color var(--dur-hover) ease, border-color var(--dur-hover) ease; }
.index-list a:hover { color: var(--brand-dark); }
.index-list a[aria-current="page"], .page-index a[aria-current="true"] { color: var(--ink); font-weight: 600; border-left-color: var(--brand); }
.index-list .idx-meta { font-size: var(--text-label); font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-faint); }
.page-index a { min-height: calc(32 * var(--unit)); }
.doc-head { display: flex; flex-direction: column; gap: var(--space-3); padding-bottom: var(--space-5); margin-bottom: var(--space-5); border-bottom: 1px solid var(--line); }
.doc-title { font-size: var(--text-h2); font-weight: 600; line-height: var(--leading-heading); letter-spacing: var(--tracking-heading); color: var(--ink); max-width: calc(760 * var(--unit)); text-wrap: balance; }
.deck { font-size: var(--text-lede); line-height: 1.45; color: var(--ink-muted); text-wrap: pretty; }
.doc-body { font-size: var(--text-body); line-height: var(--leading-doc); color: var(--ink); display: flex; flex-direction: column; gap: var(--space-4); }
.doc-body h2 { font-size: calc(28 * var(--unit)); font-weight: 600; line-height: 1.25; letter-spacing: var(--tracking-heading); margin-top: var(--space-4); scroll-margin-top: var(--space-5); text-wrap: balance; }
.doc-body h3 { font-size: calc(20 * var(--unit)); font-weight: 600; line-height: 1.3; margin-top: var(--space-2); }
.doc-body h4 { font-size: var(--text-h4); font-weight: 600; line-height: 1.3; }
.doc-body p { margin: 0; }
.doc-body .studio-html > * + * { margin-top: var(--space-3); }
.doc-body ul, .doc-body ol { margin: 0; padding-left: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); }
.doc-body li > ul, .doc-body li > ol { margin-top: var(--space-2); }
.doc-body blockquote { margin: 0; border-left: 3px solid var(--brand); background: var(--surface-soft); padding: var(--space-4) var(--space-5); border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.doc-body blockquote.tone-dark { background: var(--black); color: var(--white); border-left-color: var(--brand-lifted); border-radius: var(--radius-md); padding: var(--space-5) var(--space-6); }
.doc-body blockquote.tone-dark h2, .doc-body blockquote.tone-dark h3, .doc-body blockquote.tone-dark strong { color: var(--white); }
.doc-body blockquote.tone-dark em, .doc-body blockquote.tone-dark .muted { color: rgba(255, 255, 255, 0.72); }
.doc-body blockquote.tone-dark li::marker { color: var(--brand-lifted); }
.doc-body blockquote.tone-dark a { color: var(--white); text-decoration: underline; }
.doc-body pre { margin: 0; background: var(--black); color: var(--white); font: 13px/1.65 var(--font-mono); padding: var(--space-5); border-radius: var(--radius-lg); overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.doc-body pre code { font: inherit; }
.doc-body code { font-family: var(--font-mono); font-size: 0.9em; }
.doc-body .checklist { list-style: none; padding: 0; gap: var(--space-2); }
.doc-body .checklist li { display: flex; gap: var(--space-3); align-items: flex-start; }
.doc-body .table-wrap { overflow-x: auto; }
.doc-body table { border-collapse: collapse; width: 100%; font-size: var(--text-small); line-height: 1.5; }
.doc-body th, .doc-body td { text-align: left; vertical-align: top; padding: var(--space-3); border: 1px solid var(--line); min-width: calc(96 * var(--unit)); }
.doc-body th { background: var(--surface-soft); font-weight: 600; }
.doc-body td:empty { height: var(--control); }
.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-2) 0; width: 100%; }
.doc-body figure { margin: 0; }
.doc-body .doc-figure img { border-radius: var(--radius-md); }
.doc-body figcaption { font-size: var(--text-label); font-weight: 500; color: var(--ink-faint); margin-top: var(--space-2); }
/* a Button block (cta) is a button in every host — the site and the app's viewer draw it from this one rule (Vault audit §3.8:
   the app has no stage.css, so it read as plain text, d-05); without a link yet it stays a button, inert */
.doc-body .btn { align-self: flex-start; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); max-width: 100%; min-height: var(--control); padding: 0 var(--space-6); border-radius: var(--radius-full); border: 1px solid transparent; font-size: var(--text-small); font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none; transition: background-color var(--dur-hover) ease, color var(--dur-hover) ease; }
.doc-body .btn-primary { background: var(--brand); color: var(--white); }
.doc-body a.btn-primary:hover { background: var(--brand-dark); color: var(--white); }
.doc-body .btn.is-inert { opacity: 0.6; cursor: default; }
.doc-body .chip { align-self: flex-start; }
.doc-body .callout { max-width: none; font-size: var(--text-body); padding: var(--space-4) var(--space-5); }
.doc-body .callout > * + * { margin-top: var(--space-3); }
.doc-body .tiles { display: grid; gap: var(--space-3); }
.doc-body .tiles.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.doc-body .tiles.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.doc-body .tiles.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.doc-body .tile { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); color: inherit; font-size: var(--text-small); line-height: 1.5; min-width: 0; }
.doc-body a.tile:hover { border-color: var(--brand); }
.doc-body .tile-label { font-size: var(--text-label); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--brand); }
.doc-body .tile h4 { margin: 0; }
.doc-body .tile .studio-html { color: var(--ink-muted); }
.doc-body .tile .studio-html > * + * { margin-top: var(--space-2); }
.doc-body .tile ul { padding-left: var(--space-4); gap: var(--space-1); }
.doc-body .doc-chart { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.doc-body .doc-chart svg { width: 100%; height: auto; display: block; }
.doc-body .doc-chart .chart-title { font-size: var(--text-small); font-weight: 600; color: var(--ink); margin: 0; letter-spacing: 0; text-transform: none; }
.doc-body .chart-legend { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--text-label); font-weight: 500; color: var(--ink-muted); }
.doc-body .chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: var(--space-2); vertical-align: middle; }
/* Context Summary (Content Engine 6b): a dated header with counts, then sections of short dated items */
.doc-body .summary-head { display: flex; flex-direction: column; gap: var(--space-2); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.doc-body .summary-asof { margin: 0; font-size: var(--text-label); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--brand); }
.doc-body .summary-scope { margin: 0; font-size: var(--text-small); color: var(--ink-muted); }
.doc-body .summary-counts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin: var(--space-2) 0 0; }
@media (min-width: 560px) { .doc-body .summary-counts { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.doc-body .summary-counts div { padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.doc-body .summary-counts dt { font-size: var(--text-label); color: var(--ink-muted); }
.doc-body .summary-counts dd { margin: 0; font-size: var(--text-h3); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.doc-body .summary-section { display: flex; flex-direction: column; gap: var(--space-2); }
.doc-body .summary-section h3 { margin: 0; }
.doc-body .summary-section p { margin: 0; }
.doc-body .summary-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.doc-body .summary-list li { display: flex; gap: var(--space-3); align-items: baseline; padding: var(--space-2) 0; border-top: 1px solid var(--line); font-size: var(--text-small); line-height: 1.5; }
.doc-body .summary-list li:first-child { border-top: 0; }
.doc-body .summary-list time, .doc-body .summary-list .summary-nodate { flex: none; width: 5.5em; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.doc-body .summary-list span { flex: 1; min-width: 0; }
.doc-body .summary-list em { flex: none; font-style: normal; font-size: var(--text-label); font-weight: 700; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--ink); }
.doc-body .summary-state p { font-size: var(--text-body); color: var(--ink); }
.doc-body .doc-page { display: flex; flex-direction: column; gap: var(--space-4); }
.doc-body .doc-page + .doc-page { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px dashed var(--line); }
.doc-body .page-mark { display: flex; gap: var(--space-3); align-items: baseline; font-size: var(--text-label); font-weight: 600; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--ink-faint); }
.doc-body .access-gate { margin-top: var(--space-2); padding: var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-soft); display: flex; flex-direction: column; gap: var(--space-3); }
.doc-body .studio-html .muted { color: var(--ink-muted); }
.doc-body .studio-html .strand { color: var(--brand); font-weight: 600; }
.doc-body .studio-html .center { text-align: left; }
.doc-body .studio-html .card { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-4); }
.doc-section { display: flex; flex-direction: column; gap: var(--space-3); scroll-margin-top: var(--space-5); }
.doc-section + .doc-section { margin-top: var(--space-6); }
.doc-section h2 { margin-top: 0; }
.doc-section .grid { display: grid; gap: var(--space-3); }
.doc-section .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.doc-section .grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.doc-section .card { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-small); }
.doc-section .card h3 { font-size: var(--text-h4); margin: 0; }
.doc-section .card .eyebrow { font-size: var(--text-label); }
.doc-section .small { font-size: var(--text-small); }
.doc-section .muted { color: var(--ink-muted); }
.doc-meta { margin-top: var(--space-8); padding-top: var(--space-4); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); font-size: var(--text-label); font-weight: 500; color: var(--ink-faint); }
.doc-meta a { color: var(--ink-muted); display: inline-flex; align-items: center; min-height: 24px; }
.print-head { display: none; }

/* ── Frames per kind: a Template reads on a sheet (print-first); a Prompt opens on its copy block ── */
.viewer[data-kind="template"] .surface-main { background: var(--surface-soft); }
.viewer[data-kind="template"] .sheet-frame { background: var(--surface); border-radius: calc(3 * var(--unit)); box-shadow: var(--shadow-object); padding: var(--space-8) var(--space-8) var(--space-10); }
.viewer[data-kind="template"] .doc-head { border-bottom: 0; margin-bottom: 0; padding-bottom: var(--space-4); }
.viewer[data-kind="template"] .doc-meta { border-top: 0; margin-top: var(--space-5); }
.prompt-block { position: relative; }
.prompt-block pre { padding-top: calc(var(--space-5) + 28 * var(--unit)); }
.prompt-block .prompt-copy { position: absolute; top: var(--space-3); right: var(--space-3); display: inline-flex; align-items: center; min-height: 28px; padding: 0 var(--space-3); border: 1px solid rgba(255, 255, 255, 0.28); border-radius: var(--radius-full); background: rgba(255, 255, 255, 0.08); font: inherit; font-size: var(--text-label); font-weight: 600; color: var(--white); cursor: pointer; }
.prompt-block .prompt-copy:hover { background: rgba(255, 255, 255, 0.18); }

/* ── After the document: Related as a section, then Previous · Next as the last element ── */
.doc-related { margin-top: var(--space-8); padding-top: var(--space-5); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--space-3); }
.doc-related .related-title { margin: 0; }
/* A Resource's comments on its site page (Vault audit 2026-10-11): the same comments as the app's viewer, filled after load */
.doc-comments { margin-top: var(--space-8); padding-top: var(--space-5); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--space-3); }
.doc-comments .related-title { margin: 0; }
.comments-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.comment { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.comment.is-reply { margin-left: var(--space-4); padding-left: var(--space-3); border-left: 2px solid var(--line); }
.comment-who { font-size: var(--text-label); font-weight: 600; color: var(--ink-muted); }
.comment-text { margin: 0; font-size: var(--text-small); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.comments-write { display: flex; flex-direction: column; gap: var(--space-2); }
.comments-write textarea { width: 100%; min-height: calc(72 * var(--unit)); padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--text-small); resize: vertical; }
.comments-write textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.comments-write .btn { align-self: flex-start; }
.related-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(calc(160 * var(--unit)), 1fr)); gap: var(--space-4) var(--space-5); }
.related-group { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.related { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.related a { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: calc(36 * var(--unit)); padding: var(--space-2) 0; font-size: var(--text-small); font-weight: 600; line-height: 1.35; color: var(--ink); text-decoration: none; }
.related a:hover { color: var(--brand-dark); }
.related a span { font-size: var(--text-label); font-weight: 500; color: var(--ink-faint); }
.doc-steps { margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.doc-steps a { display: flex; flex-direction: column; gap: 2px; min-height: var(--control); padding: var(--space-2) 0; color: var(--ink); text-decoration: none; }
.doc-steps a:hover b { color: var(--brand-dark); }
.doc-steps .step-word { font-size: var(--text-label); font-weight: 500; color: var(--ink-faint); }
.doc-steps b { font-size: var(--text-small); font-weight: 600; }
.doc-steps .viewer-prev .step-word::before { content: '← '; color: var(--brand); }
.doc-steps .viewer-next { text-align: right; align-items: flex-end; }
.doc-steps .viewer-next .step-word::after { content: ' →'; color: var(--brand); }

/* ── Reflow ── */
@media (max-width: 1179px) {
  .surface-grid.has-aside { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .surface-aside { grid-row: 1; overflow: visible; padding: var(--space-5) var(--space-6) 0; }
  .surface-main { grid-row: 2; padding: var(--space-5) var(--space-6) var(--space-10); }
  .page-toc .index-list { flex-direction: row; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
  .page-toc .index-list a { flex-direction: row; align-items: center; gap: var(--space-2); min-height: 32px; padding: 0 var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-full); }
  .page-toc .index-list a[aria-current="true"] { border-color: var(--brand); }
  .viewer-page .surface-aside { position: static; max-height: none; }
  .doc-section .grid.cols-3, .doc-body .tiles.cols-3, .doc-body .tiles.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 899px) {
  .viewer { padding: 0; grid-template-columns: 1fr; }
  .viewer-panel { grid-column: 1; border-radius: 0; border: 0; }
  .viewer-body, .viewer[data-viewer-kind="document"] .viewer-body { display: block; overflow-y: auto; padding: var(--space-4) var(--gutter) var(--space-6); }
  .viewer-body .surface-grid, .viewer-body .surface-grid.has-aside { display: flex; flex-direction: column; gap: var(--space-5); }
  .surface-aside, .surface-main { overflow: visible; padding: 0; }
  .page-toc > summary { padding-left: 0; }
  .viewer-sheet .viewer-panel { width: 100%; border-left: 0; }
  .viewer-bar { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; gap: var(--space-1) var(--space-3); padding: var(--space-2) var(--space-3); }   /* two rows: back + the item (Close pinned), then its controls */
  .viewer-back { padding: 0 var(--space-2) 0 var(--space-1); }
  .viewer-back .back-label { display: inline-block; max-width: 9em; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }   /* Back keeps its word on a phone ("← Your PLAIT"), never a bare ← (Vault audit step 4) */
  .viewer-ident { padding-right: calc(var(--control) + var(--space-2)); }
  .viewer-nav { grid-column: 1 / -1; flex-wrap: wrap; gap: 0 var(--space-1); }
  .viewer-nav .viewer-close { position: absolute; top: var(--space-2); right: var(--space-3); margin: 0; }
  .viewer-nav .viewer-full { display: none; }
  .viewer-nav .viewer-action, .viewer-nav .viewer-prev, .viewer-nav .viewer-next { padding: 0 var(--space-2); }
  .more-menu { right: auto; left: 0; }
  .viewer-page .viewer-bar { padding-left: var(--gutter); padding-right: var(--gutter); }
  .viewer[data-kind="template"] .sheet-frame { padding: var(--space-5) var(--space-4) var(--space-6); }
  .surface-document { padding: 0; }
  .doc-steps { grid-template-columns: 1fr; }
  .doc-steps .viewer-next { text-align: left; align-items: flex-start; }
  .doc-section .grid.cols-2, .doc-section .grid.cols-3, .doc-body .tiles.cols-2, .doc-body .tiles.cols-3, .doc-body .tiles.cols-4 { grid-template-columns: 1fr; }
}

/* ── PAGE: a direct visit is a standalone reading page (CE-07) — the frame sits in the page flow, the window scrolls, the bar
   sticks under the header, the contents rail sticks under the bar. These rules follow the document surface rules so they win. ── */
.surface-page { display: flex; flex-direction: column; min-height: calc(100vh - var(--header-h)); }
.viewer.viewer-page { position: static; inset: auto; z-index: auto; display: block; padding: 0; background: transparent; flex: 1; }
.viewer.viewer-page .viewer-panel { border: 0; border-radius: 0; box-shadow: none; overflow: visible; min-height: 0; }
.viewer.viewer-page .viewer-bar { position: sticky; top: var(--header-h); z-index: 3; background: var(--surface); padding-left: var(--gutter); padding-right: var(--gutter); }
.viewer.viewer-page[data-viewer-kind="document"] .viewer-body, .viewer.viewer-page .viewer-body { display: block; overflow: visible; padding: 0; }
.viewer.viewer-page .surface-grid { max-width: var(--canvas-w); margin: 0 auto; }
.viewer.viewer-page .surface-main { overflow: visible; min-height: calc(100vh - var(--header-h) - var(--viewer-bar-h) - 120 * var(--unit)); }
.viewer.viewer-page .surface-aside { position: sticky; top: calc(var(--header-h) + var(--viewer-bar-h)); align-self: start; overflow: visible; max-height: none; }
.viewer.viewer-page[data-kind="template"] .surface-main { background: transparent; }
.viewer.viewer-page[data-kind="template"] .surface-document { padding-top: var(--space-2); }
.surface-page > .stage-foot { margin: 0; width: auto; }
.viewer.viewer-page.is-full { position: fixed; inset: 0; z-index: var(--z-content-overlay); overflow: auto; background: var(--surface); }
.viewer.viewer-page.is-full .viewer-bar { top: 0; }
@media (max-width: 1179px) { .viewer.viewer-page .surface-aside { position: static; } }
@media (max-width: 899px) {
  .viewer-ident { flex-wrap: wrap; row-gap: 2px; }
  .viewer-title { flex-basis: 100%; order: 3; }
  .viewer-set { white-space: normal; text-align: left; }
  .viewer-set .muted { display: none; }
  .viewer.viewer-page .viewer-bar { padding-left: var(--gutter); padding-right: var(--gutter); }
  .surface-page > .stage-foot { margin: 0; width: auto; padding-left: var(--gutter); padding-right: var(--gutter); }
}

@media (prefers-reduced-motion: reduce) { .viewer-sheet .viewer-panel { animation: none; } }
