*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 4rem; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text);
  line-height: var(--lh);
  overflow-x: hidden;
}
a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 20; }
.skip:focus { left: 0; }

/* Navigation */
.nav {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: var(--w-wide); margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex; align-items: center; gap: 0.75rem;
  height: 3rem;
}
.brand { font-weight: 650; color: var(--ink); text-decoration: none; flex: none; }
.nav-links {
  flex: 1; min-width: 0;
  display: flex; gap: 0.25rem; overflow-x: auto;
  scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  flex: none; padding: 0.25rem 0.6rem; border-radius: 999px;
  color: var(--ink-2); text-decoration: none; font-size: var(--text-s);
}
.nav-links a:hover { color: var(--ink); background: var(--surface-2); }
.nav-links a[aria-current] { color: var(--ink); background: var(--accent-soft); }
.theme-btn {
  flex: none; width: 28px; height: 28px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); background: var(--surface);
  border: 1px solid var(--line-strong); cursor: pointer;
}
.theme-btn:hover { background: var(--surface-2); }
.theme-btn svg { display: block; }

/* Hero */
.hero { padding: 3.5rem 0 2.5rem; border-bottom: 1px solid var(--line); }
.hero-inner { max-width: var(--w-wide); margin: 0 auto; padding: 0 var(--gutter); }
.hero-inner { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 2.5rem; align-items: center; }
.hero-fig { min-height: 482px; min-width: 0; align-self: center; }
.hero-fig .widget { min-height: 482px; }
.hero-fig.is-empty { display: none; }
.hero-fig .widget.w-hero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; box-sizing: border-box; }
@media (min-width: 761px) { .hero-inner.has-empty, .hero-inner:has(.is-empty) { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .hero-inner { grid-template-columns: minmax(0, 1fr); gap: 1.75rem; } .hero-fig { min-height: 0; } .hero-fig .widget { min-height: 0; } }
@media (max-width: 640px) { .hero-fig .widget.w-hero { padding: 0.875rem; } }
.hero h1 {
  font-family: var(--font-serif); font-weight: 600;
  font-size: clamp(1.8rem, 4.6vw, 2.5rem); line-height: 1.15;
  margin: 0 0 1.5rem; text-wrap: balance;
}
.authors { list-style: none; padding: 0; margin: 0 0 0.75rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }
.authors a { color: var(--ink); text-decoration-color: var(--line-strong); }
.authors a:hover { color: var(--accent); }
.authors sup, .affils sup { font-size: max(11px, 0.7em); color: var(--ink-3); margin-left: 1px; }
.affils { margin: 0 0 1.75rem; color: var(--ink-2); font-size: var(--text-xs); display: flex; flex-wrap: wrap; gap: 0.1rem 1rem; }
.affils sup { margin: 0 2px 0 0; }
.buttons { margin: 0; display: flex; flex-wrap: wrap; gap: 0.6rem; }
.btn {
  display: inline-block; padding: 0.45rem 0.9rem; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--ink);
  background: transparent; text-decoration: none; font-size: var(--text-s); font-weight: 550;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

/* Layout */
.prose { max-width: var(--w-wide); margin: 0 auto; padding: 0 var(--gutter); }
.wide { max-width: var(--w-wide); margin: 1.75rem auto; padding: 0 var(--gutter); }
.sec { padding: 3.5rem 0 1rem; }
.sec + .sec { border-top: 1px solid var(--line); margin-top: 2.5rem; }
h2 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 1rem; font-weight: 650; }
p { margin: 0 0 1rem; }
.eq { overflow-x: auto; overflow-y: hidden; margin: 0.5rem 0 1rem; padding-bottom: 0.4rem; max-width: 100%; }
/* Text blocks keep a 42rem measure, flush with the left edge of the wide figures. Placed after .eq so equations share it. */
.prose > * { max-width: calc(var(--w-prose) - 2 * var(--gutter)); }
.katex-display { margin: 0.4rem 0; }
.steps { padding-left: 1.4rem; margin: 0 0 1rem; }
.steps li { margin-bottom: 0.3rem; }
.try { margin-bottom: 1.25rem; }

/* Boxes */
.tldr, .finding {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  padding: 0.9rem 1.1rem;
  margin: 1.25rem 0;
}
.tldr { margin-top: 2rem; }
.tldr h2 { font-size: var(--text); margin: 0 0 0.4rem; }
.tldr ul { margin: 0; padding-left: 1.2rem; }
.tldr li { margin-bottom: 0.4rem; }
.tldr li:last-child { margin-bottom: 0; }
.finding p { margin: 0; }

/* Widgets */
/* reserved heights: see end of file */
.widget-error { margin: 0; color: var(--ink-2); }
@media (max-width: 640px) { .wide { padding: 0 0.5rem; } }

/* Demo card */
.demo-card {
  display: grid; grid-template-columns: 62fr 38fr; gap: 2rem; align-items: center;
}
.demo-shot { display: block; }
.demo-shot img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.demo-shot:hover img { border-color: var(--accent); }
.demo-text h2 { margin-top: 0; }
.demo-text p { color: var(--ink-2); }
.demo-text p:last-child { margin-bottom: 0; }
@media (max-width: 760px) { .demo-card { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; } }

/* BibTeX */
.bib { position: relative; }
.bib pre {
  margin: 0; padding: 1rem; padding-top: 2.6rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  overflow-x: auto; font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.5;
}
.copy-btn {
  position: absolute; top: 0.5rem; right: 0.5rem;
  font: inherit; font-size: var(--text-xs); cursor: pointer;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 0.15rem 0.8rem;
}
.copy-btn:hover { background: var(--accent-soft); }

main > .sec:last-child { padding-bottom: 4rem; }

@media (max-width: 640px) {
  .hero { padding-top: 2.25rem; }
  .sec { padding-top: 2.5rem; }
  h2 { font-size: 1.4rem; }
  .nav-inner { gap: 0.4rem; }
}

.insym { font-size: var(--text); margin: 1.75rem 0 0.5rem; font-weight: 650; }
.guarantee { border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); padding: 0.9rem 1.1rem; margin: 1.25rem 0; }
.guarantee h3 { font-size: var(--text); margin: 0 0 0.5rem; }
.guarantee p:last-child { margin-bottom: 0; }
.notfound { padding: 4rem var(--gutter); }

@media (pointer: coarse) {
  .theme-btn { width: 44px; height: 44px; }
  .btn, .nav-links a, .copy-btn, .brand { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .brand { justify-content: flex-start; }
  .authors a { display: inline-block; padding: 0.6rem 0; }
  .nav-inner { height: 3.25rem; }
}

/* Reserved heights until a widget has mounted (measured at 1280 and 390 px). */
.widget[data-widget="samples"]:not([data-ready]) { min-height: 607px; }
.widget[data-widget="frontier"]:not([data-ready]) { min-height: 804px; }
@media (max-width: 760px) {
  .widget[data-widget="samples"]:not([data-ready]) { min-height: 1128px; }
  .widget[data-widget="frontier"]:not([data-ready]) { min-height: 957px; }
}

.lede { margin: 0 0 1.25rem; max-width: 36rem; font-size: 1.125rem; line-height: 1.5; color: var(--ink-2); }

/* Toy-model pop-out */
html:has(dialog[open]) body { overflow: hidden; }
.toy-dialog {
  width: min(var(--w-wide), calc(100vw - 2rem)); max-width: none; max-height: 90vh;
  margin: auto; padding: 1.25rem 1.5rem 1.5rem; overflow: auto; box-sizing: border-box;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overscroll-behavior: contain;
}
.toy-dialog:focus { outline: none; }
.toy-dialog::backdrop { background: var(--backdrop); }
.toy-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; }
.toy-head h2 { margin: 0; font-size: 1.35rem; }
.toy-lead { margin: 0 0 1rem; color: var(--ink-2); max-width: 40rem; }
.toy-close {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: 50%; cursor: pointer;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong);
}
.toy-close:hover { background: var(--surface-2); }
@media (pointer: coarse) { .toy-close { width: 44px; height: 44px; } }
.toy-dialog .widget { background: transparent; border: 0; box-shadow: none; padding: 0; border-radius: 0; }
@media (max-width: 640px) {
  .toy-dialog { width: 100vw; height: 100dvh; max-height: none; border: 0; border-radius: 0; padding: 1rem; }
}

/* Collapsed section part */
.more { max-width: var(--w-wide); margin: 1.5rem auto 0; }
.more > summary {
  display: flex; align-items: center; gap: 0.6rem; cursor: pointer; list-style: none;
  margin: 0 var(--gutter); padding: 0.75rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-family: var(--font); font-size: var(--text); font-weight: 600; color: var(--ink);
  text-transform: none; letter-spacing: normal;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.more .chev { flex: none; color: var(--ink-3); transition: transform 0.15s; }
.more[open] > summary .chev { transform: rotate(90deg); }
.more[open] > summary { margin-bottom: 1rem; }
@media (pointer: coarse) { .more > summary { min-height: 44px; } }
@media (prefers-reduced-motion: reduce) { .more .chev { transition: none; } }
