/* credence. — a credit memorandum on paper.
 *
 * Every colour here was measured off the project's own X banner (PIL, modal pixel counts) or
 * read out of brand/mark.svg. Nothing is rounded and nothing is borrowed. See SPEC.md §3.
 *
 * There is no dark mode. A printed credit document does not have one, and the dark page with a
 * three.js stage is precisely what was rejected.
 */

:root {
  color-scheme: only light;

  --paper: #F9F4E9;     /* banner ground, modal of 76 480 sampled pixels */
  --paper-2: #F2EFE4;   /* brand/mark.svg bars */
  --rule: #D0D2C5;      /* banner bar track — never text */
  --rule-2: #B9C4B6;    /* hairline over a plate */
  --ink: #0E2A1F;       /* brand/mark.svg circle fill — 13.98:1 on paper */
  --green: #204C3B;     /* banner bar fill — 8.87:1 on paper */
  --green-mid: #1C4133; /* banner wordmark core — 10.33:1 on paper */
  --muted: #4A6456;     /* 5.89:1 on paper */
  --seal: #8A2B21;      /* 7.82:1 on paper */

  --doc: 1012px;
  --side: 268px;
  --gap: 48px;
  --pad: clamp(18px, 4vw, 40px);

  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: "Poppins", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

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

html { -webkit-text-size-adjust: 100% }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 19px/1.62 var(--serif);
  font-variant-numeric: oldstyle-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* belt; the audit still asserts scrollWidth, which this does not hide */
}

::selection { background: var(--green); color: var(--paper) }

a { color: var(--green); text-underline-offset: 3px; text-decoration-thickness: 1px }
a:hover { color: var(--ink) }

strong { font-weight: 600 }
em { font-style: italic }

/* ── the sheet grid ──────────────────────────────────────────────────────────────────────── */

.doc {
  max-width: var(--doc);
  margin: 0 auto;
  padding-inline: var(--pad);
}

/* One row of the memorandum: prose on the left, the figure it needs in the margin. */
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side);
  column-gap: var(--gap);
  align-items: start;
}
.row > * { min-width: 0 }

.body > p { max-width: 62ch; margin: 0 0 1.05em }
.body > p:last-child { margin-bottom: 0 }
.body > h3 { max-width: 62ch }

/* A schedule whose third column is a sentence does not fit a 62ch text column. Those rows give
 * up the margin and take the whole sheet, instead of scrolling a table on a 1440 px screen. */
.row.wide { grid-template-columns: minmax(0, 1fr) }

@media (max-width: 980px) {
  .row { grid-template-columns: minmax(0, 1fr); row-gap: 26px }
  .side { border-left: 2px solid var(--green); padding-left: 16px }
}

/* ── running head ────────────────────────────────────────────────────────────────────────── */

.head {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.head-in {
  max-width: var(--doc);
  margin: 0 auto;
  padding: 9px var(--pad);
  display: flex;
  align-items: center;
  gap: 14px;
}
.head .wm { display: flex; align-items: center; gap: 7px; text-decoration: none; flex: none }
.head .wm img { display: block; width: 19px; height: 19px }
.head .wm b {
  font: 600 16px/1 var(--sans);
  letter-spacing: -0.015em;
  color: var(--green-mid);
}
.folio {
  font: 500 10px/1 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-inline-start: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head nav { display: flex; gap: 14px; flex: none }
.head nav a {
  font: 500 10px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 7px 0;
}
.head nav a[aria-current="page"] { border-bottom: 2px solid var(--green); color: var(--ink) }
.progress {
  height: 2px;
  background: var(--rule);
  position: relative;
  z-index: 1;
}
.progress i { display: block; height: 100%; width: 0; background: var(--green) }

@media (max-width: 620px) { .folio { display: none } }

/* ── cover sheet ─────────────────────────────────────────────────────────────────────────── */

.cover-wrap { padding: clamp(18px, 3.4vw, 44px) var(--pad) 0 }

.cover {
  max-width: var(--doc);
  margin: 0 auto;
  border-style: solid;
  border-color: transparent;
  border-width: clamp(30px, 7.2vw, 104px);
  border-image-source: url("/img/frame.webp");
  border-image-slice: 212 240;
  border-image-repeat: stretch;
  border-image-width: 1;
}
.cover-in { padding: clamp(4px, 1.4vw, 18px) 0 }

.stamp {
  display: inline-block;
  font: 500 11px/1 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--seal);
  border: 1.5px solid var(--seal);
  padding: 8px 12px;
  transform: rotate(-2.2deg);
  margin-bottom: 22px;
}

.sheet-title {
  font: 600 clamp(38px, 6.4vw, 62px)/1.02 var(--sans);
  letter-spacing: -0.02em;
  color: var(--green-mid);
  margin: 0 0 18px;
}
.sheet-title .dot { color: var(--seal) }

.strap {
  font: 500 11px/1 var(--sans);
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--green);
  margin: 0 0 26px;
}

.lede {
  font: 400 clamp(20px, 2.2vw, 23px)/1.52 var(--serif);
  max-width: 54ch;
  margin: 0 0 26px;
}

/* the banner's own idiom: labelled bars, square ends, green on the pale track */
.bars { display: grid; gap: 15px; margin: 0 0 28px; max-width: 62ch }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px }
.bar-name {
  font: 500 10.5px/1.3 var(--sans);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--green);
}
.bar-val { font: 500 13px/1 var(--mono); color: var(--ink) }
.bar-track { height: 11px; background: var(--rule); margin-top: 7px }
.bar-track i { display: block; height: 100%; background: var(--green) }
.bar-why { font: 400 15px/1.5 var(--serif); color: var(--muted); margin: 7px 0 0 }

/* the contents list — a prospectus has one, a landing page does not */
.contents { border-top: 1px solid var(--rule); margin: 30px 0 0; padding: 0; list-style: none }
.contents li { border-bottom: 1px solid var(--rule) }
.contents a {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 9px 2px;
  text-decoration: none;
  color: var(--ink);
}
.contents a:hover { background: var(--paper-2) }
.contents .n { font: 400 12px/1 var(--mono); color: var(--muted); flex: none; width: 2.6em }
.contents .t { font: 400 16.5px/1.35 var(--serif) }
.contents .p { margin-inline-start: auto; font: 400 12px/1 var(--mono); color: var(--muted); flex: none }

/* ── sections ────────────────────────────────────────────────────────────────────────────── */

.sec { padding: clamp(42px, 5.4vw, 78px) 0 }
.sec + .sec { border-top: 1px solid var(--rule) }

.sec-no {
  font: 400 12px/1 var(--mono);
  letter-spacing: 0.1em;
  color: var(--muted);
  display: block;
  margin: 0 0 10px;
}
.sec h2 {
  font: 600 clamp(24px, 3vw, 31px)/1.16 var(--sans);
  letter-spacing: -0.012em;
  color: var(--green-mid);
  margin: 0 0 20px;
  max-width: 22ch;
}
.sec h3 {
  font: 600 18px/1.3 var(--sans);
  color: var(--green-mid);
  margin: 1.6em 0 0.5em;
}
.sec h3:first-child { margin-top: 0 }

/* ── margin apparatus ────────────────────────────────────────────────────────────────────── */

.note {
  font: 400 15.5px/1.5 var(--serif);
  color: var(--muted);
}
.note + .note { margin-top: 20px }
.note .k {
  display: block;
  font: 500 10.5px/1.3 var(--sans);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 6px;
}
.fig {
  display: block;
  font: 500 clamp(26px, 3.4vw, 34px)/1.05 var(--mono);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 4px;
}
.fig-sub { display: block; font: 400 12px/1.4 var(--mono); color: var(--muted); margin: 0 0 7px }
code, .mono {
  font: 400 0.84em/1.5 var(--mono);
  color: var(--green);
  overflow-wrap: anywhere;   /* a 54-character invariant must wrap at 390 px, not widen the page */
}

/* a pull-quote set as a marginal gloss, the way a memo annotates its own argument */
.gloss {
  border-left: 2px solid var(--green);
  padding-left: 16px;
  margin: 1.4em 0;
  max-width: 54ch;
  font-style: italic;
}

/* ── tables: the schedule idiom ──────────────────────────────────────────────────────────── */

.tw { overflow-x: auto; -webkit-overflow-scrolling: touch }
/* A schedule is wider than a phone. The table scrolls rather than reflows, so the caption says
 * so — an affordance a reader cannot guess from a cut-off column. */
@media (max-width: 760px) {
  caption::after { content: " · scroll sideways"; color: var(--muted) }
}
table { border-collapse: collapse; width: 100%; font: 400 14px/1.5 var(--mono) }
caption {
  text-align: left;
  font: 500 10.5px/1.4 var(--sans);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--green);
  padding-bottom: 9px;
}
th {
  text-align: left;
  font: 500 10px/1.3 var(--sans);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--green);
  border-bottom: 1.5px solid var(--green);
  padding: 7px 12px 7px 0;
  white-space: nowrap;
}
td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--rule); vertical-align: top }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper-2) 62%, transparent) }
td.sym { color: var(--green); white-space: nowrap }
td.lead { font: 400 15px/1.5 var(--serif); color: var(--ink); min-width: 20ch }
td.num { text-align: right; font-variant-numeric: tabular-nums }
.dim { color: var(--muted) }

.tag {
  font: 500 9.5px/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid var(--rule-2);
  color: var(--muted);
  padding: 4px 6px;
  white-space: nowrap;
  display: inline-block;
}
.tag.ok { border-color: var(--green); color: var(--green) }
.tag.empty { border-color: var(--green); color: var(--paper); background: var(--green) }
.tag.bad { border-color: var(--seal); color: var(--seal) }

.src {
  font: 400 13px/1.55 var(--mono);
  color: var(--muted);
  margin: 12px 0 0;
  max-width: 76ch;
}

/* ── plates ──────────────────────────────────────────────────────────────────────────────── */

/* Full bleed, no blend mode and no translucency: each plate's ground was mapped per channel to
 * exactly --paper, so it meets the page with no visible edge. */
/* On the ledger plate the darkest pixel is #B4B7AB (relative luminance 0.465, the shadow floor
 * baked into the file). Against that, --ink measures 7.52:1 and --green 4.77:1, but --muted is
 * 3.17:1 — so inside a plate section --muted is redefined to --green rather than text being
 * allowed to sit at 3.7:1 over the guilloche strip at phone width. One line, whole subtree. */
.on-ledger {
  --muted: #204C3B;
  background-image: url("/img/ledger.webp");
  background-size: cover;
  background-position: 62% center;
  background-repeat: no-repeat;
}

.tiers { display: grid; grid-template-columns: minmax(0, 1fr) var(--side); column-gap: var(--gap) }
.tiers-plate {
  aspect-ratio: 1200 / 800;
  background: url("/img/tiers.webp") center / cover no-repeat;
  border: 1px solid var(--rule-2);
}
.tiers-keys { position: relative; margin: 0; padding: 0; list-style: none }
.tiers-keys li { position: absolute; left: 0; right: 0; transform: translateY(-50%) }
.tiers-keys li::before {
  content: "";
  position: absolute;
  left: calc(var(--gap) * -1);
  width: var(--gap);
  top: 9px;
  border-top: 1px solid var(--rule-2);
}
.tiers-keys li:nth-child(1) { top: 24.5% }
.tiers-keys li:nth-child(2) { top: 49.5% }
.tiers-keys li:nth-child(3) { top: 70% }

@media (max-width: 980px) {
  .tiers { grid-template-columns: minmax(0, 1fr); row-gap: 24px }
  .tiers-keys li { position: static; transform: none }
  .tiers-keys li::before { display: none }
  .tiers-keys li + li { margin-top: 18px }
  .tiers-keys { border-left: 2px solid var(--green); padding-left: 16px }
}

/* ── signature foot ──────────────────────────────────────────────────────────────────────── */

.foot-plate {
  background: url("/img/seal.webp") center / cover no-repeat;
  border-top: 1px solid var(--rule);
}
.foot-plate .doc { padding-block: clamp(40px, 6vw, 96px) }
/* At phone width `cover` scales the seal plate until its engraved rule runs straight through the
 * sentence above it. Anchored to the foot instead, with room left under the text, the rule and
 * the seal sit below the signature where they belong. */
@media (max-width: 760px) {
  .foot-plate {
    background-size: 150% auto;
    background-position: 72% bottom;
  }
  .foot-plate .doc { padding-bottom: 215px }
}
.sig { max-width: 46ch }
.sig p { margin: 0 0 0.9em }
.sig p:last-child { margin-bottom: 0 }

.foot {
  border-top: 1px solid var(--rule);
  padding: 22px 0 34px;
}
.foot-in {
  max-width: var(--doc);
  margin: 0 auto;
  padding-inline: var(--pad);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: baseline;
}
.foot-in a { font: 400 14px/1.4 var(--mono); text-decoration: none }
.foot-note { font: 400 14px/1.5 var(--serif); color: var(--muted); flex-basis: 100%; max-width: 70ch }
/* the banner's own running foot, bottom right, behind a vertical rule */
.runfoot {
  margin-inline-start: auto;
  padding-left: 12px;
  border-left: 1px solid var(--rule);
  font: 500 9.5px/1 var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

/* ── utilities ───────────────────────────────────────────────────────────────────────────── */

.sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
/* Off-screen vertically, never horizontally: a negative `left` is a horizontal overflow the
 * browser will happily report and then blame on something else. */
.skip {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 60;
  transform: translateY(-300%);
  background: var(--green);
  color: var(--paper);
  padding: 10px 14px;
  font: 500 12px/1 var(--sans);
  text-decoration: none;
}
.skip:focus { transform: none }

:focus-visible { outline: 2px solid var(--green); outline-offset: 3px }

/* Nothing on this site loops. This runs once, on load, and only if the reader allows motion. */
@media (prefers-reduced-motion: no-preference) {
  .cover-in > * { animation: rise 520ms cubic-bezier(.22,.61,.36,1) both }
  .cover-in > *:nth-child(2) { animation-delay: 60ms }
  .cover-in > *:nth-child(3) { animation-delay: 110ms }
  .cover-in > *:nth-child(4) { animation-delay: 150ms }
  .cover-in > *:nth-child(5) { animation-delay: 190ms }
  .cover-in > *:nth-child(6) { animation-delay: 230ms }
}
@keyframes rise { from { opacity: 0; transform: translateY(9px) } to { opacity: 1; transform: none } }

@media print {
  .head, .progress, .foot { display: none }
  body { font-size: 11pt }
}
