/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-body: 'Source Serif 4', 'Georgia', serif;
  --font-heading: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --c-bg: #ffffff;
  --c-surface: #f8f9fa;
  --c-border: #e1e4e8;
  --c-text: #1a1a2e;
  --c-text-secondary: #586069;
  --c-accent: #2563eb;
  --c-accent-light: #eef2ff;
  --c-heading: #0f172a;
  --c-code-bg: #f1f3f5;
  --c-table-header: #f0f3f6;

  --content-width: min(80%, 1000px);
  --gap: 1.6rem;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:ital,wght@0,400;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

html { font-size: 17px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--c-accent);
  text-decoration: none;
  letter-spacing: 0.04em;
}

.site-nav { display: flex; gap: 1.4rem; }
.site-nav a {
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--c-text-secondary);
  text-decoration: none;
  transition: color 0.15s;
}
.site-nav a:hover { color: var(--c-accent); }

/* ── Page Content ── */
.page-content {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ── Post Header ── */
.post-header { margin-bottom: 2.5rem; }

.post-title {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--c-heading);
  margin-bottom: 0.4rem;
}

.post-subtitle {
  font-size: 1.15rem;
  color: var(--c-text-secondary);
  font-style: italic;
  margin-bottom: 1rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  color: var(--c-text-secondary);
}

.meta-authors { font-weight: 600; color: var(--c-text); }
.meta-equal::before { content: "· "; }
.meta-affiliation::before { content: "· "; }
.meta-date::before { content: "· "; }

/* ── TL;DR ── */
.tldr {
  background: var(--c-accent-light);
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  margin-bottom: 2.5rem;
}

.tldr summary {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--c-accent);
  cursor: pointer;
  letter-spacing: 0.02em;
}

.tldr summary::marker {
  color: var(--c-accent);
}

.tldr-content {
  margin-top: 0.6rem;
  font-size: 0.92rem;
  line-height: 1.65;
}

.tldr-content ul {
  margin: 0.4rem 0 0 1.4rem;
  padding: 0;
}

.tldr-content li {
  margin-bottom: 0.3rem;
}

.tldr-content strong {
  color: var(--c-heading);
}

/* ── Post Body ── */
.post-body h1, .post-body h2, .post-body h3, .post-body h4 {
  font-family: var(--font-heading);
  color: var(--c-heading);
  margin-top: 2.4rem;
  margin-bottom: 0.8rem;
}

.post-body h1 { font-size: 1.7rem; padding-bottom: 0.3rem; border-bottom: 2px solid var(--c-border); }
.post-body h2 { font-size: 1.4rem; }
.post-body h3 { font-size: 1.15rem; }

.post-body p { margin-bottom: 1.1rem; }

.post-body a {
  color: var(--c-accent);
  text-decoration: underline;
  text-decoration-color: rgba(37, 99, 235, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}
.post-body a:hover { text-decoration-color: var(--c-accent); }

.post-body strong { font-weight: 700; color: var(--c-heading); }
.post-body em { font-style: italic; }

/* ── Lists ── */
.post-body ul, .post-body ol {
  margin: 0.6rem 0 1.2rem 1.6rem;
}

.post-body li { margin-bottom: 0.35rem; }
.post-body li::marker { color: var(--c-text-secondary); }

/* ── Code ── */
.post-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--c-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.post-body pre {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 1.2rem 0;
  line-height: 1.55;
}

.post-body pre code {
  background: none;
  padding: 0;
  font-size: 0.84rem;
}

/* ── Tables ── */
.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4rem 0;
  font-size: 0.92rem;
}

.post-body thead th {
  font-family: var(--font-heading);
  font-weight: 600;
  background: var(--c-table-header);
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 2px solid var(--c-border);
  font-size: 0.85rem;
  color: var(--c-heading);
}

.post-body tbody td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--c-border);
}

.post-body tbody tr:last-child td { border-bottom: none; }
.post-body tbody tr:hover { background: var(--c-surface); }

/* ── Async inference timeline viz ── */
.async-viz {
  --av-dur: 8s;
  margin: 1.8rem 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 1.2rem 1rem 0;
  overflow: hidden;
}

.av-legend {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.72rem;
  font-family: var(--font-heading);
}
.av-speed-control {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
}
.av-speed-label { font-size: 0.85rem; }
#avSpeed {
  -webkit-appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  background: var(--c-border);
  outline: none;
  cursor: pointer;
}
#avSpeed::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c-accent);
  cursor: pointer;
}
#avSpeed::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c-accent);
  cursor: pointer;
  border: none;
}
.av-toggle-btn {
  background: none;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1;
  color: var(--c-text);
}
.av-toggle-btn:hover { background: var(--c-surface); }
.av-caption {
  margin: 0.9rem 0 0 0;
  font-size: 0.82rem;
  color: var(--c-text-secondary);
  line-height: 1.55;
  border-top: 1px solid var(--c-border);
  padding: 1.2rem 1rem 0;
}
.av-leg-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}
.av-leg-exec  { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.av-leg-stall { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.av-leg-infer { background: #e0e7ff; color: #3730a3; border: 1px solid #a5b4fc; }
.av-leg-wm    { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }

.av-row {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}
.av-row:last-child { margin-bottom: 0; }

.av-label {
  width: 110px;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--c-text-secondary);
  padding-top: 7px;
  text-align: right;
}
.av-label-sync { color: var(--c-text-secondary); }
.av-label-bad  { color: #dc2626; }
.av-label-good { color: #16a34a; }

.av-track {
  flex: 1;
  position: relative;
  height: 60px;
}

.av-playhead {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: var(--c-heading);
  border-radius: 1px;
  opacity: 0;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 0 4px rgba(0,0,0,0.25);
}

.av-block {
  position: absolute;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  font-family: var(--font-heading);
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: visible;
  padding: 0 4px;
  opacity: 0;
  clip-path: inset(0 100% 0 0);
}

/* Execution: top layer — all exec variants share top/height */
.av-exec,
.av-exec-warn,
.av-exec-good {
  top: 2px;
  height: 30px;
}
.av-exec {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}
.av-exec-warn {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}
.av-exec-good {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

/* Stall: top layer, pulsing */
.av-stall {
  top: 2px;
  height: 30px;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}
.av-stall.av-pulsing {
  animation: av-stall-pulse 0.7s ease-in-out infinite;
}
@keyframes av-stall-pulse {
  0%, 100% { background: #fee2e2; color: #991b1b; transform: scaleY(1);    }
  50%       { background: #ef4444; color: #fff;    transform: scaleY(1.1); }
}

/* Inference: bottom layer */
.av-infer {
  bottom: 2px;
  height: 20px;
  background: #e0e7ff;
  color: #3730a3;
  border: 1px solid #a5b4fc;
  font-size: 0.62rem;
}

/* World model: exec-layer height, gold */
.av-wm {
  top: 2px;
  height: 56px;   /* spans full track: exec + gap + infer */
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  font-size: 0.6rem;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.02em;
  z-index: 2;
}
.av-wm.av-pulsing {
  animation: av-wm-pulse 0.8s ease-in-out infinite;
}
@keyframes av-wm-pulse {
  0%, 100% { background: #fef9c3; border-color: #fde047; transform: scaleY(1);    color: #854d0e; }
  50%       { background: #eab308; border-color: #ca8a04; transform: scaleY(1.15); color: #fff;    }
}

/* ── Dual side-by-side charts ── */
.dual-chart-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.dual-chart-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--c-heading);
  text-align: center;
  margin-bottom: 0.5rem;
}
.dual-chart-item {
  position: relative;
  height: 280px;
}
.dual-chart-item canvas {
  width: 100% !important;
  height: 100% !important;
}
@media (max-width: 640px) {
  .dual-chart-wrap { grid-template-columns: 1fr; }
}

/* ── Video column labels ── */
.video-col-labels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  margin-bottom: 0.3rem;
}

/* ── Comparison table ── */
.comparison-table thead th { text-align: center; }
.comparison-table thead th:first-child { text-align: left; }
.comparison-table td { text-align: center; }
.comparison-table td:first-child { text-align: left; font-weight: 500; }
.comparison-table td.yes  { color: #16a34a; font-weight: 600; }
.comparison-table td.no   { color: #dc2626; font-weight: 600; }
.comparison-table td.na   { color: var(--c-text-secondary); }
.comparison-table tr.ours-row td {
  background: #f0fdf4;
  border-top: 2px solid #16a34a;
}

/* ── Blockquotes ── */
.post-body blockquote {
  border-left: 3px solid var(--c-accent);
  padding: 0.6rem 1.2rem;
  margin: 1.2rem 0;
  background: var(--c-accent-light);
  border-radius: 0 6px 6px 0;
  color: var(--c-text);
}

.post-body blockquote p { margin-bottom: 0.4rem; }
.post-body blockquote p:last-child { margin-bottom: 0; }

.note-quote blockquote {
  border-left-color: #d97706;
  background: #fffbeb;
}

/* ── Images & Figures ── */
.post-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1rem 0;
}

.post-body .figure {
  margin: 1.8rem 0;
  text-align: center;
}

.post-body .figure img {
  max-width: 90%;
}

.post-body .figure .caption,
.post-body .caption {
  font-family: var(--font-heading);
  font-size: 0.82rem;
  color: var(--c-text-secondary);
  margin-top: 0.5rem;
  font-style: italic;
}

/* ── Custom callout boxes ── */
.callout {
  padding: 1rem 1.2rem;
  border-radius: 8px;
  margin: 1.4rem 0;
  font-size: 0.94rem;
}

.callout-insight {
  background: #eef2ff;
  border-left: 4px solid #2563eb;
}

.callout-warning {
  background: #fefce8;
  border-left: 4px solid #ca8a04;
}

/* ── Math ── */
.katex-display { margin: 1.4rem 0; overflow-x: auto; }

/* ── Horizontal rules ── */
.post-body hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 2rem 0;
}

/* ── References section ── */
.references {
  font-size: 0.88rem;
  line-height: 1.6;
}

.references ol { padding-left: 1.6rem; }
.references li { margin-bottom: 0.5rem; color: var(--c-text-secondary); }

/* ── Footer ── */
.site-footer {
  border-top: 1px solid var(--c-border);
  margin-top: 3rem;
}

.footer-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.5rem;
  text-align: center;
  font-family: var(--font-heading);
  font-size: 0.82rem;
  color: var(--c-text-secondary);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  html { font-size: 16px; }
  .post-title { font-size: 1.7rem; }
  .site-nav { gap: 0.8rem; }
  .site-nav a { font-size: 0.75rem; }
  .post-body table { font-size: 0.8rem; }
  .post-body thead th, .post-body tbody td { padding: 0.4rem 0.5rem; }
}
