/* ================================================================
   article.css — long-form article pages (/blog/<slug>/)

   Loaded ONLY by article pages. Everything here is built on the site's
   existing tokens (--margin, --gutter, --ink, --card, --r-lg, --ease)
   and the same grid the landing page and the blog listing use.

   THE GRID — 4 columns, site margins and gutters:

     col 1        col 2        col 3        col 4
     ┌──────┐     ┌───────────────────┐     ┌──────┐
     │ scroll│    │   all content     │     │ side │
     │ nav   │    │   lives here      │     │ notes│
     └──────┘     └───────────────────┘     └──────┘

   Title block and the cover span all four. Everything else sits in the
   two middle columns. The nav pins 100px from the top as you scroll.

   TYPE — three sizes, no exceptions:
     28 / 20 / 18   headings
     18px           all regular text
     14px           captions, code, side notes, meta

   BLOCKS: .a-head .a-cover .a-nav .a-body .a-figure .a-quote
           .a-stats .a-callout .a-side .a-code .a-related
   ================================================================ */

/* ---------- Grid ---------- */
.article { padding-top: clamp(110px, 15vh, 170px); }
.a-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: var(--gutter);
  padding-inline: var(--margin);
}

/* ---------- Title block — spans the grid, centred ---------- */
.a-head {
  grid-column: 1 / 5;
  text-align: center;
  padding-bottom: clamp(40px, 6vh, 70px);
}
.a-title {
  max-width: 800px;
  margin-inline: auto;
  /* the site's display face and tracking, one step down from the hero */
  font-size: clamp(34px, 4.2vw, 60px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.a-sub {
  max-width: 60ch;
  margin: 22px auto 0;
  font-size: 20px;
  line-height: 1.4;
  color: rgba(38, 38, 38, 0.55);
}
.a-meta {
  margin-top: 34px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(38, 38, 38, 0.5);
}
.a-meta strong { color: var(--ink); font-weight: 500; }
.a-meta i { font-style: normal; opacity: 0.45; }

/* ---------- Cover — the one thing wider than the text, capped ---------- */
.a-cover {
  grid-column: 1 / 5;
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  margin-bottom: clamp(44px, 7vh, 80px);   /* cover → first paragraph */
  aspect-ratio: 16 / 9;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--card);
}
.a-cover img,
.a-cover video { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Scroll nav — column 1, pins under the header ---------- */
.a-nav { grid-column: 1 / 2; }
.a-nav-inner {
  position: sticky;
  top: 100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* the rule overhangs the first and last item by the same amount, so the
     ends read as deliberate instead of clipped to a line box */
  padding: 8px 0 8px 18px;
  border-left: 1px solid rgba(38, 38, 38, 0.14);
}
.a-nav-inner a {
  font-size: 14px;
  line-height: 1.35;
  color: rgba(38, 38, 38, 0.45);
  transition: color 0.25s var(--ease);
}
.a-nav-inner a:hover { color: rgba(38, 38, 38, 0.75); }
.a-nav-inner a.on { color: var(--ink); }
/* one marker for the whole rail — js moves and resizes it, so it travels
   between items rather than blinking from one to the next */
.a-nav-mark {
  position: absolute;
  left: -1px;   /* straight over the 1px rule */
  top: 0;
  width: 1px;
  /* 35px centred on a 19px item + the rail's 8px padding means the marker
     lands flush with the rail's ends on the first and last entries */
  height: 35px;
  background: var(--ink);
  opacity: 0;
  transition: transform 0.45s var(--ease), opacity 0.25s var(--ease);
}
.a-nav-mark.on { opacity: 1; }

/* ---------- Body — the two middle columns ---------- */
.a-body {
  grid-column: 2 / 4;
  position: relative;   /* side notes hang off this */
  /* a grid item defaults to min-width:auto, so one long unbreakable code
     line would widen the whole column past the viewport */
  min-width: 0;
  font-size: 18px;
  line-height: 1.65;
  color: rgba(38, 38, 38, 0.78);
}
.a-body > * + * { margin-top: 22px; }
.a-body h2 {
  margin-top: 56px;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.022em;
  line-height: 1.2;
  color: var(--ink);
  scroll-margin-top: 140px;   /* clears the pinned header on a nav jump */
}
.a-body h3 {
  margin-top: 40px;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.a-body h4 {
  margin-top: 30px;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
}
.a-body h2 + p, .a-body h3 + p, .a-body h4 + p { margin-top: 12px; }
.a-body strong { font-weight: 500; color: var(--ink); }
.a-body p a, .a-body li a {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 rgba(38, 38, 38, 0.3);
  transition: box-shadow 0.25s var(--ease);
}
.a-body p a:hover, .a-body li a:hover { box-shadow: inset 0 -2px 0 var(--ink); }
.a-body ul, .a-body ol { padding-left: 20px; }
.a-body li + li { margin-top: 8px; }
.a-body li::marker { color: rgba(38, 38, 38, 0.35); }

/* ---------- Side note — column 4, level with its paragraph ----------
   the host element is position:relative; the note is pulled out of the
   measure into the next column over */
.a-body .has-side { position: relative; }
.a-side {
  position: absolute;
  top: 0;
  left: calc(100% + var(--gutter));
  width: calc((100% - var(--gutter)) / 2);   /* one grid column… */
  max-width: 280px;                          /* …but never wider than this */
  font-size: 14px;
  line-height: 1.5;
  color: rgba(38, 38, 38, 0.5);
}
.a-side sup { margin-right: 3px; }

/* ---------- Figure ---------- */
.a-figure { margin-top: 40px; }
.a-figure img,
.a-figure video {
  width: 100%;
  /* the width/height attributes reserve the right box while loading, but
     without this the height attribute wins and the image stretches */
  height: auto;
  border-radius: var(--r-md);
  background: var(--card);
}
.a-figure figcaption {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
  color: rgba(38, 38, 38, 0.5);
}

/* ---------- Pull quote ---------- */
.a-quote {
  margin-top: 44px;
  padding-left: 22px;
  border-left: 2px solid var(--ink);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.35;
  color: var(--ink);
}
.a-quote cite {
  display: block;
  margin-top: 12px;
  font-size: 14px;
  font-style: normal;
  font-weight: 500;
  color: rgba(38, 38, 38, 0.5);
}

/* ---------- Stat row — one panel, cells split by hairlines ---------- */
.a-stats {
  margin-top: 40px;
  display: flex;
  background: var(--card);
  border-radius: var(--r-md);
  padding: 22px 24px;
}
.a-stat {
  flex: 1;
  padding-left: 24px;
  border-left: 1px solid rgba(38, 38, 38, 0.14);
}
.a-stat:first-child { padding-left: 0; border-left: 0; }
.a-stat b {
  display: block;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
}
.a-stat b span { margin-left: 3px; font-size: 0.55em; vertical-align: super; }
/* direct child only — a span inside the number is a unit, not the caption */
.a-stat > span {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(38, 38, 38, 0.55);
}

/* ---------- Callout ---------- */
.a-callout {
  margin-top: 40px;
  background: var(--card);
  border-radius: var(--r-md);
  padding: 22px 24px;
  font-size: 18px;
  line-height: 1.6;
}
.a-callout strong { display: block; margin-bottom: 4px; }

/* ---------- Code embed — light card, copy button ---------- */
.a-code {
  position: relative;
  min-width: 0;
  margin-top: 40px;
  border-radius: var(--r-md);
  background: var(--card);
  padding: 22px 24px;
}
.a-code pre {
  margin: 0;
  overflow-x: auto;
  font-family: "SF Mono", ui-monospace, "Menlo", monospace;
  font-size: 14px;
  line-height: 1.75;
  color: rgba(38, 38, 38, 0.82);
}
/* monochrome, like the rest of the site — weight and value carry the
   emphasis instead of syntax colours */
.a-code .c { color: rgba(38, 38, 38, 0.42); }
.a-code .k,
.a-code .ok { color: var(--ink); }
.a-code .s,
.a-code .n,
.a-code .f { color: rgba(38, 38, 38, 0.82); }

.a-copy {
  position: absolute;
  top: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: transparent;
  padding: 4px 6px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: rgba(38, 38, 38, 0.45);
  cursor: pointer;
  transition: color 0.25s var(--ease), background 0.25s var(--ease);
}
.a-copy:hover { color: var(--ink); background: rgba(38, 38, 38, 0.06); }
.a-copy svg { width: 15px; height: 15px; }
.a-copy.done { color: var(--ink); }

/* ---------- Divider + end matter ---------- */
.a-rule { margin-top: 48px; height: 1px; border: 0; background: rgba(38, 38, 38, 0.12); }
.a-foot {
  grid-column: 2 / 4;
  margin-top: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font-size: 14px;
  font-weight: 500;
}
.a-share { display: flex; gap: 8px; }
.a-back { display: inline-flex; align-items: center; gap: 9px; color: rgba(38, 38, 38, 0.55); transition: color 0.25s var(--ease); }
.a-back:hover { color: var(--ink); }
.a-back svg { width: 16px; height: 16px; }

/* ---------- Related — label top-left, up to 3 cards packed right ---------- */
.a-related {
  grid-column: 1 / 5;
  margin-top: clamp(70px, 10vh, 120px);
  padding-top: 30px;
  border-top: 1px solid rgba(38, 38, 38, 0.12);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: var(--gutter);
}
.a-related-label {
  grid-column: 1 / 2;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
}
/* flex, not grid: with fewer than three the row packs to the right edge,
   so two cards land in columns 3–4 rather than 2–3 */
.a-related-list {
  grid-column: 2 / 5;
  display: flex;
  justify-content: flex-end;
  gap: var(--gutter);
}
.a-related-list .post { flex: 0 0 calc((100% - 2 * var(--gutter)) / 3); }

.article + .band { margin-top: clamp(90px, 14vh, 170px); }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 1100px) {
  /* tablet: three columns. The nav rail keeps column 1 and the text takes
     2–3; there's no room for a side column, so notes drop below the
     paragraph they annotate instead of running on inside it. */
  .a-grid { grid-template-columns: repeat(3, 1fr); }
  .a-head, .a-cover, .a-related { grid-column: 1 / 4; }
  .a-nav { grid-column: 1 / 2; }
  .a-body, .a-foot { grid-column: 2 / 4; }
  .a-side {
    position: static;
    display: block;   /* a span would otherwise run on inside the sentence */
    width: auto;
    max-width: none;
    margin-top: 16px;
    padding-left: 14px;
    border-left: 1px solid rgba(38, 38, 38, 0.14);
  }
  .a-related { grid-template-columns: repeat(3, 1fr); }
  .a-related-label { grid-column: 1 / 2; }
  .a-related-list { grid-column: 2 / 4; flex-wrap: wrap; }
  .a-related-list .post { flex: 0 0 calc((100% - var(--gutter)) / 2); }
}
@media (max-width: 760px) {
  .article { padding-top: 140px; }
  .a-grid { grid-template-columns: 1fr; }
  .a-head, .a-cover, .a-nav, .a-body, .a-foot, .a-related { grid-column: 1 / 2; }
  .a-nav { display: none; }
  .a-cover { aspect-ratio: 4 / 3; }
  .a-body h2 { margin-top: 44px; font-size: 24px; }
  .a-quote { margin-top: 34px; }
  /* the copy button sits above the code here — absolutely positioned it
     lands on top of the first line */
  .a-code { display: flex; flex-direction: column; padding-top: 14px; }
  .a-copy { position: static; align-self: flex-end; margin-bottom: 8px; }
  /* stat cells stack, hairlines turn horizontal */
  .a-stats { flex-direction: column; padding: 20px 22px; }
  /* padding both sides of the rule, so a caption never sits on the line */
  .a-stat { padding: 18px 0; border-left: 0; border-top: 1px solid rgba(38, 38, 38, 0.14); }
  .a-stat:first-child { padding-top: 0; border-top: 0; }
  .a-stat:last-child { padding-bottom: 0; }
  .a-related { display: block; }
  .a-related-label { margin-bottom: 22px; }
  .a-related-list { display: block; }
  .a-related-list .post + .post { margin-top: 30px; }
}
