/* ==========================================================================
   Essay pages (writing/*.html) — builds on style.css
   ========================================================================== */

.essay-page .topbar-name { opacity: 1; transform: none; }

.read-progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 60; pointer-events: none; }
.read-progress span { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }

.essay { --measure: 680px; --toc: 200px; --gap: clamp(32px, 5vw, 72px); }

/* ---------------------------------------------------------------- header */
.essay-head {
  max-width: calc(var(--measure) + var(--toc) + var(--gap));
  margin: 0 auto; padding: clamp(120px, 17vh, 176px) var(--gutter) 0;
}
.essay-head > * { max-width: 860px; }
.essay-eyebrow {
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin: 0 0 22px;
}
.essay-eyebrow span { margin: 0 .4em; }
.essay-title {
  font-family: var(--serif); font-weight: 400; color: var(--ink);
  font-size: clamp(42px, 6.4vw, 78px); line-height: 1.02; letter-spacing: -.028em;
  margin: 0 0 24px; font-variation-settings: "opsz" 72;
}
.essay-dek {
  font-family: var(--serif); font-size: clamp(19px, 2.1vw, 23px); line-height: 1.45; color: var(--ink-2);
  max-width: 34em; margin: 0 0 26px;
}
.essay-byline { font-size: 14px; color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- video */
.essay-video {
  max-width: calc(var(--measure) + var(--toc) + var(--gap));
  margin: clamp(40px, 6vw, 64px) auto 0; padding: 0 var(--gutter);
}
.essay-video-frame {
  position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000;
  box-shadow: 0 30px 80px -40px rgba(0, 0, 0, .45);
}
.essay-video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------------------------------------------------------------- layout */
.essay-layout {
  display: grid; grid-template-columns: var(--toc) minmax(0, var(--measure)); gap: var(--gap);
  justify-content: center; align-items: start;
  padding: clamp(48px, 7vw, 88px) var(--gutter) clamp(56px, 8vw, 96px);
}

/* contents: sticky, collapsible */
.toc-wrap { position: sticky; top: 92px; }
.toc summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
  padding-bottom: 12px; border-bottom: 1px solid var(--rule); user-select: none;
}
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after {
  content: ""; width: 6px; height: 6px; border-right: 1.3px solid currentColor; border-bottom: 1.3px solid currentColor;
  transform: translateY(-2px) rotate(45deg); transition: transform .3s var(--ease);
}
.toc[open] summary::after { transform: translateY(1px) rotate(-135deg); }
.toc summary:hover { color: var(--ink); }
.toc ol { list-style: none; margin: 10px 0 0; padding: 0; position: relative; }
.toc li a {
  display: block; padding: 7px 0 7px 14px; font-size: 14px; line-height: 1.35; color: var(--muted);
  text-decoration: none; border-left: 1px solid var(--rule); transition: color .25s var(--ease), border-color .25s var(--ease);
}
.toc li a:hover { color: var(--ink); }
.toc li a.is-active { color: var(--ink); border-left-color: var(--ink); }
@media (prefers-reduced-motion: no-preference) {
  .toc[open] ol { animation: tocIn .45s var(--ease); }
}
@keyframes tocIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- body */
.essay-body {
  font-family: var(--serif); font-size: 20px; line-height: 1.68; color: var(--ink-2);
  font-variation-settings: "opsz" 18;
}
.essay-body p { margin: 0 0 1.15em; }
.essay-body .lede { font-size: 23px; line-height: 1.5; color: var(--ink); }
.essay-body h2 {
  font-family: var(--serif); font-weight: 400; color: var(--ink);
  font-size: clamp(27px, 3vw, 33px); line-height: 1.15; letter-spacing: -.015em;
  margin: 2.1em 0 .7em; scroll-margin-top: 92px;
}
.essay-body a { color: var(--ink); }
.essay-body .closing {
  font-size: 24px; line-height: 1.4; color: var(--ink); margin-top: 1.6em;
  padding-top: 1.1em; border-top: 1px solid var(--rule);
}

.essay-embed { margin: 2em 0; display: flex; justify-content: center; }
.essay-embed .twitter-tweet {
  font-family: var(--sans); font-size: 15px; line-height: 1.55; margin: 0; max-width: 550px;
  padding: 18px 22px; border: 1px solid var(--rule); border-radius: 14px; background: var(--surface);
}
.essay-embed .twitter-tweet p { margin: 0 0 .8em; }
.essay-embed .twitter-tweet-rendered { padding: 0; border: 0; background: none; }

.loop { margin: 2.2em 0; color: var(--muted); }
.loop svg { width: 100%; height: auto; display: block; overflow: visible; }
.loop .loop-mobile { display: none; max-width: 400px; margin: 0 auto; }
.loop-lines path { fill: none; stroke: currentColor; stroke-width: 1.4; }
.loop-lines text { fill: var(--ink); font-family: var(--sans); font-size: 15px; }

.essay-authors { margin-top: 3em; padding-top: 1.6em; border-top: 1px solid var(--rule); font-family: var(--sans); }
.essay-authors-label { font-size: 11.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin: 0 0 14px !important; }
.essay-authors-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 32px; }
.essay-authors .name { font-family: var(--serif); font-size: 20px; color: var(--ink); margin: 0; }
.essay-authors .role { font-size: 14px; color: var(--muted); margin: 2px 0 0; }
.essay-source { font-size: 13.5px; color: var(--faint); margin: 28px 0 0 !important; line-height: 1.6; }
.essay-source a { color: var(--muted); }

/* ---------------------------------------------------------------- entrance */
@media (prefers-reduced-motion: no-preference) {
  .js .essay-head > *, .js .essay-video { animation: heroIn 1.1s var(--ease) both; }
  .js .essay-head > :nth-child(2) { animation-delay: .07s; }
  .js .essay-head > :nth-child(3) { animation-delay: .14s; }
  .js .essay-head > :nth-child(4) { animation-delay: .2s; }
  .js .essay-video { animation-delay: .28s; }
}

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 960px) {
  .essay-layout { grid-template-columns: minmax(0, var(--measure)); gap: 28px; }
  .toc-wrap { position: static; }
  .toc { border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
  .toc summary { border-bottom: 0; padding-bottom: 0; }
  .toc[open] summary { padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
}
@media (max-width: 720px) {
  .essay-head { padding-top: 104px; }
  .essay-body { font-size: 18.5px; line-height: 1.65; }
  .essay-body .lede { font-size: 20.5px; }
  .essay-body .closing { font-size: 21px; }
  .essay-video { padding: 0; }
  .essay-video-frame { border-radius: 0; }
  .loop .loop-desktop { display: none; }
  .loop .loop-mobile { display: block; }
  .loop-lines text { font-size: 17px; }
}
@media print {
  .read-progress, .toc-wrap, .essay-video { display: none !important; }
  .essay-layout { display: block; }
}

/* keep the way home visible on small phones */
@media (max-width: 420px) {
  .essay-page .topbar-name { display: inline; font-size: 17px; }
  .essay-page .topbar-inner { justify-content: space-between; }
  .essay-page .topbar-nav { gap: 14px; }
}
