/* ---------------------------------------------------------------------------
   Reading typography for /writing/.

   Loaded alongside tokens.css and NOTHING else. No styles.css, no app.js, no
   three.js. The whole point of these pages is that someone tapping a link on
   a phone gets text in under a second.

   The surface is the same paper as the .u-note stack on the main site, so an
   article reads as one of those notes opened up rather than a different site.
--------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: #fdfcfb;
  color: var(--paper-ink);
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.article-page {
  --paper: #fdfcfb;
  --paper-deep: #f7f4ee;
  --paper-ink: #26231e;
  --paper-ink-soft: #585247;
  --paper-ink-faint: #8a8274;
  --paper-rule: rgba(38, 35, 30, 0.14);
  --paper-accent: #4d6b2c;
  color-scheme: light;
  background: var(--paper);
}

.wrap {
  /* The article is an editorial canvas now: prose keeps a readable measure,
     while paired illustrations use the room around it. */
  max-width: 78rem;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 5vw, 4rem);
}

/* --- masthead ------------------------------------------------------------ */

.masthead {
  padding: 1.75rem 0 0;
}

.masthead a {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-ink-faint);
  text-decoration: none;
  transition: color 160ms ease;
}

.masthead a:hover { color: var(--paper-ink); }
.masthead img { width: 20px; height: 20px; opacity: 0.75; }

.article-back {
  max-width: 54rem;
  margin-top: 1.75rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--paper-rule);
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--paper-ink-faint);
}

.article-back a {
  color: inherit;
  text-underline-offset: 0.16em;
}

.article-back a:hover { color: var(--paper-ink); }

/* --- article head -------------------------------------------------------- */

.article-head {
  max-width: 54rem;
  padding: 3.5rem 0 0;
  border-bottom: 1px solid var(--paper-rule);
  margin-bottom: 2.75rem;
  padding-bottom: 2rem;
}

.kicker {
  margin: 0 0 1rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper-accent);
}

.article-head h1 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 2.9rem);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.byline {
  margin: 1.4rem 0 0;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--paper-ink-faint);
}

/* --- body ---------------------------------------------------------------- */

/* Flow spacing. The reset and the rhythm rule have equal specificity, so the
   later one wins. Do NOT reset margins with a type selector like `.body p`
   instead, because (0,1,1) would outrank (0,1,0) and silently collapse every
   gap in the article. */
.body > * { margin: 0; }
.body > * + * { margin-top: 1.45em; }

/* Article sections alternate between copy and illustration. Copy remains at
   a comfortable reading width; the page itself no longer feels like a narrow
   strip surrounded by unused paper. */
.editorial-section {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(19rem, 0.96fr);
  gap: clamp(2.5rem, 6vw, 6rem);
  align-items: start;
  margin: 0;
  padding: clamp(3.5rem, 7vw, 6rem) 0;
  border-top: 1px solid var(--paper-rule);
}

.editorial-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.editorial-section--image-left .editorial-copy {
  grid-column: 2;
}

.editorial-section--image-left > figure {
  grid-column: 1;
  grid-row: 1;
}

.editorial-copy > *,
.editorial-prose > * {
  margin: 0;
}

.editorial-copy > * + *,
.editorial-prose > * + * {
  margin-top: 1.35em;
}

.editorial-prose {
  max-width: 48rem;
  margin: 0 auto;
  padding: clamp(3.5rem, 7vw, 6rem) 0;
  border-top: 1px solid var(--paper-rule);
}

.body h2 {
  margin: 2.9rem 0 0;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.editorial-copy h2:first-child,
.editorial-prose h2:first-child {
  margin-top: 0;
}

.body h3 {
  margin: 2.2rem 0 0;
  font-family: var(--font-body);
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.body a {
  color: inherit;
  text-decoration-color: var(--paper-accent);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1.5px;
}

.body a:hover { color: var(--paper-accent); }

.body strong { font-weight: 650; }

.body blockquote {
  margin: 2.2rem 0;
  padding: 0 0 0 1.4rem;
  border-left: 2px solid var(--paper-accent);
  color: var(--paper-ink-soft);
  font-style: italic;
}

.body blockquote p + p { margin-top: 1em; }

/* Padding only. Margins are left to the flow rule above, for the same
   specificity reason. */
.body ul, .body ol { padding-left: 1.3rem; }
.body li + li { margin-top: 0.55em; }
.body li > ul, .body li > ol { margin-top: 0.55em; }
.body li::marker { color: var(--paper-ink-faint); }

.body hr {
  margin: 3rem auto;
  width: 60px;
  border: 0;
  border-top: 1px solid var(--paper-rule);
}

.body code {
  padding: 0.12em 0.38em;
  border-radius: 3px;
  background: var(--paper-deep);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.body pre {
  margin: 2rem 0;
  padding: 1.1rem 1.25rem;
  border-radius: 6px;
  background: var(--paper-deep);
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.6;
}

.body pre code { padding: 0; background: none; font-size: inherit; }

/* --- images and diagrams -------------------------------------------------- */

/* Safety net: any image that ends up outside a <figure>, inline in a
   sentence or in hand-written HTML, still respects the measure instead of
   forcing the whole page to scroll sideways. */
.body img {
  max-width: 100%;
  height: auto;
}

/* Diagrams are the point of this series, so they break the measure and run
   wider than the text. On mobile they go full-bleed and scroll horizontally
   rather than shrinking into illegibility. */
.body figure {
  margin: 2.8rem 0;
  width: 100%;
}

.editorial-section > figure {
  width: 100%;
  margin: 0;
  position: sticky;
  top: 2rem;
}

@media (min-width: 56rem) {
  .body > figure {
    width: calc(100% + 9rem);
    margin-left: -4.5rem;
  }
}

.body figure img,
.body figure svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: var(--paper-deep);
}

.editorial-section figure img {
  border-radius: 14px;
}

.body figcaption {
  margin-top: 0.85rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--paper-ink-faint);
  text-align: center;
}

/* --- end card ------------------------------------------------------------ */

/* Someone who reached this point just gave you eight minutes. This is the
   warmest visitor the site ever gets, and the only place the main site is
   pitched to them. */
.endcard {
  margin: 4.5rem 0 0;
  padding: 2rem 1.75rem;
  border-radius: 10px;
  background: var(--paper-deep);
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.endcard img {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
}

.endcard p {
  margin: 0;
  font-family: var(--font-body);
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--paper-ink-soft);
}

.endcard strong { color: var(--paper-ink); font-weight: 650; }

.endcard a {
  color: var(--paper-accent);
  text-underline-offset: 0.16em;
}

footer.foot {
  margin: 3rem 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--paper-rule);
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--paper-ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

footer.foot a { color: inherit; }

/* --- index page ---------------------------------------------------------- */

.index-head { padding: 4rem 0 2.5rem; }

.index-head,
.post-list {
  max-width: 54rem;
}

.index-head h1 {
  margin: 0 0 0.9rem;
  font-size: clamp(2rem, 6vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -0.02em;
}

.index-head p {
  margin: 0;
  max-width: 30rem;
  color: var(--paper-ink-soft);
}

.post-list { list-style: none; margin: 0; padding: 0; }

.post-list li { border-top: 1px solid var(--paper-rule); }

.post-list a {
  display: block;
  padding: 1.75rem 0;
  color: inherit;
  text-decoration: none;
}

.post-list a:hover h2 { color: var(--paper-accent); }

.post-list h2 {
  margin: 0.5rem 0 0.45rem;
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.2;
  transition: color 160ms ease;
}

.post-list p {
  margin: 0;
  font-size: 0.98rem;
  color: var(--paper-ink-soft);
}

/* --- writing index backdrop --------------------------------------------- */

.writing-index {
  --paper-ink: #25251f;
  --paper-ink-soft: #3f4239;
  --paper-ink-faint: #6f7466;
  --paper-rule: rgba(37, 37, 31, 0.15);
  --paper-accent: #486b2d;
  min-height: 100vh;
  color-scheme: light;
  background:
    linear-gradient(90deg, rgba(20, 30, 17, 0.28), rgba(20, 30, 17, 0.04)),
    url("/writing/media/writing-index-backdrop.jpg") center / cover fixed;
}

.writing-index .wrap {
  min-height: 100vh;
  max-width: 100rem;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.writing-index .masthead a {
  color: rgba(255, 255, 255, 0.98);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.17em;
  text-shadow: 0 2px 14px rgba(9, 18, 8, 0.72);
}

.writing-index .masthead a:hover { color: #fff; }

.writing-index-main {
  align-self: center;
  padding: clamp(3rem, 8vh, 7rem) 0;
}

.writing-index-panel {
  width: min(100%, 68rem);
  min-height: clamp(26rem, 48vh, 36rem);
  margin-inline: auto;
  padding: clamp(2rem, 5vw, 3.5rem);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.72), rgba(239, 238, 222, 0.6));
  box-shadow: 0 20px 56px rgba(17, 26, 14, 0.16), inset 0 1px rgba(255, 255, 255, 0.26);
  backdrop-filter: blur(8px) saturate(1.05);
  -webkit-backdrop-filter: blur(8px) saturate(1.05);
}

.writing-index .index-head {
  max-width: none;
  padding: 0 0 2.25rem;
}

.writing-index .post-list { max-width: none; }

.writing-index .post-list li { border-top-color: rgba(37, 37, 31, 0.44); }

.writing-index-section-label {
  margin: 0 0 1.4rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(24, 28, 19, 0.98);
  text-shadow: 0 1px 10px rgba(255, 255, 255, 0.72);
}

.writing-index .post-list a { padding: 1.4rem 0 0; }

.writing-index .post-number {
  margin: 0 0 0.65rem;
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: rgba(24, 28, 19, 0.98);
  text-shadow: 0 1px 10px rgba(255, 255, 255, 0.72);
}

.writing-index-panel .post-list h2,
.writing-index-panel .post-list p:not(.post-number) {
  text-shadow: 0 1px 10px rgba(255, 255, 255, 0.64);
}

.writing-index footer.foot {
  color: rgba(255, 255, 255, 0.9);
  border-top-color: rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 10px rgba(9, 18, 8, 0.55);
}

@media (max-width: 46rem) {
  .writing-index {
    background:
      linear-gradient(rgba(21, 29, 17, 0.18), rgba(21, 29, 17, 0.3)),
      url("/writing/media/writing-index-backdrop.jpg") 42% center / cover fixed;
  }

  .writing-index-main { align-self: end; }

  .writing-index-panel {
    background: rgba(250, 247, 238, 0.78);
    border-radius: 16px;
  }
}

@media (max-width: 30rem) {
  body { font-size: 18px; }
  .endcard { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 52rem) {
  .wrap { padding-inline: clamp(1.15rem, 5vw, 2rem); }

  .editorial-section {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding: 3.5rem 0;
  }

  .editorial-section--image-left .editorial-copy,
  .editorial-section--image-left > figure {
    grid-column: 1;
  }

  .editorial-section--image-left > figure {
    grid-row: auto;
  }

  .editorial-section > figure {
    position: static;
    max-width: 36rem;
    margin-inline: auto;
  }

  .editorial-prose { padding: 3.5rem 0; }
}
