/* ==========================================================================
   MailmanAPI design system: "the mailroom", airmail edition
   Ink on paper white, with airmail blue for action and money and airmail red for
   edges, labels and warnings. Grays are ink at opacity. Shading is dots: stipple
   grounds, dot screens and dotted rules (art in ./art, built by scripts/art).
   The letter preview and the address sheet stay true black on white.
   Type: Archivo (variable grotesk) for headings and text, IBM Plex Mono for
   labels, rates, tracking and anything the clerk types.
   Motifs: postmarks and cancellation waves, envelope windows, sorting slots,
   ledger tables, rubber stamps, a counter window. Nothing from USPS.
   Fonts are self-hosted from ./fonts (SIL OFL). No CDN, no trackers.
   ========================================================================== */

/* ---- Fonts -------------------------------------------------------------- */
@font-face {
  font-family: "Archivo";
  src: url("fonts/Archivo-VF.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/IBMPlexMono-Italic.woff2") format("woff2");
  font-weight: 400; font-style: italic; font-display: swap;
}

/* ---- Tokens ------------------------------------------------------------- */
:root {
  /* Color. Contrast on #fff is in the comment. */
  --ink: #111827;                         /* 17.7:1 body and headings */
  --paper: #fff;
  --black: #000;                          /* the letter preview and address sheet only */
  --blue: #1E3F9A;                        /* 9.4:1  action, money, links, postmarks */
  --blue-deep: #12296A;                   /* pressed edge under blue buttons */
  --red: #C42A31;                         /* 5.6:1  airmail edge, labels, test, warnings */
  --tint: #F3F5FA;                        /* envelope tint: ground behind previews (ink 16.3:1, blue 8.6:1) */
  --red-tint: #FCEFEF;                    /* red 5.0:1 */
  --ink-2: rgba(17, 24, 39, 0.76);        /* 8.2:1  secondary text */
  --ink-3: rgba(17, 24, 39, 0.64);        /* 5.3:1  tertiary text, smallest allowed (5.2:1 on the tint) */
  --ink-line: rgba(17, 24, 39, 0.16);     /* hairlines, decorative only */
  --ink-fill-1: rgba(30, 63, 154, 0.04);  /* slips, striping */
  --ink-fill-2: rgba(30, 63, 154, 0.08);  /* pockets, pressed */
  --ink-fill-3: rgba(17, 24, 39, 0.14);

  /* Context pair: flipped by .inverse so every component works on both. */
  --fg: var(--ink);
  --bg: var(--paper);
  --fg-2: var(--ink-2);
  --fg-3: var(--ink-3);
  --line: var(--ink-line);
  --fill-1: var(--ink-fill-1);
  --fill-2: var(--ink-fill-2);
  --act: var(--blue);        /* action and money: buttons, totals, links */
  --act-fg: var(--paper);
  --act-edge: var(--blue-deep);
  --mark: var(--red);        /* labels and warnings: test, draft, sample, void */
  --post: var(--blue);       /* postmarks and progress stamps */

  /* Type families */
  --font-text: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Type scale. Text 17/1.55, mono labels 13, display fluid. */
  --fs-mono-xs: 0.75rem;     /* 12 */
  --fs-mono-sm: 0.8125rem;   /* 13 */
  --fs-mono: 0.9375rem;      /* 15 */
  --fs-base: 1.0625rem;      /* 17 */
  --fs-lead: clamp(1.1875rem, 1.05rem + 0.5vw, 1.4375rem); /* 19 to 23 */
  --fs-h4: 1.25rem;          /* 20 */
  --fs-h3: clamp(1.5rem, 1.25rem + 0.9vw, 1.875rem);       /* 24 to 30 */
  --fs-h2: clamp(2.125rem, 1.4rem + 3vw, 3.75rem);         /* 34 to 60 */
  --fs-h1: clamp(2.875rem, 0.9rem + 8.2vw, 6.75rem);       /* 46 to 108 */
  --lh-tight: 0.95;
  --lh-head: 1.05;
  --lh-text: 1.55;
  --lh-mono: 1.5;
  --track-display: -0.035em;
  --track-head: -0.025em;
  --track-stamp: 0.09em;

  /* Spacing: 4px base */
  --s-1: 0.25rem;  --s-2: 0.5rem;   --s-3: 0.75rem;  --s-4: 1rem;
  --s-5: 1.5rem;   --s-6: 2rem;     --s-7: 3rem;     --s-8: 4rem;
  --s-9: 6rem;     --s-10: 8rem;
  --section-y: clamp(4rem, 3rem + 5vw, 8rem);

  /* Layout */
  --wrap: 1240px;
  --gutter: clamp(1rem, 0.4rem + 3vw, 2.5rem);
  --read: 62ch;

  /* Rules and borders: a ledger is made of lines */
  --rule-hair: 1px solid var(--line);
  --rule: 1px solid var(--fg);
  --rule-2: 2px solid var(--fg);
  --rule-heavy: 4px dotted var(--blue);   /* a row of dots: the airmail edition's section rule */
  --rule-double: 4px double var(--fg);
  --radius: 0;               /* paper has corners */
  --radius-btn: 10px;        /* buttons and chips are pressed, not cut */
  --radius-pill: 999px;      /* postmarks, oval stamps, chips */

  /* Motion: mechanical. Few frames, short, never eased like software. */
  --dur-fast: 90ms;
  --dur-stamp: 240ms;
  --dur-print: 560ms;
  --ease-hard: steps(4, end);
  --ease-slam: cubic-bezier(0.2, 0.9, 0.25, 1);

  /* Ink texture for rubber stamps (SVG filters inlined so this file is self-contained) */
  --ink-rough: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='r' x='-5%' y='-5%' width='110%' height='110%'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7' result='n'/><feDisplacementMap in='SourceGraphic' in2='n' scale='1.7'/></filter></svg>#r");
  --ink-dropout: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='m'><feTurbulence type='fractalNoise' baseFrequency='0.55' numOctaves='3' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -3.2 2.7'/></filter><rect width='240' height='240' filter='url(%23m)'/></svg>");

  /* Cancellation waves: rows of dots, not strokes */
  --waves: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='14' viewBox='0 0 44 14'><path d='M0 7 Q11 -1.2 22 7 T44 7' fill='none' stroke='%231E3F9A' stroke-width='2.2' stroke-linecap='round' stroke-dasharray='0 3.67'/></svg>");
  --waves-light: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='14' viewBox='0 0 44 14'><path d='M0 7 Q11 -1.2 22 7 T44 7' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-dasharray='0 3.67'/></svg>");
  --waves-v: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='32' viewBox='0 0 14 32'><path d='M7 0 Q-1.2 8 7 16 T7 32' fill='none' stroke='%231E3F9A' stroke-width='2' stroke-linecap='round' stroke-dasharray='0 3.4'/></svg>");
  /* Security-envelope tint: a blue dot weave */
  --security: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><g fill='%231E3F9A' fill-opacity='0.32'><circle cx='3' cy='3' r='0.75'/><circle cx='9' cy='9' r='0.75'/></g></svg>");
  /* Art files (cached): the airmail edge, a stipple ground, engraved corner lines; the page-head stamp is an <img> */
  --airmail: url("art/airmail.svg");
  --stipple: url("art/stipple.svg");
  --stipple-light: url("art/stipple-light.svg");   /* white dots, for blue bands */
  --corner: url("art/corner.svg");                 /* engraved cancel lines for a top-right corner, 640x300 */
  --corner-light: url("art/corner-light.svg");
  --airmail-h: 6px;
}

/* Inverse context: paper on airmail blue. Use for at most one band per page. */
.inverse {
  --fg: var(--paper);
  --bg: var(--blue);
  --fg-2: rgba(255, 255, 255, 0.86);   /* 7.4:1 on blue */
  --fg-3: rgba(255, 255, 255, 0.78);   /* 6.4:1 on blue */
  --act: var(--paper); --act-fg: var(--blue); --act-edge: rgba(0, 0, 0, 0.35);
  --mark: var(--paper); --post: var(--paper);
  --line: rgba(255, 255, 255, 0.28);
  --fill-1: rgba(255, 255, 255, 0.06);
  --fill-2: rgba(255, 255, 255, 0.12);
  background: var(--bg);
  color: var(--fg);
}

/* ---- Base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-text);
  font-size: var(--fs-base);
  line-height: var(--lh-text);
  font-stretch: 100%;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, h5, h6, p, dl, dd, figure, blockquote, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration-thickness: 0.09em; text-underline-offset: 0.2em; }
a:not([class]) { color: var(--act); }   /* text links are blue; classed links (nav, cards, buttons) set their own */
a:hover { text-decoration-thickness: 0.18em; }
::selection { background: var(--blue); color: var(--paper); }
hr { border: 0; border-top: var(--rule); margin: 0; }
table { border-collapse: collapse; }
abbr[title] { text-decoration: underline dotted; text-underline-offset: 0.2em; }

:focus-visible {
  outline: 3px solid var(--act);
  outline-offset: 3px;
}
:focus:not(:focus-visible) { outline: none; }
.is-focus { outline: 3px solid var(--act); outline-offset: 3px; }   /* forced focus ring for the component sheet */

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s-4); top: -4rem; z-index: 100;
  background: var(--ink); color: var(--paper); padding: var(--s-3) var(--s-4);
  font-family: var(--font-mono); font-size: var(--fs-mono);
}
.skip-link:focus { top: var(--s-4); }

/* ---- Layout helpers ----------------------------------------------------- */
.wrap { width: min(100% - 2 * var(--gutter), var(--wrap)); margin-inline: auto; }
.section { padding-block: var(--section-y); }
.section--tight { padding-block: calc(var(--section-y) * 0.6); }
.stack > * + * { margin-top: var(--stack, var(--s-4)); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s-3)); }
.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--s-5); }
.measure { max-width: var(--read); }

/* ---- Type --------------------------------------------------------------- */
.t-display, h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: 104%;
  font-size: var(--fs-h1);
  line-height: var(--lh-tight);
  letter-spacing: var(--track-display);
  text-wrap: balance;
}
.t-h2, h2 {
  font-family: var(--font-display);
  font-weight: 750;
  font-stretch: 102%;
  font-size: var(--fs-h2);
  line-height: var(--lh-head);
  letter-spacing: var(--track-head);
  text-wrap: balance;
}
.t-h3, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h3);
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.t-h4, h4 {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: var(--fs-h4);
  line-height: 1.2;
  letter-spacing: -0.012em;
}
.t-lead { font-size: var(--fs-lead); line-height: 1.45; letter-spacing: -0.012em; text-wrap: pretty; }
.t-body { font-size: var(--fs-base); }
.t-mono { font-family: var(--font-mono); font-size: var(--fs-mono); line-height: var(--lh-mono); }
.t-label {
  font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500;
  line-height: 1.3; letter-spacing: 0.01em;
}
.t-fine { font-family: var(--font-mono); font-size: var(--fs-mono-xs); line-height: 1.45; color: var(--fg-3); }
.t-2 { color: var(--fg-2); }
.t-3 { color: var(--fg-3); }
.nums { font-variant-numeric: tabular-nums slashed-zero; }
p { text-wrap: pretty; }

.prose > * + * { margin-top: var(--s-4); }
.prose { max-width: var(--read); }

/* Inline tag: a typed label in a box */
.tag {
  display: inline-flex; align-items: center; gap: 0.4em;
  font-family: var(--font-mono); font-size: var(--fs-mono-xs); font-weight: 500;
  padding: 0.18em 0.55em; border: 1px solid currentColor; line-height: 1.3;
}
.tag--solid { background: var(--act); color: var(--act-fg); border-color: var(--act); }
kbd, .kbd {
  font-family: var(--font-mono); font-size: 0.85em; padding: 0.1em 0.4em;
  border: 1px solid var(--fg); border-bottom-width: 3px; background: var(--bg);
}

/* Lamp: a square indicator. Filled is on. State is also in text, never color. */
.lamp { display: inline-block; width: 0.7em; height: 0.7em; border: 2px solid currentColor; flex: none; }
.lamp--on { background: currentColor; }

/* ---- Rules -------------------------------------------------------------- */
.rule-hair { border-top: var(--rule-hair); }
.rule { border-top: var(--rule); }
.rule-2 { border-top: var(--rule-2); }
.rule-heavy { border-top: var(--rule-heavy); }
.rule-double { border-top: var(--rule-double); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  --btn-bg: var(--act); --btn-fg: var(--act-fg); --btn-line: var(--act);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.7em;
  min-height: 3rem; padding: 0.7em 1.3em;
  font-family: var(--font-mono); font-size: var(--fs-mono); font-weight: 500; line-height: 1.2;
  text-decoration: none; text-align: center;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 2px solid var(--btn-line); border-radius: var(--radius-btn);
  box-shadow: 0 2px 0 var(--act-edge);
  cursor: pointer;
  transition: transform var(--dur-fast) steps(2, end);
  -webkit-tap-highlight-color: transparent;
}
.btn.is-hover { --btn-bg: var(--act-edge); text-decoration: none; }
@media (hover: hover) { .btn:hover { --btn-bg: var(--act-edge); text-decoration: none; } }
.inverse .btn.is-hover, .inverse .btn:hover { --btn-bg: var(--paper); --btn-fg: var(--blue-deep); }
.btn:active, .btn.is-active { transform: translateY(2px); box-shadow: none; }
.btn--ghost { --btn-bg: transparent; --btn-fg: var(--act); box-shadow: none; }
.btn--ghost.is-hover { --btn-bg: var(--fill-2); --btn-fg: var(--act); }
@media (hover: hover) { .btn--ghost:hover { --btn-bg: var(--fill-2); --btn-fg: var(--act); } }
.btn--ghost:active, .btn--ghost.is-active { --btn-bg: var(--act); --btn-fg: var(--act-fg); }
.btn--sm { min-height: 2.5rem; padding: 0.45em 0.9em; font-size: var(--fs-mono-sm); }
@media (pointer: coarse) { .btn--sm { min-height: 2.75rem; } }   /* a finger needs 44px, even for the small actions */
.btn--copy { min-height: 2.75rem; min-width: 5.5rem; padding: 0.4em 1em; font-size: var(--fs-mono-sm); }
.btn--block { display: flex; width: 100%; }
.btn--text {   /* no border or side padding, so the text lines up with the column edge like everything above it */
  --btn-bg: transparent; --btn-fg: var(--act); border-width: 0; box-shadow: none; border-radius: 0;
  padding-inline: 0; text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 2px;
}
@media (hover: hover) { .btn--text:hover { --btn-bg: transparent; text-decoration-thickness: 4px; } }
.btn[disabled], .btn[aria-disabled="true"] {
  --btn-bg: transparent; --btn-fg: var(--fg-3); --btn-line: var(--fg-3);
  border-style: dashed; box-shadow: none; cursor: not-allowed; transform: none;
}
.btn[aria-busy="true"] { cursor: progress; overflow: hidden; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 4px; width: 100%;
  background: currentColor; transform-origin: left; animation: slot-load 1.2s steps(6, end) infinite;
}
@keyframes slot-load { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* The stamp button: the one action that spends money. Reads as a rubber stamp
   block with a perforated inner rule. Pressing it lands a stamp (see .stamp--land). */
.btn--stamp {
  --btn-bg: var(--act); --btn-fg: var(--act-fg);
  box-shadow: 0 3px 0 var(--act-edge);
  min-height: 4rem; padding: 0.9em 1.6em;
  font-family: var(--font-display); font-weight: 800; font-stretch: 80%;
  font-size: 1.5rem; letter-spacing: -0.01em; text-transform: none;   /* sentence case, like every other action */
  gap: 1rem;
}
.btn--stamp::before {
  content: ""; position: absolute; inset: 4px; border: 2px dotted var(--btn-fg); border-radius: calc(var(--radius-btn) - 4px); opacity: 0.55; pointer-events: none;
}
.btn--stamp .btn__amount {
  font-family: var(--font-mono); font-weight: 500; font-stretch: 100%; font-size: var(--fs-mono);
  letter-spacing: 0; text-transform: none; padding-left: 1rem; border-left: 2px dotted currentColor;
}
.btn--stamp.is-hover { --btn-bg: var(--act-edge); }
@media (hover: hover) { .btn--stamp:hover { --btn-bg: var(--act-edge); } }
.btn--stamp:active, .btn--stamp.is-active { transform: translateY(3px) scale(0.985); box-shadow: none; }

/* ==========================================================================
   Inputs
   ========================================================================== */
.field { display: grid; gap: var(--s-2); }
.field__label { font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500; }
.field__hint { font-family: var(--font-mono); font-size: var(--fs-mono-xs); color: var(--fg-3); line-height: 1.45; }
.field__error {
  display: none; align-items: baseline; gap: 0.6em;
  font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500;
}
.field__error::before {
  content: "!"; display: inline-grid; place-items: center; flex: none;
  width: 1.4em; height: 1.4em; border-radius: 50%; background: var(--red); color: var(--paper); font-weight: 500;
}
.field__error { color: var(--red); }
.field:has([aria-invalid="true"]) .field__error, .field.is-invalid .field__error { display: flex; }

.input, .select, .textarea {
  width: 100%; min-height: 3rem; padding: 0.65em 0.85em;
  font-family: var(--font-mono); font-size: 1rem; line-height: 1.4;
  background: var(--bg); color: var(--fg);
  border: 2px solid rgba(17, 24, 39, 0.55); border-radius: 8px;
  appearance: none; -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--fg-3); opacity: 1; }
.textarea { min-height: 7rem; resize: vertical; line-height: 1.5; }
.input:hover, .textarea:hover, .select:hover { background: var(--fill-1); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible, .input.is-focus {
  outline: 3px solid var(--blue); outline-offset: 2px; background: var(--bg);
  border-color: var(--blue); box-shadow: none;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] {
  border-width: 2px; border-style: solid;
  border-color: var(--red); background-color: var(--red-tint);
  box-shadow: inset 6px 0 0 var(--red);
}
.input:disabled, .select:disabled, .textarea:disabled {
  border-style: dashed; border-color: var(--fg-3); color: var(--fg-3); background: var(--fill-1); cursor: not-allowed;
}
.input[readonly] { background: var(--fill-1); }
.select {
  padding-right: 2.6em;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.35em) 50%, calc(100% - 0.95em) 50%;
  background-size: 0.45em 0.45em; background-repeat: no-repeat;
}

/* Check and radio: a square box that fills like a slot */
.check { display: inline-flex; align-items: flex-start; gap: 0.75em; cursor: pointer; font-size: var(--fs-base); }
.check input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 1.5rem; height: 1.5rem; margin: 0.1em 0 0; border: 2px solid var(--fg); background: var(--bg); display: grid; place-content: center;
}
.check input[type="radio"] { border-radius: 50%; }
.check input::after { content: ""; width: 0.8rem; height: 0.8rem; background: var(--fg); transform: scale(0); transition: transform var(--dur-fast) steps(2, end); }
.check input[type="radio"]::after { border-radius: 50%; }
.check input:checked::after { transform: scale(1); }
.check input:disabled { border-style: dashed; border-color: var(--fg-3); }

/* ==========================================================================
   Rubber stamps. States are in the shape and the type; color only sorts them:
   blue for mail moving forward, red for anything that needs a look.
   <span class="stamp stamp--paid">Paid</span>
   ========================================================================== */
.stamp {
  --tilt: -3deg;
  --stamp-size: 1.375rem;
  position: relative;
  display: inline-block;
  font-family: var(--font-display); font-weight: 800; font-stretch: 76%;
  font-size: var(--stamp-size); line-height: 1; letter-spacing: var(--track-stamp); text-transform: uppercase;
  white-space: nowrap;
  padding: 0.34em 0.62em 0.28em;
  color: var(--post);
  border: 0.13em solid currentColor;
  box-shadow: inset 0 0 0 0.07em var(--bg), inset 0 0 0 0.13em currentColor;   /* inner rule */
  transform: rotate(var(--tilt));
  filter: var(--ink-rough);
  -webkit-mask-image: var(--ink-dropout); mask-image: var(--ink-dropout);
  -webkit-mask-size: 240px 240px; mask-size: 240px 240px;
  user-select: none;
}
.stamp--sm { --stamp-size: 0.9rem; }
.stamp--lg { --stamp-size: 2rem; }
.stamp--xl { --stamp-size: 3.25rem; }
.stamp--flat { --tilt: 0deg; }

/* Draft: dashed, not final */
.stamp--draft, .stamp--held, .stamp--void, .stamp--returned, .stamp--refunded, .stamp--sample { color: var(--mark); }
.stamp--draft { border-style: dashed; box-shadow: none; letter-spacing: 0.16em; }
/* Paid: the double-ruled receipt stamp (base look) */
.stamp--paid { --tilt: -4deg; }
/* Printed: a flat machine imprint, single rule, wide */
.stamp--printed { --tilt: 0deg; box-shadow: none; letter-spacing: 0.2em; font-stretch: 90%; }
/* Mailed: oval, like a datestamp */
.stamp--mailed { --tilt: -7deg; border-radius: var(--radius-pill); padding-inline: 1.05em; }
/* In transit: dotted */
.stamp--transit { border-style: dotted; box-shadow: none; --tilt: 2deg; }
/* Delivered: solid block, the terminal good state. Paper letters knocked out. */
.stamp--delivered { --tilt: -2deg; background: var(--post); color: var(--bg); box-shadow: inset 0 0 0 0.07em var(--post), inset 0 0 0 0.13em var(--bg); border-color: var(--post); }
/* Returned: top and bottom bars only, open sides */
.stamp--returned { border-left: 0; border-right: 0; box-shadow: inset 0 0.07em 0 var(--bg), inset 0 0.13em 0 currentColor, inset 0 -0.07em 0 var(--bg), inset 0 -0.13em 0 currentColor; --tilt: 3deg; }
/* Held for review: heavy dashed with wide dashes */
.stamp--held { border-style: dashed; border-width: 0.2em; box-shadow: none; --tilt: 0deg; }
/* Void: struck through */
.stamp--void { box-shadow: none; --tilt: -5deg; }
.stamp--void::after {
  content: ""; position: absolute; left: -6%; right: -6%; top: 50%; height: 0.13em; background: currentColor; transform: rotate(-9deg);
}
/* Refunded: double rule, ruled arrow pointing back */
.stamp--refunded { border-style: double; border-width: 0.26em; box-shadow: none; padding-left: 1.7em; --tilt: 4deg; letter-spacing: 0.1em; }
.stamp--refunded::before {
  content: ""; position: absolute; left: 0.45em; top: 50%; width: 0.85em; height: 0.8em; transform: translateY(-50%);
  background: currentColor; clip-path: polygon(0 50%, 48% 0, 48% 28%, 100% 28%, 100% 72%, 48% 72%, 48% 100%);
}
/* Sample: outline type, large, for placeholder figures */
.stamp--sample { --tilt: -8deg; box-shadow: none; border-width: 0.1em; letter-spacing: 0.22em; background: var(--bg); }

/* Landing: a stamp comes down, overshoots, settles. Add .stamp--land on insert. */
@media (prefers-reduced-motion: no-preference) {
  .stamp--land { animation: stamp-land var(--dur-stamp) linear both; }
  .thud { animation: thud 160ms steps(2, end) 120ms; }
}
@keyframes stamp-land {
  0%   { transform: rotate(var(--tilt)) scale(2.1); opacity: 0; }
  45%  { transform: rotate(var(--tilt)) scale(0.93); opacity: 1; }
  70%  { transform: rotate(var(--tilt)) scale(1.04); opacity: 1; }
  100% { transform: rotate(var(--tilt)) scale(1); opacity: 1; }
}
@keyframes thud { 0% { transform: translateY(0); } 50% { transform: translateY(3px); } 100% { transform: translateY(0); } }

/* ==========================================================================
   Postmark and cancellation waves
   The ring text is SVG (see the postmark symbol in components.html).
   ========================================================================== */
.postmark {
  --pm: 132px; --tilt: -12deg;
  width: var(--pm); height: var(--pm); flex: none;
  color: var(--post);
  transform: rotate(var(--tilt));
  filter: var(--ink-rough);
  -webkit-mask-image: var(--ink-dropout); mask-image: var(--ink-dropout);
  -webkit-mask-size: 240px 240px; mask-size: 240px 240px;
}
.postmark svg { width: 100%; height: 100%; overflow: visible; fill: currentColor; font-family: var(--font-mono); font-weight: 500; }
/* Note: text inside <use> inherits from the <svg>, so type is set here and on the symbol's own text. */

.cancel-waves {
  --rows: 5;
  height: calc(var(--rows) * 14px);
  background: var(--waves) 0 0 / 44px 14px repeat;
  -webkit-mask-image: var(--ink-dropout); mask-image: var(--ink-dropout);
  -webkit-mask-size: 240px 240px; mask-size: 240px 240px;
}
.inverse .cancel-waves { background-image: var(--waves-light); }
.cancel-waves--fade {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 45%), var(--ink-dropout);
          mask-image: linear-gradient(90deg, transparent, #000 45%), var(--ink-dropout);
  -webkit-mask-size: 100% 100%, 240px 240px; mask-size: 100% 100%, 240px 240px;
  -webkit-mask-composite: source-in; mask-composite: intersect;
}

/* Mini postmark: CSS only, a dated ring used in ledgers and timelines */
.pm-mini {
  display: inline-grid; place-content: center; text-align: center;
  width: 4rem; height: 4rem; flex: none; border-radius: 50%;
  border: 2.5px dotted var(--post); box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 4.5px var(--post);
  font-family: var(--font-display); font-stretch: 80%; font-weight: 800; line-height: 0.95; background: var(--bg); color: var(--post);
}
.pm-mini b { display: block; font-size: 1.35rem; letter-spacing: 0; font-weight: 800; }
.pm-mini span { display: block; font-family: var(--font-mono); font-stretch: 100%; font-weight: 500; font-size: 0.625rem; letter-spacing: 0.1em; text-transform: uppercase; }
.pm-mini--solid { background: var(--post); color: var(--bg); border-style: solid; box-shadow: inset 0 0 0 3px var(--post), inset 0 0 0 4.5px var(--bg); }

/* ==========================================================================
   Envelope window: a DL envelope with an address showing through glassine
   ========================================================================== */
.envelope {
  position: relative; aspect-ratio: 2.1 / 1; width: 100%;
  background:   /* an airmail edge top and bottom over the security tint */
    var(--airmail) 0 0 / 44px 6px repeat-x, var(--airmail) 22px 100% / 44px 6px repeat-x,
    var(--security) 0 0 / 12px 12px, var(--bg);
  border: 2px solid var(--fg); border-radius: 4px;
  overflow: hidden;
}
.inverse .envelope { background-color: var(--bg); }
.envelope::before, .envelope::after {   /* flap lines meeting at the center */
  content: ""; position: absolute; top: 0; width: 50%; height: 56%;
  border-top: 2px solid var(--fg); pointer-events: none;
}
.envelope::before { left: 0; border-right: 0; background: linear-gradient(to bottom right, transparent calc(50% - 1px), var(--fg) calc(50% - 1px), var(--fg) calc(50% + 1px), transparent calc(50% + 1px)); border-top: 0; }
.envelope::after  { right: 0; background: linear-gradient(to bottom left, transparent calc(50% - 1px), var(--fg) calc(50% - 1px), var(--fg) calc(50% + 1px), transparent calc(50% + 1px)); border-top: 0; }
.envelope__window {
  position: absolute; left: 7%; bottom: 14%; width: 58%; height: 38%;
  background: var(--bg);
  border: 2px solid var(--fg); border-radius: 4px;
  padding: 0.5em 0.8em; display: grid; align-content: center;
  font-family: var(--font-mono); font-size: clamp(0.5rem, 0.35rem + 0.55vw, 0.8125rem); line-height: 1.35; z-index: 1;
}
.envelope__window b { font-weight: 500; }
.envelope__return {
  position: absolute; left: 4%; top: 6%; z-index: 1;
  font-family: var(--font-mono); font-size: clamp(0.45rem, 0.3rem + 0.4vw, 0.6875rem); line-height: 1.3; color: var(--fg-2);
  background: var(--bg); padding: 0.2em 0.5em;
}
.envelope__mark { position: absolute; right: 5%; top: 8%; z-index: 1; background: var(--bg); padding: 0.3em; }
.envelope--back .envelope__window { display: none; }

/* ==========================================================================
   Sorting slots: pigeonholes. Filled slots show mail; empty slots wait.
   <ul class="slot-grid"><li class="slot slot--filled">…
   ========================================================================== */
.slot-grid {
  --cols: 4;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 3px;
  background: var(--ink); border: 3px solid var(--ink);
}
.slot {
  --i: 0; --hide: 105%;
  position: relative; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden; isolation: isolate;
}
.slot__tag {   /* pigeonhole label holder */
  position: absolute; left: 0; top: 0; z-index: 3;
  font-family: var(--font-mono); font-size: var(--fs-mono-xs); font-weight: 500;
  padding: 0.35em 0.8em; border-right: 2px solid var(--fg); border-bottom: 2px solid var(--fg); background: var(--bg); color: var(--red);
}
.slot__bay { position: relative; flex: none; height: 9.5rem; overflow: hidden; }   /* fixed picture height so every title in a row starts on the same line */
.slot__pocket {   /* the dark inside of the hole */
  position: absolute; inset: 0; z-index: 0;
  background: var(--stipple) 0 0 / 96px 96px, var(--tint);
  box-shadow: inset 0 14px 0 -8px var(--fill-2);
}
.slot__mail {
  position: absolute; left: 14%; right: 14%; bottom: 0; height: 74%; z-index: 1;
  background: var(--bg) var(--security); border: 2px solid var(--fg); border-bottom: 0;
  transition: transform var(--dur-print) steps(6, end) calc(var(--i) * 140ms);
}
.slot__mail::before {   /* a window with two address lines */
  content: ""; position: absolute; left: 10%; top: 24%; width: 54%; height: 30%;
  border: 2px solid var(--fg); background: var(--bg) repeating-linear-gradient(0deg, transparent 0 5px, var(--ink-fill-3) 5px 7px);
}
.slot__mail::after {    /* postage box */
  content: ""; position: absolute; right: 9%; top: 12%; width: 17%; aspect-ratio: 0.85; border: 2px dotted var(--red);
}
.slot__lip {   /* the front of the pocket, carries the text */
  position: relative; z-index: 2; flex: 1; min-height: 6.5rem;
  background: var(--bg); border-top: 3px solid var(--fg); padding: var(--s-3) var(--s-4) var(--s-4);
}
.slot__title { font-family: var(--font-display); font-weight: 700; font-size: 1.1875rem; line-height: 1.15; letter-spacing: -0.015em; }
.slot__meta { font-family: var(--font-mono); font-size: var(--fs-mono-xs); color: var(--fg-2); margin-top: 0.35em; line-height: 1.4; }
.slot--empty .slot__mail { display: none; }
.slot--empty .slot__title { color: var(--fg-2); font-weight: 600; }
.slot--empty .slot__lip { border-top-style: dashed; }
.slot--empty .slot__pocket { background: var(--security) 0 0 / 12px 12px; box-shadow: none; opacity: 0.6; }
.slot-grid[data-await]:not(.is-in) .slot__mail { transform: translateY(var(--hide)); }

/* What is in each slot tells you the mail type */
.slot__bar {   /* barcode label: tracked mail */
  position: absolute; left: 10%; bottom: 9%; width: 52%; height: 15%; padding: 3px;
  border: 2px solid var(--fg);
  background: var(--bg) repeating-linear-gradient(90deg, var(--fg) 0 2px, transparent 2px 4px, var(--fg) 4px 5px, transparent 5px 8px) content-box;
}
.slot__rr {    /* the return receipt card clipped to the envelope: signature line */
  position: absolute; right: 9%; bottom: 9%; width: 28%; height: 20%; border: 2px solid var(--fg); background: var(--bg);
}
.slot__rr::before { content: "X"; position: absolute; left: 12%; top: 6%; font: 500 0.6rem/1 var(--font-mono); }
.slot__rr::after { content: ""; position: absolute; left: 12%; right: 12%; bottom: 22%; border-bottom: 2px solid var(--fg); }
.slot--card .slot__mail {   /* a card, not an envelope: message lines, divider, stamp box, address lines */
  left: 9%; right: 9%; height: 62%;
  background:
    linear-gradient(var(--fg), var(--fg)) 52% 16% / 2px 66% no-repeat,
    repeating-linear-gradient(0deg, transparent 0 6px, var(--ink-fill-3) 6px 8px) 8% 24% / 36% 56% no-repeat,
    var(--bg);
}
.slot--card .slot__mail::before { left: 58%; top: 46%; width: 34%; height: 34%; border: 0; background: repeating-linear-gradient(0deg, transparent 0 6px, var(--ink-fill-3) 6px 8px); }
.slot--card .slot__mail::after { right: 7%; top: 11%; width: 16%; }
.slot-later {   /* slots that are not open yet: one quiet line, not four empty cards */
  display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; margin-top: var(--s-4); padding: var(--s-3) var(--s-4);
  border: 2px dashed var(--fg-3); font-family: var(--font-mono); font-size: var(--fs-mono-sm); color: var(--fg-2); line-height: 1.5;
}
.slot-later b { color: var(--fg); font-weight: 500; }
@media (max-width: 900px) { .slot-grid { --cols: 2; } }

/* ==========================================================================
   Ledger table: manifest and rate board
   ========================================================================== */
.ledger {
  width: 100%; font-family: var(--font-mono); font-size: var(--fs-mono); line-height: 1.4;
  font-variant-numeric: tabular-nums slashed-zero; border-top: var(--rule-heavy); border-bottom: var(--rule-double);
}
.ledger caption { text-align: left; padding-bottom: var(--s-3); caption-side: top; }
.ledger { --ledger-pad: 1rem; }
.ledger caption { padding-inline: var(--ledger-pad); }
.ledger th, .ledger td { padding: 0.9em 0.9em; text-align: left; vertical-align: baseline; border-bottom: var(--rule-hair); }
.ledger tr > :first-child { padding-left: var(--ledger-pad); }
.ledger tr > :last-child { padding-right: var(--ledger-pad); }
.ledger thead th {
  font-size: var(--fs-mono-sm); font-weight: 500; color: var(--fg-2); border-bottom: 2px solid var(--fg); vertical-align: bottom;
  padding-block: 0.8em;
}
.ledger .num { text-align: right; white-space: nowrap; }
.ledger tbody th { font-family: var(--font-display); font-weight: 650; font-size: 1.125rem; letter-spacing: -0.012em; line-height: 1.2; }
.ledger tbody th small { display: block; margin-top: 0.3em; font-family: var(--font-mono); font-weight: 400; font-size: var(--fs-mono-xs); letter-spacing: 0; color: var(--fg-2); }
.ledger tbody tr:last-child > * { border-bottom: 0; }
.ledger .total { font-weight: 500; font-size: 1.0625rem; }
.ledger .empty { color: var(--fg-3); }
.ledger tbody tr { transition: none; }
.ledger tbody tr.is-hover { background: var(--blue); color: var(--paper); }
.ledger tbody tr.is-hover small, .ledger tbody tr.is-hover .empty, .ledger tbody tr.is-hover td::before, .ledger tbody tr.is-hover a { color: var(--paper); }
@media (hover: hover) {   /* touch screens keep a tapped row's hover until the next tap, so only hover-capable devices get it */
  .ledger tbody tr:hover { background: var(--blue); color: var(--paper); }
  .ledger tbody tr:hover small, .ledger tbody tr:hover .empty, .ledger tbody tr:hover td::before, .ledger tbody tr:hover a { color: var(--paper); }
}
.ledger tfoot td, .ledger tfoot th { border-top: var(--rule-2); border-bottom: 0; font-weight: 500; }
.ledger--zebra tbody tr:nth-child(even) { background: var(--fill-1); }
.ledger--zebra tbody tr:nth-child(even).is-hover { background: var(--blue); }
@media (hover: hover) { .ledger--zebra tbody tr:nth-child(even):hover { background: var(--blue); } }

@media (max-width: 960px) {
  .ledger--stack, .ledger--stack tbody, .ledger--stack tr, .ledger--stack th, .ledger--stack td { display: block; }
  .ledger--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .ledger--stack tbody tr { padding: var(--s-4) var(--ledger-pad) var(--s-3); border-bottom: var(--rule-2); }
  .ledger--stack tbody tr:last-child { border-bottom: 0; }
  .ledger--stack th, .ledger--stack td, .ledger--stack tr > :first-child, .ledger--stack tr > :last-child { border: 0; padding: 0.2em 0; }
  .ledger--stack tbody th { margin-bottom: var(--s-2); font-size: 1.3125rem; }
  .ledger--stack td { display: flex; justify-content: space-between; gap: var(--s-4); align-items: baseline; }
  .ledger--stack td::before {
    content: attr(data-label); font-size: var(--fs-mono-sm); color: var(--fg-2);
    flex: 1; display: flex; align-items: baseline; gap: 0.5em;
  }
  .ledger--stack td::after { content: none; }
  .ledger--stack td.num { text-align: right; }
  .ledger--stack td.total { border-top: var(--rule-2); margin-top: var(--s-2); padding-top: var(--s-2); }
  .ledger--stack td.cta { justify-content: flex-start; margin-top: var(--s-2); }
  .ledger--stack td.cta::before { content: none; }
  /* Text tables (docs, status) line up with the headings and rules around them; the rate boards keep their inset. */
  .endpoints, .refusals, .statusboard, .tiers { --ledger-pad: 0; }
}

/* Ledger list: itemized lines with dot leaders (the counter's price slip) */
.ledger-list { font-family: var(--font-mono); font-size: var(--fs-mono); font-variant-numeric: tabular-nums slashed-zero; }
.ledger-list > div { display: grid; grid-template-columns: 1fr auto; column-gap: 0.5em; padding: 0.4em 0; }
.ledger-list dt { display: flex; align-items: baseline; gap: 0.5em; min-width: 0; }
.ledger-list dt::after { content: ""; flex: 1; min-width: 1em; border-bottom: 2px dotted var(--line); transform: translateY(-0.25em); }
.ledger-list dd { text-align: right; white-space: nowrap; }
.ledger-list .sub { color: var(--fg-2); font-size: var(--fs-mono-sm); }
.ledger-list .total { color: var(--act); border-top: 4px double var(--fg); margin-top: var(--s-2); padding-top: var(--s-3); font-weight: 500; font-size: 1.125rem; }
.ledger-list .total dt::after { content: none; }
.ledger-list .total dt { justify-content: space-between; }

/* ==========================================================================
   Timeline: tracking as a postmarked ledger
   ========================================================================== */
.timeline { counter-reset: none; }
.timeline > li { position: relative; display: grid; grid-template-columns: 4rem 1fr; column-gap: var(--s-5); padding-bottom: var(--s-6); }
.timeline > li:last-child { padding-bottom: 0; }
.timeline > li:not(:last-child)::after {   /* cancellation wave carries you to the next postmark */
  content: ""; position: absolute; left: calc(2rem - 7px); top: 4.3rem; bottom: 0.3rem; width: 14px;
  background: var(--waves-v) 0 0 / 14px 32px repeat-y;
}
.inverse .timeline > li:not(:last-child)::after { filter: invert(1); }
.timeline__body { padding-top: 0.1rem; min-width: 0; }
.timeline__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); }
.timeline__title { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.2; letter-spacing: -0.015em; }
.timeline__meta { font-family: var(--font-mono); font-size: var(--fs-mono-sm); color: var(--fg-2); margin-top: 0.4em; line-height: 1.5; }
.timeline__note { font-size: 0.9375rem; color: var(--fg-2); margin-top: 0.4em; max-width: 52ch; }
.timeline > li.is-pending .pm-mini { border-style: dashed; box-shadow: none; color: var(--fg-3); }
.timeline > li.is-pending .timeline__title { color: var(--fg-3); }

/* ==========================================================================
   Documents: the copy of what was mailed, and the return receipt
   ========================================================================== */
.doc {
  --pad: 12%;
  position: relative; aspect-ratio: 8.5 / 11; width: 100%; background: var(--bg);
  border: 2px solid var(--fg); padding: 11% var(--pad) var(--pad);
  display: flex; flex-direction: column; gap: 3.6%;
}
.doc::after {   /* folded corner */
  content: ""; position: absolute; right: -2px; top: -2px; width: 14%; aspect-ratio: 1;
  background: linear-gradient(225deg, var(--bg) 50%, var(--fg) 50%, var(--fg) calc(50% + 2px), var(--fill-2) calc(50% + 2px));
}
.doc__line { height: 0.34rem; background: var(--ink-fill-3); width: 100%; }
.doc__line--head { height: 0.6rem; background: var(--fg); width: 46%; margin-bottom: 4%; }
.doc__line--short { width: 62%; }
.doc__line--gap { margin-top: 2.5%; }
.doc__sig { margin-top: auto; width: 34%; border-top: 2px solid var(--fg); }
.doc__stamp { position: absolute; right: 7%; bottom: 9%; }
.doc--sm { width: 7.5rem; flex: none; padding: 12% 11% 10%; gap: 4.5%; }
.doc--sm .doc__line { height: 0.2rem; }
.doc--sm .doc__line--head { height: 0.34rem; }

.receipt { border: 2px solid var(--fg); background: var(--bg); position: relative; }
.receipt__bar { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); padding: 0.55rem 1rem; background: var(--blue); color: var(--paper); font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500; }
.receipt__body { padding: var(--s-4) var(--s-4) var(--s-5); }
.receipt dl > div { display: grid; grid-template-columns: 8.5rem 1fr; gap: var(--s-3); padding: 0.55em 0; border-bottom: var(--rule-hair); font-family: var(--font-mono); font-size: var(--fs-mono-sm); }
.receipt dl > div:last-child { border-bottom: 0; }
.receipt dt { color: var(--fg-2); }
.receipt dd { overflow-wrap: anywhere; }

/* ==========================================================================
   Code and tabs (connect your assistant)
   ========================================================================== */
.code { border: 2px solid var(--fg); background: var(--bg); color: var(--fg); min-width: 0; }
/* The bar's Copy is the same part as the .url box's (site.css): a square segment, flush with the frame on three sides,
   set off by one 2px rule. No radius, no shadow, no inset. */
.code__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 2.75rem; background: var(--blue); color: var(--paper); padding: 0 0 0 0.9rem; font-family: var(--font-mono); font-size: var(--fs-mono-sm); }
.code__bar > span { padding-block: 0.45rem; min-width: 0; }
.code__bar .btn { --btn-bg: var(--paper); --btn-fg: var(--blue); --btn-line: var(--fg); align-self: stretch; flex: none; border-width: 0 0 0 2px; border-radius: 0; box-shadow: none; }
@media (hover: hover) { .code__bar .btn:hover { --btn-bg: var(--blue-deep); --btn-fg: var(--paper); } }
.code__bar .btn:focus-visible { outline-color: var(--blue-deep); outline-offset: -5px; }
.code pre { margin: 0; padding: var(--s-4); overflow-x: auto; font-family: var(--font-mono); font-size: var(--fs-mono); line-height: 1.65; tab-size: 2; background: var(--ink-fill-1); }
.code pre:focus-visible { outline-offset: -3px; }
.code[data-more] pre {   /* edge fade: there is more to the right */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 2.75rem), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - 2.75rem), transparent);
}
.code[data-less] pre {   /* scrolled: the left edge fades too, so a cut glyph reads as "more this way" */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 2rem);
          mask-image: linear-gradient(90deg, transparent, #000 2rem);
}
.code[data-less][data-more] pre {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 2rem, #000 calc(100% - 2.75rem), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 2rem, #000 calc(100% - 2.75rem), transparent);
}
/* Prose that is meant to be pasted (a setup prompt) wraps; code keeps its lines and scrolls. */
.code--wrap pre { white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: visible; }
.code .c { color: var(--fg-3); }
.code .s { color: var(--blue); }
.code .k { font-weight: 500; }
.code mark { background: var(--blue); color: var(--paper); padding: 0.05em 0.3em; }
.code--inverse { --fg: var(--paper); --bg: var(--blue-deep); }

.tabs [role="tablist"] { display: flex; gap: 0; border-bottom: 2px solid var(--blue); overflow-x: auto; scrollbar-width: none; }
.tabs [role="tablist"]::-webkit-scrollbar { display: none; }
.tab {
  flex: none; position: relative; min-height: 3rem; padding: 0.6em 1.2em; background: transparent; color: var(--fg);
  border: 2px solid transparent; border-bottom: 0; margin-bottom: -2px;
  font-family: var(--font-mono); font-size: var(--fs-mono); font-weight: 500; cursor: pointer; border-radius: 0;
}
@media (hover: hover) { .tab:hover { background: var(--fill-1); border-color: var(--line); } .tab[aria-selected="true"]:hover { background: var(--blue); border-color: var(--blue); } }
.tab[aria-selected="true"] { background: var(--blue); color: var(--paper); border-color: var(--blue); border-radius: 6px 6px 0 0; }
.tab:focus-visible { outline-offset: -5px; outline-color: var(--fg); }
.tab[aria-selected="true"]:focus-visible { outline-color: var(--bg); }
.tabpanel[hidden] { display: none; }
@media (max-width: 640px) {   /* one strip that scrolls sideways, the phone pattern for five tabs; the fade shows only while
                                 there is more that way (mailroom.js sets data-more and data-less), and the chosen tab is
                                 scrolled clear of it */
  .tabs [role="tablist"] { scroll-snap-type: x proximity; scroll-padding-inline: 2rem; }
  .tabs [role="tablist"][data-more] {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 2rem), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 2rem), transparent); }
  .tabs [role="tablist"][data-less] {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 2rem);
            mask-image: linear-gradient(90deg, transparent, #000 2rem); }
  .tabs [role="tablist"][data-less][data-more] {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 2rem, #000 calc(100% - 2rem), transparent);
            mask-image: linear-gradient(90deg, transparent, #000 2rem, #000 calc(100% - 2rem), transparent); }
  .tab { scroll-snap-align: start; min-height: 3.25rem; padding-inline: 1em; }
}

/* ==========================================================================
   Counter window: where the AI Mailman works.
   data-state: idle | asking | quoting | approved
   ========================================================================== */
.counter {
  --pad: clamp(1rem, 0.5rem + 1.8vw, 1.75rem);
  position: relative; background: var(--bg); color: var(--fg);
  border: 2px solid var(--blue); border-radius: 12px; overflow: hidden;
}
.counter__sign {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  background: var(--blue); color: var(--paper); padding: 0.55rem var(--pad);
  font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500;
}
.counter__sign .plate { display: inline-flex; align-items: center; gap: 0.7em; white-space: nowrap; }
.counter__sign .counter__open { white-space: nowrap; }
.counter__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; margin-top: 0.6rem; }
.counter__open { display: inline-flex; align-items: center; gap: 0.6em; }
.counter__steps { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: var(--rule-2); margin: 0; }
.counter__steps li {
  position: relative; padding: 0.7rem var(--s-3) 0.9rem; font-family: var(--font-mono); font-size: var(--fs-mono-xs); line-height: 1.2; color: var(--fg-3);
  border-right: var(--rule-hair);
}
.counter__steps li:last-child { border-right: 0; }
.counter__steps li::after {   /* slot that fills */
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: 0.4rem; height: 4px; border: 1px solid var(--fg-3); background: transparent;
}
.counter__steps li { white-space: nowrap; }
.counter__steps li.is-done, .counter__steps li.is-now { color: var(--fg); font-weight: 500; }
.counter__steps li.is-done::after { background: var(--fg); border-color: var(--fg); }
.counter__steps li.is-now::after { border-color: var(--fg); background: repeating-linear-gradient(90deg, var(--fg) 0 6px, transparent 6px 9px); }
.counter__steps .n { display: none; }
.counter__steps li.is-error { color: var(--fg); font-weight: 500; }
.counter__steps li.is-error::before {   /* a square mark, so the error is not only color or position */
  content: "!"; display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; margin-right: 0.3em; background: var(--fg); color: var(--bg);
}
.counter__steps li.is-error::after { border-color: var(--fg); background: repeating-linear-gradient(135deg, var(--fg) 0 2px, transparent 2px 4px); }

.counter__body { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.counter__talk { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-5); padding: var(--pad); align-content: start; }
.counter__paper {   /* the desk: what the clerk lays on the counter */
  border-left: var(--rule-2); background: var(--fill-1); padding: var(--pad); display: grid; gap: var(--s-4); align-content: start;
}
.counter__paper-title { font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500; display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); }
.paper { background: var(--bg); border: 2px solid var(--ink-line); border-radius: 10px; padding: var(--s-4); position: relative; }
.paper--empty { border-style: dashed; border-color: var(--fg-3); background: transparent; min-height: 12rem; display: grid; place-content: center; text-align: center; color: var(--fg-2); font-family: var(--font-mono); font-size: var(--fs-mono-sm); padding: var(--s-5); gap: var(--s-3); justify-items: center; }
.clerk { display: grid; justify-items: center; align-content: start; gap: var(--s-2); text-align: center; }
.clerk__seal { --pm: 4.75rem; --tilt: 0deg; filter: none; -webkit-mask-image: none; mask-image: none; }
.clerk__name, .clerk__role { white-space: nowrap; }   /* the seal caption is two lines, never a ladder */
.clerk__name { font-family: var(--font-mono); font-size: var(--fs-mono-xs); font-weight: 500; line-height: 1.25; }
.clerk__role { font-family: var(--font-mono); font-size: var(--fs-mono-xs); color: var(--fg-3); line-height: 1.25; }

.exchange { display: grid; gap: var(--s-4); min-width: 0; align-content: start; }
.turn { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); gap: var(--s-3); align-items: first baseline; }   /* each label sits on its turn's first line, whatever that turn's padding */
.turn__who { font-family: var(--font-mono); font-size: var(--fs-mono-xs); font-weight: 500; color: var(--fg-3); }
.turn--you .turn__text {   /* what the customer wrote on the counter: plain, underlined like a form line */
  font-weight: 500; font-size: 1.1875rem; line-height: 1.35; letter-spacing: -0.012em;
  padding: 0.4rem 0 0.45rem; border-bottom: var(--rule-2);
}
.slip {   /* what the clerk types: a tear-off slip */
  position: relative; background: var(--tint); font-family: var(--font-mono); font-size: var(--fs-mono); line-height: 1.55;
  padding: 0.95rem 1.05rem 1.25rem; border-top: 2px dotted var(--blue);
  --tooth: 7px;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--tooth) * 2) 100%;
          mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--tooth) * 2) 100%;
}
.slip p + p { margin-top: 0.6em; }
.slip--wide { padding-bottom: 1.5rem; }

.draft {   /* draft preview + facts */
  display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--s-4); align-items: start;
}
.draft__thumb { position: relative; }
.draft__thumb .stamp { position: absolute; left: 50%; top: 42%; --stamp-size: 0.8rem; margin-left: -2.4em; }
.draft__facts { display: grid; gap: 0.15rem; font-size: var(--fs-mono-sm); }
.draft__facts div { display: grid; grid-template-columns: 4.1rem 1fr; gap: var(--s-2); }
.draft__facts dt { color: var(--fg-2); }
.draft__facts dd { overflow-wrap: anywhere; }
.draft__link { grid-column: 1 / -1; margin-top: var(--s-1); }

.quote { position: relative; }
.loadbar { display: block; position: relative; overflow: hidden; height: 8px; margin-top: 0.75rem; border: 1px solid var(--fg); }
.loadbar::after { content: ""; position: absolute; inset: 0; background: var(--blue); transform-origin: left; animation: slot-load 1.2s steps(6, end) infinite; }
.paper--wait { border-style: dashed; background: transparent; }
.paper--wait p { font-family: var(--font-mono); font-size: var(--fs-mono-sm); color: var(--fg-2); margin-bottom: var(--s-3); }
.skel { display: block; height: 0.85rem; margin-top: 0.55rem; border: 1px solid var(--fg-3); background: var(--security) 0 0 / 6px 6px; }
.skel--short { width: 60%; }
.paper--error { box-shadow: inset 6px 0 0 var(--red); background: var(--red-tint); padding-left: calc(var(--s-4) + 6px); }
.paper__flag { display: flex; align-items: baseline; gap: 0.6em; font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500; margin-bottom: var(--s-2); }
.paper__flag { color: var(--red); }
.paper__flag::before { content: "!"; display: inline-grid; place-items: center; flex: none; width: 1.4em; height: 1.4em; border-radius: 50%; background: var(--red); color: var(--paper); }
.paper--error p:not(.paper__flag) { font-family: var(--font-mono); font-size: var(--fs-mono-sm); color: var(--fg-2); line-height: 1.5; }
.turn--you .turn__text--error {   /* what you typed that did not pass: solid bar and hatch, like an invalid field */
  border-bottom: 2px solid var(--red); padding-left: 0.8rem; box-shadow: inset 6px 0 0 var(--red);
  background: var(--red-tint);
}
.counter .field__error { margin-top: 0.1rem; }
.counter[data-state="badaddress"] .field__error { display: flex; }
.counter[data-state="checking"] .counter__form .btn { opacity: 1; }
.quote__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); margin-bottom: var(--s-2); font-family: var(--font-mono); font-size: var(--fs-mono-sm); font-weight: 500; }
.counter__approve { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3); }
.counter__approve .fine { font-family: var(--font-mono); font-size: var(--fs-mono-xs); color: var(--fg-2); max-width: 56ch; line-height: 1.45; }
.quote .stamp--paid-slot, .quote .stamp--held-slot { position: absolute; right: 6.5rem; bottom: 0.75rem; z-index: 2; --stamp-size: 2rem; background: var(--bg); }
.quote .stamp--held-slot { --stamp-size: 1.45rem; bottom: 0.85rem; }

.counter__ledge {   /* the counter shelf: where you type */
  border-top: 2px solid var(--line); padding: var(--s-3) var(--pad) var(--pad); background: var(--tint);
}
/* Label, then the field and Send on one row, then the error under both: an error never moves Send off the field. */
.counter__form { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s-3); row-gap: var(--s-2); align-items: stretch; }
.counter__form .field { display: contents; }
.counter__form .field__label { grid-column: 1 / -1; grid-row: 1; }
.counter__form .input { grid-column: 1; grid-row: 2; }
.counter__form .btn { grid-column: 2; grid-row: 2; }
.counter__form .field__error { grid-column: 1 / -1; grid-row: 3; }
.counter__chips { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); }
.chip {
  font-family: var(--font-mono); font-size: var(--fs-mono-xs); padding: 0.4em 0.9em; background: var(--bg); color: var(--blue);
  border: 1.5px solid var(--blue); cursor: pointer; border-radius: var(--radius-pill); min-height: 2rem;
}
@media (hover: hover) { .chip:hover { background: var(--blue); color: var(--paper); } }

/* State visibility. Everything is in the DOM; data-state decides what shows.
   States: idle, asking, checking (loading), badaddress (error), quoting, declined (error), approved. */
.counter [data-show] { display: none; }
.counter[data-state="idle"] [data-show~="idle"],
.counter[data-state="asking"] [data-show~="asking"],
.counter[data-state="checking"] [data-show~="checking"],
.counter[data-state="badaddress"] [data-show~="badaddress"],
.counter[data-state="quoting"] [data-show~="quoting"],
.counter[data-state="declined"] [data-show~="declined"],
.counter[data-state="approved"] [data-show~="approved"] { display: block; }
.counter[data-state="idle"] [data-show~="idle"].turn,
.counter[data-state="asking"] [data-show~="asking"].turn,
.counter[data-state="checking"] [data-show~="checking"].turn,
.counter[data-state="badaddress"] [data-show~="badaddress"].turn,
.counter[data-state="quoting"] [data-show~="quoting"].turn,
.counter[data-state="declined"] [data-show~="declined"].turn,
.counter[data-state="approved"] [data-show~="approved"].turn { display: grid; }
.counter[data-state="idle"] [data-show~="idle"].counter__approve,
.counter[data-state="asking"] [data-show~="asking"].counter__approve,
.counter[data-state="checking"] [data-show~="checking"].counter__approve,
.counter[data-state="badaddress"] [data-show~="badaddress"].counter__approve,
.counter[data-state="quoting"] [data-show~="quoting"].counter__approve,
.counter[data-state="declined"] [data-show~="declined"].counter__approve,
.counter[data-state="approved"] [data-show~="approved"].counter__approve { display: flex; }

/* The print-in: slips come out of the slot one by one on first view. */
@media (prefers-reduced-motion: no-preference) {
  .counter--play .turn { animation: print var(--dur-print) steps(8, end) both; animation-delay: calc(var(--t, 0) * 1s); }
  .counter--play .quote, .counter--play .draft { animation: print var(--dur-print) steps(8, end) both; animation-delay: calc(var(--t, 0) * 1s); }
  .counter--play .counter__approve { animation: print 300ms steps(4, end) both; animation-delay: calc(var(--t, 0) * 1s); }
}
@keyframes print {
  from { clip-path: inset(0 0 100% 0); transform: translateY(-6px); opacity: 1; }
  to   { clip-path: inset(0 0 0 0); transform: translateY(0); opacity: 1; }
}

@media (max-width: 1020px) {   /* one column: you talk at the window, and the paperwork is laid out below the shelf */
  .counter { display: flex; flex-direction: column; }
  .counter__body { display: contents; }
  .counter__talk { order: 1; }
  .counter__ledge { order: 2; }
  .counter__paper { order: 3; border-left: 0; border-top: var(--rule-2); }
}
@media (max-width: 640px) {
  .counter__talk { grid-template-columns: 1fr; gap: var(--s-3); }
  .clerk { grid-template-columns: auto 1fr; justify-items: start; text-align: left; align-items: center; column-gap: var(--s-3); }
  .clerk__seal { --pm: 3.5rem; grid-row: span 2; }
  .turn { grid-template-columns: 1fr; gap: 0; }
  .turn__who { padding-top: 0; margin-bottom: 0.2rem; }
  .turn > span:empty { display: none; }
  .draft { grid-template-columns: 6rem minmax(0, 1fr); }
  .counter__steps li { padding-inline: 0.4rem; }
  .counter__steps li::after { left: 0.5rem; right: 0.5rem; }
  .counter__steps .long { display: none; }
  .counter__steps .n { display: inline; }
  .counter__form { grid-template-columns: 1fr; }
  .counter__form .btn { grid-column: 1; grid-row: 4; margin-top: var(--s-1); }
  .btn--stamp { font-size: 1.125rem; width: 100%; padding-inline: 0.8em; gap: 0.7rem; }
  .btn--stamp .btn__amount { padding-left: 0.7rem; }
}

@media (max-width: 480px) {   /* narrow detail columns stack instead of ladder */
  .counter__chips { flex-direction: column; align-items: stretch; }
  .chip { width: 100%; text-align: left; justify-content: flex-start; min-height: 2.75rem; }
  .quote .stamp--held-slot, .quote .stamp--paid-slot { right: 5.5rem; }
  .quote .stamp--held-slot { --stamp-size: 1.2rem; }
  .quote .stamp--paid-slot { --stamp-size: 1.6rem; }
  .draft { grid-template-columns: minmax(0, 1fr); gap: var(--s-3); }
  .draft__thumb { width: 6.5rem; }
  .draft__facts { gap: 0.6rem; }
  .draft__facts div { grid-template-columns: minmax(0, 1fr); gap: 0.1rem; }
}

/* ==========================================================================
   Utilities for pages
   ========================================================================== */
.hide-sm { display: initial; }
@media (max-width: 640px) { .hide-sm { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; transition-delay: 0ms !important; }
  .btn[aria-busy="true"]::after, .loadbar::after { animation: none; transform: scaleX(0.5); }
}

@media print { .skip-link { display: none; } body { background: #fff; color: #000; } }
