/*
 * Element defaults, typography, and the reading column.
 * Every colour here MUST be a var(--…) from tokens.css — enforced by
 * test/unit/tokens.test.js. See spec.md §10.
 *
 * Mobile-first. The only breakpoints in the whole design system are 48rem and
 * 64rem. Anything animated is inside @media (prefers-reduced-motion:
 * no-preference).
 */

/* ---- Reset ------------------------------------------------------------- */

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

html {
  /* Percentage keeps the user's browser font-size preference intact. */
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-body);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd,
pre {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding-inline-start: var(--space-6);
}

/* ---- Focus and selection ---------------------------------------------- */

/* `outline: none` is never used anywhere in this codebase. The default ring is
   replaced, not removed. */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--color-selection);
  color: var(--color-text-strong);
}

/* ---- Skip link --------------------------------------------------------- */

/* First focusable element of layout.ejs. Off-canvas until focused; it must
   never be display:none, or keyboard users cannot reach it. */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border: var(--border-hairline);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-strong);
  font-size: var(--text-sm);
  text-decoration: none;
  transform: translateY(calc(-100% - var(--space-4)));
}

.skip-link:focus {
  transform: translateY(0);
}

/* ---- Reusable utility -------------------------------------------------- */

/* Available to screen readers, invisible on screen. Used for icon-only button
   labels (see .btn-icon in components.css). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Layout primitives ------------------------------------------------- */

/* §10 component inventory row 1. */
.shell {
  width: 100%;
  max-width: var(--width-shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* §10 component inventory row 2. The reading column. */
.prose {
  max-width: var(--width-prose);
  line-height: var(--leading-body);
}

.prose > * + * {
  margin-block-start: var(--space-5);
}

.prose > * + :is(h2, h3, h4) {
  margin-block-start: var(--space-10);
}

/* ---- Headings ---------------------------------------------------------- */

h1 {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  font-weight: var(--weight-normal);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-strong);
}

h2 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--color-text-strong);
}

h3 {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--color-text-strong);
}

h4 {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  color: var(--color-text-strong);
}

h5,
h6 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--color-text-strong);
}

h6 {
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Anchors appended by rehype-autolink-headings. Only revealed on hover or
   keyboard focus so the prose stays clean. */
:is(h1, h2, h3, h4, h5, h6) > a[href^='#'] {
  margin-inline-start: var(--space-2);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  text-decoration: none;
  opacity: 0;
}

:is(h1, h2, h3, h4, h5, h6):hover > a[href^='#'],
:is(h1, h2, h3, h4, h5, h6) > a[href^='#']:focus-visible {
  opacity: 1;
}

/* ---- Links ------------------------------------------------------------- */

a {
  color: var(--color-link);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--color-border-strong);
}

a:hover {
  color: var(--color-link-hover);
  text-decoration-color: currentColor;
}

/* ---- Inline text ------------------------------------------------------- */

strong,
b {
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
}

small {
  font-size: var(--text-sm);
}

hr {
  height: 0;
  margin-block: var(--space-10);
  border: 0;
  border-top: var(--border-hairline);
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* ---- Code, keystrokes -------------------------------------------------- */

pre {
  padding: var(--space-4);
  border: var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  overflow-x: auto;
  tab-size: 2;
}

pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  color: inherit;
}

code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--accent-blue-bg);
  color: var(--accent-blue-fg);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

kbd {
  padding: 0.15em 0.4em;
  border: var(--border-hairline);
  border-radius: var(--radius-sm);
  background: var(--color-surface-subtle);
  color: var(--color-text-strong);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: 1;
}

/* ---- Quotes ------------------------------------------------------------ */

blockquote {
  padding-inline-start: var(--space-5);
  border-inline-start: 2px solid var(--color-border);
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  color: var(--color-text-muted);
}

blockquote > * + * {
  margin-block-start: var(--space-4);
}

/* ---- Tables ------------------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  text-align: start;
}

/* Tables are the one element that can overflow the reading column on phones. */
.prose :is(table) {
  display: block;
  overflow-x: auto;
}

th,
td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-hairline);
  text-align: start;
  vertical-align: top;
}

th {
  font-weight: var(--weight-semibold);
  color: var(--color-text-strong);
  white-space: nowrap;
}

caption {
  margin-block-end: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-align: start;
}

/* ---- Media ------------------------------------------------------------- */

img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

img {
  border-radius: var(--radius-sm);
}

figure > figcaption {
  margin-block-start: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* ---- Forms (Pagefind injects an input; nothing else uses forms) -------- */

input,
button,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* ---- Details / summary ------------------------------------------------- */

summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-strong);
}

/* ---- Responsive: the only two breakpoints in the design system --------- */

/* 48rem — roomier gutters and a larger reading measure once the viewport is
   wider than a phone. */
@media (min-width: 48rem) {
  :root {
    --gutter: var(--space-8);
  }

  h1 {
    font-size: var(--text-4xl);
  }
}

/* 64rem — the reading column stops growing; extra width becomes margin. */
@media (min-width: 64rem) {
  :root {
    --gutter: var(--space-12);
  }
}

/* ---- Motion ------------------------------------------------------------ */

/* Everything below is opt-in motion, so it lives behind the reduced-motion
   guard. With reduced motion the page is simply static — no feature is lost. */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  .skip-link {
    transition: transform var(--dur-fast) var(--ease-out);
  }

  :is(h1, h2, h3, h4, h5, h6) > a[href^='#'] {
    transition: opacity var(--dur-fast) var(--ease-out);
  }

  a {
    transition:
      color var(--dur-fast) var(--ease-out),
      text-decoration-color var(--dur-fast) var(--ease-out);
  }

  /* Scroll-entry reveal. site.js toggles [data-reveal] to 'shown' from an
     IntersectionObserver; the initial state is only applied when the observer
     is actually present, so a no-JS page never stays invisible. */
  [data-reveal='hidden'] {
    opacity: 0;
    transform: translateY(12px);
  }

  [data-reveal='shown'] {
    opacity: 1;
    transform: translateY(0);
    transition:
      opacity var(--dur-base) var(--ease-out),
      transform var(--dur-base) var(--ease-out);
  }
}
