/* Pencilwick base: reset, typography and layout primitives.
   Colours, type, space and motion all come from tokens.css. */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 72px;
  hanging-punctuation: first last;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
}
img, picture, video, canvas { display: block; max-width: 100%; height: auto; }
svg { flex-shrink: 0; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; text-align: inherit; }
button:disabled { cursor: not-allowed; }
textarea { resize: vertical; }
table { border-collapse: collapse; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
[hidden] { display: none !important; }
dialog { color: inherit; }
::placeholder { color: var(--ink-3); opacity: 1; }
::selection { background: var(--wattle-wash); color: var(--ink); }

/* ---------- Focus: always visible for keyboard users ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid transparent; /* shows in forced-colours mode */
  outline-offset: 2px;
  box-shadow: var(--focus);
  border-radius: var(--r-xs);
}
/* headings receive programmatic focus after navigation; they are not controls */
h1[tabindex="-1"]:focus, main[tabindex="-1"]:focus { box-shadow: none; }

/* ---------- Type ---------- */
h1, h2, h3, h4, h5, h6, .display {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  font-stretch: 92%;
  font-variation-settings: "opsz" 48;
  text-wrap: balance;
  color: var(--ink);
}
h1, .h1 { font-size: var(--fs-3xl); letter-spacing: -0.025em; font-weight: 740; }
h2, .h2 { font-size: var(--fs-2xl); letter-spacing: -0.02em; }
h3, .h3 { font-size: var(--fs-xl); letter-spacing: -0.015em; font-weight: 680; }
h4, .h4 { font-size: var(--fs-lg); letter-spacing: -0.01em; font-weight: 660; }
h5, h6 { font-size: var(--fs-md); font-weight: 660; }
p { text-wrap: pretty; }
small, .small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
strong, b { font-weight: 700; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.88em; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); }

a { color: var(--gum); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
a:not([class]) { text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); }
a:not([class]):hover { text-decoration-color: currentColor; }

hr { border: 0; border-top: 1px solid var(--line); margin-block: var(--s-6); }

/* ---------- Utilities ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; z-index: 100; left: var(--s-4); top: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--gum); color: var(--on-gum);
  border-radius: var(--r-sm); font-weight: 700; text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--t-fast) var(--ease-out);
}
.skip-link:focus { transform: none; }

/* ---------- Layout primitives ---------- */
.container { width: 100%; max-width: 1120px; }
.stack { display: flex; flex-direction: column; gap: var(--gap, var(--s-4)); }
.stack--xs { --gap: var(--s-1); }
.stack--sm { --gap: var(--s-2); }
.stack--md { --gap: var(--s-6); }
.stack--lg { --gap: var(--s-10); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s-3)); }
.row { display: flex; align-items: center; gap: var(--gap, var(--s-3)); min-width: 0; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* 12-column grid, 24px gutters on desktop; single column on small screens */
.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap, var(--s-6)); }
.grid-12 > * { grid-column: span 12; }
@media (min-width: 760px) {
  .grid-12 > .span-4 { grid-column: span 6; }
  .grid-12 > .span-6 { grid-column: span 6; }
  .grid-12 > .span-8 { grid-column: span 12; }
}
@media (min-width: 1024px) {
  .grid-12 > .span-3 { grid-column: span 3; }
  .grid-12 > .span-4 { grid-column: span 4; }
  .grid-12 > .span-5 { grid-column: span 5; }
  .grid-12 > .span-7 { grid-column: span 7; }
  .grid-12 > .span-8 { grid-column: span 8; }
  .grid-12 > .span-9 { grid-column: span 9; }
}
.auto-grid { display: grid; gap: var(--gap, var(--s-6)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--min, 260px)), 1fr)); }

/* ---------- Long-form text ---------- */
.prose { max-width: var(--measure); }
.prose > * + * { margin-top: 1em; }
.prose h2, .prose h3, .prose h4 { margin-top: 1.6em; }
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: 0.5em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.35em; }
.prose li::marker { color: var(--ink-3); }
.prose ol > li::marker { font-family: var(--font-display); font-weight: 650; color: var(--ink-2); }
.prose a { color: var(--ocean); }
.prose code:not(pre code) {
  padding: 0.1em 0.35em; border-radius: var(--r-xs);
  background: var(--sheet-2); color: var(--ink);
}
.prose pre {
  padding: var(--s-4); border-radius: var(--r-sm);
  background: var(--sheet-2); overflow-x: auto;
  font-size: var(--fs-sm); line-height: 1.5;
}
.prose table { width: 100%; font-size: var(--fs-sm); }
.prose .table-wrap { overflow-x: auto; contain: inline-size; }
.prose th, .prose td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { font-weight: 700; border-bottom-color: var(--rule-strong); }
.prose img { border-radius: var(--r-sm); }

/* MathJax: display maths may be wider than a phone — scroll it, never the page */
mjx-container[display="true"] { display: block; overflow-x: auto; overflow-y: hidden; max-width: 100%; padding-block: 2px; }
mjx-container { color: inherit; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Forced colours ---------- */
@media (forced-colors: active) {
  .icon { forced-color-adjust: auto; }
}
