/*
 * payment-router · shared doc design system
 * Linked from DOC.html and every doc/0N-*.html chapter.
 * Per-file <style> blocks should hold widget-specific rules only.
 *
 * Source-of-truth: doc/01-reference.html (extracted, then aligned with the
 * usemux pattern). Iowan Old Style serif matches the usemux --display stack
 * exactly, for visual consistency across the two doc sets.
 *
 * Extensibility note — dark-mode `:is(...)` union below lists every widget
 * class that needs slate surfaces in dark mode. Adding a new widget? Two
 * options: (a) add its root class to the union here (current pattern), or
 * (b) preferred long-term: bind the widget's background to var(--paper) /
 * var(--margin) so the token flip carries it automatically with no edit
 * to this file. Option (b) requires the widget's CSS to use tokens, not
 * literal colors.
 */

:root {
  /* ── fonts: system stacks (no web fonts) — serif headings, sans body, mono labels ── */
  --serif:
    'Iowan Old Style', Palatino, 'Palatino Linotype', ui-serif, Georgia, 'Times New Roman', Times,
    serif;
  --sans:
    'Anthropic Sans Web', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace;
  --bg: #faf9f5;
  --paper: #ffffff;
  --margin: #f0eee6;
  --ink: #141413;
  --ink-2: #3d3d3a;
  --ink-faint: #87867f;
  --rule: #e6e2d6;
  --rule-strong: #d1cfc5;
  --accent: #d97757;
  --accent-2: #b8501c;
  --accent-tint: #f5e4da;
  --code-bg: #1c1917;
  --code-ink: #ece9e0;
  --code-comment: #8a8980;
  --ok: #788c5d;
  --warn: #c78e3f;
  --stop: #b04a4a;
  --get: #5c7ca3;
  --post: #d97757;
  --del: #b04a4a;
  --shadow-1: 0 1px 0 rgba(60, 40, 20, 0.05);
  --shadow-2: 0 14px 32px -18px rgba(60, 40, 20, 0.35), 0 2px 6px rgba(60, 40, 20, 0.08);
}

/* Dark theme — scoped to widget surfaces only. The page stays ivory in both
   modes (no body background flip); only the listed card-like widgets become
   slate. Union of every widget class declared dark-aware across the doc set. */
html[data-theme='dark']
  :is(
    figure.fig,
    .callout,
    table.data,
    .endpoint,
    .seq-walker,
    .playground,
    .control-group,
    .curve-wrap,
    .lab,
    .checklist,
    .cb-widget,
    .ring-wrap,
    .epsilon-row
  ) {
  --paper: #1c1b18;
  --margin: #2a2925;
  --ink: #f0eee6;
  --ink-2: #d1cfc5;
  --ink-faint: #9a9890;
  --rule: #33312b;
  --rule-strong: #46443d;
  --accent-2: #e8a07f;
  --accent-tint: #2e2018;
  --code-bg: #0d0c0a;
  /* set color on the container so INHERITED text (titles, body, SVG
     currentColor labels) flips light too, not just var(--ink) callers */
  color: var(--ink);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings:
    'kern' 1,
    'liga' 1,
    'onum' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1100px 600px at 12% 10%, rgba(217, 119, 87, 0.05), transparent 60%),
    radial-gradient(900px 600px at 90% 80%, rgba(20, 20, 19, 0.03), transparent 60%);
}
/* no dark atmosphere override — page is ivory in both modes */
::selection {
  background: var(--accent-tint);
  color: var(--accent-2);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 36px;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.brand .title {
  color: var(--ink);
  font-weight: 600;
}
.jump {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
}
.jump a {
  color: var(--ink-faint);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 3px;
  transition:
    color 0.15s,
    background 0.15s;
}
.jump a:hover {
  color: var(--accent);
  background: var(--accent-tint);
}
.jump a.active {
  color: var(--accent);
  background: var(--accent-tint);
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.15s,
    color 0.15s;
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.page {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 80px 36px 120px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 64px;
  align-items: end;
  padding-bottom: 48px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 80px;
}
.hero .eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hero .eyebrow::before {
  content: '';
  display: block;
  width: 30px;
  height: 1px;
  background: var(--accent);
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(34px, 4.8vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.018em;
  font-weight: 600;
  margin: 0 0 24px;
  color: var(--ink);
}
.hero h1 em {
  font-style: italic;
  color: var(--accent);
}
.hero .lede {
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 580px;
}
.hero-meta {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-faint);
  padding-left: 24px;
  border-left: 1px solid var(--rule);
}
.hero-meta .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
}
.hero-meta .row span:first-child {
  color: var(--ink-faint);
}
.hero-meta .row span:last-child {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chapter {
  display: grid;
  grid-template-columns: minmax(0, 760px) 1fr;
  gap: 64px;
  margin: 0 auto 80px;
}
.chapter-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}
.chapter-num {
  display: inline-block;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent-2);
  background: var(--margin);
  border: 1px solid var(--rule);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 0;
}
.chapter-title {
  font-family: var(--serif);
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: -0.012em;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}
.chapter-summary {
  font-size: 16.5px;
  line-height: 1.55;
  color: var(--ink-2);
  margin: 0 0 36px;
  max-width: 600px;
}
.chapter-marginalia {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
  padding-top: 64px;
}
.chapter-marginalia .label {
  color: var(--accent);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 10px;
  margin-bottom: 6px;
  display: block;
}
.chapter-marginalia ul {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}
.chapter-marginalia li {
  padding: 3px 0;
  border-bottom: 1px dotted var(--rule);
}
.chapter-marginalia li:last-child {
  border: 0;
}

.prose {
  max-width: 760px;
}
.prose p {
  margin: 16px 0;
  font-size: 16px;
  line-height: 1.7;
}
.prose h3 {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.3;
  letter-spacing: -0.008em;
  font-weight: 600;
  margin: 44px 0 10px;
  color: var(--ink);
}
.prose h4 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 32px 0 8px;
}
.prose ul,
.prose ol {
  padding-left: 24px;
  margin: 14px 0;
}
.prose li {
  margin: 4px 0;
}
.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.prose a:hover {
  color: var(--accent-2);
}
.prose strong {
  font-weight: 600;
}
.prose em {
  font-style: italic;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--margin);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--ink);
  border: 1px solid var(--rule);
}
.path {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--accent-2);
  background: var(--accent-tint);
  padding: 2px 8px;
  border-radius: 3px;
}
.path::before {
  content: '⌥';
  font-size: 9px;
  opacity: 0.7;
}
pre {
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 18px 22px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  margin: 20px 0;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--rule);
  position: relative;
}
pre .c {
  color: var(--code-comment);
}
pre .k {
  color: #e8a05a;
}
pre .s {
  color: #b9c97a;
}
pre .n {
  color: #7ac4e8;
}
pre .lbl {
  position: absolute;
  top: 0;
  right: 14px;
  background: var(--code-bg);
  color: var(--code-comment);
  padding: 2px 8px;
  border-radius: 0 0 3px 3px;
  font-size: 10px;
  letter-spacing: 0.1em;
}
pre code {
  background: transparent;
  padding: 0;
  border: 0;
  color: inherit;
  font-size: inherit;
}

.gl {
  border-bottom: 1px dotted var(--accent);
  cursor: help;
  position: relative;
}
.gl:hover::after {
  content: attr(data-def);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  width: 280px;
  z-index: 10;
  box-shadow: var(--shadow-2);
  white-space: normal;
}
.gl:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 8px;
  border: 5px solid transparent;
  border-top-color: var(--ink);
}

.callout {
  border-left: 3px solid var(--accent);
  background: var(--margin);
  padding: 16px 22px;
  margin: 24px 0;
  border-radius: 0 4px 4px 0;
}
.callout.note {
  border-color: var(--ink-faint);
}
.callout.warn {
  border-color: var(--warn);
}
.callout .label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.callout.note .label {
  color: var(--ink-faint);
}
.callout.warn .label {
  color: var(--warn);
}
.callout p {
  margin: 6px 0;
  font-size: 15px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  margin: 24px 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}
table.data thead th {
  text-align: left;
  font-weight: 500;
  background: var(--margin);
  border-bottom: 1px solid var(--rule-strong);
  padding: 10px 14px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
table.data td {
  border-bottom: 1px solid var(--rule);
  padding: 9px 14px;
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data .num {
  text-align: right;
}
table.data td.num {
  color: var(--accent-2);
  font-weight: 600;
}
table.data .ok {
  color: var(--ok);
}
table.data .stop {
  color: var(--stop);
}

figure.fig {
  margin: 36px 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 32px 32px 22px;
  box-shadow: var(--shadow-1);
  position: relative;
}
figure.fig::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  height: 1px;
  background: var(--rule);
}
figure.fig::after {
  content: '';
  position: absolute;
  top: 9px;
  left: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
figure.fig svg {
  width: 100%;
  height: auto;
  display: block;
}
figure.fig figcaption {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dotted var(--rule);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-faint);
}
figure.fig .fig-num {
  color: var(--accent);
  letter-spacing: 0.12em;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
}

footer.bottom {
  margin-top: 120px;
  padding: 48px 0 0;
  border-top: 1px solid var(--rule-strong);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 48px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
}
footer.bottom h5 {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px;
}
footer.bottom ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
footer.bottom li {
  padding: 3px 0;
}
footer.bottom a {
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 1px dotted var(--rule);
}
footer.bottom a:hover {
  color: var(--accent);
}

@media (max-width: 900px) {
  .topbar-inner {
    padding: 12px 20px;
  }
  .jump {
    display: none;
  }
  .page {
    padding: 36px 20px 80px;
  }
  .hero {
    grid-template-columns: 1fr;
    gap: 32px;
    padding-bottom: 32px;
    margin-bottom: 48px;
  }
  .hero-meta {
    border-left: 0;
    padding-left: 0;
    padding-top: 16px;
    border-top: 1px solid var(--rule);
  }
  .chapter {
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 48px;
  }
  .chapter-marginalia {
    padding-top: 24px;
    border-top: 1px dotted var(--rule);
  }
  footer.bottom {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

@media print {
  .topbar {
    display: none;
  }
  body {
    background: #fff;
    font-size: 11pt;
  }
  .chapter {
    page-break-inside: avoid;
  }
}
