/* Documentation page — reading layout only: the contents rail, prose rhythm,
   tables, code blocks, anchors. Every colour comes from tokens.css. */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* The header, the footer and the language menu are dressed by chrome.css,
   which both pages load before this file. */

/* Page frame */

.docs {
  max-width: 1100px;
  margin-inline: auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  outline: none;
}

.docs-head { margin-bottom: var(--space-5); }

.docs-head h1 {
  margin: 0 0 var(--space-3);
  font-size: clamp(1.9rem, 6vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0;
  max-width: 62ch;
  color: var(--fg-dim);
  font-size: 1.0625rem;
}

.docs-content {
  min-width: 0;
  max-width: 72ch;
}

/* Contents — a collapsible block on a phone, a sticky rail on a wide screen */

.toc { margin-bottom: var(--space-6); }

.toc-box {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.toc-title {
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.toc-title::marker { color: var(--fg-faint); }

.toc-list {
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
  counter-reset: toc;
  font-size: 0.9375rem;
}

.toc-list li { counter-increment: toc; }

.toc-list a {
  display: block;
  padding: var(--space-1) 0;
  color: var(--fg-dim);
  text-decoration: none;
}

.toc-list a::before {
  content: counter(toc) '.';
  display: inline-block;
  width: 1.6em;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.toc-list a:hover { color: var(--accent); }

/* Sections */

.sec {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
  scroll-margin-top: var(--space-5);
}

.sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.sec h2 {
  margin: 0 0 var(--space-4);
  font-size: clamp(1.3rem, 4vw, 1.6rem);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.sec h3 {
  margin: var(--space-5) 0 var(--space-2);
  font-size: 1rem;
  letter-spacing: 0.01em;
}

.sec p {
  margin: 0 0 var(--space-4);
  max-width: 70ch;
}

.note { color: var(--fg-dim); font-size: 0.9375rem; }

/* Heading anchor: links the section and copies the address */

.h-anchor {
  margin-left: 0.4em;
  color: var(--fg-faint);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease;
}

.sec h2:hover .h-anchor { opacity: 1; }
.h-anchor:hover { color: var(--accent); }
.h-anchor.is-done { color: var(--ok); opacity: 1; }

@media (hover: none) {
  .h-anchor { opacity: 0.45; }
}

/* Code */

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

p code,
td code,
li code {
  padding: 0.1em 0.3em;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 5px;
  white-space: nowrap;
}

.code {
  position: relative;
  margin: 0 0 var(--space-4);
}

.code pre {
  margin: 0;
  padding: var(--space-4);
  padding-right: 5.5rem;
  overflow-x: auto;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.8125rem;
  line-height: 1.6;
  tab-size: 2;
}

.code pre code {
  font-size: inherit;
  white-space: pre;
}

.code-copy {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font: inherit;
  font-size: 0.75rem;
  color: var(--fg-dim);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.code-copy:hover { color: var(--fg); border-color: var(--line-strong); }
.code-copy .c-done { display: none; }
.code-copy.is-done { color: var(--ok); border-color: var(--ok); }
.code-copy.is-done .c-idle { display: none; }
.code-copy.is-done .c-done { display: inline; }

/* Tables — they scroll inside their own box, the page never does */

.table-wrap {
  margin: 0 0 var(--space-4);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 30rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

/* Two-column tables have room to wrap instead of scrolling */
table.t-narrow { min-width: 0; }

th,
td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
  white-space: nowrap;
  background: var(--bg-sunken);
}

tbody tr:last-child td { border-bottom: 0; }
td:last-child { color: var(--fg-dim); }
td code { font-size: 0.8125rem; }

.verb { color: var(--accent); font-weight: 600; }
.s-4xx { color: var(--warn); }
.s-5xx { color: var(--err); }

/* Questions */

.faq-item + .faq-item {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.faq-item h3 { margin-top: 0; }
.faq-item p { margin-bottom: 0; color: var(--fg-dim); }

/* Wide screens: contents becomes a rail beside the text */

@media (min-width: 62rem) {
  .docs {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    gap: 0 var(--space-6);
    align-items: start;
    padding-inline: var(--space-5);
  }

  .docs-head {
    grid-column: 1 / -1;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--line);
  }

  .docs-head h1 { font-size: 2.5rem; }
  .lead { font-size: 1.125rem; }

  .toc {
    position: sticky;
    top: var(--space-5);
    margin-bottom: 0;
    max-height: calc(100vh - var(--space-6) * 2);
    overflow-y: auto;
  }

  .toc-box { background: transparent; border: 0; padding: 0; }
  .toc-title { list-style: none; }
  .toc-title::-webkit-details-marker { display: none; }
  .sec { scroll-margin-top: var(--space-4); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}
