/* base.css — reset, type ladder, prose.
 *
 * Every value here names a ROLE from assets/theme/tokens.css. No literal
 * colours, no pack primitives (--surface-container-*, --primary, --ink-*).
 * tools/check.py fails the build on either. That discipline is the only thing
 * that lets the theme be swapped by replacing one file.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;   /* sticky header height, for #anchor jumps */
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-relaxed);
  font-weight: var(--fw-regular);
  -webkit-font-smoothing: antialiased;
}

/* ---- headings ---------------------------------------------------------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: var(--lh-tight);
  margin: 0 0 var(--sp-4);
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); font-weight: var(--fw-extra); letter-spacing: var(--ls-tight); }
h2 { font-size: var(--fs-h2); font-weight: var(--fw-bold); margin-top: var(--sp-8); }
h3 { font-size: var(--fs-h3); font-weight: var(--fw-semibold); margin-top: var(--sp-7); }
h4 { font-size: var(--fs-body-lg); font-weight: var(--fw-semibold); margin-top: var(--sp-6); }

h1 + .lede {
  font-size: var(--fs-body-lg);
  color: var(--text-secondary);
  margin-top: calc(var(--sp-2) * -1);
  max-width: 62ch;
}

/* A heading you can link to. The anchor appears on hover, and is always
 * reachable by keyboard -- it is a real link, not a decoration. */
.anchor {
  color: var(--text-tertiary);
  text-decoration: none;
  margin-left: var(--sp-2);
  opacity: 0;
  font-weight: var(--fw-regular);
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }

/* ---- prose ------------------------------------------------------------- */

p, ul, ol, dl, table, figure, blockquote, pre { margin: 0 0 var(--sp-5); }

ul, ol { padding-left: var(--sp-6); }
li { margin-bottom: var(--sp-2); }
li > ul, li > ol { margin-top: var(--sp-2); margin-bottom: var(--sp-2); }

strong { font-weight: var(--fw-semibold); color: var(--text-primary); }
em { font-style: italic; }

a { color: var(--text-link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-shadow);
  border-radius: var(--r-sm);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-9) 0;
}

blockquote {
  margin-left: 0;
  padding: var(--sp-4) var(--sp-5);
  border-left: 3px solid var(--accent);
  background: var(--bg-well);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-secondary);
}
blockquote > :last-child { margin-bottom: 0; }

/* ---- code -------------------------------------------------------------- */

code, kbd, samp, pre { font-family: var(--font-mono); font-size: var(--fs-mono); }

code {
  background: var(--bg-well);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 0.1em 0.35em;
  overflow-wrap: break-word;
}

pre {
  background: var(--bg-well);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  overflow-x: auto;
}
pre code { background: none; border: 0; padding: 0; }

kbd {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  padding: 0.1em 0.4em;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

/* ---- tables ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; margin: 0 0 var(--sp-5); }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--fs-sm);
}
th, td {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  background: var(--bg-well);
  white-space: nowrap;
}
tbody tr:hover { background: var(--row-hover); }
td code { white-space: nowrap; }

/* ---- media ------------------------------------------------------------- */

img, svg, video { max-width: 100%; height: auto; }

::selection { background: var(--accent-glow); }
