/* ═══════════════════════════════════════════════════════════════════════
   THE CW STANDARD · paper.css · the design system · 2026-07-08
   Build for the slot, not the screen. Mobile is the base; everything is a
   min-width enhancement. Components respond to their container; only the
   page grid responds to the viewport; tokens govern all of it.
   Layers keep three years of CSS composable with no build step.
   ═══════════════════════════════════════════════════════════════════════ */
@layer reset, tokens, base, type, layout, components, utilities, themes;

/* ───────────────────────── fonts (self-hosted, CSP-clean) ───────────── */
@font-face { font-family:'Plex Mono'; font-weight:400; font-display:swap; src:url('/fonts/ibm-plex-mono-400.woff2') format('woff2'); }
@font-face { font-family:'Plex Mono'; font-weight:500; font-display:swap; src:url('/fonts/ibm-plex-mono-500.woff2') format('woff2'); }
@font-face { font-family:'Plex Mono'; font-weight:600; font-display:swap; src:url('/fonts/ibm-plex-mono-600.woff2') format('woff2'); }
@font-face { font-family:'Plex Mono'; font-weight:700; font-display:swap; src:url('/fonts/ibm-plex-mono-700.woff2') format('woff2'); }
@font-face { font-family:'Plex Serif'; font-weight:400; font-style:normal; font-display:swap; src:url('/fonts/ibm-plex-serif-400.woff2') format('woff2'); }
@font-face { font-family:'Plex Serif'; font-weight:400; font-style:italic; font-display:swap; src:url('/fonts/ibm-plex-serif-400-italic.woff2') format('woff2'); }
@font-face { font-family:'Plex Serif'; font-weight:600; font-display:swap; src:url('/fonts/ibm-plex-serif-600.woff2') format('woff2'); }

/* ───────────────────────── reset ───────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
  body { min-height: 100svh; -webkit-font-smoothing: antialiased; }
  img, picture, svg, video { display: block; max-width: 100%; height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  a { color: inherit; text-decoration: none; }
  ul[role="list"] { list-style: none; padding: 0; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
}

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

    /* type roles */
    --serif: 'Plex Serif', Charter, 'Iowan Old Style', Georgia, serif;
    --mono:  'Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    /* fluid type scale — minor-third → major-third, rem-based (a11y) */
    --step--1: clamp(0.80rem, 0.77rem + 0.14vw, 0.89rem);
    --step-0:  clamp(1.00rem, 0.96rem + 0.20vw, 1.13rem);
    --step-1:  clamp(1.20rem, 1.13rem + 0.34vw, 1.42rem);
    --step-2:  clamp(1.44rem, 1.33rem + 0.55vw, 1.80rem);
    --step-3:  clamp(1.73rem, 1.55rem + 0.90vw, 2.28rem);
    --step-4:  clamp(2.07rem, 1.79rem + 1.42vw, 2.89rem);
    --step-5:  clamp(2.49rem, 2.03rem + 2.29vw, 3.66rem);
    --step-6:  clamp(2.99rem, 2.28rem + 3.55vw, 4.63rem);

    /* fluid space */
    --space-3xs: clamp(0.25rem, 0.24rem + 0.07vw, 0.31rem);
    --space-2xs: clamp(0.50rem, 0.47rem + 0.13vw, 0.63rem);
    --space-xs:  clamp(0.75rem, 0.71rem + 0.20vw, 0.94rem);
    --space-s:   clamp(1.00rem, 0.95rem + 0.27vw, 1.25rem);
    --space-m:   clamp(1.50rem, 1.42rem + 0.40vw, 1.88rem);
    --space-l:   clamp(2.00rem, 1.89rem + 0.54vw, 2.50rem);
    --space-xl:  clamp(3.00rem, 2.84rem + 0.81vw, 3.75rem);
    --space-2xl: clamp(4.00rem, 3.78rem + 1.09vw, 5.00rem);

    /* layout */
    --measure: 66ch;
    --page: 78rem;
    --gutter: clamp(1rem, 0.7rem + 1.5vw, 2.25rem);
    --radius: 5px;

    /* color — the brand: gold, ink, paper, one link-blue. Monochrome + gold. */
    --paper:    #fafaf8;
    --surface:  #ffffff;
    --sunk:     #f2f1ec;
    --ink:      #0a1628;
    --ink-2:    #40495a;
    --ink-3:    #6b7280;
    --rule:     #e5e7eb;
    --rule-2:   #d5d8dd;
    --accent:   #b3892f;   /* gold, darkened for text contrast (AA on paper) */
    --accent-2: #d4a84b;   /* the porch light — the ONE accent */
    --link:     #3f7ca6;   /* cobalt link */
    --link-visited: #5a6b86;

    /* evidence tags — gold/ink monochrome, weight not hue */
    --tag-est:  #0a1628;   /* established = ink (solid) */
    --tag-obs:  #6b7280;   /* observation = dim */
    --tag-clm:  #b3892f;   /* claim = gold */
  }
}

/* ───────────────────────── base ───────────────────────── */
@layer base {
  body {
    background: var(--paper); color: var(--ink);
    font-family: var(--mono); font-size: var(--step-0); line-height: 1.65;
    font-synthesis: none;
  }
  .wrap  { width: min(100% - 2*var(--gutter), var(--page)); margin-inline: auto; }
  .col   { width: min(100% - 2*var(--gutter), var(--measure)); margin-inline: auto; }
  a.link, .prose a { color: var(--link); text-decoration: underline; text-underline-offset: 0.16em; text-decoration-thickness: 0.06em; text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent); }
  a.link:hover, .prose a:hover { text-decoration-color: var(--link); }
  .prose a:visited { color: var(--link-visited); }
  ::selection { background: var(--accent-2); color: #14120c; }
  .skip { position: absolute; left: -9999px; }
  .skip:focus { position: fixed; left: 1rem; top: 1rem; z-index: 99; background: var(--accent-2); color: #14120c; padding: 0.5rem 0.9rem; border-radius: var(--radius); }
  hr.rule { border: 0; border-top: 1px solid var(--rule); margin-block: var(--space-l); }
  hr.star { border: 0; text-align: center; margin-block: var(--space-l); }
  hr.star::after { content: '✳'; color: var(--accent-2); }
}

/* ───────────────────────── type primitives ───────────────────────── */
@layer type {
  .kicker { font-family: var(--mono); font-weight: 600; font-size: var(--step--1); letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
  .display { font-family: var(--serif); font-weight: 600; line-height: 1.08; letter-spacing: -0.012em; text-wrap: balance; }
  h1.display { font-size: var(--step-5); }
  h2.display { font-size: var(--step-3); }

  /* article prose */
  .prose { font-family: var(--serif); font-size: clamp(1.06rem, 1.0rem + 0.3vw, 1.24rem); line-height: 1.62; color: var(--ink); }
  .prose > p + p { margin-top: var(--space-s); }
  .prose > p:first-child { margin-top: 0; }
  .prose h2, .prose h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin-top: var(--space-l); margin-bottom: var(--space-2xs); }
  .prose h2 { font-size: var(--step-2); }
  .prose h3 { font-size: var(--step-1); }
  .prose strong { font-weight: 600; }
  .prose em { font-style: normal; font-weight: 600; color: var(--accent); }
  .prose blockquote { margin-block: var(--space-m); padding-left: var(--space-s); border-left: 3px solid var(--accent-2); color: var(--ink-2); }
  .prose ul, .prose ol { margin-block: var(--space-s); padding-left: 1.4em; }
  .prose li + li { margin-top: var(--space-2xs); }
  .prose hr { border:0; text-align:center; margin-block: var(--space-l); }
  .prose hr::after { content: '✳'; color: var(--accent-2); }

  .pull { font-family: var(--serif); font-weight: 600; font-size: var(--step-2); line-height: 1.25; color: var(--ink); margin-block: var(--space-m); padding-left: var(--space-s); border-left: 3px solid var(--accent); }
  .mono-note { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); letter-spacing: 0.02em; }
}

/* ───────────────────────── site chrome ───────────────────────── */
@layer components {
  /* masthead nav (sticky, hides on scroll-down via .nav-hidden toggled in JS) */
  .site-head { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); transition: transform 0.25s ease; }
  .site-head.nav-hidden { transform: translateY(-100%); }
  .site-head .bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-s); padding-block: var(--space-2xs); }
  .site-head .flag { font-family: var(--serif); font-weight: 600; font-size: var(--step-0); letter-spacing: 0.01em; }
  .site-head .flag .ast { color: var(--accent-2); }
  .site-nav { display: flex; gap: clamp(0.7rem, 0.4rem + 1.2vw, 1.4rem); font-size: var(--step--1); align-items: center; }
  .site-nav a { color: var(--ink-2); }
  .site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--ink); }
  .site-nav a[aria-current="page"] { border-bottom: 2px solid var(--accent-2); }
  .btn-sub { font-family: var(--mono); font-weight: 600; font-size: var(--step--1); padding: 0.4rem 0.8rem; border: 1.5px solid var(--ink); border-radius: var(--radius); white-space: nowrap; }
  .btn-sub:hover { background: var(--ink); color: var(--paper); }
  @media (max-width: 34rem) { .site-nav .nav-full { display: none; } }

  /* progress bar */
  .progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent-2); z-index: 50; transition: width 0.1s linear; }

  /* ── the hero (typographic; the asterisk motif when no photo) ── */
  .hero { position: relative; background: #0a1628; color: #f4f2ec; overflow: hidden; border-bottom: 3px solid var(--accent-2); }  /* always the dark band, both themes */
  .hero .hero-inner { position: relative; z-index: 2; padding-block: clamp(2.5rem, 6vw, 5rem); }
  .hero .kicker { color: var(--accent-2); }
  .hero h1 { color: #fbf9f3; margin-block: var(--space-2xs) var(--space-xs); }
  .hero .dek { color: #c7cbd4; }
  .hero .ast-field { position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: 0.5; }
  .hero .ast-field span { position: absolute; color: var(--accent-2); font-family: var(--serif); }
  .hero.has-photo { padding: 0; }
  .hero-photo { width: 100%; aspect-ratio: 21 / 9; object-fit: cover; }
  figure.figure { margin-block: var(--space-m); }
  figure.figure figcaption { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); margin-top: var(--space-2xs); }

  /* ── the summary (Smart-Brevity TL;DR) ── */
  .summary { margin-block: var(--space-m); padding: var(--space-s) var(--space-m); background: var(--sunk); border: 1px solid var(--rule); border-left: 3px solid var(--accent-2); border-radius: var(--radius); }
  .summary .s-label { font-family: var(--mono); font-weight: 600; font-size: var(--step--1); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: var(--space-2xs); }
  .summary ul { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-2xs); }
  .summary li { font-family: var(--serif); font-size: 1.04rem; line-height: 1.45; color: var(--ink); padding-left: 1.1em; position: relative; }
  .summary li::before { content: '✳'; position: absolute; left: 0; color: var(--accent-2); font-size: 0.85em; }

  /* ── share row ── */
  .share { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs); margin-top: var(--space-s); }
  .share .s-lead { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); margin-right: var(--space-3xs); }
  .share a, .share button { display: inline-flex; align-items: center; gap: 0.35em; min-height: 38px; padding: 0.35rem 0.7rem; font-family: var(--mono); font-size: var(--step--1); font-weight: 500; color: var(--ink-2); background: var(--surface); border: 1px solid var(--rule-2); border-radius: var(--radius); cursor: pointer; }
  .share a:hover, .share button:hover { border-color: var(--accent-2); color: var(--ink); }
  .editor-note { margin-block: var(--space-m); padding: var(--space-s) var(--space-m); border: 1px dashed var(--rule-2); border-radius: var(--radius); font-family: var(--mono); font-size: var(--step--1); line-height: 1.6; color: var(--ink-2); background: color-mix(in srgb, var(--accent-2) 6%, var(--paper)); }
  .editor-note b { color: var(--accent); }

  /* ── the article ── */
  .article-head { padding-block: var(--space-l) var(--space-m); }
  .article-head .kicker a { color: inherit; }
  .article-head h1 { margin-block: var(--space-2xs) var(--space-xs); }
  .dek { font-family: var(--serif); font-size: var(--step-1); line-height: 1.4; color: var(--ink-2); text-wrap: pretty; }
  .byline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-s); margin-top: var(--space-m); padding-top: var(--space-s); border-top: 1px solid var(--rule); font-family: var(--mono); font-size: var(--step--1); color: var(--ink-2); }
  .byline b { font-weight: 600; color: var(--ink); }
  .byline a { color: var(--ink); text-decoration: underline; text-underline-offset: 0.16em; text-decoration-color: var(--rule-2); }
  .byline a:hover { text-decoration-color: var(--accent); }
  .byline .dot { color: var(--ink-3); }

  /* evidence tags — the Semaform-style labeled block */
  .evidence { margin-block: var(--space-m); border-left: 3px solid var(--rule-2); padding: var(--space-2xs) 0 var(--space-2xs) var(--space-s); }
  .evidence .tag { display: inline-block; font-family: var(--mono); font-weight: 600; font-size: 0.66rem; letter-spacing: 0.13em; text-transform: uppercase; padding: 0.12em 0.5em; border-radius: 3px; margin-bottom: var(--space-2xs); color: #fff; }
  .evidence.established { border-left-color: var(--tag-est); } .evidence.established .tag { background: var(--tag-est); color: var(--paper); }
  .evidence.observation { border-left-color: var(--tag-obs); } .evidence.observation .tag { background: var(--tag-obs); }
  .evidence.claim       { border-left-color: var(--tag-clm); } .evidence.claim .tag { background: var(--tag-clm); color: #14120c; }
  .evidence p { font-family: var(--serif); font-size: 1.05rem; line-height: 1.55; color: var(--ink); }

  /* end-of-article furniture */
  .article-foot { margin-top: var(--space-2xl); }
  .author-card { display: grid; grid-template-columns: auto 1fr; gap: var(--space-s); align-items: start; padding: var(--space-m) 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
  .author-card .ava { width: 3rem; height: 3rem; border-radius: 50%; background: var(--sunk); display: grid; place-items: center; font-family: var(--serif); font-weight: 600; font-size: var(--step-1); color: var(--accent); border: 1px solid var(--rule-2); }
  .author-card .who { font-family: var(--mono); font-weight: 600; font-size: var(--step-0); }
  .author-card .who a { text-decoration: underline; text-underline-offset: 0.16em; text-decoration-color: var(--rule-2); }
  .author-card .role { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); }
  .author-card .bio { font-family: var(--serif); font-size: 1rem; color: var(--ink-2); margin-top: var(--space-3xs); grid-column: 1 / -1; }

  .cta-sub { margin-block: var(--space-l); padding: var(--space-m); background: var(--sunk); border: 1px solid var(--rule); border-radius: var(--radius); text-align: center; }
  .cta-sub p { font-family: var(--serif); font-size: var(--step-1); color: var(--ink); margin-bottom: var(--space-2xs); }
  .cta-sub .mono-note { display: block; margin-bottom: var(--space-s); }
  .btn { display: inline-block; font-family: var(--mono); font-weight: 600; font-size: var(--step--1); padding: 0.6rem 1.1rem; border-radius: var(--radius); border: 1.5px solid var(--ink); color: var(--ink); cursor: pointer; }
  .btn:hover { background: var(--ink); color: var(--paper); }
  .btn.gold { border-color: var(--accent-2); color: color-mix(in srgb, var(--accent-2) 78%, black); }
  .btn.gold:hover { background: var(--accent-2); color: #14120c; }

  /* related — the card deck */
  .related h2 { font-family: var(--serif); font-weight: 600; font-size: var(--step-2); margin-bottom: var(--space-s); }
  .deck { display: grid; gap: var(--gutter); grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }

  /* ── the story card: one component, container-driven ── */
  .slot { container: story / inline-size; }
  .card { display: grid; gap: var(--space-2xs); align-content: start; padding: var(--space-s) 0; border-top: 1px solid var(--rule); }
  .card .k { font-family: var(--mono); font-weight: 600; font-size: var(--step--1); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
  .card .h { font-family: var(--serif); font-weight: 600; font-size: clamp(1.1rem, 0.95rem + 2.4cqi, 2rem); line-height: 1.15; color: var(--ink); }
  .card:hover .h { color: var(--link); }
  .card .d { font-family: var(--serif); font-size: var(--step-0); line-height: 1.45; color: var(--ink-2); display: none; }
  .card .m { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); }
  @container story (min-width: 22rem) { .card .d { display: block; } }
  @container story (min-width: 34rem) { .card .h { font-size: clamp(1.6rem, 1rem + 4cqi, 3rem); } }
  .card--wire { padding-block: var(--space-2xs); }
  .card--wire .h { font-size: var(--step-0); font-weight: 400; }
  .card--wire .d { display: none !important; }

  /* ── the card (single-page home) ── */
  .lede-big { font-family: var(--serif); font-size: clamp(1.3rem, 1.1rem + 1vw, 1.9rem); line-height: 1.4; color: var(--ink); text-wrap: pretty; }
  .lede-big b { font-weight: 600; }
  .section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-s); margin-top: var(--space-2xl); margin-bottom: var(--space-s); }
  .section-head h2 { font-family: var(--serif); font-weight: 600; font-size: var(--step-2); }
  .section-head .more { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); white-space: nowrap; }
  .section-head .more a { color: var(--ink-3); text-decoration: underline; text-underline-offset: 0.16em; } .section-head .more a:hover { color: var(--ink); }
  /* work grid: one component, container-driven */
  .work { display: grid; gap: var(--gutter); grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
  .work-item { display: block; padding: var(--space-s); border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); transition: border-color .15s, transform .15s; }
  .work-item:hover { border-color: var(--accent-2); transform: translateY(-2px); }
  .work-item .wk { font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
  .work-item .wh { font-family: var(--serif); font-weight: 600; font-size: var(--step-1); line-height: 1.2; color: var(--ink); margin-top: var(--space-3xs); }
  .work-item .wd { font-family: var(--serif); font-size: 1rem; line-height: 1.45; color: var(--ink-2); margin-top: var(--space-2xs); }
  .work-item .wm { font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); margin-top: var(--space-2xs); }
  /* the porch, as a feature block */
  .porch-feature { margin-top: var(--space-2xl); background: #0a1628; border-radius: var(--radius); border: 1px solid var(--rule-2); overflow: hidden; }
  .porch-feature .pf-inner { padding: var(--space-m); }
  .porch-feature .pf-label { font-family: var(--mono); font-size: var(--step--1); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-2); }
  .porch-feature h2 { font-family: var(--serif); font-weight: 600; font-size: var(--step-2); color: #f4f2ec; margin-top: var(--space-2xs); }
  .porch-feature p { color: #c7cbd4; font-family: var(--serif); margin-top: var(--space-2xs); }
  .porch-log { display: none; margin-top: var(--space-s); max-height: 40vh; overflow-y: auto; }
  .porch-feature.talking .porch-log { display: block; }
  .porch-log .m { margin-bottom: var(--space-2xs); font-size: 0.95rem; line-height: 1.6; }
  .porch-log .m .w { font-family: var(--mono); font-weight: 600; color: var(--accent-2); }
  .porch-log .m.you .w { color: #8b93a1; }
  .porch-log .m .b { color: #e5e6ea; } .porch-log .m .b a { color: #9cc4e4; }
  .porch-form { display: flex; gap: var(--space-2xs); margin-top: var(--space-s); }
  .porch-form input { flex: 1; font-family: var(--mono); font-size: 0.95rem; color: #f2f0ec; background: rgba(255,255,255,.05); border: 1px solid #2a3a52; border-radius: var(--radius); padding: 0.7rem 0.85rem; }
  .porch-form input:focus { outline: none; border-color: var(--accent-2); }
  .porch-form input::placeholder { color: #67707e; }
  .porch-form button { font-family: var(--mono); font-weight: 600; color: #14120c; background: var(--accent-2); border: 0; border-radius: var(--radius); padding: 0 1rem; cursor: pointer; }
  .porch-form button:disabled { opacity: .5; }
  .contact-line { font-family: var(--serif); font-size: var(--step-1); color: var(--ink); margin-top: var(--space-s); }

  /* footer */
  .site-foot { margin-top: var(--space-2xl); border-top: 1px solid var(--rule); }
  .site-foot .bar { display: flex; flex-wrap: wrap; gap: var(--space-2xs) var(--space-s); align-items: center; padding-block: var(--space-l); font-family: var(--mono); font-size: var(--step--1); color: var(--ink-3); }
  .site-foot a { color: var(--ink-3); } .site-foot a:hover { color: var(--ink); }
  .site-foot .ast { color: var(--accent-2); }
  .theme-btn { background: none; border: 0; cursor: pointer; font: inherit; color: var(--ink-3); padding: 0; }
  .theme-btn:hover { color: var(--ink); }
}

/* ───────────────────────── themes ───────────────────────── */
@layer themes {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper:#0b1220; --surface:#111c30; --sunk:#0f1a2c; --ink:#e8e9ec; --ink-2:#aab2c0; --ink-3:#7a8494;
      --rule:#1e2a3f; --rule-2:#2c3a52; --accent:#d4a84b; --accent-2:#d4a84b; --link:#6ba8d4; --link-visited:#9aa8c4;
      --tag-est:#e8e9ec; --tag-obs:#7a8494; --tag-clm:#d4a84b;
    }
  }
  :root[data-theme="dark"] {
    --paper:#0b1220; --surface:#111c30; --sunk:#0f1a2c; --ink:#e8e9ec; --ink-2:#aab2c0; --ink-3:#7a8494;
    --rule:#1e2a3f; --rule-2:#2c3a52; --accent:#d4a84b; --accent-2:#d4a84b; --link:#6ba8d4; --link-visited:#9aa8c4;
    --tag-est:#e8e9ec; --tag-obs:#7a8494; --tag-clm:#d4a84b;
  }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; } }
