/* /css/base.css: reset, typography, links, focus, helpers (§4.2, §6.12, §8.1). */

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

html {
  font-size: 18px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 72px;
  hanging-punctuation: first;
}
@media (min-width: 700px) { html { font-size: 20px; } }
/* smooth only after load (main.js sets data-smooth), so /page#anchor lands exactly */
@media (prefers-reduced-motion: no-preference) {
  html[data-smooth]:not([data-motion="reduced"]) { scroll-behavior: smooth; }
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  /* A faint surveyor's dot grid: the notebook page (light) or a few stars (dark). */
  background-image: radial-gradient(circle at 1px 1px, var(--paper-dot) 1px, transparent 1.4px);
  background-size: 28px 28px;
  background-attachment: fixed;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  line-height: 1.2;
  font-weight: 700;
  margin: 0;
  text-wrap: balance;
  color: var(--ink);
}
h1 { font-size: 2.44rem; letter-spacing: -0.015em; }
h2 { font-size: 1.95rem; letter-spacing: -0.01em; }
h3 { font-size: 1.56rem; }
h4 { font-size: 1.25rem; }
@media (max-width: 699px) {
  h1 { font-size: 2.1rem; }
  h2 { font-size: 1.7rem; }
  h3 { font-size: 1.4rem; }
}

/* Zero specificity, so the prose rhythm in layout.css (:where(.beat, …) > * + *) can space consecutive blocks. */
:where(p, ul, ol, dl, blockquote, pre, table, figure) { margin: 0; }
p { text-wrap: pretty; }
ul, ol { padding-left: 1.4em; }
li + li { margin-top: .3em; }
li::marker { color: var(--ink-muted); }

small, .small { font-family: var(--font-sans); font-size: .8rem; }
strong, b { font-weight: 700; }
em, i, cite { font-style: italic; }
/* Titles in running text read as text, not as disabled grey; attributions under quotes and figures stay quiet. */
cite { color: inherit; }
blockquote cite, figcaption cite, .callout cite, .fine cite { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }
abbr[title] { text-decoration: underline dotted; text-underline-offset: .15em; }
sup, sub { line-height: 0; }

a {
  color: var(--c-lab);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--c-lab) 45%, transparent);
  text-underline-offset: .18em;
  transition: text-decoration-color var(--t-ui) var(--ease), text-decoration-thickness var(--t-ui) var(--ease);
}
a:hover { text-decoration-color: currentColor; text-decoration-thickness: 2px; }
a.ext::after {
  content: "\2197";
  font-family: var(--font-sans);
  font-size: .72em;
  margin-left: .12em;
  vertical-align: .25em;
  text-decoration: none;
  display: inline-block;
}

blockquote {
  margin: 0;
  padding: var(--s-2) 0 var(--s-2) var(--s-5);
  border-left: 3px solid var(--rule);
  font-style: italic;
  color: var(--ink);
}
blockquote cite { display: block; margin-top: var(--s-2); font-family: var(--font-sans); font-size: .8rem; font-style: normal; }

hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: var(--s-7) auto;
  max-width: 12rem;
}

img, svg, video, canvas { max-width: 100%; height: auto; }
svg { overflow: visible; }
svg:not([fill]) { fill: currentColor; }
img { display: block; }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: .86em; font-variant-ligatures: none; }
code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: .08em .32em;
  overflow-wrap: anywhere;
}
pre code { background: none; padding: 0; border-radius: 0; }
pre { overflow-x: auto; tab-size: 2; }
kbd {
  display: inline-block;
  font-size: .76em;
  line-height: 1.4;
  padding: 0 .4em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}

table {
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
th, td { padding: .4em .7em; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
thead th { font-weight: 600; color: var(--ink-muted); border-bottom: 1.5px solid var(--ink-muted); font-size: .9em; }
caption { caption-side: top; text-align: left; font-size: .8rem; color: var(--ink-muted); padding-bottom: var(--s-2); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
input, select, textarea { accent-color: var(--c-lab); }

::selection { background: color-mix(in srgb, var(--c-light) 30%, transparent); }

/* Focus: 3px ring in --focus, offset 2px from the element (§8.1). */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}
main:focus-visible, [tabindex="-1"]:focus-visible { outline: none; }

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -100px;
  z-index: 1000;
  padding: var(--s-2) var(--s-4);
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-sans);
  font-size: .85rem;
  border-radius: var(--r-s);
  text-decoration: none;
}
.skip-link:focus { top: var(--s-2); }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

[hidden] { display: none !important; }

.noscript {
  position: fixed;
  bottom: var(--s-4);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90vw, 560px);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
  font-size: .8rem;
  z-index: 50;
}

/* Icons from /img/shared/icons.svg inherit color and size from text. */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -.2em;
  fill: none;
  stroke: currentColor;
}

/* Reduced motion: honor the OS setting and the learner's own preference (§4.7). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
html[data-motion="reduced"] *, html[data-motion="reduced"] *::before, html[data-motion="reduced"] *::after {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important;
}

/* KaTeX: if the vendored files fail to load, keep TeX readable. */
.no-katex main { font-variant-ligatures: none; }
.katex { font-size: 1.06em; }
.katex-display { margin: var(--s-4) 0; overflow-x: auto; overflow-y: hidden; padding: var(--s-1) 0; scrollbar-width: thin; }
/* math.js marks a clipped edge of a too-wide display equation; the fade says "this scrolls". */
.katex-display.has-more-right { -webkit-mask-image: linear-gradient(to left, transparent, #000 32px); mask-image: linear-gradient(to left, transparent, #000 32px); }
.katex-display.has-more-left { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px); mask-image: linear-gradient(to right, transparent, #000 32px); }
.katex-display.has-more-left.has-more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }

.math-nobr { white-space: nowrap; }
