/*
 * The docs site's own stylesheet.
 *
 * The palette is not here. `tokens.css` beside this file is a verbatim copy of
 * `src/styles/tokens.css`, taken at build time, so the site is emerald on sage
 * in light and dark for the same reason the app is, and a palette change in
 * the app reaches the docs on the next build rather than being re-typed here.
 * Only what the app has no use for is defined below: a reading measure, a
 * three-column shell, and prose rhythm.
 *
 * The app's tokens are mobile-first and deliberately narrow (`--content-max`
 * is 34rem, a phone list). Long-form prose wants more, so the measure here is
 * its own token and the app's is left alone.
 */

:root {
  --measure: 44rem;
  --rail: 15.5rem;
  --toc: 14rem;
  --bar-h: 3.25rem;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  --code-bg: color-mix(in oklab, var(--surface) 70%, var(--bg));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Anchored headings land below the sticky bar rather than under it. */
  scroll-padding-top: calc(var(--bar-h) + var(--space-4));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  accent-color: var(--accent);
}

a {
  color: var(--accent);
  text-decoration-color: color-mix(in oklab, var(--accent) 35%, transparent);
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* The skip link is the first thing in the tab order and invisible until it
   has focus: a sidebar of two hundred decision titles is a long way to tab
   through to reach the page you are already looking at. */
.skip {
  position: absolute;
  left: var(--space-3);
  top: var(--space-3);
  z-index: 40;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  transform: translateY(-200%);
}

.skip:focus {
  transform: none;
}

/* ---------------------------------------------------------------- the bar */

.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--bar-h);
  padding-inline: var(--space-4);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand b {
  font-weight: 600;
}

.brand span {
  display: none;
  color: var(--text-faint);
  font-size: var(--text-sm);
  font-weight: 400;
}

@media (min-width: 40rem) {
  .brand span {
    display: inline;
  }
}

.bar-spacer {
  flex: 1;
}

.app-link {
  display: none;
  font-size: var(--text-sm);
  white-space: nowrap;
}

@media (min-width: 62rem) {
  .app-link {
    display: inline;
  }
}

/* The sidebar toggle. A checkbox rather than a script, so the nav works on a
   phone with JavaScript still loading or blocked. */
.nav-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding-inline: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  font-size: var(--text-sm);
  cursor: pointer;
  user-select: none;
}

.nav-check:focus-visible + .bar .nav-btn {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------- the shell */

.shell {
  display: grid;
  grid-template-areas: 'nav' 'toc' 'main';
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  max-width: 100rem;
  margin-inline: auto;
}

.rail {
  grid-area: nav;
  display: none;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.nav-check:checked ~ .shell .rail {
  display: block;
}

.toc {
  grid-area: toc;
  padding: var(--space-4) var(--space-4) 0;
}

main {
  grid-area: main;
  min-width: 0;
  padding: var(--space-5) var(--space-4) var(--space-6);
}

.prose {
  max-width: var(--measure);
  margin-inline: auto;
}

@media (min-width: 62rem) {
  .shell {
    grid-template-areas: 'nav toc' 'nav main';
    grid-template-columns: var(--rail) minmax(0, 1fr);
  }

  .nav-btn {
    display: none;
  }

  .rail {
    display: block;
    position: sticky;
    top: var(--bar-h);
    align-self: start;
    max-height: calc(100vh - var(--bar-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    border-bottom: 0;
    border-right: 1px solid var(--border);
    padding: var(--space-5) var(--space-4);
  }

  .toc {
    padding: var(--space-5) var(--space-6) 0;
  }

  .toc details {
    margin-inline: 0;
  }

  main {
    padding: var(--space-5) var(--space-6) var(--space-6);
  }

  .prose {
    margin-inline: 0;
  }
}

@media (min-width: 86rem) {
  .shell {
    grid-template-areas: 'nav main toc';
    grid-template-columns: var(--rail) minmax(0, 1fr) var(--toc);
  }

  .toc {
    position: sticky;
    top: var(--bar-h);
    align-self: start;
    max-height: calc(100vh - var(--bar-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-5) var(--space-4);
  }

  .prose {
    margin-inline: auto;
  }
}

/* ---------------------------------------------------------------- the nav */

.rail h3,
.toc h3 {
  margin: 0 0 var(--space-2);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.rail section + section {
  margin-top: var(--space-5);
}

.rail ul,
.toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail a {
  display: block;
  padding: 0.3rem var(--space-2);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
}

.rail a:hover {
  background: var(--surface);
  color: var(--text);
}

.rail a[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.rail .sub {
  margin: var(--space-1) 0 var(--space-2) var(--space-3);
  border-left: 1px solid var(--border);
  padding-left: var(--space-2);
}

.rail .sub a {
  font-size: var(--text-sm);
  padding-block: 0.2rem;
}

/* The on-page contents. A fold on narrow screens, a rail on wide ones. */
.toc details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  padding: var(--space-2) var(--space-3);
  margin: 0 auto var(--space-5);
  max-width: var(--measure);
}

.toc summary {
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding-block: var(--space-1);
}

.toc a {
  display: block;
  padding: 0.2rem 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  line-height: 1.4;
}

.toc a:hover {
  color: var(--accent);
}

.toc a.lv3 {
  padding-left: var(--space-3);
}

@media (min-width: 86rem) {
  .toc details {
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    max-width: none;
  }

  .toc summary {
    display: none;
  }

  .toc .toc-list {
    border-left: 1px solid var(--border);
    padding-left: var(--space-3);
  }
}

/* -------------------------------------------------------------- the prose */

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  position: relative;
  line-height: 1.25;
  margin: 0;
  scroll-margin-top: calc(var(--bar-h) + var(--space-4));
}

.prose h1 {
  font-size: 1.875rem;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-4);
}

.prose h2 {
  font-size: 1.375rem;
  letter-spacing: -0.01em;
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.prose h3 {
  font-size: 1.0625rem;
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
}

.prose h4 {
  font-size: var(--text-base);
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  color: var(--text-muted);
}

/* Present but out of the way until the heading is hovered or focused, so the
   page reads as prose and still hands over a link to any one section. */
.prose .anchor {
  position: absolute;
  right: 100%;
  padding-right: 0.35rem;
  color: var(--text-faint);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.prose :is(h1, h2, h3, h4):hover .anchor,
.prose .anchor:focus {
  opacity: 1;
}

.prose p,
.prose ul,
.prose ol,
.prose pre,
.prose blockquote,
.prose .table-wrap {
  margin: 0 0 var(--space-4);
}

.prose li {
  margin-bottom: var(--space-2);
}

.prose li > ul,
.prose li > ol {
  margin-top: var(--space-2);
  margin-bottom: 0;
}

.prose ul,
.prose ol {
  padding-left: 1.35rem;
}

.prose ::marker {
  color: var(--text-faint);
}

.prose strong {
  font-weight: 600;
  color: var(--text);
}

.prose code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.32em;
  overflow-wrap: break-word;
}

.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}

.prose pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.55;
}

.prose blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--space-3) var(--space-4);
  color: var(--text);
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

/* A table is the one thing allowed to be wider than the measure, and it
   scrolls inside its own box rather than making the page scroll sideways. */
.prose .table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9375rem;
}

.prose th,
.prose td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose thead th {
  background: var(--surface);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
}

.prose tbody tr:last-child :is(td, th) {
  border-bottom: 0;
}

/* ------------------------------------------------------------ the callout */

.note {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--surface-raised);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-5);
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.note > :last-child {
  margin-bottom: 0;
}

.note strong {
  color: var(--text);
}

/* --------------------------------------------------------------- the home */

.lede {
  max-width: var(--measure);
}

.lede h1 {
  font-size: 2.25rem;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-3);
}

.doors {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  max-width: var(--measure);
  margin-top: var(--space-5);
  padding: 0;
  list-style: none;
}

.door {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-soft);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.door:hover {
  border-color: var(--accent);
}

.door b {
  display: block;
  color: var(--accent);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.door span {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* ------------------------------------------------------------- the search */

.search {
  position: relative;
  flex: 1 1 8rem;
  min-width: 0;
}

@media (min-width: 62rem) {
  .search {
    flex: 0 1 22rem;
  }
}

.search input {
  width: 100%;
  min-height: 2.25rem;
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.search input::placeholder {
  color: var(--text-faint);
}

.results {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  width: min(32rem, calc(100vw - 2 * var(--space-4)));
  max-height: min(28rem, calc(100vh - var(--bar-h) - var(--space-5)));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: var(--space-2);
}

.results:empty {
  display: none;
}

.results a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
}

.results a:hover,
.results a[aria-selected='true'] {
  background: var(--surface);
}

.results b {
  display: block;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
}

.results .where {
  color: var(--accent);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.results .snip {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.45;
  margin-top: 0.1rem;
}

.results mark {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 2px;
}

.results .empty {
  padding: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* --------------------------------------------------------------- the foot */

.foot {
  max-width: var(--measure);
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: var(--text-sm);
}

.foot a {
  color: var(--text-muted);
}

/* --------------------------------------------------------------- printing */

@media print {
  .bar,
  .rail,
  .toc,
  .skip {
    display: none;
  }

  body {
    background: #fff;
  }

  .prose {
    max-width: none;
  }
}
