/**
 * distill.css — Distill.pub-inspired layout for "Geometry of Seeing" series.
 * Used with _layouts/distill.html.
 *
 * Typography: Merriweather (body) + Source Sans 3 (UI/captions) + JetBrains Mono (code).
 * Layout: l-body/l-middle/l-page each independently centred (no jump vs site-main).
 * Golden ratio: --mid-w = --body-w × φ ≈ 1100px.
 * Margin notes: float right into viewport gutter at ≥ 1130px, inline below.
 */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --accent:       #1565c0;
  --accent-light: #e8f0fe;
  --accent-warm:  #e65100;
  --text:         #1a1a1a;
  --text-light:   #555;
  --text-muted:   #888;
  --border:       #e0e0e0;
  --fig-bg:       #fafafa;
  --code-bg:      #f4f4f4;

  --serif:  'Merriweather', Georgia, serif;
  --sans:   'Source Sans 3', 'Helvetica Neue', sans-serif;
  --mono:   'JetBrains Mono', 'Fira Code', monospace;

  --body-w:   680px;
  --mid-w:    1100px;   /* body-w × φ  (≈ 680 × 1.618) */
  --gutter-w: 220px;    /* aside column width */
}

/* ── Page reset ──────────────────────────────────────────────────────────── */
.distill-page { margin: 0; padding: 0; background: #fff; color: var(--text); }
.distill-page *, .distill-page *::before, .distill-page *::after { box-sizing: border-box; }

/* ── Series badge (inside .site-nav) ────────────────────────────────────── */
.d-series-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent-light); color: var(--accent);
  border-radius: 3px; padding: 2px 8px;
}

/* ── Article header ──────────────────────────────────────────────────────── */
/*
 * Match the .l-body container width (body-w + gap + gutter-w = 932px) so the
 * header's left edge sits on the same x as the body's text column.
 * Children (title, subtitle, byline, TOC) are capped at body-w (680px) and
 * flow left-aligned inside the wider container.
 */
.d-header {
  max-width: calc(var(--body-w) + 32px + var(--gutter-w));
  margin: 0 auto;
  padding: 56px 0 52px;
  border-bottom: 1px solid var(--border);
}
.d-header > * { max-width: var(--body-w); }
.d-eyebrow {
  font-family: var(--sans); font-size: 12px; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 18px;
}
.d-title {
  font-family: var(--sans); font-size: clamp(1.9rem, 4vw, 2.7rem);
  font-weight: 700; letter-spacing: -0.025em; line-height: 1.2;
  color: #111; margin: 0 0 20px;
}
.d-subtitle {
  font-family: var(--serif); font-size: 1.1rem; font-weight: 300;
  color: var(--text-light); line-height: 1.75; max-width: 580px;
  margin-bottom: 28px;
}
.d-byline {
  font-family: var(--sans); font-size: 13px; color: var(--text-muted);
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
}
.d-byline a { color: var(--text-muted); text-decoration: underline; }
.d-byline .d-dot { opacity: 0.4; }
.d-byline-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.d-byline-tags .post-tag {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  background: var(--fig-bg); border: 1px solid var(--border);
  color: var(--text-light); border-radius: 3px; padding: 1px 7px;
  letter-spacing: 0.02em;
}
.d-byline .d-doi {
  font-family: var(--mono); font-size: 11px;
  background: var(--fig-bg); border: 1px solid var(--border);
  border-radius: 3px; padding: 2px 7px; color: var(--text-light);
}

/* ── Series TOC strip ────────────────────────────────────────────────────── */
.d-series-toc {
  background: var(--fig-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 16px 20px; margin: 36px 0 0;
  font-family: var(--sans); font-size: 13px;
}
.d-series-toc .d-series-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px;
}
.d-series-toc ol { margin: 0; padding: 0 0 0 20px; list-style: decimal; }
.d-series-toc li { padding: 2px 0; }
.d-series-toc li.current { font-weight: 700; color: var(--accent); }
.d-series-toc li.upcoming { color: var(--text-muted); font-style: italic; }
.d-series-toc a { color: var(--accent); text-decoration: none; }
.d-series-toc a:hover { text-decoration: underline; }

/* ── Article body — full width, children self-centre ────────────────────── */
.d-article {
  padding-bottom: 80px;
}
.d-article { counter-reset: section figure; }

/* ── Layout layers ───────────────────────────────────────────────────────── */

/*
 * l-body is a regular block formatting context wide enough for body + gutter.
 * Body content (paragraphs, headings, code, math) is capped at --body-w and
 * sits flush left; margin notes float into the right gutter (see below).
 * A grid layout is intentionally avoided: with grid, a tall aside grows the
 * shared row and pushes the next paragraph in column 1 down by the aside's
 * full height. Floats let column 1 keep flowing past the aside's bottom edge.
 */
.l-body {
  max-width: calc(var(--body-w) + 32px + var(--gutter-w));
  margin: 0 auto;
  display: flow-root;
}

.l-body > * {
  max-width: var(--body-w);
  min-width: 0;
}

/*
 * l-middle: figure left edge aligns with the body's text column,
 * and the figure expands to the right up to --mid-w (1100px).
 * margin-left = max(0, half-the-extra-page-width) puts the left edge
 * exactly where .l-body starts.
 */
.l-middle {
  max-width: var(--mid-w);
  margin-left: max(0px, calc((100% - var(--body-w) - 32px - var(--gutter-w)) / 2));
  margin-right: 0;
  padding: 0;
}
.l-page {
  max-width: 100%;
  padding: 0 32px;
}

/* ── Margin notes ────────────────────────────────────────────────────────── */

/*
 * Wide screen: each aside floats into the right gutter beside its preceding
 * paragraph. `clear: right` prevents two consecutive asides from overlapping
 * when they're both taller than the prose between them — the second one
 * starts below the first's bottom edge instead. The body column keeps
 * flowing without being pushed down: paragraphs are capped at --body-w, and
 * the float occupies only the right gutter, so column 1 is unaffected even
 * when the aside is taller than the paragraph beside it.
 */
.l-body { position: relative; }

.l-body > aside, .l-body > .marginnote {
  float: right;
  clear: right;
  width: var(--gutter-w);
  margin: 0 0 1em 32px;
  font-family: var(--sans); font-size: 12.5px; line-height: 1.6;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 14px;
}
.l-body > aside a, .l-body > .marginnote a { color: var(--accent); }

/* Narrow screen: collapse back into the flow below the paragraph */
@media (max-width: 900px) {
  .l-body > * { max-width: none; }
  .l-body > aside, .l-body > .marginnote {
    float: none;
    clear: none;
    display: block;
    width: auto;
    border-left: none;
    border-top: 2px solid var(--border);
    padding-left: 0;
    padding-top: 10px;
    margin: 12px 0;
  }
}

/* ── Typography ──────────────────────────────────────────────────────────── */
.d-article p {
  font-family: var(--serif); font-size: 1rem; line-height: 1.88;
  color: var(--text); margin: 0 0 18px;
}
.d-article h2 {
  font-family: var(--sans); font-size: 1.35rem; font-weight: 700;
  letter-spacing: -0.02em; color: #111;
  margin: 60px 0 20px; scroll-margin-top: 56px;
  border-top: 1px solid var(--border); padding-top: 0.2em;
}
/* The .d-header already draws a divider below the byline; the first h2
 * of the article body would otherwise repeat it, producing a double rule
 * with a tall empty band between the two lines. */
.d-article .l-body > h2:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 28px;
}
/* The "Related posts" section has its own .related top border; the inner
 * h2 must not repeat it, and the eyebrow-style sizing from site.css needs
 * to win over the generic .d-article h2 rule loaded above. */
.d-article .related h2 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-top: none;
  padding-top: 0;
  margin: 0 0 1rem;
}
/*
 * Section numbering is a distill-essay trait — an "1. Section, 2. Section"
 * counter that suits long-form articles. We restrict it to body.layout-distill
 * so regular posts (using post.html) don't suddenly get auto-numbered headings.
 */
body.layout-distill .d-article h2::before {
  content: counter(section) ". ";
  counter-increment: section;
  color: var(--text-muted); font-weight: 400;
}
.d-article h3 {
  font-family: var(--sans); font-size: 1.05rem; font-weight: 600;
  color: #222; margin: 32px 0 12px;
}
.d-article strong { font-weight: 700; }
.d-article em { font-style: italic; }
.d-article a {
  color: var(--accent); text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.d-article a:hover { text-decoration: underline; }

/* Lists */
.d-article ul, .d-article ol {
  font-family: var(--serif); font-size: 1rem; line-height: 1.85;
  color: var(--text); padding-left: 1.6em; margin-bottom: 1.2em;
}
.d-article li { margin-bottom: 0.35em; }

/* Blockquote */
.d-article blockquote {
  border-left: 3px solid var(--accent); margin: 1.5em 0;
  padding: 0.6em 1.2em; background: var(--accent-light);
  font-style: italic; color: var(--text-light);
  font-family: var(--serif); font-size: 0.95rem;
}

/*
 * Code blocks. Jekyll's rouge highlighter wraps the code as
 *   <div class="highlight"><pre class="highlight"><code>…</code></pre></div>
 * The outer .highlight div carries the dark panel (set in syntax.css), so
 * the inner <pre> must stay transparent and zero-margin — otherwise the
 * dark background, rounded corners and hairline border double up and the
 * block reads as two nested boxes.
 */
.d-article code {
  font-family: var(--mono); font-size: 0.82em;
  background: #f3f3f3; border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px;
}

/* Standalone <pre> (no .highlight wrapper, e.g. handwritten in markdown) */
.d-article pre {
  background: #1e2228; color: #abb2bf; border-radius: 6px;
  padding: 18px 20px; overflow-x: auto; margin: 1.5em 0;
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.6;
}

/* <pre> inside the .highlight wrapper — let the wrapper be the visual box */
.d-article .highlight {
  margin: 1.5em 0;
}
.d-article .highlight pre,
.d-article pre.highlight {
  background: transparent;
  border: 0;
  border-radius: 0;
  margin: 0;
}

.d-article pre code {
  background: none; border: none; padding: 0; font-size: inherit; color: inherit;
}

/* Tables — same look the old `.site-main table` rules used to provide,
   now scoped to .d-article so old posts (which previously lived inside
   `.site-main`) keep their look after migrating to the unified layout. */
.d-article table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-family: var(--sans);
  font-size: 0.9rem;
}
.d-article thead { border-bottom: 2px solid var(--border); }
.d-article th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 700;
  color: var(--text);
}
.d-article td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-light);
  font-family: var(--serif);
  font-size: 0.9rem;
  vertical-align: top;
}
.d-article tbody tr:last-child td { border-bottom: none; }

/*
 * Math display blocks. KaTeX over-reports width by a sub-pixel, which makes
 * `overflow-x: auto` create a scroll container even when the formula clearly
 * fits. `clip` prevents the scroll container without rendering a scrollbar.
 */
.d-article .MathJax_Display, .d-article .katex-display {
  margin: 1.4em 0;
  overflow-x: clip;
  max-width: 100%;
}

/* ── Figures ─────────────────────────────────────────────────────────────── */
.d-article figure {
  margin-top: 40px;
  margin-bottom: 64px;
  counter-increment: figure;
}

.fig-box {
  background: var(--fig-bg); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; position: relative;
}
.fig-box svg { display: block; width: 100%; }

figcaption {
  font-family: var(--sans); font-size: 13px; line-height: 1.55;
  color: var(--text-muted); margin-top: 12px; padding: 0 2px;
}
figcaption strong { color: var(--text-light); }

.figure-label::before {
  content: "Figure " counter(figure) ". ";
  font-weight: 700; color: var(--text-light);
}

/* Figure controls */
.fig-controls {
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  font-family: var(--sans); font-size: 13px; color: var(--text-muted);
  background: #fff;
}
.fig-controls label { display: flex; align-items: center; gap: 8px; }
.fig-controls input[type=range] { width: 160px; accent-color: var(--accent); }
.fig-controls select {
  border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 8px; font-size: 12.5px; background: #fff;
  font-family: var(--sans); color: var(--text-light);
}
.fig-controls .ctrl-val {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--fig-bg); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 6px; color: var(--accent);
}
.fig-toggle {
  padding: 4px 12px; border: 1px solid var(--border);
  border-radius: 4px; background: #fff; font-size: 12px;
  font-family: var(--sans); cursor: pointer; color: var(--text-muted);
  transition: all 0.15s;
}
.fig-toggle:hover, .fig-toggle.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Geodesic-type checkboxes (Figure 2) */
.fig-controls .v1-type {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-light);
  cursor: pointer; user-select: none;
}
.fig-controls .v1-type input[type=checkbox] {
  accent-color: var(--accent);
  margin: 0;
}
.fig-controls .v1-swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
}

/* ── Callout / theorem boxes ─────────────────────────────────────────────── */
.callout {
  background: var(--accent-light); border-left: 4px solid var(--accent);
  border-radius: 0 6px 6px 0; padding: 14px 18px; margin: 1.8em 0;
  font-family: var(--sans); font-size: 14px; line-height: 1.65; color: #1a237e;
}
.callout.theorem { background: #fff8e1; border-color: var(--accent-warm); color: #4e342e; }
.callout.open-problem { background: #fce4ec; border-color: #c62828; color: #4a0000; }
.callout-title {
  font-weight: 700; letter-spacing: 0.04em; margin-bottom: 4px;
  text-transform: uppercase; font-size: 11px; opacity: 0.7;
}

/* ── References ──────────────────────────────────────────────────────────── */
.d-references {
  border-top: 1px solid var(--border);
  margin-top: 60px; padding-top: 24px;
  font-family: var(--sans); font-size: 0.875rem; line-height: 1.7;
  color: var(--text-muted);
}
.d-references h2 {
  font-size: 1rem; border-top: none; margin-top: 0; padding-top: 0;
  color: var(--text-muted); letter-spacing: 0.08em; text-transform: uppercase;
}
.d-references h2::before { content: none; }
.d-references ol { padding-left: 1.4em; }
.d-references li { margin-bottom: 0.5em; }
.d-references a { color: var(--accent); }

/* ── Series navigation ───────────────────────────────────────────────────── */
.d-series-nav {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 20px; padding: 28px 0 0; margin-top: 48px;
  border-top: 1px solid var(--border);
  font-family: var(--sans); font-size: 13px;
}
.d-series-nav a {
  color: var(--accent); text-decoration: none;
  display: flex; flex-direction: column; gap: 4px; max-width: 280px;
}
.d-series-nav a:hover .d-nav-title { text-decoration: underline; }
.d-nav-label { color: var(--text-muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.d-nav-title { font-weight: 600; color: var(--text); line-height: 1.3; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.d-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  font-family: var(--sans); font-size: 13px; color: var(--text-muted);
  display: flex; gap: 16px; flex-wrap: wrap;
  max-width: calc(var(--body-w) + 32px + var(--gutter-w));
  margin: 0 auto;
}
.d-footer a { color: var(--text-muted); text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .d-article { padding-bottom: 60px; }
  .d-header { padding: 40px 20px 36px; }
  .d-footer { padding: 20px; }
  .l-body, .l-middle, .l-page { padding: 0 20px; }
}
@media (max-width: 560px) {
  .d-title { font-size: 1.6rem; }
  .l-middle { overflow-x: auto; }
}
