/* ── Shared essay stylesheet ─────────────────────────────────────────────
   Designed to be loaded after ../style.css (which provides tokens + nav/footer).
   ────────────────────────────────────────────────────────────────────────── */

/* ── Layout wrapper ─────────────────────────────────────────────────────── */
.essay-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 2rem;
}

/* ── Essay header ───────────────────────────────────────────────────────── */
.essay-header {
  max-width: 680px;
  margin: 3.5rem auto 3rem;
  padding: 0 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 2.5rem;
}

.essay-kicker {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 1rem;
}

.essay-kicker a {
  color: inherit;
  text-decoration: none;
}

.essay-kicker a:hover {
  color: var(--text-secondary);
}

.essay-title {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.025em;
  color: var(--text);
  margin-bottom: 1.2rem;
}

.essay-lede {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-style: italic;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.essay-meta {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-faint);
}

.essay-meta a {
  color: var(--text-secondary);
  text-decoration: none;
}

.essay-meta a:hover {
  color: var(--text);
}

/* ── Prose area — two-column grid on desktop ────────────────────────────── */
.essay-prose {
  padding: 0 2rem;
  max-width: 960px;
  margin: 0 auto 4rem;
}

@media (min-width: 900px) {
  .essay-prose {
    display: grid;
    grid-template-columns: 1fr 220px;
    column-gap: 3rem;
  }

  /* Prose body: independent of the sidenote column */
  .prose-main {
    min-width: 0; /* prevent grid blowout */
  }

  /* Sidenote column: stretches to full prose height so absolutes work */
  .prose-margin {
    position: relative;
    align-self: stretch;
  }

  .sidenote {
    position: absolute;
    width: 100%;
    top: 0; /* overridden per-note by essay.js */
  }
}

@media (max-width: 899px) {
  .prose-margin { display: none; }
}

/* ── Prose typography ───────────────────────────────────────────────────── */
.essay-prose p {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  line-height: 1.82;
  margin-bottom: 1.5em;
  color: var(--text);
}

.essay-prose em {
  font-style: italic;
}

.essay-prose strong {
  font-weight: 600;
}

.essay-prose h2 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 2.8rem 0 0.8rem;
}

.essay-prose h3 {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-style: italic;
  font-weight: 400;
  margin: 2rem 0 0.6rem;
  color: var(--text-secondary);
}

/* Links: underline-only, low key */
.essay-prose a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}

.essay-prose a:hover {
  text-decoration-color: var(--text-secondary);
}

/* Blockquote */
.essay-prose blockquote {
  margin: 2rem 0;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
  font-style: italic;
  color: var(--text-secondary);
}

/* ── Footnote references (superscript in text) ──────────────────────────── */
.fn-ref {
  font-family: var(--font-sans);
  font-size: 0.65em;
  font-weight: 600;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
  text-decoration: none;
  margin-left: 0.05em;
}

.fn-ref:hover {
  text-decoration: underline;
}

/* ── Sidenotes (desktop col 2) ──────────────────────────────────────────── */
.sidenote {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-secondary);
  border-left: 2px solid var(--border);
  padding-left: 1rem;
}

.sidenote em {
  font-style: italic;
}

.sn-num {
  font-weight: 600;
  color: var(--accent);
  margin-right: 0.25rem;
}


/* ── Diffusion widget ───────────────────────────────────────────────────── */

/* The figure wrapper inherits .essay-figure margin; no extra needed */
.dw-figure {
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  padding: 1rem 1rem 0;
}

/* Controls row */
.dw-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dw-label {
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.68rem;
}

.dw-select {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
}

.dw-slider-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.dw-slider-label {
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.68rem;
  white-space: nowrap;
}

.dw-slider {
  flex: 1;
  min-width: 80px;
  max-width: 200px;
  accent-color: var(--accent);
  cursor: pointer;
}

.dw-time-label {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 3.2rem;
  text-align: right;
}

/* Allow SVG chart content (axes, reference lines) to extend slightly beyond
   the viewBox without being clipped. The browser's default overflow:hidden
   on root SVG elements silently clips lines drawn at the edge of a plot area.
   Scoped to .essay-figure so it doesn't affect other SVGs on the page. */
.essay-figure svg {
  overflow: visible;
}

/* Inline chart containers (D3 bundles injected via script) */
#ecoli-genome-chart,
#diffusion-comparison-chart,
#brownian-motion-chart,
#rnap-fidelity-chart,
#ecoli-composition-chart {
  margin: 2.5rem 0 1rem;
}

#ecoli-genome-chart svg,
#diffusion-comparison-chart svg {
  overflow: visible;
  display: block;
  max-width: 100%;
  height: auto;
}

/* Div-based chart roots: widen to match SVG charts, cap at 100% */
#brownian-motion-chart > div,
#rnap-fidelity-chart > div,
#ecoli-composition-chart > div {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Override hardcoded #fff on interactive elements for dark-mode compat */
#brownian-motion-chart select,
#brownian-motion-chart button,
#rnap-fidelity-chart select,
#rnap-fidelity-chart button,
#ecoli-composition-chart select,
#ecoli-composition-chart button {
  background: var(--bg) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

/* SVG chart: override the bundle's inline width attr + hardcoded colours */
.dw-chart svg {
  width:   100% !important;
  height:  auto !important;
  display: block !important;
  background: var(--bg-canvas) !important;
  border: none !important;       /* border lives on the .dw-figure wrapper */
  border-radius: 0 !important;
}

/* Table: override IBM Plex Mono + hardcoded palette */
.dw-table {
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.dw-table table {
  font-family: var(--font-sans) !important;
  font-size:   0.75rem !important;
  color:       var(--text-secondary) !important;
  max-width:   100% !important;
}

.dw-table th {
  color: var(--text-faint) !important;
  border-bottom-color: var(--border) !important;
}

.dw-table tr {
  border-bottom-color: var(--border) !important;
}

/* figcaption inside .dw-figure */
.dw-figure figcaption {
  padding: 0.75rem 0 0.9rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}

@media (max-width: 600px) {
  .dw-controls { gap: 0.5rem; }
  .dw-slider   { max-width: none; }
}

/* ── Figure ─────────────────────────────────────────────────────────────── */
.essay-figure {
  margin: 2.5rem 0 1rem;
}

.essay-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.figure-placeholder {
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.figure-placeholder-sub {
  font-size: 0.72rem;
  color: var(--text-faint);
  opacity: 0.7;
}

.essay-figure figcaption {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-top: 0.75rem;
}

/* ── Footnotes (mobile only) ────────────────────────────────────────────── */
.footnotes {
  max-width: 960px;
  margin: 0 auto 3rem;
  padding: 2rem 2rem 0;
  border-top: 1px solid var(--border);
}

.footnotes-title {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 1rem;
}

.footnotes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.footnotes-list li {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--text-secondary);
}

.fn-back-ref {
  color: var(--accent);
  text-decoration: none;
  margin-right: 0.4rem;
  font-size: 0.75rem;
}

/* Hide footnotes on desktop (sidenotes take over) */
@media (min-width: 900px) {
  .footnotes {
    display: none;
  }
}

/* ── Feedback + acknowledgments ─────────────────────────────────────────── */
.essay-feedback {
  max-width: 960px;
  margin: 0 auto 5rem;
  padding: 2rem 2rem 0;
  border-top: 1px solid var(--border);
}

@media (min-width: 900px) {
  .essay-feedback {
    display: grid;
    grid-template-columns: 1fr 220px;
    column-gap: 3rem;
    align-items: start;
  }

  .essay-feedback > * {
    grid-column: 1;
  }
}

.feedback-heading {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.feedback-body {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.feedback-body a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.acknowledgments {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-faint);
  line-height: 1.6;
}

.acknowledgments-label {
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.acknowledgments-list {
  font-style: italic;
}

/* ── Mobile padding adjustments ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .essay-header,
  .essay-prose,
  .footnotes,
  .essay-feedback {
    padding-left: 1.2rem;
    padding-right: 1.2rem;
  }

  .essay-header {
    margin-top: 2rem;
  }

  .essay-title {
    font-size: 2.3rem;
  }
}
