/* =====================================================================
   The 406: Montana — docs
   =====================================================================

   Loaded AFTER site.css and adds to it rather than replacing it. Every
   colour, font, radius and easing here comes from the tokens site.css
   already defines on :root, so the theme toggle works on these pages
   with no extra code and a token change reaches them for free.

   WHY A SECOND STYLESHEET AT ALL. site.css is 2,000 lines of a landing
   page — sticky scenes, a hero pan, an interest counter. None of it
   applies to a page of prose, and appending a documentation layout to it
   would mean every visitor to the front page downloads a sidebar they
   will never see. These are separate documents with separate jobs.

   The pages are also deliberately static: no scroll listeners, no
   IntersectionObserver, no animation beyond a hover colour. A page
   somebody is reading rules on should not be doing anything.
   ===================================================================== */

/* ------------------------------------------------------------- layout */

/*
 * Single column on a phone, sidebar and content on a desktop.
 *
 * `--docs-nav` is the fixed bar's height plus breathing room, and it is
 * used in three places — the sticky sidebar's offset, the scroll-margin
 * on headings, and the top padding here. One number, so an anchor never
 * lands underneath the bar.
 */
:root {
  /* Derived from site.css rather than repeated. The two were separate
     literals and nothing kept them in step. */
  --docs-nav: var(--nav-h);
  --docs-side: 15rem;
}

.docs {
  display: block;
  max-width: var(--max);
  margin-inline: auto;
  padding: calc(var(--docs-nav) + 2rem) var(--gutter) 5rem;
}

@media (min-width: 900px) {
  .docs {
    display: grid;
    grid-template-columns: var(--docs-side) minmax(0, 1fr);
    gap: 3.5rem;
    align-items: start;
  }
}

/* ------------------------------------------------------------ sidebar */

/*
 * A <details> on a phone and a plain sticky <nav> on a desktop.
 *
 * The same element does both, which is why the summary is hidden rather
 * than the whole block being duplicated: two copies of a navigation list
 * is two places for a new page to be forgotten. `open` is forced at the
 * breakpoint so the desktop version cannot be collapsed by a click that
 * only makes sense on a phone.
 */
.docs__side {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  padding: 0.35rem 0;
  margin-bottom: 2.5rem;
}

.docs__side summary {
  cursor: pointer;
  list-style: none;
  padding: 0.85rem 1.1rem;
  font: 600 0.72rem/1 var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.docs__side summary::-webkit-details-marker {
  display: none;
}

.docs__side summary::after {
  content: '+';
  float: right;
  color: var(--primary-text);
}

.docs__side[open] summary::after {
  content: '–';
}

.docs__side ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0.5rem;
}

.docs__side a {
  display: block;
  padding: 0.55rem 1.1rem;
  font-size: 0.92rem;
  color: var(--text-dim);
  border-left: 2px solid transparent;
  transition: color var(--tap) var(--ease), border-color var(--tap) var(--ease);
}

.docs__side a:hover {
  color: var(--text);
}

/*
 * The page you are on. Set as a static attribute in each file rather
 * than computed in JavaScript — it is one attribute per page, it works
 * with scripting off, and it cannot get out of step with the URL.
 */
.docs__side a[aria-current='page'] {
  color: var(--primary-text);
  border-left-color: var(--primary);
  font-weight: 600;
}

@media (min-width: 900px) {
  .docs__side {
    position: sticky;
    top: calc(var(--docs-nav) + 1.5rem);
    margin-bottom: 0;
  }

  .docs__side summary {
    display: none;
  }

  .docs__side ul {
    padding-block: 0.5rem;
  }
}

/* -------------------------------------------------------------- prose */

.docs__body {
  min-width: 0;
  max-width: 46rem;
}

.docs__body h1 {
  font-size: clamp(1.9rem, 4.5vw, 2.7rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-wrap: balance;
}

.docs__lede {
  margin-top: 0.9rem;
  font-size: 1.08rem;
  line-height: 1.65;
  color: var(--text-dim);
  text-wrap: pretty;
}

.docs__body h2 {
  margin-top: 3rem;
  font-size: 1.35rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 700;
  /* So an anchored heading never lands under the fixed bar. */
  scroll-margin-top: calc(var(--docs-nav) + 1rem);
}

.docs__body h3 {
  margin-top: 1.9rem;
  font-size: 1.05rem;
  font-weight: 600;
  scroll-margin-top: calc(var(--docs-nav) + 1rem);
}

.docs__body p,
.docs__body li {
  margin-top: 0.9rem;
  color: var(--text-dim);
  text-wrap: pretty;
}

.docs__body strong {
  color: var(--text);
  font-weight: 600;
}

.docs__body a:not(.btn) {
  color: var(--primary-text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.docs__body ul,
.docs__body ol {
  margin: 0.4rem 0 0;
  padding-left: 1.15rem;
}

.docs__body li::marker {
  color: var(--primary-text);
}

.docs__body hr {
  margin: 3rem 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}

/* A rule that matters enough to be looked at rather than read past. */
.docs__note {
  margin-top: 1.4rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  background: var(--card);
  padding: 1rem 1.15rem;
}

.docs__note p {
  margin-top: 0;
  color: var(--text);
}

.docs__note p + p {
  margin-top: 0.7rem;
}

/* The index page's grid of cards. */
.docs__cards {
  display: grid;
  gap: 0.9rem;
  margin-top: 2rem;
}

@media (min-width: 640px) {
  .docs__cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.docs__card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  padding: 1.25rem;
  transition: border-color var(--move) var(--ease), transform var(--move) var(--ease);
}

.docs__card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.docs__card h2 {
  margin-top: 0;
  font-size: 1.05rem;
}

.docs__card p {
  margin-top: 0.45rem;
  font-size: 0.95rem;
}

/* Previous / next, at the foot of every page. */
.docs__ends {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 3rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
}

.docs__ends a {
  font: 600 0.72rem/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  transition: border-color var(--tap) var(--ease), color var(--tap) var(--ease);
  text-decoration: none;
}

.docs__ends a:hover {
  border-color: var(--primary);
  color: var(--primary-text);
}

.docs__ends a:last-child {
  margin-left: auto;
}

/* The updated-on line. Maintained by hand, like sitemap.xml's lastmod. */
.docs__stamp {
  margin-top: 2rem;
  font: 600 0.66rem/1.5 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ------------------------------------------------------------- footer */

/*
 * A short footer, not the landing page's four-column one.
 *
 * .footer__base is deliberately not reused: it carries its own top
 * border and a 3rem margin, meant to sit UNDER the four columns. On a
 * page with no columns above it that draws a second rule a finger's
 * width below the first one.
 */
.docs-foot {
  border-top: 1px solid var(--border);
  padding: 2rem 0 3rem;
}

.docs-foot .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.5rem;
  align-items: baseline;
  justify-content: space-between;
}

.docs-foot p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.docs-foot a {
  color: var(--text-dim);
  transition: color var(--tap) var(--ease);
}

.docs-foot a:hover {
  color: var(--primary-text);
}
