/* microspend.dev static site. Tokens and rules from docs/DESIGN.md §4 (type), §5 (colour), §6 (space, radius,
   shadow, motion), §9 (accessibility). Plain CSS: no Tailwind and no build step for this site. Light and dark follow
   the system setting only (prefers-color-scheme), because the site has no JavaScript for a theme menu (DESIGN §6.6
   needs a cookie or a script). No inline styles anywhere: the CSP allows only this file. */

/* Fonts: Atkinson Hyperlegible Next and Mono, variable wght axis, Latin subset, from the @fontsource-variable
   packages (OFL 1.1; licences in /fonts). Glyphs outside the subset (≈, →) fall back per character. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Mono";
  src: url("/fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* DESIGN §5.1, light ("day ledger"), the default. */
:root {
  color-scheme: light dark;
  --paper: #EEF2EC;
  --sheet: #FBFCFA;
  --sunken: #E3E9E2;
  --ink: #17221E;
  --ink-hover: #2A3933;
  --on-ink: #FBFCFA;
  --ink-muted: #475750;
  --rule: #C3D1C6;
  --rule-strong: #6E8479;
  --pencil: #1F5A96;
  --pencil-wash: #DCE7F3;
  --elev-sheet: 0 1px 0 rgb(23 34 30 / 0.05), 0 1px 3px rgb(23 34 30 / 0.07);

  --font-sans: "Atkinson Hyperlegible Next", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Consolas, monospace;

  /* DESIGN §4.3 */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.3125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2.25rem;
  --text-3xl: 3rem;
  --text-4xl: 3.75rem;

  /* DESIGN §6.1, §6.2, §6.4 */
  --gutter: 1rem;
  --stack: 1.5rem;
  --section: 4rem;
  --row: 0.75rem;
  --content: 72rem;
  --prose: 68ch;
  --radius-sheet: 2px;
  --radius-tag: 4px;
  --radius-control: 6px;
  --duration-fast: 120ms;
  --duration-mark: 260ms;
  --stagger-mark: 80ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
}

/* DESIGN §5.1, dark ("night ledger"). */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121B18;
    --sheet: #19241F;
    --sunken: #0D1412;
    --ink: #E2EAE4;
    --ink-hover: #C9D4CD;
    --on-ink: #121B18;
    --ink-muted: #A0B1A8;
    --rule: #2B3A34;
    --rule-strong: #62786E;
    --pencil: #8DB8EC;
    --pencil-wash: #1B2F46;
    --elev-sheet: 0 0 0 1px var(--rule);
  }
}

@media (min-width: 48rem) {
  :root { --gutter: 1.5rem; }
}
@media (min-width: 64rem) {
  :root { --section: 6rem; }
}
@media (min-width: 80rem) {
  :root { --gutter: 4rem; }
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 100%;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-variant-numeric: lining-nums;
  scroll-padding-top: 1.5rem;
}
body { margin: 0; }
::selection { background: var(--pencil-wash); color: var(--ink); }
:focus-visible { outline: 2px solid var(--pencil); outline-offset: 2px; }

h1, h2, h3, h4 {
  font-weight: 750;
  color: var(--ink);
  text-wrap: balance;
  margin: 0;
}
h1 { font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -0.01em; }
h2 { font-size: var(--text-xl); line-height: 1.3; }
h3 { font-size: var(--text-lg); line-height: 1.35; }
h4 { font-size: var(--text-md); line-height: 1.5; }
p, ul, ol, pre { margin: 0; }

a {
  color: var(--pencil);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: text-decoration-thickness var(--duration-fast) var(--ease-out);
}
a:hover { text-decoration-thickness: 2px; }

strong, b { font-weight: 600; }

code, pre, kbd, samp, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums slashed-zero;
}
code { font-size: 0.9em; overflow-wrap: anywhere; }
:not(pre) > code {
  background: var(--sunken);
  border-radius: var(--radius-tag);
  padding: 0.05em 0.3em;
}
pre {
  background: var(--sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sheet);
  padding: 1rem;
  font-size: var(--text-sm);
  line-height: 1.5;
  /* DESIGN §9.5: prompts wrap rather than scroll. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
pre code { font-size: inherit; }

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

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

/* Skip link: the first focusable element (DESIGN §9.1). */
.skip-link {
  position: absolute;
  left: var(--gutter);
  top: 0.5rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--ink);
  color: var(--on-ink);
  border-radius: var(--radius-control);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.wrap {
  width: 100%;
  max-width: calc(var(--content) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Header and wordmark (DESIGN §3.6: lowercase, Next Bold, ink, a double rule under it). */
.site-header { border-bottom: 1px solid var(--rule); }
.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  min-height: 4.5rem;
  padding-block: 0.75rem;
}
.wordmark {
  display: inline-block;
  color: var(--ink);
  font-size: var(--text-lg);
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-decoration: none;
  padding-bottom: 0.2rem;
  border-bottom: 5px double var(--ink);
}
.wordmark:hover { text-decoration: none; }
.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  list-style: none;
  padding: 0;
}
.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
}
.site-nav a[aria-current="page"] { color: var(--ink); text-decoration-color: var(--rule-strong); }

main { display: block; padding-bottom: var(--section); }

/* A primary action, styled like a stamp: solid ink (DESIGN §3.1). */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 600;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}
.button:hover { background: var(--ink-hover); text-decoration: none; }

/* Prose: readable measure (DESIGN §4.3, 68ch). */
.prose > * + * { margin-top: 1rem; }
.prose > :is(h2, h3, h4) + * { margin-top: 0.75rem; }
.prose > h2 { margin-top: var(--section); scroll-margin-top: 1.5rem; }
.prose > hr + h2 { margin-top: 2.5rem; }
.prose > h3 { margin-top: 2.5rem; }
.prose > :is(p, ul, ol, pre, h1, h2, h3, h4) { max-width: var(--prose); }
.prose li + li { margin-top: 0.375rem; }
.prose ul, .prose ol { padding-left: 1.5rem; }
.prose li > ul, .prose li > ol { margin-top: 0.375rem; }
.prose :is(h2, h3, h4)[id] { scroll-margin-top: 1.5rem; }

/* Checklists: the guide's "- [ ]" items, drawn as empty boxes to tick on paper. No form controls. */
.prose li.task { list-style: none; position: relative; padding-left: 0.25rem; }
.prose li.task > .box {
  position: absolute;
  left: -1.5rem;
  top: 0.22em;
  width: 1.05em;
  height: 1.05em;
  border: 1.5px solid var(--rule-strong);
  border-radius: 3px;
  background: var(--sheet);
}

/* Source references like (F-114): inline links in running text. */
a.ref { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Tables: a sheet of ledger paper that scrolls sideways inside itself when it is wider than the screen. */
.table-scroll {
  margin-top: var(--stack);
  overflow-x: auto;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sheet);
  box-shadow: var(--elev-sheet);
}
.table-scroll:focus-visible { outline-offset: 3px; }
.table-scroll + * { margin-top: var(--stack); }
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums lining-nums;
  text-align: left;
}
caption { text-align: left; }
th, td {
  padding: var(--row) 1rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  text-align: left;
}
thead th {
  background: var(--sunken);
  font-weight: 600;
  white-space: nowrap;
}
tbody th { font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
td a, th a { overflow-wrap: anywhere; }
table[data-cols="3"] :is(td, th) { min-width: 12rem; }
table[data-cols="4"] :is(td, th) { min-width: 14rem; }
table[data-cols] :is(td, th):first-child { min-width: 9rem; }
table.sources td:last-child { min-width: 20rem; }
table.sources tr:target > * { background: var(--pencil-wash); }
table.sources th[scope="row"] { font-family: var(--font-mono); white-space: nowrap; }

/* Below 640 px each row becomes a stacked entry (DESIGN §9.5): the row header on top, then each cell with its column
   name above it. The labels come from data-label, which build.mjs copies from the column headers. Only code blocks
   scroll sideways. */
@media (max-width: 39.9375rem) {
  .table-scroll { overflow-x: visible; }
  .table-scroll :is(table, tbody, tr, th, td) { display: block; }
  .table-scroll thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  .table-scroll table[data-cols] tr > :is(th, td) {
    min-width: 0;
    padding: 0;
    border-bottom: 0;
  }
  .table-scroll tbody tr {
    padding: 1rem;
    border-bottom: 1px solid var(--rule);
  }
  .table-scroll tbody tr:last-child { border-bottom: 0; }
  .table-scroll tbody th[scope="row"] { font-size: var(--text-md); line-height: 1.4; }
  .table-scroll tbody tr > * + td { margin-top: 0.75rem; }
  .table-scroll td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--ink-muted);
    font-size: var(--text-sm);
    font-weight: 600;
  }
  table.sources tr:target { background: var(--pencil-wash); }
}

/* Header and footer of every page. */
.site-footer {
  border-top: 1px solid var(--rule);
  color: var(--ink-muted);
  font-size: var(--text-sm);
}
.site-footer .wrap { padding-block: 2rem 3rem; }
.site-footer p { max-width: var(--prose); }
.site-footer p + p { margin-top: 0.5rem; }
.site-footer a { color: var(--pencil); }

/* ---------- Home ---------- */
.hero { padding-top: 3rem; }
.hero h1 { max-width: 18ch; }
.lead { font-size: var(--text-md); line-height: 1.5; max-width: var(--prose); margin-top: 1.25rem; }
.hero .lead + p { margin-top: 1rem; max-width: var(--prose); }

/* The one bold element: the status sheet, ruled like a ledger, with blue-pencil marks in the margin. */
.status { margin-top: 3rem; max-width: 52rem; }
.status h2 { font-size: var(--text-lg); line-height: 1.35; }
.status .sheet {
  margin-top: 0.75rem;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sheet);
  box-shadow: var(--elev-sheet);
}
.ledger { width: 100%; }
.ledger thead th { white-space: normal; }
.ledger th, .ledger td { padding: 1rem; }
.ledger tbody th { width: 38%; }
.ledger td { padding-right: 3.75rem; position: relative; }
.ledger .mark {
  position: absolute;
  right: 1rem;
  top: 0.85rem;
  width: 1.75rem;
  height: 1.75rem;
  color: var(--pencil);
}
.ledger .mark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ledger .mark path, .ledger .mark circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ledger .mark text { fill: currentColor; font: 600 13px var(--font-sans); }
.ledger .note { display: block; margin-top: 0.25rem; color: var(--pencil); font-size: var(--text-sm); }
/* The accounting convention for a checked total: a single rule above, a double rule under (DESIGN §3.1). */
.ledger tfoot :is(th, td) {
  border-top: 1px solid var(--ink);
  border-bottom: 4px double var(--ink);
  font-weight: 600;
}
.ledger tfoot td { font-family: var(--font-mono); }

/* Signature moment (DESIGN §6.4): the marks draw once, top to bottom. CSS only. */
.ledger .mark .stroke {
  --len: 30;
  stroke-dasharray: var(--len);
  stroke-dashoffset: 0;
  animation: mark-draw var(--duration-mark) var(--ease-out) both;
}
.ledger .mark circle.stroke { --len: 70; }
.ledger tbody tr:nth-child(1) .stroke { animation-delay: 400ms; }
.ledger tbody tr:nth-child(2) .stroke { animation-delay: calc(400ms + var(--stagger-mark)); }
.ledger tbody tr:nth-child(3) .stroke { animation-delay: calc(400ms + 2 * var(--stagger-mark)); }
@keyframes mark-draw {
  from { stroke-dashoffset: var(--len); }
  to { stroke-dashoffset: 0; }
}

.block { margin-top: var(--section); max-width: var(--prose); }
.block > * + * { margin-top: 1rem; }
.block ol, .block ul { padding-left: 1.5rem; }
.block li + li { margin-top: 0.5rem; }
.cta { margin-top: 1.5rem; }
.pending {
  border-left: 3px solid var(--pencil);
  padding-left: 1rem;
  color: var(--ink);
}

/* ---------- Guide ---------- */
.guide-intro { padding-top: 3rem; }
.guide-body > h2:first-child { margin-top: 3rem; }
.toc {
  margin-top: 2rem;
  padding: 1rem 1.25rem 1.25rem;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sheet);
  box-shadow: var(--elev-sheet);
  max-width: var(--prose);
}
.toc h2 { font-size: var(--text-base); line-height: 1.55; }
.toc ul { list-style: none; padding: 0; margin-top: 0.5rem; }
.toc li { border-top: 1px solid var(--rule); }
.toc li:first-child { border-top: 0; }
.toc a { display: flex; align-items: center; min-height: 44px; padding-block: 0.25rem; }

.guide .prose > h1 { font-size: var(--text-2xl); max-width: 30ch; }
.guide .prose > h1 + p { margin-top: 1.25rem; }

@media (min-width: 64rem) {
  .hero h1 { font-size: var(--text-4xl); line-height: 1; }
  .guide .prose > h1 { font-size: var(--text-3xl); line-height: 1.05; }
}

/* Wide screens: the contents list sits in its own column and stays in view. */
@media (min-width: 75rem) {
  .guide-layout {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    grid-template-areas: "toc intro" "toc body";
    column-gap: 3rem;
    align-items: start;
  }
  .guide-layout > .guide-intro { grid-area: intro; }
  .guide-layout > .guide-body { grid-area: body; }
  .guide-layout .toc {
    grid-area: toc;
    position: sticky;
    top: 1.5rem;
    margin-top: 3rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    font-size: var(--text-sm);
  }
  .guide-layout .toc a { min-height: 36px; }
}

/* ---------- Accessibility preferences (DESIGN §9.5) ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
@media (prefers-contrast: more) {
  :root { --rule: var(--rule-strong); }
}
@media (forced-colors: active) {
  .ledger .mark { color: CanvasText; }
  .button { border: 1px solid ButtonText; }
  .prose li.task > .box { border-color: CanvasText; }
}

@media print {
  .site-nav, .skip-link, .toc { display: none; }
  html { background: #fff; color: #000; }
  .table-scroll { overflow: visible; box-shadow: none; }
  a { color: inherit; }
}
