/* ==========================================================================
   Project page components (load after site.css)
   ========================================================================== */

.progress { position: fixed; top: 0; left: 0; height: 4px; width: 0; z-index: 200; background: var(--accent-ink); }

/* ── Hero ─────────────────────────────────────────────────────────────── */
.p-hero { padding: 48px 0 26px; text-align: center; position: relative; }
.p-hero::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: calc(50% - 50vw); right: calc(50% - 50vw); z-index: -1;
  background:
    radial-gradient(600px 240px at 50% 0%, var(--accent-soft), transparent 70%),
    linear-gradient(var(--bg), var(--bg));
}
.p-kicker { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.p-title { font-size: clamp(28px, 4.2vw, 44px); font-weight: 900; letter-spacing: -.02em; line-height: 1.15; max-width: 900px; margin: 0 auto; }
.p-title .accent { color: var(--accent); }
.p-subtitle { font-size: 18px; color: var(--ink-2); margin: 12px auto 0; max-width: 760px; }
.p-authors { margin: 18px auto 2px; font-size: 17px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; }
.p-authors a { color: var(--ink); font-weight: 700; }
.p-authors a:hover { color: var(--accent-ink); }
.p-authors sup { color: var(--ink-3); font-weight: 400; }
.p-affil { color: var(--ink-3); font-size: 14.5px; }
.p-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 20px 0 0; }
.p-buttons .pill { font-size: 14.5px; padding: 8px 18px; }
.p-buttons .pill.disabled { opacity: .55; pointer-events: none; border-style: dashed; }

.p-teaser {
  margin: 30px auto 0; max-width: 980px; background: #fff; border-radius: 16px;
  border: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 14px; cursor: zoom-in;
}
.p-teaser img { display: block; width: 100%; border-radius: 8px; }
.p-teaser-cap { font-size: 14px; color: var(--ink-3); margin-top: 10px; text-align: center; }

/* ── Layout with sticky TOC ───────────────────────────────────────────── */
.p-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 44px; margin-top: 30px; }
.toc { position: sticky; top: 84px; align-self: start; font-size: 13.5px; }
.toc-title { font: 500 11px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.toc a { display: block; padding: 5px 0 5px 14px; margin-left: -2px; border-left: 2px solid transparent; color: var(--ink-3); line-height: 1.35; }
.toc a:hover { color: var(--accent-ink); text-decoration: none; }
.toc a.active { color: var(--accent-ink); border-left-color: var(--accent); font-weight: 700; }
.toc .back { display: inline-flex; gap: 6px; align-items: center; margin-top: 18px; font-weight: 700; }

.p-content { min-width: 0; max-width: 820px; }
.p-section { padding: 18px 0 26px; }
.p-section + .p-section { border-top: 1px solid var(--line); }
.p-section h2 { font-size: 26px; font-weight: 900; letter-spacing: -.01em; margin-bottom: 12px; }
.p-section h2 .num { font: 500 13px var(--mono); color: var(--accent-ink); display: block; letter-spacing: .1em; margin-bottom: 4px; }
.p-section h3 { font-size: 18px; margin: 20px 0 8px; }
.p-section p { color: var(--ink-2); margin: 0 0 14px; }
.p-section p strong, .p-section li strong { color: var(--ink); }
.p-section ul.bullets { padding-left: 20px; color: var(--ink-2); }
.p-section ul.bullets li { margin-bottom: 6px; }

@media (max-width: 900px) {
  .p-layout { grid-template-columns: 1fr; gap: 0; }
  .toc { display: none; }
}

/* ── TL;DR and stats ─────────────────────────────────────────────────── */
.tldr {
  position: relative; padding: 18px 20px 18px 22px; margin: 4px 0 22px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--ink); font-size: 16.5px; line-height: 1.6;
}
.tldr::before { content: 'TL;DR'; display: block; font: 500 11px var(--mono); letter-spacing: .16em; color: var(--accent-ink); margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 8px 0 22px; }
.stat { padding: 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.stat-num { font-size: 30px; font-weight: 900; color: var(--accent-ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--ink-3); margin-top: 4px; line-height: 1.35; }

/* ── Figures and lightbox ────────────────────────────────────────────── */
.fig { margin: 18px 0 24px; }
.fig-frame {
  background: #fff; border-radius: 12px; border: 1px solid var(--line); padding: 12px;
  cursor: zoom-in; transition: box-shadow .2s, transform .2s; position: relative;
}
.fig-frame:hover { box-shadow: var(--shadow-lg); }
.fig-frame::after {
  content: '\f00e'; font-family: 'Font Awesome 6 Free'; font-weight: 900; position: absolute; right: 12px; top: 12px;
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(29, 35, 48, .72); color: #fff; font-size: 12px; opacity: 0; transition: opacity .2s;
}
.fig-frame:hover::after { opacity: 1; }
.fig-frame img { display: block; width: 100%; height: auto; border-radius: 6px; }
.fig figcaption { font-size: 14px; color: var(--ink-3); margin-top: 10px; line-height: 1.55; }
.fig figcaption b { color: var(--ink); }
.fig.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.fig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .fig-row { grid-template-columns: 1fr; } }

.lightbox {
  position: fixed; inset: 0; z-index: 500; display: none; align-items: center; justify-content: center;
  background: rgba(10, 14, 22, .86); padding: 30px; cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox-close {
  position: absolute; top: 16px; right: 18px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; cursor: pointer;
}

/* ── Tabs ───────────────────────────────────────────────────────────── */
.tabs { margin: 16px 0 24px; }
.tab-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab {
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--bg);
  color: var(--ink-2); font: 700 13.5px var(--font); cursor: pointer; transition: all .15s;
}
.tab:hover { border-color: var(--accent); color: var(--accent-ink); }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab-panel[hidden] { display: none; }
.tab-panel { animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ── Charts ─────────────────────────────────────────────────────────── */
.chart-card { margin: 16px 0 24px; padding: 18px 18px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.chart-title { font-weight: 900; font-size: 15.5px; }
.chart-sub { font-size: 13px; color: var(--ink-3); }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 999px; padding: 2px; background: var(--bg); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font: 700 12.5px var(--font); color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 10px; }
.chart-legend label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chart-legend input { accent-color: var(--accent); }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.bars { position: relative; margin-top: 24px; }
.bar-row { display: grid; grid-template-columns: 210px 1fr 58px; align-items: center; gap: 10px; height: 26px; font-size: 12.5px; }
.bar-row .lbl { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.bar-row .track { position: relative; height: 16px; }
.bar-row .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px 5px 5px 3px; transition: width .7s cubic-bezier(.2,.8,.2,1); }
.bar-row .val { font: 500 12px var(--mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bar-row.hl .lbl { color: var(--ink); font-weight: 700; }
.bar-row:hover .fill { filter: brightness(1.1); }
.bar-row.dim { opacity: .35; }
.ref-line { position: absolute; top: -6px; bottom: -6px; width: 0; border-left: 2px dashed var(--ink-3); pointer-events: none; transition: left .7s; }
.ref-line span { position: absolute; top: -18px; right: 4px; font: 500 11px var(--mono); color: var(--ink-3); white-space: nowrap; }
.chart-note { font-size: 12.5px; color: var(--ink-3); margin-top: 10px; }
@media (max-width: 640px) { .bar-row { grid-template-columns: 120px 1fr 48px; } }

/* Before/after comparison */
.compare { display: grid; gap: 10px; }
.compare-row { display: grid; grid-template-columns: 170px 1fr; gap: 12px; align-items: center; font-size: 13.5px; }
.compare-row .name { color: var(--ink-2); text-align: right; }
.stack { display: flex; height: 30px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.stack div { display: flex; align-items: center; justify-content: center; color: #fff; font: 700 11.5px var(--mono); transition: width .7s cubic-bezier(.2,.8,.2,1); white-space: nowrap; overflow: hidden; }

/* ── Odd-one-out demo ───────────────────────────────────────────────── */
.ooo { margin: 16px 0 26px; padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.ooo-prompt { font-weight: 900; font-size: 16px; margin-bottom: 4px; }
.ooo-hint { font-size: 13.5px; color: var(--ink-3); margin-bottom: 12px; }
.ooo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ooo-item {
  position: relative; border-radius: 10px; overflow: hidden; border: 3px solid transparent; cursor: pointer; background: #000;
  transition: border-color .2s, transform .2s; padding: 0;
}
.ooo-item:hover { transform: translateY(-2px); border-color: var(--accent-line); }
.ooo-item video { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.ooo-item .tag {
  position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 999px;
  font: 700 11px var(--font); background: rgba(0,0,0,.6); color: #fff;
}
.ooo-item.odd { border-color: #e07a5f; }
.ooo-item.odd .tag { background: #e07a5f; }
.ooo-item.sim { border-color: #3d9970; }
.ooo-item.sim .tag { background: #3d9970; }
.ooo-result { margin-top: 12px; font-size: 14px; color: var(--ink-2); min-height: 44px; }
.ooo-result b { color: var(--ink); }
.ooo-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.ooo-count { font: 500 12px var(--mono); color: var(--ink-3); }
@media (max-width: 560px) { .ooo-grid { grid-template-columns: 1fr 1fr; } }

/* ── Chips (clickable explanations) ─────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.chip {
  padding: 6px 13px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--bg);
  color: var(--ink-2); font: 700 13px var(--font); cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--c, var(--accent)); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--c, var(--accent)); border-color: var(--c, var(--accent)); color: #fff; }
.chip-panel { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14.5px; color: var(--ink-2); min-height: 70px; }
.chip-panel b { color: var(--ink); }

/* ── Callout / key findings ─────────────────────────────────────────── */
.findings { display: grid; gap: 10px; margin: 10px 0 20px; counter-reset: f; }
.finding {
  display: grid; grid-template-columns: 34px 1fr; gap: 12px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); font-size: 15px; color: var(--ink-2);
}
.finding::before {
  counter-increment: f; content: counter(f); width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 900; font-size: 14px;
}
.finding b { color: var(--ink); }

.callout { padding: 14px 16px; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; font-size: 14.5px; color: var(--ink-2); margin: 10px 0 18px; }

/* ── BibTeX ─────────────────────────────────────────────────────────── */
.bibtex { position: relative; }
.bibtex pre {
  margin: 0; padding: 18px 20px; border-radius: 12px; overflow-x: auto; background: #0f1624; color: #d7e3f4;
  font: 500 13px/1.6 var(--mono); border: 1px solid var(--line);
}
.copy-btn {
  position: absolute; top: 10px; right: 10px; padding: 6px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08); color: #fff; font: 700 12.5px var(--font); cursor: pointer;
}
.copy-btn:hover { background: rgba(255,255,255,.18); }

/* ── Share + neighbours ─────────────────────────────────────────────── */
.share { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 14px; font-size: 13px; color: var(--ink-3); }
.share a { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.share a:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); text-decoration: none; }
.neighbours { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 30px; }
.neighbours a { display: block; padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--line); color: var(--ink); font-weight: 900; font-size: 15px; transition: border-color .2s, transform .2s; }
.neighbours a:hover { border-color: var(--accent); transform: translateY(-2px); text-decoration: none; }
.neighbours small { display: block; font: 500 11px var(--mono); color: var(--ink-3); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 3px; }
.neighbours a.next { text-align: right; }
@media (max-width: 560px) { .neighbours { grid-template-columns: 1fr; } .neighbours a.next { text-align: left; } }

/* Math */
mjx-container { color: var(--ink); }

/* ── Scroll-driven story ─────────────────────────────────────────────
   <section class="story"> <div class="story-steps"> .story-step[data-step] …
   </div> <div class="story-stage"> .stage-panel[data-step] … </div> </section>
   On narrow screens JS moves each panel under its step. */
.story { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 36px; margin: 10px 0 30px; }
.story-steps { padding: 10vh 0 30vh; }
.story-step {
  min-height: 62vh; display: flex; flex-direction: column; justify-content: center;
  opacity: .35; transition: opacity .35s;
}
.story-step.active { opacity: 1; }
.story-step .kicker { font: 500 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); margin-bottom: 6px; }
.story-step h3 { font-size: 22px; font-weight: 900; margin: 0 0 8px; }
.story-step p { color: var(--ink-2); margin: 0 0 10px; }
.story-step p strong { color: var(--ink); }
.story-stage { position: sticky; top: max(84px, calc(50vh - 290px)); align-self: start; height: min(580px, calc(100vh - 110px)); min-height: 420px; }
.stage-panel {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
  padding: 22px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
  opacity: 0; transform: translateY(10px) scale(.985); pointer-events: none; transition: opacity .45s, transform .45s;
}
.stage-panel.active { opacity: 1; transform: none; pointer-events: auto; }
.stage-title { font-weight: 900; font-size: 15px; margin-bottom: 4px; }
.stage-sub { font-size: 12.5px; color: var(--ink-3); margin-bottom: 14px; }
.stage-panel .fig-frame { cursor: zoom-in; }
.stage-panel img { max-height: 60vh; object-fit: contain; }

/* mini bars inside story panels: widths animate in when the panel becomes active */
.mbars { display: grid; gap: 9px; }
.mbar { display: grid; grid-template-columns: 150px 1fr 52px; gap: 10px; align-items: center; font-size: 13px; }
.mbar .lbl { color: var(--ink-2); text-align: right; }
.mbar.hl .lbl { color: var(--ink); font-weight: 700; }
.mbar .trk { position: relative; height: 18px; background: var(--surface-2); border-radius: 5px; overflow: visible; }
.mbar .fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 5px; transition: width .9s cubic-bezier(.2,.8,.2,1); }
.stage-panel.active .mbar .fill, .inline-panel .mbar .fill { width: var(--w); }
.mbar .val { font: 500 12px var(--mono); color: var(--ink-2); }
.mbars .ceil { position: absolute; top: -6px; bottom: -6px; border-left: 2px dashed var(--ink-3); }
.mbars-wrap { position: relative; }
.mbars-note { font-size: 12px; color: var(--ink-3); margin-top: 12px; }

@media (max-width: 900px) {
  .story { grid-template-columns: 1fr; gap: 0; }
  .story-steps { padding: 0; }
  .story-step { min-height: 0; opacity: 1; padding: 18px 0 8px; }
  .story-stage { display: none; }
  .stage-panel.inline-panel { position: relative; inset: auto; opacity: 1; transform: none; pointer-events: auto; margin-top: 10px; }
}

/* ── Before/after wipe slider ──────────────────────────────────────── */
.wipe { position: relative; overflow: hidden; border-radius: 12px; background: #000; user-select: none; touch-action: pan-y; aspect-ratio: 1 / 1; }
.wipe img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.wipe .top { clip-path: inset(0 0 0 var(--pos, 50%)); }
.wipe .handle { position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 8px rgba(0,0,0,.5); pointer-events: none; }
.wipe .handle::after {
  content: '\f337'; font-family: 'Font Awesome 6 Free'; font-weight: 900; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #1d2330; display: flex; align-items: center; justify-content: center; font-size: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.wipe .tag { position: absolute; top: 10px; padding: 3px 10px; border-radius: 999px; font: 700 11.5px var(--font); color: #fff; background: rgba(0,0,0,.6); pointer-events: none; }
.wipe .tag.l { left: 10px; } .wipe .tag.r { right: 10px; background: var(--accent); }
.wipe input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.thumb-btn { position: relative; width: 70px; height: 70px; padding: 0; border-radius: 9px; overflow: hidden; border: 2.5px solid transparent; cursor: pointer; background: #000; }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .75; transition: opacity .15s; }
.thumb-btn:hover img, .thumb-btn[aria-pressed="true"] img { opacity: 1; }
.thumb-btn[aria-pressed="true"] { border-color: var(--accent); }
.thumb-btn span { position: absolute; left: 4px; bottom: 3px; font: 700 10px var(--mono); color: #fff; text-shadow: 0 1px 3px #000; }

/* ── Picker card ───────────────────────────────────────────────────── */
.picker { margin: 16px 0 24px; padding: 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.picker-metric { padding: 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.picker-metric .name { font: 500 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.picker-metric .nums { font-size: 26px; font-weight: 900; color: var(--ink); margin: 4px 0 8px; font-variant-numeric: tabular-nums; }
.picker-metric .nums .arrow { color: var(--ink-3); font-weight: 400; margin: 0 6px; }
.picker-metric .nums .after { color: var(--accent-ink); }
.picker-metric .delta { font: 700 12.5px var(--mono); }
.picker-metric .delta.up { color: #2f7d5a; } .picker-metric .delta.down { color: #c0573d; }
[data-theme="dark"] .picker-metric .delta.up { color: #6fcf9f; } [data-theme="dark"] .picker-metric .delta.down { color: #f09a82; }
.pbar { position: relative; height: 14px; border-radius: 5px; background: var(--surface-2); margin-top: 6px; }
.pbar .seg-before, .pbar .seg-after { position: absolute; inset: 0 auto 0 0; border-radius: 5px; transition: width .7s cubic-bezier(.2,.8,.2,1); }
.pbar .seg-before { background: #8a94a6; z-index: 2; height: 6px; top: 4px; }
.pbar .seg-after { background: var(--accent); z-index: 1; }
.pbar .mark { position: absolute; top: -5px; bottom: -5px; border-left: 2px dashed; z-index: 3; transition: left .7s; }
.pbar-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11.5px; color: var(--ink-3); margin-top: 8px; }
.pbar-legend i { display: inline-block; width: 14px; height: 0; border-top: 2px dashed; vertical-align: middle; margin-right: 4px; }
.picker-desc { font-size: 14px; color: var(--ink-2); margin-top: 12px; }
@media (max-width: 640px) { .picker-grid { grid-template-columns: 1fr; } }
