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

/* The {% picture %} tag wraps every <img> in a <picture> for AVIF/WebP
   sources. Left alone, that extra box becomes the actual flex/grid item
   in layouts built around sizing the <img> directly (e.g. flex-shrink: 0
   on .about-header__image) - the unstyled <picture> shrinks instead,
   squishing the image inside it. display: contents removes <picture>'s
   own box from layout entirely so the <img> participates directly, same
   as before every image went through this tag. Doesn't affect the
   browser's source-selection behavior, only how it's laid out. */
picture {
  display: contents;
}

html {
  color-scheme: light dark;
  scroll-padding-top: 2rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading-normal);
  background: var(--color-bg);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

img,
svg {
  max-width: 100%;
  display: block;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h1 {
  font-size: var(--step-4);
  font-weight: 700;
}
h2 {
  font-size: var(--step-3);
}
h3 {
  font-size: var(--step-2);
}
h4 {
  font-size: var(--step-1);
}

a {
  color: inherit;
}

.richtext a,
.lede a {
  color: var(--color-accent);
}

@media (prefers-reduced-motion: no-preference) {
  a,
  .button,
  .link-arrow,
  .index-row,
  .tag {
    transition:
      color 0.15s ease,
      background-color 0.15s ease,
      border-color 0.15s ease,
      opacity 0.2s ease;
  }
}

/* Accessible focus states - never remove without a visible replacement. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-3);
  background: var(--color-ink);
  color: var(--color-paper);
  padding: var(--space-2) var(--space-3);
  z-index: 100;
  font-family: var(--font-display);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-3);
}

/* Frame -----------------------------------------------------------------
   The whole site is two columns: a fixed-width spine (identity + index of
   sections + a colophon) and the content column. This replaces the usual
   sticky top navbar - it reads as a book's running margin, not a product
   header, which is the point. */

.frame {
  min-height: 100vh;
}

@media (min-width: 64rem) {
  .frame {
    display: grid;
    grid-template-columns: var(--spine-width) 1fr;
    align-items: start;
  }
}

.spine {
  border-bottom: var(--border-width) solid var(--color-line);
}

@media (min-width: 64rem) {
  .spine {
    position: sticky;
    top: 0;
    height: 100vh;
    border-bottom: 0;
    border-right: var(--border-width) solid var(--color-line);
  }
}

.spine__inner {
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

@media (min-width: 64rem) {
  .spine__inner {
    height: 100%;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--space-5) var(--space-4);
  }
}

.spine__mark {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-display);
  line-height: 0.92;
}

.spine__mark-line {
  font-size: var(--step-2);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.spine__mark-line--outline {
  color: transparent;
  -webkit-text-stroke: 1.25px var(--color-text);
  margin-top: 0.05em;
}

@supports not (-webkit-text-stroke: 1px black) {
  .spine__mark-line--outline {
    color: var(--color-text);
    -webkit-text-stroke: initial;
    opacity: 0.55;
  }
}

@media (min-width: 64rem) {
  .spine__mark-line {
    font-size: var(--step-3);
  }

  .spine__mark-line--outline {
    -webkit-text-stroke-width: 1.5px;
  }
}

/* Mobile nav uses the checkbox-toggle pattern (not <details>, whose
   closed-state box collapses to 0x0 in every engine even when the child
   list's display is forced open via CSS). On mobile it opens a full
   overlay panel; at the spine breakpoint the toggle disappears and the
   index is simply always visible down the rail. */
.nav-toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.spine__toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  user-select: none;
}

.spine__toggle::before {
  content: "Index";
}

.nav-toggle-input:checked ~ .spine__toggle::before {
  content: "Close";
}

.nav-toggle-input:focus-visible ~ .spine__toggle {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.spine__nav {
  display: none;
}

.nav-toggle-input:checked ~ .spine__nav {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--color-bg);
  padding: var(--space-6) var(--space-4) var(--space-4);
  overflow-y: auto;
}

.spine__nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: nav-index;
}

.spine__nav-list li {
  counter-increment: nav-index;
  border-top: var(--border-width) solid var(--color-line);
}

.spine__nav-list li:last-child {
  border-bottom: var(--border-width) solid var(--color-line);
}

.spine__nav-list a {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
}

@media (min-width: 64rem) {
  .spine__nav-list a {
    font-size: var(--step-1);
    padding: var(--space-2) 0;
  }
}

.spine__nav-list a::before {
  content: counter(nav-index, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 400;
  color: var(--color-text-muted);
}

.spine__nav-list a:hover,
.spine__nav-list a[aria-current="page"] {
  color: var(--color-accent);
}

.theme-toggle {
  margin-top: var(--space-4);
}

@media (min-width: 64rem) {
  .spine__toggle {
    display: none;
  }

  .spine__nav {
    display: block;
    position: static;
    background: none;
    padding: 0;
    overflow: visible;
  }
}

.content-column {
  min-width: 0;
}

main {
  display: block;
}

.container {
  max-width: var(--wide-width);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.container--narrow {
  max-width: var(--content-width);
}

.container--medium {
  max-width: var(--content-width-wide);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack > * {
  margin: 0;
}

section {
  padding-block: var(--space-6);
}

@media (max-width: 40rem) {
  section {
    padding-block: var(--space-5);
  }
}

.section-divider {
  border: none;
  border-top: var(--border-width) solid var(--color-line);
  margin: 0;
}

/* Footer - a single colophon line, not a link farm. */

.site-footer {
  border-top: var(--border-width) solid var(--color-line);
  padding-block: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--step--1);
}

.site-footer__inner {
  max-width: var(--wide-width);
  margin-inline: auto;
  padding-inline: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.site-footer .richtext,
.site-footer .richtext p {
  margin: 0;
}

.social-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.social-links a {
  text-decoration: none;
}

.social-links li:not(:last-child)::after {
  content: "\00b7";
  margin-inline: var(--space-2);
  color: var(--color-line);
}

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