/* The article: what prose, lists, tables, and code fences look like inside
   the reading column, and the tabbed code blocks a page can build. */

/* ── Content / prose ─────────────────────────────────────────────────────── */

#content {
  padding: 2rem 0 3rem;
  min-width: 0;
}

.prose {
  max-width: var(--content-max);
}

/* The end of the page, marked the way a book marks the end of a chapter: one
   small ornament, centred, with room around it. It is the project's own stack,
   used once and quietly, rather than a glyph repeated down the margin. */
#content::after {
  content: "";
  display: block;
  width: 1.35rem;
  height: 1.35rem;
  margin: 3.5rem auto 0.5rem;
  /* The rim's own amber, so the drawn mark matches the outline the shader
     draws. Linework encloses far less ink than a filled shape, so it keeps
     more of that color and still sits back from the text. */
  color: var(--mark-rim);
  opacity: 0.7;
  background: currentColor;
  -webkit-mask: var(--mark-line) center / contain no-repeat;
  mask: var(--mark-line) center / contain no-repeat;
}

.prose :is(p, li, td, th, figcaption) a:where(:not(.btn, .card)) {
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-thickness: 0.06em;
}

.prose > :first-child {
  margin-top: 0;
}

h1, h2, h3, h4 {
  line-height: 1.2;
  color: var(--ink);
  /* Keep an in-page anchor from landing under the sticky header. */
  scroll-margin-top: calc(var(--site-header-height, 4.5rem) + 0.75rem);
  /* A heading is short text, so balance its lines instead of letting a lone
     word drop to a second row. */
  text-wrap: balance;
}

/* A heading's last two words, kept together by the site build so the last
   line never holds one word. An inline block stays whole when it fits and
   wraps inside itself when it does not, so it cannot push the page wider. */
.keep {
  display: inline-block;
}

/* Display sizes use Plex's semibold weight. Body emphasis keeps the stronger
   bold, so page structure and emphasis remain distinct. */
h1 {
  color: var(--teal-ink);
  font-size: 2.9rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  letter-spacing: 0;
}

h2 {
  color: var(--accent-ink);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0;
  margin: 2.2rem 0 0.8rem;
}

/* Sections are separated by a rule, not by a glyph in front of the heading. A
   hairline across the column is how a printed page marks a new section: it
   reads at a glance while scrolling, costs no colour, and leaves the heading
   itself to be read as words. */
.prose h2 {
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}

h3 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0;
  margin: 1.8rem 0 0.5rem;
}

p, li {
  color: var(--ink);
  /* Tune the last lines of body copy so a paragraph or list item never strands
     a single word on a line of its own. `pretty` only touches the tail, so the
     rag of the rest is left alone; browsers without it fall back to normal. */
  text-wrap: pretty;
}

/* Lists: an accent marker and a little room to breathe, so a bulleted or
   numbered run reads as a tidy list rather than crowded paragraphs. */
.prose ul,
.prose ol {
  padding-left: 1.4rem;
  margin: 1rem 0;
}

.prose li {
  margin: 0.35rem 0;
}

.prose li::marker {
  color: var(--accent);
}

/* Diagrams. SuperMD renders a captioned image as a figure, and these are the
   hand-drawn SVGs that sit inside the prose. The card framing tells a reader
   "this is a picture of the idea," distinct from the clickable route cards. */
.prose figure {
  margin: 1.75rem 0;
  padding: 1.1rem 1.1rem 0.5rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
}

/* The live preview themes raw figures in the browser before showing them. */
:root.inlining-diagrams .prose figure img[src$=".svg"] {
  visibility: hidden;
}

/* The site build embeds each SVG in a declarative shadow root. Its styles
   stay inside the drawing while page tokens cross the boundary, so diagrams
   follow the theme from their first paint, including without JavaScript. */
.prose .diagram {
  display: block;
  width: 100%;
}

/* Both kinds of drawing, the embedded diagrams and the inline walkthrough,
   want the lighter end of the amber and teal ramps for their strokes and
   labels. `--dia-*` carries a light identity of its own in `:root`, so this
   needs no literal fallback; in the light theme it resolves to the core value
   and nothing shifts. */
.prose .diagram,
.prose .capwalk {
  --accent-deep: var(--dia-accent-deep);
  --teal-deep: var(--dia-teal-deep);
}

.prose figure img {
  display: block;
  /* Full-width means a diagram's viewBox width sets its display scale: the
     hand-drawn SVGs share a 760-unit canvas, and a narrower canvas magnifies. */
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.prose figcaption {
  margin-top: 0.7rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: center;
  /* Even the lines out so a short centered caption never strands a lone word
     on a line of its own. */
  text-wrap: balance;
}

/* Product captures are interface evidence. Let the
   whole window remain readable and give it the same framed surface as a
   diagram. The `rooms-` prefix scopes this to the reproducible captures
   `site/scripts/capture-rooms.ts` writes rather than changing every image on
   the site. The frame stays a hairline: a shadow under a window read as a
   hole. */
.prose figure:has(img[src*="/rooms-"][src$=".webp"]) {
  max-width: none;
  padding: 0.45rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
}

.prose figure:has(img[src*="/rooms-"][src$=".webp"]) img {
  width: 100%;
  max-width: none;
  border-radius: calc(var(--radius-card) - 0.45rem);
}

/* Each capture comes as a pair, the app's dark face and its light one, and
   a page carries both figures because the generator installs an asset only
   where a page names it. The page's theme is the `data-theme` stamp, never
   the desktop's preference (see tokens.css), so a `picture` element keyed on
   `prefers-color-scheme` would show the wrong face; the theme picks the
   figure here, in CSS alone, so the right face is there at first paint and
   the hidden one leaves the accessibility tree. Both images are lazy with
   their dimensions set, so a hidden figure is never fetched and the shown one
   reserves its space. Syrup is the default face, so the dark capture shows
   until the root is stamped light. */
.prose figure:has(img[src*="/rooms-"][src$="-light.webp"]) {
  display: none;
}

:root[data-theme="light"] .prose figure:has(img[src*="/rooms-"][src$="-dark.webp"]) {
  display: none;
}

:root[data-theme="light"] .prose figure:has(img[src*="/rooms-"][src$="-light.webp"]) {
  display: block;
}

/* The join card and the session choice are cropped to the control, so at
   full column width their type would set larger than the page's own. Hold
   them near their captured size instead. */
.prose figure:has(img[src*="/rooms-join-"][src$=".webp"]),
.prose figure:has(img[src*="/rooms-session-dark"][src$=".webp"]),
.prose figure:has(img[src*="/rooms-session-light"][src$=".webp"]) {
  max-width: 36rem;
  margin-left: auto;
  margin-right: auto;
}

/* The attached sessions are phones, and a phone is a portrait: hold each at
   a phone's width so it reads as one rather than as a tall wall. These
   selectors carry the same two attribute tests as the frame rule above, so
   they match its specificity and win by coming later. */
.prose figure:has(img[src*="/rooms-session-attached-"][src$=".webp"]),
.prose figure:has(img[src*="/rooms-directories-phone-"][src$=".webp"]) {
  max-width: 24rem;
  margin-left: auto;
  margin-right: auto;
}

/* Two short lists read against each other, the member's Rooms beside the
   host's. A table gave the longer cells' column the width and squeezed the
   other to a third; equal columns let both read at body measure, and they
   stack on a phone. Authored as an HTML block in SuperMD. */
.prose .columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 2rem;
  margin: 1.25rem 0;
}

.prose .columns h3 {
  margin-top: 0;
}

@media (max-width: 40rem) {
  .prose .columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* The protocol page's object catalog: tiers of cards, one card per object,
   each saying how you come to hold it, the calls it answers as a row of
   chips, and what it hands back. A four-column table set the same facts as
   a wall of wrapped chips. The tiers read top to bottom as the chain from
   the one published name down to a single line, and the tint says who
   holds the object, in the modules stack's own palette: cool lives on the
   server, warm is handed to you, neutral is the one you make. Authored as
   an HTML block. */
.prose .objects {
  margin: 1.25rem 0 1.75rem;
}

/* A tier's label is a small caption, not a heading, so the page outline
   stays the page's and the catalog keeps its own rhythm. */
.prose .objects-tier {
  margin: 1.1rem 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.prose .objects-row {
  /* Wrapped lines always fill: a card grows to its share, so a row's last
     line is a full-width band rather than a narrow card stranded beside
     empty space, at every width. */
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.prose .object {
  flex: 1 1 14rem;
  padding: 0.9rem 1.05rem 1rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
}

.prose .object[data-tone="cool"] {
  background: color-mix(in srgb, var(--teal) 8%, var(--paper-raised));
}

.prose .object[data-tone="warm"] {
  background: color-mix(in srgb, var(--accent) 8%, var(--paper-raised));
}

.prose .object[data-tone="own"] {
  background: color-mix(in srgb, var(--ink-soft) 7%, var(--paper-raised));
}

.prose .object p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* The object's name is a noun in the prose, not something a reader types,
   so it stays in the sans; only the calls below it are mono. */
.prose .object-name {
  margin: 0 0 0.3rem;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
}

.prose .object[data-tone="cool"] .object-name {
  color: var(--teal-ink);
}

.prose .object[data-tone="warm"] .object-name {
  color: var(--accent-ink);
}

.prose .object-from {
  color: var(--ink-soft);
}

/* The chips are the calls, and the row is the object's whole vocabulary. */
.prose .object-calls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.35rem;
  margin: 0.6rem 0 !important;
}

.prose .object-back {
  color: var(--ink-soft);
}

.prose .object-back b {
  color: var(--ink);
  font-weight: 600;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.34em;
  border-radius: var(--radius-chip);
  /* Protocol tokens (`op:start-session`, `ocapn-sturdyref`) are single names;
     keep the hyphen from being a line-break opportunity that splits one. */
  white-space: nowrap;
}

pre {
  background: var(--code-bg);
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-control);
  overflow-x: auto;
  border: 1px solid var(--rule);
  /* A listing is a well cut into the page: the darker ground and the hairline
     say so, and a shadow on top of them said it a third time. */
  /* The TypeScript examples are tab-indented, matching deno fmt; render the
     tab four columns wide like every editor here, not the browser's eight. */
  tab-size: 4;
}

/* Copy-to-clipboard. The button is built by the script in the base template, so
   a reader without JavaScript simply gets the code block as it always was. It
   stays faint until the block is hovered or the button itself is focused, so a
   page of listings is not a page of buttons; it never fades out on touch, where
   there is no hover to reveal it. */
.code-block {
  position: relative;
}

.copy-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper-raised) 85%, transparent);
  border: 1px solid var(--rule);
  border-radius: var(--radius-chip);
  padding: 0.32rem 0.6rem;
  cursor: pointer;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.code-block .copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  opacity: 0;
}

.code-block:hover .copy-btn,
.code-block .copy-btn:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .code-block .copy-btn {
    opacity: 1;
  }
}

/* Inside a tabbed block the button joins the tab strip and copies whichever tab
   is showing. It matches the tabs' box exactly so the row is level, but it is
   drawn as a quiet action rather than a chip: given the same border and fill as
   the tabs it reads as a third tab, which is the one thing it must not do. */
.code-tabs .tab-bar .copy-btn {
  margin-left: auto;
  align-self: stretch;
  margin-bottom: 0;
  background: transparent;
  border-color: transparent;
  font-weight: 600;
}

.code-tabs .tab-bar .copy-btn:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.copy-btn:hover {
  color: var(--accent-ink);
  border-color: var(--accent);
}

.copy-btn.is-done {
  color: var(--teal-ink);
  border-color: var(--teal);
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.86em;
  /* Block code follows its `pre` parent (preserve + scroll), not the inline
     nowrap above, so multi-line listings stay multi-line. */
  white-space: pre;
}

/* ── Code tabs ───────────────────────────────────────────────────────────────
   A `code-tabs` block holds label/code pairs (authored as bold one-word
   paragraphs before each fence). The script in the base template turns the
   pairs into tabs; without JavaScript the pairs render as labeled, stacked
   code blocks, which is the intended fallback. */
.code-tabs .tab-bar {
  display: flex;
  /* A long strip (eight transports plus Copy) must fold on a phone rather
     than widen the page: wrapped rows keep every tab tappable, and only the
     last row sits on the panel. */
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.3rem;
  /* The bar sits directly on the panel below; the buttons themselves overlap
     the panel's top border (see `margin-bottom` below), so the strip and the
     code block read as one shape rather than two stacked boxes. */
  position: relative;
  z-index: 1;
}

.code-tabs .tab-bar button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--ink) 5%, var(--code-bg));
  border: 1px solid var(--rule);
  border-radius: var(--radius-control) var(--radius-control) 0 0;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
  /* Drop onto the panel's 1px top border so the active tab can punch through
     it and unselected tabs share the same baseline. */
  margin-bottom: -1px;
}

.code-tabs .tab-bar button[aria-pressed="true"] {
  color: var(--teal-ink);
  /* Same fill as the panel, with the seam erased where they meet, so the
     selected tab opens straight into the code block. */
  background: var(--code-bg);
  border-bottom-color: var(--code-bg);
}

/* Once the script has built a bar, every panel behind it drops its top margin
   (`pre` keeps the browser default elsewhere) and squares its top corners so
   the tabs sit flush on the panel; the bottom stays rounded. The no-JS
   fallback has no bar, so its stacked blocks keep the normal `pre` shape. */
.code-tabs .tab-bar ~ pre {
  margin-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* The no-JS fallback labels. The script removes them when it builds the bar. */
.code-tabs > p {
  margin: 0.6rem 0 -0.6rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Forced colors replace the wash that marks the chosen tab, so the state
   moves to a border, which the system palette keeps. */
@media (forced-colors: active) {
  .code-tabs .tab-bar button[aria-pressed="true"] {
    border: 2px solid SelectedItem;
  }
}

/* A short set of links a reader picks one from. Small tiles keep the choice
   on one screen, two columns wide on a phone, and each tile is a full target.
   Authored as a `link-grid` block around a plain Markdown list. */
.prose .link-grid ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr));
  gap: 0.5rem;
  margin: 1.25rem 0;
  padding: 0;
  list-style: none;
}

.prose .link-grid li {
  margin: 0;
  padding: 0;
}

.prose .link-grid a {
  display: block;
  padding: 0.6rem 0.85rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.12s ease;
}

.prose .link-grid a:hover {
  border-color: var(--accent);
}
