/* Docs page: three-column reading layout in the site's tokens (DESIGN.md, reading playbook).
   Left rail 272, content 720, right "On this page" 256. Spacing from the s-* scale only. */

html:has(body.docs) { height: auto; scroll-behavior: smooth; }

/* The app page never shows a scrollbar (owner: "remove the side bar too"), so the docs page hides its own:
   a visible bar narrows the viewport and shifts the centred header sideways when moving between pages. */
html:has(body.docs) { scrollbar-width: none; }
html:has(body.docs)::-webkit-scrollbar { display: none; }

body.docs {
  display: block;
  height: auto;
  overflow: visible;
  background: var(--ground);
  color: var(--text-body);
  font-family: var(--font-sans);
}

@media (prefers-reduced-motion: reduce) {
  html:has(body.docs) { scroll-behavior: auto; }
  body.docs * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* The site header (vanity.css) sits on top of the docs too; everything sticky starts below its 56px + hairline. */
.docs { --head: calc(3.5rem + 1px); }
.docs .topbar { position: sticky; top: 0; }

.docs [id] { scroll-margin-top: calc(var(--head) + var(--s-9)); }

@media (min-width: 1024px) {
  .docs [id] { scroll-margin-top: calc(var(--head) + var(--s-6)); }
}

/* ---------------------------------------------------------------- Shell */
.dshell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 100rem;
  margin-inline: auto;
}

/* ---------------------------------------------------------------- Left rail (and phone header) */
.dside {
  position: sticky;
  top: var(--head);
  z-index: 15;
  max-height: calc(100dvh - var(--head));
  overflow-y: auto;
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--line-row);
  background: var(--ground);
}

/* Phones: a "Sections" row under the header opens the section list (the site's tabs live in the bottom bar). */
.dmenu > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--hit);
  padding: 0 var(--s-3);
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--text-strong);
  font-size: var(--type-body);
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.dmenu > summary::-webkit-details-marker { display: none; }
.dmenu > summary:hover { background: var(--raised-hover); }
.dmenu > summary:active { background: var(--raised-active); }

.dnav { padding-block: var(--s-2) var(--s-4); }
.dnav ul, .dtoc ul { margin: 0; padding: 0; list-style: none; }

.dgroup {
  margin: var(--s-5) 0 var(--s-2);
  padding-inline: var(--s-3);
  color: var(--text-dim);
  font-size: var(--type-label);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dnav .dgroup:first-child { margin-top: 0; }

.dnav a:not(.dapp),
.dtoc a {
  display: flex;
  align-items: center;
  min-height: var(--hit);
  padding: 0 var(--s-3);
  border-radius: var(--radius-control);
  color: var(--text-body);
  font-size: var(--type-body);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
}

.dnav a:not(.dapp):hover,
.dtoc a:hover { background: var(--raised); color: var(--text-strong); }

.dnav a[aria-current],
.dtoc a[aria-current] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.dapp {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--hit);
  margin-top: var(--s-5);
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--text-strong);
  font-size: var(--type-body);
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.dapp:hover { background: var(--raised-hover); }
.dapp:active { background: var(--raised-active); }

/* ---------------------------------------------------------------- Content */
.dmain {
  min-width: 0;
  padding: var(--s-6) var(--s-4) var(--s-8);
}

.prose {
  max-width: 45rem;
  margin-inline: auto;
  font-size: var(--type-reading);
  line-height: var(--leading-reading);
}

.prose > h1 {
  margin: 0 0 var(--s-4);
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  text-wrap: balance;
}

.lede {
  max-width: 60ch;
  margin: 0 0 var(--s-4);
  color: var(--text-body);
  font-size: var(--type-head);
  line-height: 1.55;
}

.prose p,
.prose ul { max-width: 68ch; margin: 0 0 var(--s-4); }

.prose ul { padding-left: var(--s-5); }
.prose li { margin-bottom: var(--s-2); }
.prose li::marker { color: var(--text-dim); }
.prose strong { color: var(--text-strong); font-weight: 600; }

.prose section > h2 {
  margin: var(--s-7) 0 var(--s-4);
  padding-top: var(--s-7);
  border-top: 1px solid var(--line-row);
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.prose section:first-of-type > h2 { margin-top: var(--s-6); }

.prose h3 {
  margin: var(--s-6) 0 var(--s-3);
  color: var(--text-strong);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

/* Heading anchors: the heading text is the link; a # appears on hover and focus */
.anchor { color: inherit; text-decoration: none; }
.anchor::after {
  content: "#";
  margin-left: var(--s-2);
  color: var(--text-dim);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
}
:is(h2, h3):hover .anchor::after,
.anchor:focus-visible::after { opacity: 1; }
.anchor:focus-visible { border-radius: var(--radius-control); }

.prose a:not(.anchor) {
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.prose a:not(.anchor):hover { color: var(--accent-hover); }

/* Inline code */
.prose code {
  padding: 0.1em var(--s-1);
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--text-strong);
  font-family: var(--font-mono);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}

/* Callouts: a surface step up, a bold lead word, no side stripe */
.dcallout {
  max-width: 68ch;
  margin: var(--s-5) 0;
  padding: var(--s-4);
  border-radius: var(--radius-panel);
  background: var(--surface);
}
.dcallout p { margin: 0; }
.dcallout strong { color: var(--info); }
.dcallout.is-warning strong { color: var(--warning); }

/* Code block */
.codeblock {
  position: relative;
  margin: var(--s-4) 0;
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.codeblock pre {
  margin: 0;
  padding: var(--s-4) var(--s-8) var(--s-4) var(--s-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--type-body);
  line-height: 1.6;
  tab-size: 2;
}

.codeblock pre code {
  padding: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
  white-space: pre;
}

.copy {
  position: absolute;
  top: var(--s-1);
  right: var(--s-1);
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--text-strong);
  font: 500 var(--type-body) var(--font-sans);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}
.copy:hover { background: var(--raised-hover); }
.copy:active { background: var(--raised-active); }
.copy[hidden] { display: none; }

/* Spec rows: label left, value right; stacked on phones */
.specs { max-width: 68ch; margin: var(--s-4) 0; }
.specs > div {
  display: grid;
  gap: var(--s-1) var(--s-4);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line-row);
}
.specs dt, .specs dd { margin: 0; min-width: 0; }

/* Previous / next */
.pager {
  display: grid;
  gap: var(--s-3);
  max-width: 45rem;
  margin: var(--s-8) auto 0;
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-height: var(--hit);
  padding: var(--s-4);
  border-radius: var(--radius-panel);
  background: var(--surface);
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}
.pager-link:hover { background: var(--raised); }
.pager-link:active { background: var(--raised-hover); }
.pager-dir { color: var(--text-dim); font-size: var(--type-small); }
.pager-title { color: var(--text-strong); font-size: var(--type-head); font-weight: 600; }
.pager-link.is-next { text-align: right; }

/* ---------------------------------------------------------------- Right rail */
.dtoc { display: none; }

/* Phones: room above the site's bottom tab bar. */
@media (max-width: 639px) {
  .dmain { padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px) + var(--s-8)); }
}

/* ---------------------------------------------------------------- Breakpoints */
@media (min-width: 640px) {
  .dside { padding-inline: var(--s-6); }
  .dmain { padding-inline: var(--s-6); }
  .prose > h1 { font-size: 2.75rem; }
  .pager { grid-template-columns: 1fr 1fr; }
  .specs > div { grid-template-columns: 12rem minmax(0, 1fr); }
}

@media (min-width: 1024px) {
  .dshell { grid-template-columns: 17rem minmax(0, 1fr); }

  .dside {
    height: calc(100dvh - var(--head));
    padding: var(--s-6) var(--s-4) var(--s-5);
    border-right: 1px solid var(--line-row);
    border-bottom: 0;
  }

  .dmenu > summary { display: none; }
  .dmain { padding-block: var(--s-7) var(--s-9); }
}

@media (min-width: 1280px) {
  .dshell { grid-template-columns: 17rem minmax(0, 1fr) 16rem; }

  .dtoc {
    display: block;
    position: sticky;
    top: var(--head);
    align-self: start;
    max-height: calc(100dvh - var(--head));
    overflow-y: auto;
    padding: var(--s-7) var(--s-4) var(--s-5);
  }

  .dtoc ul ul { padding-left: var(--s-3); }
}
