/* ==========================================================================
   narain.io — production stylesheet (design-system binding)
   --------------------------------------------------------------------------
   ONE file, no build step. Drop it at the site root and link it from every
   page; then DELETE that page's inline <style> block. It is mapped to the
   site's EXISTING class names (.container, .work, .chip.product, .post,
   .article-content, .back, .byline, .banner, .previously, .links, .dates)
   so the HTML and all inline JS stay untouched.

   Governing idea: a clean workshop bench of bronze tools.
     committed (names, prose, titles) = Spectral serif
     provisional / operational (chips, dates, labels, nav) = IBM Plex Mono
     figure (rare, high-amplitude) = polished bronze
   ========================================================================== */

/* ---- Fonts (self-hosted) ------------------------------------------------ *
   Place the 8 woff2 files in a sibling `fonts/` folder (see fonts/GET-FONTS.md
   for the exact filenames and where to download them — both families are
   open-source / OFL). No external requests, no Google dependency.            */
@font-face { font-family: "Spectral"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/spectral-400.woff2") format("woff2"); }
@font-face { font-family: "Spectral"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/spectral-italic-400.woff2") format("woff2"); }
@font-face { font-family: "Spectral"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/spectral-500.woff2") format("woff2"); }
@font-face { font-family: "Spectral"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/spectral-600.woff2") format("woff2"); }
@font-face { font-family: "Spectral"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/spectral-700.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-mono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/ibm-plex-mono-600.woff2") format("woff2"); }

/* ==========================================================================
   TOKENS
   ========================================================================== */
:root {
  color-scheme: light dark;

  /* families */
  --font-committed:   "Spectral", Georgia, "Times New Roman", serif;
  --font-provisional: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* ground */
  --color-canvas:         #f6f3ee;
  --color-surface:        #fbf9f5;
  --color-surface-subtle: #efebe2;
  --color-surface-inset:  #e8e3d8;
  --color-edge:           #e1dccf;
  --color-edge-strong:    #c7c0ae;
  --color-text:           #1d1a15;
  --color-text-muted:     #585249;   /* AA ~7:1   — secondary / descriptions */
  --color-text-subtle:    #6e695b;   /* AA ~4.95:1 — metadata, dates, labels */

  /* figure — polished bronze, rare/high-amplitude */
  --color-figure:         #9a661f;
  --color-figure-hover:   #855818;
  --color-figure-tint:    #f0e6d4;

  /* semantic — decayed metals (used here for category classification) */
  --color-info:           #50707e;  --color-info-tint:    #e2e9ec;
  --color-success:        #5d7a5f;  --color-success-tint: #e7ece2;
  --color-warning:        #927b35;  --color-warning-tint: #efe9d6;
  --color-error:          #a4502c;  --color-error-tint:   #f1e2d8;

  /* utility */
  --color-focus:          #50707e;
  --color-focus-ring:     rgba(80, 112, 126, 0.40);
  --color-selection:      rgba(154, 102, 31, 0.20);

  /* radius / motion */
  --radius-small:  2px;
  --radius-medium: 4px;
  --motion-fast:   120ms;
  --ease-state:    cubic-bezier(0.30, 0.70, 0.30, 1.00);

  /* type roles */
  --type-label:   0.6875rem;
  --type-caption: 0.75rem;

  /* reading measure (≈58–68ch) */
  --measure: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-canvas:         #15130e;
    --color-surface:        #1c1913;
    --color-surface-subtle: #211d16;
    --color-surface-inset:  #100e0a;
    --color-edge:           #332e24;
    --color-edge-strong:    #4b4536;
    --color-text:           #ece7da;
    --color-text-muted:     #a8a18f;   /* AA ~7:1   */
    --color-text-subtle:    #888270;   /* AA ~4.84:1 */

    --color-figure:         #cb9a4f;
    --color-figure-hover:   #ddab5f;
    --color-figure-tint:    #2b2316;

    --color-info:    #7c9aa8;  --color-info-tint:    #16222a;
    --color-success: #7f9a80;  --color-success-tint: #1d251c;
    --color-warning: #bb9e58;  --color-warning-tint: #262112;
    --color-error:   #c47a52;  --color-error-tint:   #2a1d14;

    --color-focus:      #7c9aa8;
    --color-focus-ring: rgba(124, 154, 168, 0.45);
    --color-selection:  rgba(203, 154, 79, 0.26);
  }
}

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

/* ==========================================================================
   BASE / RESET  (replaces each page's reset + body rules)
   ========================================================================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
@media (max-width: 480px) { html { font-size: 16px; } }

body {
  font-family: var(--font-committed);
  background-color: var(--color-canvas);
  color: var(--color-text);
  line-height: 1.62;
  min-height: 100vh;
  padding: 4rem 1.5rem;
  /* home + archive center their single column; writing index/articles top-align */
}
@media (max-width: 480px) { body { padding: 2.5rem 1.25rem; } }

/* The home and archive pages center the column vertically. Their <body> uses
   display:flex already in markup-less CSS — we replicate via these helpers.
   Home/archive: add nothing; the column is centered horizontally by .container.
   If you want the original vertical centering on home/archive, keep their
   body{display:flex;flex-direction:column;align-items:center;justify-content:center}. */

.container { max-width: 540px; width: 100%; margin: 0 auto; }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-small);
}
:focus:not(:focus-visible) { outline: none; }

/* ==========================================================================
   HOME  (index.html)
   ========================================================================== */
h1 {
  font-family: var(--font-committed);
  font-size: 2rem;            /* figure-scale exception: the name is the subject */
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 3rem;
  text-wrap: balance;
}

/* work list — name (serif) · description (serif, muted) · category chip (mono) */
.work { list-style: none; margin-bottom: 3rem; }
.work li {
  display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.work-name {
  font-family: var(--font-committed);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
}
a.work-name {
  border-bottom: 1px solid var(--color-edge-strong);
  padding-bottom: 1px;
  transition: border-color var(--motion-fast) var(--ease-state);
}
a.work-name:hover { border-bottom-color: var(--color-text); }
.work-desc {
  font-family: var(--font-committed);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-left: 0;            /* override old inline margin; gap handles spacing */
  flex: 1 1 auto;
}

/* chips — mono, uppercase, machined. Category = classification color. */
.chip, .banner-chip {
  font-family: var(--font-provisional);
  font-size: var(--type-label);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  padding: 4px 7px 3px;
  border-radius: var(--radius-small);
  border: 1px solid transparent;
  white-space: nowrap;
  vertical-align: middle;
  flex: none;
}
.chip.product  { color: var(--color-info);    background: var(--color-info-tint); }
.chip.tool     { color: var(--color-success); background: var(--color-success-tint); }
.chip.advisory { color: var(--color-warning); background: var(--color-warning-tint); }
.chip.editorial{ color: var(--color-text-muted); background: transparent; border-color: var(--color-edge-strong); }
.chip.org      { color: var(--color-text-muted); background: transparent; border-color: var(--color-edge-strong); }

/* banner — the one figure moment: a true "new" event */
.banner { margin-bottom: 2rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.banner-chip { color: #fff; background: var(--color-figure); }
.banner a {
  font-family: var(--font-committed);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.banner a:hover { color: var(--color-text); border-color: var(--color-text); }

/* previously — mono aside */
.previously {
  font-family: var(--font-provisional);
  font-size: 0.8rem;
  color: var(--color-text-subtle);
  margin-bottom: 3rem;
}
.previously a {
  color: var(--color-text-subtle);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.previously a:hover { color: var(--color-text-muted); border-color: var(--color-text-subtle); }

/* footer links — mono nav, hairline */
.links { display: flex; flex-wrap: wrap; gap: 1.25rem; margin-bottom: 2.5rem; }
.links a {
  font-family: var(--font-provisional);
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.links a:hover { color: var(--color-text); border-color: var(--color-text); }

/* contact (Turnstile-revealed email) — keep behavior, restyle */
address { font-style: normal; }
.contact-section { display: none; }
.contact-section.is-visible { display: block; }
.contact a {
  font-family: var(--font-provisional);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.contact a:hover { color: var(--color-text); border-color: var(--color-text); }

/* ==========================================================================
   WRITING INDEX  (writing/index.html)
   ========================================================================== */
.posts { list-style: none; margin-bottom: 2rem; }
.post {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-edge);
}
.post:last-of-type { border-bottom: none; padding-bottom: 0; margin-bottom: 1rem; }
.post-title { font-size: 1.0625rem; font-weight: 500; margin-bottom: 0.25rem; }
.post-title a {
  font-family: var(--font-committed);
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
  border-bottom: 1px solid transparent;
  transition: border-color var(--motion-fast) var(--ease-state);
}
.post-title a:hover { border-bottom-color: var(--color-text-subtle); }
.post-description {
  font-family: var(--font-committed);
  color: var(--color-text-subtle);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
  max-width: var(--measure);
}
.post-date {
  font-family: var(--font-provisional);
  color: var(--color-text-subtle);
  font-size: var(--type-caption);
  letter-spacing: 0.02em;
}

/* ==========================================================================
   BACK LINK  (writing index, archive, articles)  — mono, hairline
   ========================================================================== */
.back {
  font-family: var(--font-provisional);
  font-size: var(--type-caption);
  color: var(--color-text-subtle);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  display: inline-block;
  margin-bottom: 2rem;
  white-space: nowrap;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.back:hover { color: var(--color-text-muted); border-color: var(--color-text-subtle); }

/* ==========================================================================
   ARCHIVE  (archive.html)
   ========================================================================== */
h2 {
  font-family: var(--font-committed);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0.2rem;
}
.dates {
  font-family: var(--font-provisional);
  font-size: var(--type-caption);
  color: var(--color-text-subtle);
  margin-bottom: 1.25rem;
}
/* archive reuses .work / .work-name / .work-desc from HOME above */

/* ==========================================================================
   ARTICLE  (writing/*.html, aeo-playbook.html)
   ========================================================================== */
.byline {
  font-family: var(--font-provisional);
  font-size: 0.78rem;
  color: var(--color-text-subtle);
  margin-bottom: 2.5rem;
}
.byline a {
  color: var(--color-text-subtle);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state), border-color var(--motion-fast) var(--ease-state);
}
.byline a:hover { color: var(--color-text-muted); border-color: var(--color-text-subtle); }

/* article <h1> is a title, not the home figure — tighten it back down */
/* Article <h1> is a TITLE, not the home figure. On article pages the <h1> is
   immediately followed by .byline, so we can detect and tighten it with :has()
   — no HTML change needed. (Falls back to the 2rem home size if :has is absent.) */
h1:has(+ .byline) {
  font-size: 1.6rem;
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

.article-content { font-family: var(--font-committed); max-width: var(--measure); }
.article-content h2 {
  font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em;
  margin-top: 2.5rem; margin-bottom: 0.75rem;
}
.article-content h3 { font-size: 1rem; font-weight: 600; margin-top: 2rem; margin-bottom: 0.5rem; }
.article-content p { font-size: 1.0625rem; line-height: 1.62; margin-bottom: 1.25rem; text-wrap: pretty; }
.article-content ul, .article-content ol { margin-bottom: 1.25rem; padding-left: 1.5rem; font-size: 1.0625rem; line-height: 1.62; }
.article-content li { margin-bottom: 0.4rem; }
.article-content blockquote {
  border-left: 2px solid var(--color-edge-strong);
  padding-left: 1rem;
  margin: 1.5rem 0;
  color: var(--color-text-muted);
  font-style: italic;
}
.article-content hr { border: none; border-top: 1px solid var(--color-edge); margin: 2rem 0; }
.article-content a {
  color: var(--color-text);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge-strong);
  padding-bottom: 1px;
  transition: border-color var(--motion-fast) var(--ease-state);
}
.article-content a:hover { border-color: var(--color-text); }
.article-content strong { font-weight: 600; }
.article-content em { font-style: italic; }
.article-content code, .article-content pre, .article-content kbd {
  font-family: var(--font-provisional);
  font-size: 0.92em;
}
.article-content pre {
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-edge);
  border-radius: var(--radius-medium);
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}
.article-content img { max-width: 100%; height: auto; }

/* The :has() rule above sizes the article <h1> to 1.6rem with no HTML change.
   If you must support a browser without :has(), instead add
   style="font-size:1.6rem;line-height:1.3" to each article <h1>. */

/* ==========================================================================
   SITE-SPECIFIC ADDITIONS (beyond the handoff's verbatim narain-io.css)
   ========================================================================== */

/* Back link — markup varies by page:
     · home / writing index / archive use <a class="back"> directly (styled above)
     · the 31 essays wrap it as <nav class="back"><a>…</a></nav>
   The rules above target .back as the link; these cover the nav-wrapped form so
   essay back links match (mono hairline) instead of falling back to a UA link. */
nav.back { border-bottom: none; padding-bottom: 0; }
.back a {
  font-family: var(--font-provisional);
  font-size: var(--type-caption);
  color: var(--color-text-subtle);
  text-decoration: none;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 1px;
  transition: color var(--motion-fast) var(--ease-state),
              border-color var(--motion-fast) var(--ease-state);
}
.back a:hover { color: var(--color-text-muted); border-color: var(--color-text-subtle); }

/* Home + archive vertical centering — opt-in via <body class="centered">.
   Uses auto margins (not justify-content:center) so a column taller than the
   viewport top-aligns and stays fully scrollable instead of clipping its top. */
body.centered { display: flex; flex-direction: column; }
body.centered .container { margin: auto; }
