/* "On this page" section navigator. Loaded only by the pages listed in
   scripts/sync_section_nav.py (How it works, under the approved freeze exception),
   so nothing here reaches another page. The list itself is generated into
   each page by sync_section_nav.py; section-nav.js adds .is-enhanced, the current-section
   marker and the narrow-screen disclosure. Without script the list is a
   plain "On this page" block above the content, and every link works.

   Existing tokens, type and focus style only: no new visual language. */

.section-nav {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.45;
}
.sn-h {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-nav ol { list-style: none; margin: 0; padding: 0; }
.sn-list { border-left: 1px solid var(--line); }
.sn-list a {
  display: block;
  padding: 6px 0 6px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  /* The site's in-content link underline (chrome.css) is a border-bottom. */
  border-bottom: 0;
  color: var(--muted);
  text-decoration: none;
}
.sn-list ol a { padding-left: 26px; }
.sn-list a:hover { color: var(--ink); }
.sn-list a[aria-current="location"] { color: var(--ink); border-left-color: var(--accent-text); }
.sn-list a.is-parent { color: var(--ink); }
.sn-list a:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

/* Collapsed sub-lists, except under the current section. Only with
   script: without it there is no current section, so everything shows. */
.section-nav.is-enhanced .sn-list li > ol { display: none; }
.section-nav.is-enhanced .sn-list li.is-open > ol { display: block; }

.sn-toggle { display: none; }

/* A heading that a navigator link moved focus to. */
.sn-main h2:focus-visible,
.sn-main h3:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 4px; }
.sn-main h2:focus:not(:focus-visible),
.sn-main h3:focus:not(:focus-visible) { outline: none; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ==== Desktop: a sticky column beside the content ==== */
@media (min-width: 1080px) {
  .sn-layout {
    max-width: var(--max);
    margin: 0 auto;
    padding: 0 var(--gutter);
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    column-gap: 56px;
    align-items: start;
  }
  /* The sections keep their own measure (.doc); only the outer wrap's
     centring and gutter move up to .sn-layout. */
  .sn-main .wrap { max-width: none; padding: 0; }
  .section-nav {
    position: sticky;
    top: calc(var(--bar-h) + 24px);
    /* Level with the first section's heading (.room-sec padding). */
    margin-top: clamp(88px, 11vw, 148px);
    max-height: calc(100vh - var(--bar-h) - 48px);
    overflow-y: auto;
    /* Below the mega-menu surface and its scrim (z-index 55 and up). */
    z-index: 1;
  }
}

/* ==== Narrow: a single "On this page" row under the bar ==== */
@media (max-width: 1079.98px) {
  .section-nav {
    margin: 48px var(--gutter) 0;
  }
  .section-nav.is-enhanced {
    position: sticky;
    /* The bar is --bar-h plus its 1px bottom border. */
    top: calc(var(--bar-h) + 1px);
    z-index: 40;
    margin: 32px 0 0;
    padding: 0 var(--gutter);
    background: var(--void);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }
  .section-nav.is-enhanced .sn-h { display: none; }
  .section-nav.is-enhanced .sn-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 44px;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 12px;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
  }
  .sn-toggle-k { color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; font-size: 11px; flex: none; }
  .sn-toggle-v { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sn-toggle::after {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: translateY(-2px) rotate(45deg);
  }
  .section-nav.is-open .sn-toggle::after { transform: translateY(2px) rotate(-135deg); }
  .sn-toggle:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: -2px; }

  .section-nav.is-enhanced .sn-list {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    max-height: calc(100vh - var(--bar-h) - 44px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px var(--gutter) 20px;
    background: var(--void);
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }
  .section-nav.is-enhanced.is-open .sn-list { display: block; }
  .section-nav.is-enhanced .sn-list a { padding-top: 9px; padding-bottom: 9px; }

  /* Linked headings land below the bar and this row, not under the row.
     Later than chrome.css's main [id] rule at equal specificity, so it wins. */
  .sn-main [id] { scroll-margin-top: calc(var(--bar-h) + 44px + 36px); }

  /* Out of the way while the mobile menu covers the page. */
  html.menu-locked .section-nav { visibility: hidden; }
}
