/* ============================================================
   Essay page: long-form reading layout.
   Site chrome stays in the ORE system; the essay itself is set in
   EB Garamond with the burgundy accent of the original PDF, so the
   charts (cropped from that PDF) sit naturally in the text.
   ============================================================ */

@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebg-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebg-italic-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

.page-essay {
  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --essay-accent: #8a2e3b;
  --essay-ink: #22201c;
  --essay-measure: 680px;
}

/* ---------- reading progress ---------- */

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

/* ---------- hero ---------- */

.essay-hero {
  padding: calc(var(--nav-h) + clamp(44px, 9vh, 104px)) clamp(20px, 6vw, 96px) clamp(52px, 8vh, 96px);
  background: linear-gradient(180deg, #f4f3ee 0%, var(--bg) 80%);
  border-bottom: 1px solid var(--line);
  overflow: clip;
}
.essay-hero-grid {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, .7fr);
  gap: clamp(40px, 6vw, 96px);
  align-items: center;
}
.essay-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(48px, 7.2vw, 108px);
  line-height: .96;
  letter-spacing: -0.012em;
  color: var(--ink);
  text-wrap: balance;
}
.essay-dek {
  margin-top: 22px;
  font-family: var(--serif);
  font-size: clamp(21px, 2vw, 27px);
  line-height: 1.35;
  color: var(--ink-soft);
}
.essay-byline {
  margin-top: 28px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 6px;
  font-size: 14.5px;
  color: var(--ink-soft);
}
.essay-byline > span + span::before {
  content: "\00B7";
  margin: 0 12px;
  color: #b3b3ac;
}
.essay-byline strong { color: var(--ink); font-weight: 600; }
.essay-actions {
  margin-top: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.btn-download svg { flex: none; }

/* the PDF's first page, as a small stack of paper */
.essay-cover {
  position: relative;
  justify-self: center;
  width: min(100%, 360px);
  display: block;
  isolation: isolate;
}
.essay-cover::before,
.essay-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: 4px;
  background: #fff;
  border: 1px solid #e8e7e2;
  transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}
.essay-cover::before { transform: rotate(-4deg) translate(-10px, 8px); }
.essay-cover::after  { transform: rotate(-1.5deg) translate(-4px, 4px); }
.essay-cover img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid #e8e7e2;
  background: #fff;
  transform: rotate(2.2deg);
  box-shadow: 0 42px 70px -42px rgba(20, 20, 18, .45), 0 16px 30px -20px rgba(20, 20, 18, .22);
  transition: transform .7s cubic-bezier(.2, .8, .2, 1), box-shadow .7s ease;
}
.essay-cover:hover img,
.essay-cover:focus-visible img {
  transform: rotate(0deg) translateY(-8px);
  box-shadow: 0 56px 80px -44px rgba(20, 20, 18, .5), 0 20px 34px -22px rgba(20, 20, 18, .25);
}
.essay-cover:hover::before { transform: rotate(-6deg) translate(-18px, 12px); }
.essay-cover:hover::after  { transform: rotate(-2.6deg) translate(-8px, 6px); }
.essay-cover-badge {
  position: absolute;
  left: 50%;
  bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--display);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .35s ease, transform .45s cubic-bezier(.2, .8, .2, 1);
}
.essay-cover:hover .essay-cover-badge,
.essay-cover:focus-visible .essay-cover-badge {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes essay-rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: none; }
}
.essay-hero .rise {
  animation: essay-rise 1s cubic-bezier(.2, .75, .2, 1) both;
  animation-delay: var(--d, 0s);
}

/* ---------- reading layout ---------- */

.essay-body {
  padding: clamp(56px, 9vh, 104px) clamp(20px, 5vw, 64px) clamp(72px, 11vh, 128px);
}
.essay-layout {
  max-width: 1160px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 210px minmax(0, var(--essay-measure));
  justify-content: center;
  gap: clamp(48px, 7vw, 120px);
}

/* contents rail */
.essay-rail {
  position: sticky;
  top: calc(var(--nav-h) + 40px);
  align-self: start;
}
.essay-toc { font-family: var(--body); }
.essay-toc-label,
.essay-toc-inline summary {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #8f8f88;
}
.essay-toc-label { margin-bottom: 14px; }
.essay-toc ol {
  list-style: none;
  border-left: 1px solid var(--line);
}
.essay-toc a {
  display: grid;
  grid-template-columns: 34px 1fr;
  margin-left: -1px;
  padding: 7px 0 7px 14px;
  border-left: 2px solid transparent;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--ink-soft);
  transition: color .25s ease, border-color .25s ease;
}
.essay-toc .toc-num {
  padding-top: 2px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: #aaaaa3;
}
.essay-toc a:hover { color: var(--ink); }
.essay-toc a.is-active { color: var(--ink); border-left-color: var(--essay-accent); }
.essay-toc a.is-active .toc-num { color: var(--essay-accent); }

.essay-rail-download {
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  transition: border-color .25s ease, transform .35s cubic-bezier(.2, .9, .3, 1.3), box-shadow .35s ease;
}
.essay-rail-download:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 14px 26px -18px rgba(18, 18, 18, .35);
}
.essay-rail-download .dl-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
}
.essay-rail-download strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}
.essay-rail-download small {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .06em;
  color: #8f8f88;
}

.essay-toc-inline { display: none; }

/* ---------- article typography ---------- */

.essay-article {
  min-width: 0;
  font-family: var(--serif);
  font-size: clamp(19px, 1.3vw, 21px);
  line-height: 1.68;
  color: var(--essay-ink);
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  text-rendering: optimizeLegibility;
}
.essay-article p { margin: 0; }
/* book-style paragraphs, as in the PDF: indent, no gap, never after a heading or figure */
.essay-article p + p { text-indent: 1.5em; }
.essay-article :is(.essay-abstract, .essay-signoff) p { text-indent: 0; }
.essay-article ::selection { background: rgba(255, 210, 30, .55); }

.fig-ref {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: rgba(138, 46, 59, .4);
  text-decoration-color: color-mix(in srgb, var(--essay-accent) 42%, transparent);
  transition: color .2s ease, text-decoration-color .2s ease;
}
.fig-ref:hover { color: var(--essay-accent); text-decoration-color: currentColor; }

.essay-abstract,
.essay-section,
.essay-fig { scroll-margin-top: calc(var(--nav-h) + 32px); }

.essay-abstract-label {
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--essay-accent);
}
.essay-abstract-text {
  font-style: italic;
  font-size: .95em;
  line-height: 1.64;
  color: #3a3833;
}

.essay-sep {
  margin: clamp(44px, 7vh, 68px) 0 clamp(36px, 6vh, 56px);
  text-align: center;
  font-size: 24px;
  line-height: 1;
  color: var(--essay-accent);
  user-select: none;
}

.essay-lede .essay-dropcap {
  float: left;
  font-size: 5.05em;
  line-height: .8;
  margin: .07em .09em 0 -.02em;
  color: var(--essay-accent);
}
.essay-lede .essay-smallcaps {
  font-variant-caps: all-small-caps;
  letter-spacing: .07em;
}

.essay-section { margin-top: clamp(64px, 10vh, 100px); }
.essay-h { margin-bottom: 24px; }
.essay-num {
  display: block;
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .22em;
  color: var(--essay-accent);
}
.essay-h h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(32px, 3.3vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.008em;
  color: var(--ink);
  text-wrap: balance;
}

/* ---------- figures ---------- */

.essay-fig { margin: clamp(38px, 6vh, 58px) 0; }
.essay-fig-plate {
  padding: clamp(8px, 1.4vw, 18px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 22px 44px -36px rgba(20, 20, 18, .3);
}
.essay-fig img { display: block; width: 100%; height: auto; }
.essay-fig figcaption {
  margin-top: 14px;
  padding: 0 4px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  color: #56544e;
}
.fig-label {
  margin-right: 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--essay-accent);
}
.fig-title { font-style: italic; color: var(--essay-ink); }
.fig-source {
  display: block;
  margin-top: 7px;
  font-family: var(--body);
  font-size: 12.5px;
  line-height: 1.5;
  color: #8f8f88;
}

/* charts carry small labels, so give them more width than the text column */
@media (min-width: 1200px) {
  .essay-fig { margin-left: -56px; margin-right: -56px; }
}

/* scroll-driven entrance where supported; without support, figures simply show */
@keyframes essay-fig-in {
  from { opacity: 0; transform: translateY(28px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .essay-fig {
      animation: essay-fig-in linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 55%;
    }
  }
}

/* ---------- sign-off ---------- */

.essay-signoff {
  margin-top: clamp(56px, 9vh, 88px);
  padding-left: 45%;
}
.essay-signoff-name {
  font-style: italic;
  font-size: clamp(34px, 3.4vw, 44px);
  line-height: 1;
  color: var(--ink);
}
.essay-signoff-cred {
  margin-top: 8px !important;
  font-style: italic;
  font-size: 17px;
  color: var(--ink-soft);
}


/* ---------- responsive ---------- */

@media (max-width: 1099px) {
  .essay-layout { grid-template-columns: minmax(0, var(--essay-measure)); }
  .essay-rail { display: none; }
  .essay-toc-inline {
    display: block;
    margin-bottom: 44px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
  }
  .essay-toc-inline summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 18px;
    cursor: pointer;
    list-style: none;
  }
  .essay-toc-inline summary::-webkit-details-marker { display: none; }
  .essay-toc-inline summary::after {
    content: "+";
    font-size: 17px;
    color: var(--ink);
    transition: transform .3s ease;
  }
  .essay-toc-inline[open] summary::after { transform: rotate(45deg); }
  .essay-toc-inline ol { margin: 0 18px 16px; }
}

@media (max-width: 860px) {
  .essay-hero-grid { grid-template-columns: 1fr; }
  .essay-cover { width: min(64%, 280px); margin-top: 8px; }
  .essay-signoff { padding-left: 0; text-align: right; }
}

@media (max-width: 640px) {
  .essay-article { font-size: 18.5px; line-height: 1.64; }
  .essay-fig-plate { padding: 6px; border-radius: 12px; }
  /* one fact per line: wrapped rows would start with a stray separator */
  .essay-byline { flex-direction: column; align-items: flex-start; row-gap: 4px; }
  .essay-byline > span + span::before { content: none; }
  .essay-actions { flex-direction: column; align-items: stretch; }
  .essay-actions .btn { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .essay-hero .rise { animation: none; }
}

@media print {
  .nav, .read-progress, .essay-rail, .essay-toc-inline, .essay-actions,
  .essay-cover, .footer { display: none !important; }
  .essay-hero { padding: 0 0 24px; background: none; border: 0; }
  .essay-hero-grid, .essay-layout { display: block; }
  .essay-body { padding: 0; }
  .essay-article { font-size: 11.5pt; }
  .essay-fig { break-inside: avoid; margin-inline: 0; }
}
