/* editorial.css — the reading page (post.html).
 *
 * A post is read, not browsed: one column at a ~65-character measure, a text
 * serif for the prose (Newsreader, drawn for continuous screen reading), the
 * house headline face (Playfair Display) for the title, Inter for everything
 * that is interface. Values and sources: .claude/skills/editorial-ux/
 * references/design-research.md.
 *
 * Theming follows the site convention — light tokens on :root, dark tokens on
 * body.dark-mode (js/dark-mode-toggle.js sets it from the OS
 * preference or the reader's choice).
 */

@import url("tokens.css");

:root {
  --ed-bg: #fbfaf7;
  --ed-surface: #ffffff;
  --ed-ink: #1a1a2e;
  --ed-ink-soft: #3d4458;
  --ed-muted: #5f6675;          /* 5.6:1 on --ed-bg */
  --ed-rule: rgba(26, 26, 46, 0.12);
  --ed-rule-strong: rgba(26, 26, 46, 0.28);
  --ed-accent: #6d28d9;         /* links + kicker, 7.4:1 on --ed-bg */
  --ed-accent-soft: rgba(109, 40, 217, 0.08);
  --ed-code-bg: #f1eff8;
  --ed-mark: #7c3aed;

  --ed-font-body: 'Newsreader', 'Iowan Old Style', 'Charter', Georgia, serif;
  --ed-font-display: 'Playfair Display', Georgia, serif;
  --ed-font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ed-font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Utopia-style fluid scale: 18px → 21px body across 360px → 1240px. */
  --ed-step-0: clamp(1.125rem, 1.048rem + 0.341vw, 1.3125rem);
  --ed-step-1: clamp(1.35rem, 1.22rem + 0.58vw, 1.65rem);
  --ed-step-4: clamp(2rem, 1.489rem + 2.273vw, 3.25rem);
  --ed-measure: 44rem;
}

body.dark-mode {
  --ed-bg: #0d0f1a;
  --ed-surface: #141729;
  --ed-ink: #e8e8f2;
  --ed-ink-soft: #c3c8d8;
  --ed-muted: #9aa2b6;          /* 7.3:1 on --ed-bg */
  --ed-rule: rgba(255, 255, 255, 0.12);
  --ed-rule-strong: rgba(255, 255, 255, 0.3);
  --ed-accent: #a5b4fc;         /* the house dark accent (WCAG AA) */
  --ed-accent-soft: rgba(165, 180, 252, 0.1);
  --ed-code-bg: #1b1f35;
  --ed-mark: var(--ds-cyan);
}

/* ------------------------------------------------------------- page frame */

html { scroll-padding-top: 1.5rem; }  /* a jumped-to heading keeps a little air above it */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  @view-transition { navigation: auto; }
}

body.ed-page {
  margin: 0;
  background: var(--ed-bg);
  color: var(--ed-ink);
  font-family: var(--ed-font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Class rules like .post-tags{display:flex} outrank the UA's [hidden] rule. */
.ed-page [hidden] { display: none !important; }

.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 1000;
  padding: 0.6rem 1rem; border-radius: 6px;
  background: var(--ed-ink); color: var(--ed-bg);
  font: 600 0.9rem var(--ed-font-ui); text-decoration: none;
}
.skip-link:focus { top: 0.75rem; }

.ed-page :focus-visible {
  outline: 2px solid var(--ed-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Reading progress — a scroll-driven animation, so no JavaScript and no
   scroll listener. Browsers without animation-timeline simply show nothing. */
.post-progress { display: none; }
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .post-progress {
      display: block;
      position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 999;
      background: var(--ed-mark);
      transform-origin: 0 50%;
      transform: scaleX(0);
      animation: ed-progress linear both;
      animation-timeline: scroll(root block);
    }
  }
}
@keyframes ed-progress { to { transform: scaleX(1); } }

.post-shell {
  max-width: var(--ed-measure);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3.5rem) 1.25rem 4rem;
}

/* ----------------------------------------------------------- loading/error */

.post-skeleton { padding-top: 0.5rem; }
.post-skeleton span {
  display: block; height: 1rem; margin: 0 0 0.9rem; border-radius: 4px;
  background: var(--ed-rule);
}
.post-skeleton .sk-kicker { width: 8rem; height: 0.75rem; }
.post-skeleton .sk-title { width: 92%; height: 2.6rem; }
.post-skeleton .sk-title.short { width: 60%; margin-bottom: 1.6rem; }
.post-skeleton .sk-line.short { width: 70%; }
@media (prefers-reduced-motion: no-preference) {
  .post-skeleton span { animation: ed-pulse 1.4s ease-in-out infinite alternate; }
}
@keyframes ed-pulse { from { opacity: 0.55; } to { opacity: 1; } }

.post-error {
  padding: 2rem 0; font-size: 1.05rem; color: var(--ed-ink-soft);
}
.post-error a { color: var(--ed-accent); }

/* ------------------------------------------------------------------ header */

.post-header { margin: 0 0 2.25rem; }

.post-kicker {
  margin: 0 0 0.9rem;
  font: 600 0.75rem/1.2 var(--ed-font-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.post-kicker a { color: var(--ed-accent); text-decoration: none; }
.post-kicker a:hover { text-decoration: underline; text-underline-offset: 0.2em; }

.post-title {
  margin: 0 0 1rem;
  font-family: var(--ed-font-display);
  font-weight: 700;
  font-size: var(--ed-step-4);
  line-height: 1.1;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.post-dek {
  margin: 0 0 1.5rem;
  font-family: var(--ed-font-body);
  font-size: var(--ed-step-1);
  line-height: 1.4;
  color: var(--ed-ink-soft);
  text-wrap: pretty;
}

.post-byline {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.35rem 0.6rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--ed-rule);
  border-bottom: 1px solid var(--ed-rule);
  font-size: 0.875rem;
  color: var(--ed-muted);
}
.post-byline .post-author { color: var(--ed-ink); font-weight: 600; }
.post-byline .sep { opacity: 0.6; }
.post-byline time { font-variant-numeric: tabular-nums; }

.post-share {
  margin-left: auto;
  min-height: 2rem; padding: 0.3rem 0.85rem;
  border: 1px solid var(--ed-rule-strong); border-radius: 999px;
  background: transparent; color: var(--ed-ink);
  font: 500 0.8rem var(--ed-font-ui); cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.post-share:hover { background: var(--ed-accent-soft); border-color: var(--ed-accent); }
.post-share-status { font-size: 0.8rem; color: var(--ed-accent); }

.post-provenance {
  margin: 0.7rem 0 0;
  font: 0.72rem/1.5 var(--ed-font-mono);
  letter-spacing: 0.02em;
  color: var(--ed-muted);
}

/* ------------------------------------------------------- contents (TOC) */

.post-layout { display: block; }

.post-toc { margin: 0 0 2rem; }
.post-toc details {
  border: 1px solid var(--ed-rule); border-radius: 8px;
  padding: 0.75rem 1rem;
}
.post-toc summary {
  cursor: pointer; list-style: none;
  font: 600 0.75rem var(--ed-font-ui); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ed-muted);
}
.post-toc summary::-webkit-details-marker { display: none; }
.post-toc summary::after { content: ' +'; }
.post-toc details[open] summary::after { content: ' −'; }
.post-toc-list { list-style: none; margin: 0.65rem 0 0; padding: 0; }
.post-toc-item { margin: 0; }
.post-toc-item.level-3 { padding-left: 0.9rem; }
.post-toc-item a {
  display: block; padding: 0.3rem 0 0.3rem 0.75rem;
  border-left: 2px solid transparent;
  color: var(--ed-ink-soft); text-decoration: none;
  font-size: 0.9rem; line-height: 1.35;
}
.post-toc-item a:hover { color: var(--ed-accent); }
.post-toc-item a[aria-current="true"] {
  color: var(--ed-ink); font-weight: 600; border-left-color: var(--ed-mark);
}

/* Wide screens: the contents list becomes a sticky margin column. */
@media (min-width: 1180px) {
  .post-shell.has-toc { max-width: calc(var(--ed-measure) + 17rem); }
  .post-shell.has-toc .post-header,
  .post-shell.has-toc .post-footer { max-width: var(--ed-measure); }
  .post-shell.has-toc .post-layout {
    display: grid;
    grid-template-columns: minmax(0, var(--ed-measure)) 13rem;
    column-gap: 4rem;
  }
  .post-shell.has-toc .post-toc {
    grid-column: 2; grid-row: 1;
    position: sticky; top: 2rem; align-self: start;
    margin: 0; max-height: calc(100vh - 4rem); overflow: auto;
  }
  .post-shell.has-toc .post-toc details { border: 0; padding: 0; }
  .post-shell.has-toc .post-toc summary { pointer-events: none; }
  .post-shell.has-toc .post-toc summary::after { content: ''; }
  .post-shell.has-toc .post-body { grid-column: 1; grid-row: 1; }
}

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

.post-body {
  font-family: var(--ed-font-body);
  font-size: var(--ed-step-0);
  line-height: 1.62;
  font-optical-sizing: auto;
  font-variant-numeric: proportional-nums;
  color: var(--ed-ink);
  overflow-wrap: break-word;
}
.post-body > :first-child { margin-top: 0; }

.post-body p,
.post-body li { text-wrap: pretty; hanging-punctuation: first allow-end last; }
.post-body p { margin: 0 0 1.15em; }

.post-body h2,
.post-body h3,
.post-body h4 {
  font-family: var(--ed-font-body);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ed-ink);
}
.post-body h2 { font-size: 1.55em; margin: 2.2em 0 0.6em; }
.post-body h3 { font-size: 1.25em; margin: 1.8em 0 0.5em; }
.post-body h4 { font-size: 1.05em; margin: 1.6em 0 0.4em; }
.post-body h1 { font-family: var(--ed-font-display); font-size: 1.8em; line-height: 1.15; margin: 1.6em 0 0.6em; }

/* Section anchors — appear on hover/focus so a reader can link a section. */
.post-body .heading-anchor {
  margin-left: 0.4em; font-weight: 400; color: var(--ed-muted);
  text-decoration: none; opacity: 0; transition: opacity 0.15s ease;
}
.post-body :is(h2, h3):hover .heading-anchor,
.post-body .heading-anchor:focus-visible { opacity: 1; }

.post-body a {
  color: var(--ed-accent);
  text-decoration-line: underline;
  text-decoration-thickness: max(1px, 0.0625rem);
  text-underline-offset: 0.18em;
}
.post-body a:hover { text-decoration-thickness: 2px; }

.post-body strong { font-weight: 650; }

/* Drop cap on a real opening paragraph (see EditorialUX.wantsDropCap).
   initial-letter is Chromium + Safari; Firefox just shows a normal letter. */
@supports ((initial-letter: 3) or (-webkit-initial-letter: 3)) {
  .post-body p.has-dropcap::first-letter {
    -webkit-initial-letter: 3;
    initial-letter: 3;
    font-family: var(--ed-font-display);
    font-weight: 700;
    color: var(--ed-mark);
    margin-right: 0.12em;
  }
}

.post-body ul,
.post-body ol { margin: 0 0 1.3em; padding-left: 1.4em; }
.post-body li { margin: 0 0 0.5em; padding-left: 0.2em; }
.post-body ul > li::marker { color: var(--ed-mark); }
.post-body ol > li::marker { color: var(--ed-muted); font-family: var(--ed-font-ui); font-size: 0.85em; }

.post-body blockquote {
  margin: 1.8em 0;
  padding: 0.2em 0 0.2em 1.2em;
  border-left: 3px solid var(--ed-mark);
  font-size: 1.12em;
  font-style: italic;
  line-height: 1.5;
  color: var(--ed-ink-soft);
}
.post-body blockquote p:last-child { margin-bottom: 0; }

/* A thematic break is an asterism, not a hairline across the column. */
.post-body hr {
  border: 0; margin: 2.4em 0; text-align: center; color: var(--ed-muted);
}
.post-body hr::before { content: '⁂'; font-size: 1.1em; letter-spacing: 0.3em; }

.post-body code {
  font-family: var(--ed-font-mono);
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--ed-code-bg);
}
.post-body pre {
  margin: 1.6em 0; padding: 1rem 1.1rem;
  border-radius: 8px; border: 1px solid var(--ed-rule);
  background: var(--ed-code-bg);
  overflow-x: auto;
  font-size: 0.82em; line-height: 1.55;
}
.post-body pre code { padding: 0; background: transparent; font-size: 1em; }

.post-body table {
  display: block; max-width: 100%; overflow-x: auto;
  margin: 1.6em 0; border-collapse: collapse;
  font-family: var(--ed-font-ui); font-size: 0.82em;
  font-variant-numeric: lining-nums tabular-nums;
}
.post-body th,
.post-body td { padding: 0.5em 0.8em; border-bottom: 1px solid var(--ed-rule); text-align: left; vertical-align: top; }
.post-body th { font-weight: 600; border-bottom-color: var(--ed-rule-strong); }

/* Figures. Generated illustrations are square (1024²), so the box is reserved
   up front (no layout shift) and capped so the opening text stays in view. */
.post-body .post-figure { margin: 2em auto; text-align: center; }
.post-body .post-figure img,
.post-body img {
  display: block; max-width: 100%; height: auto; margin: 0 auto;
  border-radius: 8px;
}
.post-body .post-figure img[src*="/illustrations/"] { aspect-ratio: 1 / 1; width: min(100%, 26rem); object-fit: cover; }
.post-body .post-figure.is-hero { margin: 0 auto 2.2em; }
.post-body .post-figure.is-hero img[src*="/illustrations/"] { width: min(100%, 30rem); }
.post-body figcaption { margin-top: 0.6em; font: 0.8rem/1.4 var(--ed-font-ui); color: var(--ed-muted); }

/* The closing sign-off line ("*The Eschaton — … Compiled by The Synthesist.*").
   post.html tags it only when the whole last paragraph is one <em>. */
.post-body .post-signoff { font-size: 0.85em; color: var(--ed-muted); text-align: center; }

/* ------------------------------------------------------------------ footer */

.post-footer { margin-top: 3rem; }

.post-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; margin: 0 0 2rem; padding: 0; }
.post-tags a {
  display: inline-flex; align-items: center; min-height: 1.75rem;
  padding: 0.2rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--ed-rule-strong);
  color: var(--ed-ink-soft); text-decoration: none;
  font-size: 0.8rem;
}
.post-tags a::before { content: '#'; opacity: 0.5; margin-right: 0.1em; }
.post-tags a:hover { border-color: var(--ed-accent); color: var(--ed-accent); }

.post-series { margin: 0 0 2.25rem; padding-top: 1.5rem; border-top: 1px solid var(--ed-rule-strong); }
.post-series-label {
  margin: 0 0 0.8rem;
  font: 600 0.72rem var(--ed-font-ui); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ed-muted);
}
.post-series-links { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.post-series-link {
  display: grid; gap: 0.3rem; align-content: start;
  color: var(--ed-ink); text-decoration: none;
}
.post-series-link.is-next { text-align: right; }
.post-series-dir { font-size: 0.78rem; font-weight: 600; color: var(--ed-accent); }
.post-series-title { font-family: var(--ed-font-body); font-size: 1.1rem; line-height: 1.3; text-wrap: balance; }
.post-series-date { font-size: 0.78rem; color: var(--ed-muted); }
.post-series-link:hover .post-series-title { text-decoration: underline; text-underline-offset: 0.18em; }
@media (max-width: 560px) {
  .post-series-links { grid-template-columns: 1fr; }
  .post-series-link.is-next { text-align: left; }
}

/* "See also" — the swarm output this editorial synthesizes. Thin rules, no cards. */
.see-also { margin: 0 0 2.25rem; padding-top: 1.5rem; border-top: 1px solid var(--ed-rule); }
.see-also-label {
  margin: 0 0 0.6rem;
  font: 600 0.72rem var(--ed-font-ui); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ed-muted);
}
.see-also-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); column-gap: 1.5rem; }
.see-also-card {
  display: grid; gap: 0.15rem; align-content: start; padding: 0.7rem 0;
  border-bottom: 1px solid var(--ed-rule);
  color: var(--ed-ink); text-decoration: none;
}
.see-also-card:hover .see-also-title { color: var(--ed-accent); }
.see-also-kind { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ed-muted); }
.see-also-title { font-size: 0.92rem; line-height: 1.4; }

.follow-synthesis {
  margin: 0 0 1.5rem; padding: 1rem 1.15rem;
  border-radius: 8px; background: var(--ed-accent-soft);
  font-size: 0.9rem; line-height: 1.55; color: var(--ed-ink-soft);
}
.follow-synthesis p { margin: 0; }
.follow-synthesis .follow-synthesis-label {
  margin: 0 0 0.3rem;
  font: 600 0.72rem var(--ed-font-ui); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ed-muted);
}
.follow-synthesis a { color: var(--ed-accent); font-weight: 600; text-decoration: none; }
.follow-synthesis a:hover { text-decoration: underline; text-underline-offset: 0.18em; }

.back-link { color: var(--ed-accent); font-size: 0.9rem; font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; text-underline-offset: 0.18em; }

/* --------------------------------------------------------------- printing */

@media print {
  .post-progress, .skip-link, .ds-sitenav, .post-share, .post-toc,
  .post-series, .see-also, .follow-synthesis, .back-link, [data-ds-footer] { display: none !important; }
  body.ed-page { background: #fff; color: #000; }
  .post-shell { max-width: none; padding: 0; }
  .post-body a { color: inherit; }
}
