/* The manual's chrome, both editions. Tokens mirror landing/page.css
   so the manual reads as the same publication as the marketing site. */

:root {
  --accent: #2f4a6b; /* scripts/build.mjs swaps the two accent values per brand */
  --accent-deep: #1e3350;
  --sage: #7a8466;
  --ochre: #c89456;
  --paper: #fdfbf5;
  --cream: #f9f5ec;
  --canvas: #f5f1e7;
  --ink: #1a1612;
  --ink-soft: #3d342a;
  --muted: #6e6152; /* ≥4.5:1 on paper — the label voice must pass AA at its size */
  --line: rgba(26, 22, 18, 0.1);
  --line-soft: rgba(26, 22, 18, 0.06);

  --font-display: "Instrument Serif", Georgia, serif;
  --font-ui: "Bricolage Grotesque", -apple-system, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Type scale — mirrors ds-bundle --tc-fs-* */
  --fs-eyebrow: 12px;
  --ls-eyebrow: 2px;
  --fs-page-title: 56px;
  --fs-section-title: 30px;
  --fs-card-title: 17px;
  --fs-body: 15px;
  --fs-meta: 13px;
  --fs-mono: 12px;
  --lh-tight: 1.1;
  --lh-body: 1.6;
}

@media (max-width: 767px) {
  :root {
    --fs-page-title: 40px;
  }
}

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

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Reaches the article without tabbing the whole rail. */
.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  background: var(--paper);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  text-decoration: none;
}

main:focus {
  outline: none;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: var(--paper);
}

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
}

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

/* ── Masthead ─────────────────────────────────────────────────────────── */

.masthead {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--ink);
  text-decoration: none;
}

.brand em {
  font-style: italic;
}

.masthead-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--muted);
}

.masthead-app {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
}

.masthead-app:hover {
  border-color: var(--accent);
}

/* ── Frame: sidebar + page ────────────────────────────────────────────── */

.frame {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 48px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 28px 72px;
}

/* The chapter rail is ~830px tall with every act in it, which is more than most laptop
   viewports. A sticky element that is taller than the scrollport pins at `top` and its overflow
   becomes unreachable — scrolling the page does not move a stuck element — so the lower acts and
   both release-notes pages were simply not there, and the links in them stayed in the tab order
   with focus landing off-screen. Bounding it to the scrollport and letting it scroll inside
   itself is the standard answer and keeps the sticky behaviour the design wants. `dvh` first,
   `vh` behind it. */
.side {
  position: sticky;
  top: 32px;
  align-self: start;
  max-height: calc(100vh - 56px);
  max-height: calc(100dvh - 56px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.toc {
  display: none;
}

.chapters {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: chapter -1;
  border-left: 1px solid var(--line);
}

.chapters ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapters .chapter-item {
  counter-increment: chapter;
}

.chapters a {
  display: block;
  padding: 5px 0 5px 16px;
  font-size: var(--fs-meta);
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1.5px;
}

.chapters .chapter-item a::before {
  content: counter(chapter, decimal-leading-zero) " · ";
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  color: var(--muted);
  letter-spacing: 0.5px;
}

.chapters .rail-group-label {
  display: block;
  padding: 16px 0 4px 16px;
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--muted);
}

.chapters > .rail-group:first-child .rail-group-label {
  padding-top: 0;
}

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

.chapters a[aria-current="page"] {
  color: var(--ink);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* ── The page itself ──────────────────────────────────────────────────── */

.page {
  max-width: 560px;
}

article h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(34px, 5vw, 46px);
  line-height: 1.08;
  margin: 0 0 18px;
}

article h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--fs-section-title);
  line-height: var(--lh-tight);
  margin: 44px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

article h3 {
  font-size: var(--fs-card-title);
  font-weight: 600;
  margin: 30px 0 8px;
}

/* A reader arriving from search or a cross-link lands on a fragment; the accent
   rule marks the section they came for, echoing the rail's current-chapter mark. */
article h2:target,
article h3:target {
  border-left: 2px solid var(--accent);
  padding-left: 14px;
  margin-left: -14px;
}

article .permalink {
  margin-left: 8px;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
}

article h2 .permalink,
article h3 .permalink {
  font-family: var(--font-mono);
  font-size: 0.7em;
  font-weight: 400;
}

article h2:hover .permalink,
article h3:hover .permalink,
article .permalink:focus-visible {
  opacity: 1;
}

article .permalink:hover {
  color: var(--accent);
}

article p,
article ul,
article ol {
  margin: 0 0 16px;
}

article li {
  margin-bottom: 5px;
}

article img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 6px 0 10px;
  background: var(--cream);
}

article code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--canvas);
  border-radius: 4px;
  padding: 1px 5px;
}

article pre {
  background: var(--canvas);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 16px;
}

article pre code {
  background: none;
  padding: 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 0 16px;
}

article table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-meta);
}

article th {
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
}

article th,
article td {
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 14px 8px 0;
  vertical-align: top;
}

article blockquote {
  margin: 0 0 16px;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--ochre);
  color: var(--ink-soft);
}

article hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 32px 0;
}

/* ── Pager and colophon ───────────────────────────────────────────────── */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-meta);
}

.pager a {
  text-decoration: none;
}

.colophon {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 28px 40px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  letter-spacing: 0.5px;
  color: var(--muted);
}

.colophon a {
  color: var(--muted);
}

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

/* ── Search ───────────────────────────────────────────────────────────── */

/* The box is `hidden` in the markup until search.js reveals it, so these rules
   have to lose to that attribute rather than override it. */
.search[hidden],
.search-panel[hidden] {
  display: none;
}

.search {
  position: relative;
  flex: 0 1 300px;
  min-width: 0;
}

.search-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder {
  color: var(--muted);
}

.search-input:focus {
  border-color: var(--accent);
  background: var(--paper);
}

.search-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: min(420px, calc(100vw - 40px));
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(26, 22, 18, 0.12);
  padding: 6px;
}

.search-hit {
  display: block;
  padding: 9px 11px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--ink-soft);
}

.search-hit + .search-hit {
  border-top: 1px solid var(--line-soft);
}

.search-hit:hover,
.search-hit.is-active {
  background: var(--cream);
}

.search-crumb {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-eyebrow);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.search-snippet {
  display: block;
  font-size: var(--fs-meta);
  line-height: 1.5;
}

.search-panel mark {
  background: rgba(200, 148, 86, 0.28);
  color: inherit;
  border-radius: 2px;
}

/* The no-match / index-failed message. A sibling of the listbox rather than a child of it, so it
   carries the panel's own placement to land in the same place. */
#search-status {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: min(420px, calc(100vw - 40px));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(26, 22, 18, 0.12);
  padding: 6px;
}

/* Collapsed on emptiness rather than on `hidden`: a `display: none` region is not reliably
   announced, and this one has to be in the tree at the moment its text changes. An empty region
   still occupies a positioned box, so `:empty` is what keeps it from showing. */
#search-status:empty {
  display: none;
}

.search-empty {
  margin: 0;
  padding: 10px 11px;
  font-size: var(--fs-meta);
  color: var(--muted);
}

/* ── Narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .frame {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    padding: 24px 20px 56px;
  }

  .side {
    display: none;
  }

  .toc {
    display: block;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--cream);
  }

  .toc summary {
    font-family: var(--font-mono);
    font-size: var(--fs-eyebrow);
    letter-spacing: var(--ls-eyebrow);
    text-transform: uppercase;
    color: var(--ink-soft);
    cursor: pointer;
  }

  .toc .chapters {
    margin-top: 10px;
    border-left: 0;
  }

  .masthead {
    padding: 14px 20px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .masthead-eyebrow {
    display: none;
  }

  .search {
    flex: 1 1 100%;
    order: 3;
  }

  .search-panel {
    width: 100%;
  }

  #search-status {
    width: 100%;
  }

  /* Touch controls reach the 44px floor; the desktop print layout is untouched. */
  .chapters a,
  .toc summary,
  .masthead-app {
    display: flex;
    align-items: center;
    min-height: 44px;
  }

  .chapters a {
    padding-top: 0;
    padding-bottom: 0;
  }

  .chapters a::before {
    margin-right: 4px;
  }

  /* Below 16px iOS zooms the page when the field takes focus. */
  .search-input {
    font-size: 16px;
    min-height: 44px;
  }
}
