/* Take Back April — takebackapril.com
 * Green-bar ledger paper. Heavy sans display, serif argument, mono for numbers.
 * Signature: a grid of 60 Aprils, one per filing of an adult life.
 * No dependencies, no framework, no JavaScript.
 */

@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, p, figure, blockquote, dl, dd, fieldset { margin: 0; }
  fieldset { border: 0; padding: 0; min-inline-size: 0; }
  ul, ol { margin: 0; }
  img, svg { max-width: 100%; display: block; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; }
  a { color: inherit; }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Continuous-feed ledger paper: pale stock, faint green bars. */
    --paper: light-dark(#eef1e9, #11140f);
    --bar:   light-dark(#dfe7d6, #171c14);
    --panel: light-dark(#f7f9f4, #191e16);
    --ink:   light-dark(#1b1f1a, #e8ece3);
    --muted: light-dark(#5d6858, #97a38f);
    --rule:  light-dark(#b6c1ad, #2c3427);
    /* Rubber stamp. Used for the crossings-out and the villain's numbers. */
    --stamp: light-dark(#a8231f, #e8615c);
    --focus: light-dark(#2f6f3e, #8fd3a0);

    --display: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
    --text:    ui-serif, "Iowan Old Style", Charter, Georgia, serif;
    --mono:    ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

    --fs-hero:  clamp(3rem, 12vw, 8.5rem);
    --fs-h1:    clamp(1.875rem, 4.5vw, 3rem);
    --fs-h2:    clamp(1.375rem, 2.6vw, 1.875rem);
    --fs-lead:  clamp(1.125rem, 1.6vw, 1.375rem);
    --fs-body:  clamp(1.0625rem, 0.4vw + 1rem, 1.1875rem);
    --fs-small:  0.875rem;
    --fs-micro:  0.6875rem;

    --gutter: clamp(1.125rem, 4vw, 3rem);
    --page:   68rem;
    --prose:  62ch;
    --section: clamp(3rem, 7vw, 5.5rem);
  }
}

@layer base {
  html { font-family: var(--text); }

  body {
    background: var(--paper);
    color: var(--ink);
    font-size: var(--fs-body);
    line-height: 1.62;
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3 {
    font-family: var(--display);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.025em;
  }
  h1 { font-size: var(--fs-h1); }
  h2 { font-size: var(--fs-h2); }
  h3 { font-size: 1.125rem; letter-spacing: -0.01em; }

  p { max-width: var(--prose); }
  p + p { margin-top: 0.85em; }

  strong { font-weight: 700; }

  a { color: inherit; text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }

  :focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
  ::selection { background: var(--stamp); color: var(--paper); }
}

@layer layout {
  .wrap { width: min(100% - (var(--gutter) * 2), var(--page)); margin-inline: auto; }
  .prose { max-width: var(--prose); }
  .section { padding-block: var(--section); }
  .section--barred { background: var(--bar); }
  .stack > * + * { margin-top: 1rem; }
}

@layer components {

  .masthead { border-bottom: 2px solid var(--ink); }
  .masthead__inner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    align-items: baseline;
    justify-content: space-between;
    padding-block: 0.85rem;
  }
  .wordmark {
    font-family: var(--display);
    font-weight: 800;
    font-size: 1.125rem;
    letter-spacing: -0.04em;
    text-decoration: none;
  }
  .nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; font-family: var(--mono); font-size: var(--fs-small); }
  .nav a { text-decoration: none; color: var(--muted); }
  .nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }

  /* ---- hero ---- */
  .hero { padding-block: clamp(2.5rem, 7vw, 5rem) clamp(2rem, 5vw, 3.5rem); }
  .hero__kicker {
    font-family: var(--mono);
    font-size: var(--fs-micro);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1.25rem;
  }
  .hero__figure {
    font-family: var(--display);
    font-weight: 800;
    font-size: var(--fs-hero);
    letter-spacing: -0.05em;
    line-height: 0.85;
    display: block;
  }
  .hero__figure em { font-style: normal; color: var(--stamp); }
  .hero__label {
    font-family: var(--display);
    font-weight: 600;
    font-size: var(--fs-lead);
    margin-top: 1rem;
    max-width: 26ch;
    line-height: 1.25;
  }
  .hero__lead { font-size: var(--fs-lead); margin-top: 1.5rem; }

  /* ---- SIGNATURE: the grid of sixty Aprils ---- */
  .aprils { margin-top: clamp(2rem, 5vw, 3rem); }
  .aprils__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(2.25rem, 1fr));
    gap: 0.35rem;
    max-width: 42rem;
    list-style: none;
    padding: 0;
  }
  .april {
    aspect-ratio: 1;
    border: 1px solid var(--rule);
    background: var(--panel);
    position: relative;
    display: grid;
    place-items: center;
    font-family: var(--mono);
    font-size: 0.5625rem;
    color: var(--muted);
  }
  /* The crossing-out. Two strokes through the centre of the cell.
   * Positioned as centred bars, not borders on an inset box — a border-top
   * sits on the box edge and rotates into a chevron rather than a cross. */
  .april::before,
  .april::after {
    content: "";
    position: absolute;
    left: 14%;
    right: 14%;
    top: 50%;
    height: 2px;
    margin-top: -1px;
    background: var(--stamp);
    transform-origin: center;
  }
  .april::before { transform: rotate(45deg); }
  .april::after  { transform: rotate(-45deg); }

  .aprils__caption {
    font-family: var(--mono);
    font-size: var(--fs-small);
    color: var(--muted);
    margin-top: 1rem;
    max-width: 46ch;
  }

  /* ---- numbers ---- */
  .figures {
    display: grid;
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    margin-top: 2rem;
  }
  @media (width >= 40rem) { .figures { grid-template-columns: repeat(2, 1fr); } }
  @media (width >= 62rem) { .figures { grid-template-columns: repeat(3, 1fr); } }

  .figure { background: var(--paper); padding: 1.5rem; }
  .figure__value {
    font-family: var(--display);
    font-weight: 800;
    font-size: clamp(1.75rem, 3vw, 2.25rem);
    letter-spacing: -0.03em;
    line-height: 1;
  }
  .figure__label { margin-top: 0.5rem; font-size: 1rem; max-width: none; }
  .figure__source {
    font-family: var(--mono);
    font-size: var(--fs-micro);
    line-height: 1.5;
    color: var(--muted);
    margin-top: 0.85rem;
    max-width: none;
  }

  /* ---- villain ---- */
  .charge { border-top: 1px solid var(--rule); padding-block: 1.5rem; }
  .charge__value {
    font-family: var(--display);
    font-weight: 800;
    font-size: clamp(1.5rem, 3vw, 2rem);
    letter-spacing: -0.03em;
    color: var(--stamp);
  }
  .charge__text { margin-top: 0.4rem; }
  .charge__source { font-family: var(--mono); font-size: var(--fs-micro); color: var(--muted); margin-top: 0.6rem; }

  /* ---- the ask ---- */
  .ask { background: var(--ink); color: var(--paper); }
  .ask h2 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
  .ask a { color: var(--paper); }
  .ask .field label, .ask .field__legend { color: var(--paper); }
  .ask .u-muted { color: color-mix(in oklab, var(--paper) 62%, var(--ink)); }

  .tally {
    font-family: var(--mono);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
    margin-bottom: 1.5rem;
  }
  .tally__count { font-family: var(--display); font-weight: 800; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -0.03em; }
  .tally__meta { font-size: var(--fs-small); opacity: 0.75; }
  .tally__bar { height: 4px; background: color-mix(in oklab, currentColor 25%, transparent); margin-bottom: 0.5rem; }
  .tally__bar > span { display: block; height: 100%; background: currentColor; }

  /* ---- forms ---- */
  .form { max-width: 34rem; margin-top: 1.75rem; }
  .field { margin-bottom: 1.15rem; }
  .field > label, .field__legend {
    display: block;
    font-family: var(--mono);
    font-size: var(--fs-small);
    margin-bottom: 0.35rem;
  }
  .field input[type="text"],
  .field input[type="email"],
  .field input[type="number"] {
    width: 100%;
    padding: 0.7rem 0.8rem;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: 2px;
    font-family: var(--mono);
    font-size: 1rem;
  }
  .field input:focus { border-color: var(--focus); }
  .field__help { font-size: var(--fs-small); margin-top: 0.3rem; }
  .honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

  .errorlist {
    list-style: none;
    padding: 0.5rem 0.8rem;
    margin: 0 0 0.6rem;
    border-left: 3px solid var(--stamp);
    background: color-mix(in oklab, var(--stamp) 14%, transparent);
    font-size: var(--fs-small);
  }

  .btn {
    display: inline-block;
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.0625rem;
    padding: 0.8rem 1.75rem;
    border: 2px solid currentColor;
    border-radius: 2px;
    background: var(--stamp);
    border-color: var(--stamp);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
  }
  .btn:hover { background: color-mix(in oklab, var(--stamp) 82%, #000); }
  .btn--ghost { background: none; color: inherit; border-color: currentColor; }
  .btn--ghost:hover { background: color-mix(in oklab, currentColor 12%, transparent); }

  /* ---- cross-link to the prize ---- */
  .crosslink {
    border: 2px solid var(--ink);
    padding: clamp(1.5rem, 4vw, 2.25rem);
    display: grid;
    gap: 1rem;
  }
  @media (width >= 46rem) {
    .crosslink { grid-template-columns: 1fr auto; align-items: center; gap: 2rem; }
  }
  .crosslink__figure {
    font-family: var(--mono);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2rem);
    letter-spacing: -0.03em;
  }
  .crosslink__figure span { color: var(--stamp); }

  .footer { border-top: 2px solid var(--ink); padding-block: 2.5rem 4rem; font-size: var(--fs-small); color: var(--muted); }
  .footer__inner { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; }

  .note { font-family: var(--mono); font-size: var(--fs-small); color: var(--muted); border-left: 2px solid var(--rule); padding-left: 1rem; margin-top: 1.5rem; max-width: 52ch; }

  /* ---- the research index ---- */
  .docs { list-style: none; padding: 0; margin: 2.5rem 0 0; border-top: 1px solid var(--rule); }
  .docs__item { padding-block: 1.75rem; border-bottom: 1px solid var(--rule); }
  .docs__kicker {
    font-family: var(--mono);
    font-size: var(--fs-micro);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.6rem;
  }
  .docs__title { font-size: var(--fs-h2); }
  .docs__title a { text-decoration: none; }
  .docs__title a:hover { text-decoration: underline; }
  .docs__meta { font-family: var(--mono); font-size: var(--fs-small); color: var(--muted); margin-top: 0.5rem; }
  .docs__blurb { margin-top: 0.75rem; }

  /* ---- one research document ---- */
  .doc__crumb { font-family: var(--mono); font-size: var(--fs-small); color: var(--muted); margin-bottom: 2rem; }
  .doc__crumb a { text-decoration: none; }
  .doc__crumb a:hover { text-decoration: underline; }

  .doc__layout { display: grid; gap: 2.5rem; }
  .doc__layout > * { min-width: 0; }

  .doc__toc {
    font-family: var(--mono);
    font-size: var(--fs-small);
    line-height: 1.5;
    background: var(--bar);
    padding: 1rem 1.1rem;
    max-height: 22rem;
    overflow-y: auto;
  }
  .doc__toc-heading {
    font-size: var(--fs-micro);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.6rem;
  }
  .doc__toc ul { list-style: none; padding: 0; margin: 0; }
  .doc__toc ul ul { padding-left: 0.875rem; }
  .doc__toc li { margin-block: 0.3rem; }
  .doc__toc a { text-decoration: none; color: var(--muted); }
  .doc__toc a:hover { color: var(--ink); text-decoration: underline; }

  @media (width >= 64rem) {
    .doc__layout {
      grid-template-columns: 15rem minmax(0, var(--prose));
      align-items: start;
      gap: 3.5rem;
    }
    .doc__toc { position: sticky; top: 1.5rem; max-height: calc(100dvh - 4rem); }
  }

  .doc__footer { max-width: var(--prose); margin-top: 3rem; padding-top: 1.5rem; border-top: 2px solid var(--ink); }
  .doc__footer .note { margin-top: 0; }
  .doc__seriatim { display: grid; gap: 1rem; margin-top: 1.75rem; }
  @media (width >= 40rem) {
    .doc__seriatim:has(.doc__next):has(.doc__prev) { grid-template-columns: 1fr 1fr; }
  }
  .doc__seriatim a {
    text-decoration: none;
    border: 1px solid var(--rule);
    background: var(--panel);
    padding: 0.85rem 1rem;
    font-family: var(--display);
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.3;
  }
  .doc__seriatim a:hover { border-color: var(--ink); }
  .doc__seriatim span {
    display: block;
    font-family: var(--mono);
    font-weight: 400;
    font-size: var(--fs-micro);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.3rem;
  }
  .doc__next { text-align: right; grid-column: -2; }
}

/* ---------- RENDERED MARKDOWN ----------
 * The research documents are markdown on disk (see app/core/mdcorpus.py). The
 * reset zeroes every block margin, so each element a markdown file can emit
 * needs its rhythm restored here. Numbers stay in the mono face — this site's
 * whole argument is arithmetic.
 */
@layer components {
  /* The Sources sections are lists of bare URLs, and a 60-character URL is one
   * unbreakable word. Without this the longest one sets the page width and the
   * whole document scrolls sideways on a phone. */
  .md { overflow-wrap: break-word; }

  .md > * + * { margin-top: 1em; }
  .md h1 { margin-bottom: 0.6em; }
  .md h2 { margin-top: 2.25em; padding-bottom: 0.35em; border-bottom: 1px solid var(--rule); }
  .md h3 { margin-top: 1.75em; }
  .md h4 {
    margin-top: 1.5em;
    font-family: var(--mono);
    font-size: var(--fs-small);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--stamp);
  }
  .md h2 + *, .md h3 + *, .md h4 + * { margin-top: 0.75em; }

  .md ul, .md ol { padding-left: 1.4rem; max-width: var(--prose); }
  .md li + li { margin-top: 0.4em; }
  .md li > ul, .md li > ol { margin-top: 0.4em; }
  .md li p { max-width: none; }
  .md li p + p { margin-top: 0.5em; }

  .md blockquote {
    border-left: 3px solid var(--stamp);
    padding: 0.2rem 0 0.2rem 1.25rem;
    font-size: var(--fs-lead);
  }
  .md blockquote p { max-width: none; }

  .md code {
    font-family: var(--mono);
    font-size: 0.8125em;
    background: var(--bar);
    padding: 0.1em 0.35em;
    border-radius: 2px;
    overflow-wrap: break-word;
  }
  .md pre {
    background: var(--panel);
    border: 1px solid var(--rule);
    padding: 1rem 1.15rem;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.8125rem;
    line-height: 1.55;
  }
  .md pre code { background: none; padding: 0; font-size: inherit; }

  .md hr { border: 0; border-top: 1px solid var(--rule); margin-block: 2.5rem; }

  .table-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
  .md table { border-collapse: collapse; font-family: var(--mono); font-size: 0.8125rem; line-height: 1.5; min-width: 100%; }
  .md th, .md td { border: 1px solid var(--rule); padding: 0.5rem 0.7rem; text-align: left; vertical-align: top; }
  .md th { background: var(--bar); font-weight: 700; white-space: nowrap; }
  .md td p { max-width: none; }

  /* A link the source document makes to a repository file that is not
   * published here — demoted by core/mdcorpus.py so it cannot 404. */
  .md-unpublished { color: var(--muted); border-bottom: 1px dotted var(--rule); cursor: help; }
}

@media print {
  .masthead, .footer, .btn, .doc__toc, .doc__crumb, .doc__seriatim { display: none !important; }
  .doc__layout { display: block; }
  .md h2, .md h3 { break-after: avoid; }
  .md table, .md pre, .md blockquote { break-inside: avoid; }
  .md th { background: none; border-bottom-width: 2px; }
}

@layer utilities {
  .u-mono { font-family: var(--mono); }
  .u-muted { color: var(--muted); }
  .u-small { font-size: var(--fs-small); }
  .visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
}
