/* Martingale — docs framework (hand-built in the site's tokens; NOT an
   imported docs system). Reusable across all papers. Depends on site.css for
   tokens + base; docs pages link site.css first, then this file.

   Contents:
     1. Docs shell (sidebar + main, readable measure)
     2. Sidebar: paper nav + within-paper TOC (+ mobile collapse)
     3. Docs main typography (serif headings / sans body / mono labels+math+code)
     4. Docs landing paper list
     5. Tab component (paired with docs-tabs.js; degrades to all-sections-visible)
     6. Soft-gate affordance (research-gating, not a paywall)
*/

/* ------------------------------------------------------------------ *
 * 1. Docs shell
 * ------------------------------------------------------------------ */
:root { --docs-measure: 68ch; --docs-sidebar: 15rem; }

.docs-shell {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: clamp(2.5rem, 6vh, 4.5rem);
  display: grid;
  grid-template-columns: var(--docs-sidebar) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: start;
}
.docs-main { min-width: 0; }
.docs-main > * { max-width: var(--docs-measure); }

/* ------------------------------------------------------------------ *
 * 2. Sidebar
 * ------------------------------------------------------------------ */
.docs-sidebar {
  position: sticky;
  top: calc(60px + 1.5rem);   /* clear the sticky nav */
  align-self: start;
  font-family: var(--mono);
}
.docs-sidebar__group + .docs-sidebar__group { margin-top: 2rem; }
.docs-sidebar__title {
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--ink) 55%, transparent);
  margin-bottom: 0.9rem;
}
.docs-nav, .docs-toc__list { list-style: none; padding: 0; margin: 0; }
.docs-nav li + li, .docs-toc__list li + li { margin-top: 0.55rem; }
.docs-nav a, .docs-toc a {
  font-family: var(--mono);
  font-size: var(--text-s);
  text-decoration: none;
  color: var(--ink);
  display: inline-block;
  padding-bottom: 1px;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size 150ms ease;
}
.docs-nav a:hover, .docs-toc a:hover { background-size: 100% 1px; }
.docs-nav a[aria-current="page"] { color: var(--navy); }
.docs-toc summary {
  /* summary is the mobile accordion trigger; hidden on desktop (§ below) */
  display: none;
}
.docs-toc[open], .docs-toc { display: block; }

/* ------------------------------------------------------------------ *
 * 3. Docs main typography
 * ------------------------------------------------------------------ */
.docs-kicker {
  font-family: var(--mono);
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  color: var(--navy);
}
.docs-h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: var(--text-xl);
  line-height: 1.08;
  letter-spacing: -0.01em;
  text-wrap: balance;
  margin-top: 0.6rem;
}
/* NB: scoped under .docs-main so these beat `.docs-main p` (0,1,1) — otherwise
   the lede/subtitle drop to body size (--text-m) sans. */
.docs-main .docs-lede {
  font-family: var(--sans);
  font-size: var(--text-l);
  line-height: 1.5;
  color: color-mix(in srgb, var(--ink) 80%, transparent);
  margin-top: 1.1rem;
}
/* Italic subtitle under a paper title (Thesis). Serif italic is the site's
   real-weight italic register (sans ships 400 only) and serif is allowed at
   --text-l; sits in the same slot as .docs-lede. */
.docs-main .docs-subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: var(--text-l);
  line-height: 1.35;
  color: color-mix(in srgb, var(--ink) 72%, transparent);
  margin-top: 0.7rem;
  text-wrap: balance;
}
.docs-h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
  line-height: 1.15;
  margin-top: 2.6rem;
}
.docs-h3 {
  font-family: var(--mono);
  font-weight: 500;
  font-size: var(--text-m);
  letter-spacing: 0.01em;
  margin-top: 1.8rem;
}
.docs-main p {
  font-family: var(--sans);
  font-size: var(--text-m);
  line-height: 1.62;
  margin-top: 1rem;
}
.docs-main ul, .docs-main ol { margin-top: 1rem; padding-left: 1.3rem; }
.docs-main li { font-family: var(--sans); font-size: var(--text-m); line-height: 1.6; margin-top: 0.4rem; }
.docs-main em { font-style: italic; }

/* math + inline code: mono, never images */
.docs-math, .docs-main code {
  font-family: var(--mono);
  font-size: 0.94em;
}
.docs-math--block {
  display: block;
  font-size: var(--text-s);
  line-height: 1.5;
  padding: 1.1rem 1.2rem;
  margin-top: 1.2rem;
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--ink) 2.5%, var(--paper));
  overflow-x: auto;
}
.docs-rule { border: 0; border-top: 1px solid var(--rule); margin-block: 2.4rem; }

/* Bold run-in lead-in for single-flow prose papers (e.g. User Rationale).
   Mono/medium matches the site's label register (sans ships 400 only, so this
   avoids faux-bold); the paragraph it opens gets extra top space for structure. */
.docs-runin { font-family: var(--mono); font-weight: 500; color: var(--ink); }
.docs-main p.docs-lead { margin-top: 2.2rem; }

/* Deployment ledger: long hex addresses must wrap, never force page width */
#deployment .ledger { table-layout: fixed; width: 100%; }
#deployment .ledger .k { width: 38%; }
#deployment .ledger .docs-math { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ *
 * 4. Docs landing paper list
 * ------------------------------------------------------------------ */
.doclist { border-top: 1px solid var(--rule); margin-top: 1.6rem; }
.doc-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 1.5rem;
  align-items: baseline;
  padding-block: 1.6rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: inherit;
}
a.doc-row:hover .doc-row__title { background-size: 100% 1px; }
.doc-row__title {
  font-family: var(--serif);
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
  line-height: 1.1;
  color: var(--ink);
  display: inline;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size 150ms ease;
}
.doc-row__status {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--ink) 52%, transparent);
  white-space: nowrap;
}
.doc-row__status--live { color: var(--navy); }
.doc-row__abstract {
  grid-column: 1 / -1;
  font-family: var(--sans);
  font-size: var(--text-m);
  line-height: 1.55;
  color: color-mix(in srgb, var(--ink) 78%, transparent);
  max-width: var(--prose-max);
}

/* ------------------------------------------------------------------ *
 * 5. Tab component (see docs-tabs.js). Progressive enhancement:
 *    HTML ships tabs as anchor links + all panels visible; JS upgrades to a
 *    roving-tabindex ARIA tablist and hides inactive panels.
 * ------------------------------------------------------------------ */
/* Uniform vertical tab strip: one tab per line (7 tabs never divide into an
   even multi-column grid, so a single column is the only layout with the same
   count on every row). Active = navy text + a navy left-accent. */
.tabs__list {
  display: flex;
  flex-direction: column;
  margin: 0 0 1.8rem;
  padding: 0;
  border-block: 1px solid var(--rule);
  list-style: none;
}
.tabs__tab {
  display: block;
  font-family: var(--mono);
  font-size: var(--text-s);
  text-decoration: none;
  color: color-mix(in srgb, var(--ink) 60%, transparent);
  padding: 0.55rem 0 0.55rem 0.9rem;
  border-left: 2px solid transparent;
  background: transparent;
  cursor: pointer;
}
.tabs__tab + .tabs__tab { border-top: 1px solid var(--rule); }
.tabs__tab:hover { color: var(--ink); border-left-color: var(--rule); }
.tabs__tab[aria-selected="true"] {
  color: var(--navy);
  border-left-color: var(--navy);
}
/* JS-on: hide inactive panels. JS-off: .tabs has no [data-tabs-ready], all show. */
.tabs[data-tabs-ready] .tabs__panel[hidden] { display: none; }
.tabs__panel { margin-top: 0.4rem; }
.tabs__panel:focus-visible { outline: 2px solid var(--navy); outline-offset: 6px; }
/* JS-off separator so stacked panels read as distinct sections */
.tabs:not([data-tabs-ready]) .tabs__panel + .tabs__panel {
  margin-top: 2.4rem;
  padding-top: 2.4rem;
  border-top: 1px solid var(--rule);
}

/* ------------------------------------------------------------------ *
 * 6. Soft-gate affordance (intentional research gating, not a paywall)
 * ------------------------------------------------------------------ */
.softgate {
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--ink) 2.5%, var(--paper));
  padding: 1.15rem 1.25rem;
  margin-top: 1.4rem;
  max-width: var(--docs-measure);
}
.softgate__label {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  color: color-mix(in srgb, var(--ink) 52%, transparent);
  margin: 0;
}
.softgate__title {
  font-family: var(--mono);
  font-size: var(--text-s);
  color: var(--ink);
  margin: 0.5rem 0 0;
}
.softgate__link {
  font-family: var(--mono);
  font-size: var(--text-s);
  color: var(--navy);
  text-decoration: none;
  display: inline-block;
  margin-top: 0.7rem;
  padding-bottom: 1px;
  background-image: linear-gradient(var(--navy), var(--navy));
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size 150ms ease;
}
.softgate__link:hover { background-size: 100% 1px; }

/* ------------------------------------------------------------------ *
 * Responsive — sidebar collapses under 768px (no desktop hamburger)
 * ------------------------------------------------------------------ */
@media (min-width: 768.01px) {
  /* desktop: within-paper TOC always expanded, accordion trigger hidden */
  .docs-toc[open] > summary,
  .docs-toc > summary { display: none; }
}
@media (max-width: 768px) {
  .docs-shell {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .docs-sidebar {
    position: static;
    top: auto;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 1.4rem;
  }
  .docs-nav { display: flex; flex-wrap: wrap; gap: 0.6rem 1.4rem; }
  .docs-nav li + li { margin-top: 0; }
  /* within-paper TOC becomes a labelled accordion */
  .docs-toc summary {
    display: block;
    font-family: var(--mono);
    font-size: var(--text-xs);
    letter-spacing: 0.02em;
    color: color-mix(in srgb, var(--ink) 55%, transparent);
    cursor: pointer;
    list-style: none;
    padding: 0.2rem 0;
  }
  .docs-toc summary::-webkit-details-marker { display: none; }
  .docs-toc summary::after { content: " +"; }
  .docs-toc[open] summary::after { content: " –"; }
  .docs-toc__list { margin-top: 0.9rem; }
}
