/* ==========================================================
   Writing: the /writing page and every article page.
   The HTML is generated by tools/build_writing.py; this file only styles it.
   Builds on styles.css (tokens, .page, .grid, .tile, .label, .button).
   ========================================================== */

/* ---------- Topic chips (also used for tags and Share on articles) ---------- */
.wr-chips { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.wr-chip,
.wr-back,
.wr-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: 500 13px/1.2 var(--font);
  transition: background .2s, color .2s, border-color .2s;
}
.wr-chip span { color: var(--muted); }
button.wr-chip, a.wr-chip, .wr-back, .wr-copy { cursor: pointer; }
button.wr-chip:hover, a.wr-chip:hover, .wr-back:hover { border-color: var(--outline); }
.wr-chip[aria-pressed="true"],
.wr-copy { background: var(--text); border-color: var(--text); color: var(--on-text); font-weight: 600; }
.wr-chip[aria-pressed="true"] span { color: inherit; opacity: .6; }
.wr-chip:focus-visible, .wr-back:focus-visible, .wr-copy:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
/* Copy link only works once writing.js has loaded, so it stays invisible (but keeps its space,
   so Post on X doesn't jump) until the script marks it ready. Invisible buttons can't be pressed. */
.wr-copy:not(.is-ready) { visibility: hidden; }

/* ---------- /writing: the bento grid ---------- */
.wr-intro { grid-column: span 2; }
.wr-title { font-size: clamp(24px, 2.2vw, 34px); font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.wr-lede { font-size: 16px; line-height: 1.55; color: var(--body-text); max-width: 34em; }
.wr-lede a {
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--outline);
  text-underline-offset: 3px;
  transition: text-decoration-color .2s;
}
.wr-lede a:hover { text-decoration-color: currentColor; }
.wr-lede a:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 2px; }

/* Laptops below ~1440px (4 narrow columns, shorter rows): tighter chips so the intro tile still fits its row */
@media (min-width: 1181px) and (max-width: 1439px) {
  .wr-intro { gap: 10px; }
  .wr-chips { gap: 6px; }
  .wr-intro .wr-chip { padding: 6px 11px; }
}

/* Featured article: 2×2, cover photo with a frosted caption */
.wr-hero { grid-column: span 2; grid-row: span 2; padding: 0; }
.wr-hero > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .6s ease; }
a.wr-hero:hover > img { transform: scale(1.03); }
.wr-hero-card {
  position: absolute;
  left: 16px; right: 16px; bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 22px 24px;
  border-radius: calc(var(--radius) - 10px);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.wr-hero-text { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.wr-hero-title { font-size: clamp(22px, 2vw, 28px); font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
.wr-go {
  flex-shrink: 0;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--text);
  color: var(--on-text);
  font-size: 16px;
}

/* A line from one article */
.wr-quote-text { font-size: clamp(20px, 1.8vw, 25px); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.wr-quote .small { margin-top: auto; }

/* Article tile: cover on top (fills whatever height is left), text below */
.wr-card { padding: 12px; gap: 0; }
.wr-card > img {
  flex: 1 1 0;
  min-height: 90px;
  width: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius) - 10px);
  background: var(--card);
}
.wr-card-text { display: flex; flex-direction: column; gap: 8px; padding: 16px 12px 8px; }
.wr-card-title {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- /writing: the Everything list ---------- */
.wr-list { margin-top: var(--gap); gap: 20px; scroll-margin-top: 96px; }
.wr-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }
.wr-year { display: grid; grid-template-columns: 140px minmax(0, 1fr); border-top: 1px solid var(--line); }
.wr-year h3 { padding-top: 15px; font-size: 15px; font-weight: 600; }
.wr-row a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 64px;
  align-items: baseline;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.wr-row:last-child a { border-bottom: 0; }
.wr-row-title { font-weight: 500; }
.wr-row a:hover .wr-row-title { text-decoration: underline; text-decoration-color: var(--outline); text-underline-offset: 3px; }
.wr-row-meta { font-size: 14px; color: var(--muted); }
.wr-row-time { text-align: right; }
.wr-row[hidden], .wr-year[hidden] { display: none; }

/* ---------- Article page ---------- */
.wr-top {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  min-height: clamp(420px, 34vw, 480px);
}
.wr-head { padding: 40px; gap: 18px; }
.wr-back { align-self: flex-start; margin-bottom: 12px; }
.wr-h1 { font-size: clamp(32px, 3.2vw, 46px); font-weight: 600; line-height: 1.08; letter-spacing: -0.025em; }
.wr-summary { font-size: 18px; line-height: 1.55; color: var(--body-text); }
.wr-byline { margin-top: auto; display: flex; align-items: center; gap: 12px; }
.wr-byline img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.wr-byline div { display: flex; flex-direction: column; gap: 2px; }
.wr-byline strong { font-size: 14px; font-weight: 600; }
.wr-byline span { font-size: 13px; color: var(--muted); }
.wr-cover { border-radius: var(--radius); overflow: hidden; background: var(--tile); }
.wr-cover img { width: 100%; height: 100%; object-fit: cover; }

/* Reading column in the middle, Topics/Share in the left margin */
.wr-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 720px) minmax(0, 1fr);
  gap: 40px;
  margin: 56px 0 72px;
}
.wr-prose { grid-column: 2; grid-row: 1; }
.wr-aside {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  position: sticky;
  top: 100px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  border-radius: 24px;
  background: var(--tile);
}
.wr-aside hr { border: 0; height: 1px; background: var(--line); }
.wr-tags, .wr-share { display: flex; flex-wrap: wrap; gap: 6px; }
.wr-tags .wr-chip { padding: 6px 12px; font-size: 12px; }
.wr-share .wr-chip, .wr-copy { font-size: 12px; }

/* The article text */
.wr-prose { font-size: 19px; line-height: 1.7; color: var(--body-text); overflow-wrap: break-word; }
.wr-prose > * + * { margin-top: 24px; }
.wr-prose > p:first-child { font-size: 22px; line-height: 1.55; font-weight: 500; color: var(--text); }
.wr-prose h2, .wr-prose h3, .wr-prose h4 { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.wr-prose h2 { margin-top: 56px; font-size: 28px; line-height: 1.2; }
.wr-prose h3 { margin-top: 48px; font-size: 23px; line-height: 1.25; }
.wr-prose h4 { margin-top: 36px; font-size: 19px; line-height: 1.35; }
/* Headings moved up a level by build_writing.py keep the size they were written at */
.wr-prose .wr-h3 { margin-top: 48px; font-size: 23px; line-height: 1.25; }
.wr-prose .wr-h4 { margin-top: 36px; font-size: 19px; line-height: 1.35; }
.wr-prose :is(h2, h3, h4) + * { margin-top: 12px; }
.wr-prose strong { color: var(--text); font-weight: 600; }
.wr-prose a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--outline);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: text-decoration-color .2s;
}
.wr-prose a:hover { text-decoration-color: var(--text); }
.wr-prose ul { list-style: disc; padding-left: 1.3em; }
.wr-prose ol { list-style: decimal; padding-left: 1.4em; }
.wr-prose li + li { margin-top: 8px; }
.wr-prose li::marker { color: var(--muted); }
.wr-prose blockquote {
  padding: 28px 32px;
  border-radius: 24px;
  background: var(--tile);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--text);
}
.wr-prose blockquote em { font-style: normal; }
.wr-prose blockquote p + p { margin-top: 12px; }
.wr-prose blockquote + blockquote { margin-top: 12px; }
.wr-prose img { width: 100%; height: auto; border-radius: 16px; background: var(--tile); }
.wr-prose figcaption { margin-top: 10px; font-size: 14px; line-height: 1.5; color: var(--muted); text-align: center; }
.wr-prose hr { margin: 48px 0; border: 0; height: 1px; background: var(--line); }
.wr-prose code { padding: 2px 6px; border-radius: 6px; background: var(--tile); font-size: .88em; }
.wr-prose table { width: 100%; border-collapse: collapse; font-size: 16px; }
.wr-prose th, .wr-prose td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.wr-video { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 16px; background: #000; }
.wr-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Keep reading */
.wr-more { display: flex; flex-direction: column; gap: 16px; }
.wr-more-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 8px; }
.wr-more-head a:hover { color: var(--text); }
.wr-news { background: var(--text); color: var(--on-text); }
.wr-news .label, .wr-news .small { color: var(--on-text); opacity: .7; }
.wr-news .button { background: var(--on-text); color: var(--text); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .wr-hero { min-height: 560px; }
  .wr-top { grid-template-columns: 1fr; min-height: 0; }
  .wr-cover { aspect-ratio: 16 / 9; }
  .wr-body { grid-template-columns: minmax(0, 720px); justify-content: center; gap: 32px; }
  .wr-prose, .wr-aside { grid-column: 1; }
  .wr-aside { grid-row: 2; position: static; max-width: none; }
}

@media (max-width: 640px) {
  .wr-intro, .wr-hero { grid-column: auto; }
  .wr-hero { grid-row: auto; min-height: 0; aspect-ratio: 4 / 5; }
  .wr-hero-card { left: 10px; right: 10px; bottom: 10px; padding: 18px; }
  .wr-go { display: none; }
  .wr-card { min-height: 320px; }
  .wr-year { grid-template-columns: 1fr; }
  .wr-year h3 { padding-bottom: 2px; }
  .wr-row a { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
  .wr-row-title { grid-column: 1 / -1; }
  .wr-row-time { text-align: left; }
  .wr-head { padding: var(--tile-pad); }
  .wr-body { margin: 40px 0 56px; }
  .wr-prose { font-size: 18px; }
  .wr-prose > p:first-child { font-size: 20px; }
  .wr-prose blockquote { padding: 22px 24px; font-size: 20px; }
}
