/* ============================================================
   Base — reset, typography, layout primitives, header/footer,
   buttons, and the shared post-office motif kit (stamps,
   cancellation rules, perforated tear-lines, tape).
   Every page loads tokens.css + this file first, then its own
   page-specific stylesheet.

   Written mobile-first: the bare rules target a narrow screen;
   min-width media queries add the desktop layout on top.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

body {
  position: relative;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 90vw 60vh at 8% -10%, rgba(211, 180, 111, 0.14), transparent 60%),
    radial-gradient(ellipse 70vw 55vh at 96% 4%, rgba(60, 90, 120, 0.10), transparent 55%),
    radial-gradient(ellipse 80vw 60vh at 92% 108%, rgba(181, 57, 44, 0.08), transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Paper grain over the whole page — very light, blended into the bg. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--grain);
  background-size: 160px 160px;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
}
body > * { position: relative; z-index: 1; }

main { flex: 1; }

img, svg { display: block; max-width: 100%; }

a { color: inherit; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  text-wrap: balance;
}
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }

p { text-wrap: pretty; }

:focus-visible { outline: 2px solid var(--airmail-blue-bright); outline-offset: 3px; border-radius: 2px; }

::selection { background: var(--postal-red); color: var(--on-dark); }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- Layout ---- */
.container { max-width: var(--container); margin: 0 auto; padding: 0 1.25rem; }
.section { padding: 3.25rem 0; }
.section + .section { padding-top: 0; }

@media (min-width: 640px) {
  .container { padding: 0 1.75rem; }
  .section { padding: 5rem 0; }
}

/* ============================================================
   Post-office motif kit
   ============================================================ */

/* Perforated stamp paper. Four thin strips of "punched" dots — one
   per edge — laid over a paper fill, so only the perimeter is
   scalloped (no interior dot field). --pp = perforation pitch,
   --pr = hole radius, --stamp-punch = the colour showing through the
   holes (set it to whatever surface the stamp sits on). Apply to a
   full-bleed ::before/::after layer behind the content. */
.stamp-paper {
  --pp: 12px;
  --pr: 3px;
  background:
    radial-gradient(var(--pr) at 50% 0, var(--stamp-punch) 96%, #0000) top / var(--pp) calc(var(--pr) * 2) repeat-x,
    radial-gradient(var(--pr) at 50% 100%, var(--stamp-punch) 96%, #0000) bottom / var(--pp) calc(var(--pr) * 2) repeat-x,
    radial-gradient(var(--pr) at 0 50%, var(--stamp-punch) 96%, #0000) left / calc(var(--pr) * 2) var(--pp) repeat-y,
    radial-gradient(var(--pr) at 100% 50%, var(--stamp-punch) 96%, #0000) right / calc(var(--pr) * 2) var(--pp) repeat-y,
    var(--paper);
}

/* A stuck-down postage stamp: perforated paper, inner engraved
   frame. Wrap an <img>/<svg>/short text. */
.stamp {
  position: relative;
  display: inline-block;
  padding: 0.6rem;
  color: var(--ink);
  --stamp-punch: var(--bg);
  filter: drop-shadow(0 6px 12px rgba(53, 40, 22, 0.35));
}
.stamp::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  --pp: 11px;
  --pr: 3px;
  background:
    radial-gradient(var(--pr) at 50% 0, var(--stamp-punch) 96%, #0000) top / var(--pp) calc(var(--pr) * 2) repeat-x,
    radial-gradient(var(--pr) at 50% 100%, var(--stamp-punch) 96%, #0000) bottom / var(--pp) calc(var(--pr) * 2) repeat-x,
    radial-gradient(var(--pr) at 0 50%, var(--stamp-punch) 96%, #0000) left / calc(var(--pr) * 2) var(--pp) repeat-y,
    radial-gradient(var(--pr) at 100% 50%, var(--stamp-punch) 96%, #0000) right / calc(var(--pr) * 2) var(--pp) repeat-y,
    var(--paper);
}
.stamp::after {
  content: "";
  position: absolute;
  inset: 0.42rem;
  border: 1px solid color-mix(in srgb, var(--postal-red) 45%, transparent);
  pointer-events: none;
}
.stamp > * { position: relative; display: block; }

/* Rubber cancellation stamp — a slightly crooked ring of text. */
.postmark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 5.5rem;
  height: 5.5rem;
  border: 2px solid var(--postmark-ink);
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--postmark-ink);
  transform: rotate(-11deg);
}

/* Postal cancellation waves — a divider that looks like the lines a
   clerk cancels a stamp with. */
.cancel-rule {
  height: 15px;
  border: 0;
  margin: 1rem 0;
  background:
    repeating-linear-gradient(
      var(--postmark-ink) 0 2px,
      transparent 2px 6px
    );
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 34px, #0000 34px 48px);
          mask: repeating-linear-gradient(90deg, #000 0 34px, #0000 34px 48px);
  opacity: 0.75;
}
@media (min-width: 640px) { .cancel-rule { margin: 1.5rem 0; } }

/* Perforated tear-line divider. */
.perf-rule {
  height: 0;
  border: 0;
  border-top: 2px dotted var(--border-strong);
  margin: 2.5rem 0;
}

hr:not([class]) {
  height: 0;
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--postal-red-tint);
  color: var(--postal-red);
  padding: 0.1em 0.4em;
  border-radius: 3px;
}

/* ---- Reusable text components ---- */
.kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--postal-red);
  margin-bottom: 0.9rem;
}
.kicker::before { content: "\2726"; font-size: 0.7em; }

/* An inked rubber stamp — pressed a little crooked, edge not quite
   even, ghost of a second impression behind it. */
.badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--postal-red);
  background: color-mix(in srgb, var(--postal-red) 8%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--postal-red) 55%, transparent);
  border-radius: 3px;
  padding: 0.4rem 0.8rem;
  transform: rotate(-1.4deg);
}
.badge::before {
  content: "";
  position: absolute;
  inset: -3px -2px 1px -4px;
  border: 1px solid color-mix(in srgb, var(--postal-red) 24%, transparent);
  border-radius: 4px;
  transform: rotate(1.6deg);
  pointer-events: none;
}

.lead { color: var(--text-dim); font-size: 1.05rem; max-width: 58ch; }

.section-head { max-width: 640px; margin-bottom: 2.25rem; }
.section-head h2 { margin-top: 0.3rem; }
.section-head.is-centered { margin-left: auto; margin-right: auto; text-align: center; }
@media (min-width: 640px) { .section-head { margin-bottom: 2.75rem; } }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 2.9rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
  padding: 0.7rem 1.6rem;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  line-height: 1.1;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: progress; transform: none; }

/* Primary = a postage stamp. The perforated paper + red frame live
   on a ::before layer so the focus ring and hit-target stay clean.
   --stamp-punch is the colour of the page behind the button; pages
   where the button sits on a non-default surface reset it. */
.btn-primary {
  --stamp-punch: var(--bg); /* kept: some pages still set it, harmless now */
  background: var(--postal-red);
  border: 1px solid var(--postal-red-dark);
  color: var(--paper);
  padding: 0.72rem 1.5rem;
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 6px 16px -10px rgba(53, 40, 22, 0.5);
}
.btn-primary:hover { background: var(--postal-red-dark); color: var(--paper); }
.btn-primary:active { transform: translateY(1px); }

/* Outline = a "cut here" card — dashed trim, lifts on hover. */
.btn-outline {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--postal-red); color: var(--postal-red-dark); background: var(--postal-red-tint); }

.btn-ghost {
  background: none; border: none; padding: 0.5rem 0.2rem; min-height: 0;
  color: var(--text-dim); font-family: var(--font-mono); font-weight: 500; font-size: 0.9rem;
}
.btn-ghost:hover { color: var(--text); }
.btn-ghost:disabled:hover { color: var(--text-dim); }

.btn-sm { --pp: 9px; --pr: 2.4px; min-height: 2.4rem; padding: 0.5rem 1.1rem; font-size: 0.88rem; }
.btn-sm.btn-primary { padding: 0.5rem 1.15rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--link);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.35rem 0;
  min-height: 2.2rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--postal-red-dark); }

/* ============================================================
   Header — a strip of the counter, with the wordmark franked on
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--counter-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.site-header.is-scrolled {
  border-bottom-color: var(--border);
  box-shadow: 0 8px 24px -16px rgba(53, 40, 22, 0.45);
}

.site-header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 4rem;
}
@media (min-width: 640px) { .site-header-inner { height: 4.5rem; gap: 2rem; } }

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}
/* The carrier pigeon — the PenPigeon mark. Inline SVG so it inherits
   colour and themes with the rest of the chrome. Body strokes/fills use
   currentColor; the eye + wing line are cut in the surface colour behind
   the mark via .pg-neg. */
.wordmark-mark {
  width: 1.7em;
  height: 1.7em;
  color: var(--postal-red);
  fill: currentColor;
  display: inline-block;
  transform: translateY(0.16em) rotate(-6deg);
  flex-shrink: 0;
}
.pg-neg { fill: var(--bg); stroke: var(--bg); }
.site-footer .pg-neg { fill: var(--counter-bg, var(--bg)); stroke: var(--counter-bg, var(--bg)); }
.badge-pigeon {
  width: 1.15em;
  height: 1.15em;
  fill: currentColor;
  transform: translateY(0.14em) rotate(-7deg);
  flex-shrink: 0;
}
/* Reusable decorative pigeon */
.pigeon { display: inline-block; width: 1em; height: 1em; fill: currentColor; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.9rem;
  flex: 1;
}
.site-nav a {
  text-decoration: none;
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.35rem 0;
  border-bottom: 1.5px solid transparent;
}
.site-nav a:hover { color: var(--text); }
.site-nav a.is-active { color: var(--text); border-bottom-color: var(--postal-red); }

.site-header-actions { flex-shrink: 0; display: none; align-items: center; }
.site-header .btn-primary { --stamp-punch: var(--counter-bg); }

.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: auto;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.nav-toggle span {
  display: block;
  width: 1.05rem;
  height: 1.5px;
  margin: 0 auto;
  background: var(--text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.site-header.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.site-header.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.site-header.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

/* ---- light / dark toggle ---- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }
.theme-toggle:focus-visible { outline: 2px solid var(--airmail-blue-bright); outline-offset: 2px; }
.theme-toggle svg { display: block; }
/* sits just left of the hamburger on mobile */
.site-header-inner .theme-toggle { margin-left: auto; }
.site-header-inner .theme-toggle + .nav-toggle { margin-left: 0.4rem; }
@media (min-width: 860px) {
  .site-header-inner .theme-toggle { margin-left: 0.6rem; }
}

/* Mobile nav drawer */
.site-nav {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 18px 30px -20px rgba(53, 40, 22, 0.5);
  padding: 0 1.25rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.site-header.nav-open .site-nav { max-height: 24rem; padding: 0.5rem 1.25rem 1rem; }
.site-nav a { width: 100%; padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.site-nav a.is-active { border-bottom-color: var(--border); }

@media (min-width: 860px) {
  .nav-toggle { display: none; }
  .site-header-actions { display: flex; }
  .site-nav {
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 1.9rem;
    background: none;
    border: 0;
    box-shadow: none;
    padding: 0;
    max-height: none;
    overflow: visible;
  }
  .site-header.nav-open .site-nav { padding: 0; }
  .site-nav a { width: auto; padding: 0.35rem 0; border-bottom: 1.5px solid transparent; }
  .site-nav a.is-active { border-bottom-color: var(--postal-red); }
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--counter-bg);
  padding: 2.5rem 0 2.25rem;
}
.site-footer-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.25rem;
}
.site-footer .wordmark { font-size: 1.15rem; }
.site-footer-tag {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-top: -0.6rem;
}
.site-footer-nav { display: flex; flex-wrap: wrap; gap: 1.1rem 1.4rem; }
.site-footer-nav a { text-decoration: none; color: var(--text-dim); font-size: 0.88rem; }
.site-footer-nav a:hover { color: var(--text); }
.site-footer-credit {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  padding-top: 1.4rem;
  width: 100%;
}
.site-footer-credit a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }

@media (min-width: 720px) {
  .site-footer { padding: 3rem 0 2.25rem; }
  .site-footer-inner {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem 2.5rem;
  }
  .site-footer-tag { flex-basis: 100%; margin-top: -0.9rem; }
  .site-footer-credit { flex-basis: 100%; margin-top: 0.25rem; }
}
