/* ==========================================================================
   LeVJEPA — single-page article.
   Typography and palette follow the LeVLJEPA project page; the layout is a
   Tufte-style margin column: body text in a fixed measure, with figures,
   video and asides floated into the gutter beside the text they belong to.
   Below --break the gutter collapses and margin content joins the flow.
   ========================================================================== */

:root {
  /* Palette */
  --ink:      #222;
  --body:     #333;
  --quiet:    #555;
  --quieter:  #777;
  --faint:    #9aa3ab;
  --rule:     #ececec;
  --rule-soft:#f0f2f4;
  --panel:    #f8f8f8;
  --accent:   #226999;
  --accent-d: #185579;
  --accent-bg:#f3f8fb;
  --warm:     #c8794a;

  /* Type */
  --serif: 'CMU Serif', Georgia, 'Times New Roman', serif;
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --display: 'Sora', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Margin-column geometry */
  --body-w:   680px;
  --margin-w: 300px;
  --gap:      40px;
  --total:    1020px;   /* body + gap + margin */
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: #fff;
  color: var(--body);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #cfe3f2; }

/* --------------------------------------------------------------------------
   The article grid
   -------------------------------------------------------------------------- */

.article {
  width: min(100% - 3rem, var(--total));
  margin-inline: auto;
}

/* Everything in the body column sits at a fixed measure; the leftover width
   of .article is the gutter that .margin floats into. */
.article > *:not(.full):not(.margin) {
  width: var(--body-w);
  max-width: 100%;
}

.margin {
  width: var(--margin-w);
  margin: 0.35rem 0 1.5rem;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--quieter);
}

.margin > :first-child { margin-top: 0; }
.margin > :last-child  { margin-bottom: 0; }

.margin video { aspect-ratio: 1 / 1; }

.margin img,
.margin video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  margin-bottom: 0.5rem;
}

.margin p { margin: 0.35rem 0 0; }
.margin b, .margin strong { color: var(--quiet); font-weight: 600; }

/* A numbered margin note, keyed to a superscript in the text. */
.margin .num,
.ref {
  font-family: var(--mono);
  font-size: 0.72em;
  color: var(--accent);
  font-weight: 600;
  vertical-align: super;
  line-height: 0;
}
.margin .num { margin-right: 0.35em; vertical-align: baseline; font-size: 11px; }

/* Full-bleed figures clear the gutter and span the whole article width. */
.full {
  width: 100%;
  clear: both;
  margin: 2.2rem 0 0;
}

/* --------------------------------------------------------------------------
   Masthead
   -------------------------------------------------------------------------- */

.masthead {
  text-align: center;
  padding: 4.5rem 0 2.2rem;
}

.masthead h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2.1rem, 4.9vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.035em;
  color: var(--ink);
  margin: 0 0 1.6rem;
  text-wrap: balance;
}

/* Author and affiliation runs follow the paper's own line breaks: each
   .line is one typeset row, with the entries spaced as \quad does. */
.authors {
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 0 auto 0.7rem;
}
.authors .line {
  display: flex; flex-wrap: wrap; justify-content: center;
  column-gap: 1.5em; row-gap: 0.1em;
}
.authors .a { font-weight: 700; white-space: nowrap; }
.authors a { color: var(--accent); text-decoration: none; font-weight: 700; }
.authors a:hover { text-decoration: underline; }
.authors sup { font-size: 0.66em; font-weight: 400; }

.affil {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--quiet);
  margin: 0 auto;
}
.affil .line {
  display: flex; flex-wrap: wrap; justify-content: center;
  column-gap: 1.4em; row-gap: 0.05em;
}
.affil .u { white-space: nowrap; }
.affil sup { font-size: 0.76em; padding-right: 0.15em; }

.contrib {
  font-family: var(--serif);
  font-size: 0.98rem;
  color: var(--quiet);
  margin: 0.85rem auto 0;
}
.contrib code {
  background: none; padding: 0; font-size: 0.94em; color: var(--accent);
}
.contrib a { color: var(--accent); text-decoration: none; }
.contrib a:hover { text-decoration: underline; }

/* Link buttons */
.links {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 0.5rem; margin-top: 1.5rem;
}
.btn {
  display: inline-flex; align-items: center; gap: 0.5em;
  font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0.03em;
  padding: 0.55em 1.15em; border-radius: 999px;
  text-decoration: none; border: 1px solid transparent; color: #fff;
  transition: background-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn svg { width: 1em; height: 1em; }

.btn-paper      { background: #b31b1b; border-color: #941616; box-shadow: 0 8px 20px rgba(179,27,27,.15); }
.btn-paper:hover{ background: #941616; }
.btn-code       { background: #24292f; border-color: #1f2328; box-shadow: 0 8px 20px rgba(36,41,47,.14); }
.btn-code:hover { background: #1f2328; }
.btn-ckpt       { background: var(--accent); border-color: var(--accent-d); box-shadow: 0 8px 20px rgba(34,105,153,.18); }
.btn-ckpt:hover { background: var(--accent-d); }

/* TODO: drop .btn-soon and set the real href once these are live. */
.btn-soon {
  background: #f4f6f8; border-color: #e4e8ec; color: #a8b0b8;
  box-shadow: none; pointer-events: none;
}
.btn-soon::after {
  content: "soon"; font-size: 0.72em; letter-spacing: .12em;
  text-transform: uppercase; color: #bcc4cc;
}

/* --------------------------------------------------------------------------
   Abstract
   -------------------------------------------------------------------------- */

.abstract {
  background: var(--panel);
  border-radius: 8px;
  padding: 1.8rem 2.1rem;
  margin: 0 auto 3rem;
}
.abstract h2 {
  font-family: var(--serif); font-weight: 700; font-size: 1.3rem;
  text-align: center; color: var(--ink); margin: 0 0 0.9rem;
}
.abstract p { text-align: justify; margin: 0 0 0.8rem; font-size: 0.98rem; }
.abstract p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   Body copy
   -------------------------------------------------------------------------- */

h2 {
  font-family: var(--sans);
  font-weight: 650;
  font-size: 1.22rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 3rem 0 0.9rem;
}

h3 {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 2.2rem 0 0.7rem;
}

p { margin: 0 0 1.1rem; }

a { color: var(--accent); }

strong { font-weight: 700; color: var(--ink); }
em { font-style: italic; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--panel);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: var(--quiet);
}

.lead-note {
  border-left: 2px solid #e7edf2;
  padding-left: 1rem;
  margin: 1.4rem 0;
  font-size: 0.96rem;
  color: var(--quiet);
}

/* --------------------------------------------------------------------------
   Figures
   -------------------------------------------------------------------------- */

figure { margin: 0; }

.full figure img,
.full img {
  display: block;
  width: 100%;
  max-width: 900px;
  height: auto;
  margin: 0 auto;
}

/* A chart small enough to sit in the body column reads as part of the prose
   and, unlike a .full block, never has to clear the gutter. */
.body-figure { margin: 1.8rem 0; }
.body-figure img {
  display: block; width: 100%; max-width: 500px; height: auto; margin: 0 auto;
}
.body-figure figcaption { text-align: left; max-width: none; }

/* Matplotlib exports are ~420px natural; don't upscale them past that. */
.full img.chart { max-width: 620px; }

figcaption,
.caption {
  font-family: var(--serif);
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--quiet);
  margin-top: 0.85rem;
}
.full figcaption, .full .caption { max-width: 780px; margin-inline: auto; }
figcaption b, .caption b { color: var(--ink); }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin: 1.5rem 0; }

table {
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.87rem;
  width: 100%;
  max-width: 560px;
}
th {
  font-family: var(--mono); font-size: 0.62rem; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--quieter);
  text-align: right; padding: 0.5rem 0.7rem;
  border-bottom: 1.4px solid #ccd2d8; white-space: nowrap;
}
th:first-child { text-align: left; }
td {
  text-align: right; padding: 0.5rem 0.7rem; color: var(--quiet);
  border-bottom: 1px solid var(--rule-soft); font-variant-numeric: tabular-nums;
}
td:first-child { text-align: left; color: var(--ink); }
tr.ours td { background: var(--accent-bg); font-weight: 650; color: #1e3647; }
tr.ours td:first-child { color: var(--accent); }
td .best { color: var(--accent); font-weight: 700; }

.table-cap {
  font-family: var(--serif); font-size: 0.84rem; line-height: 1.55;
  color: var(--quiet); margin-top: 0.6rem; max-width: 560px;
}

/* --------------------------------------------------------------------------
   Interactive figures
   -------------------------------------------------------------------------- */

.demo {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #fcfcfd;
  padding: 1.2rem 1.3rem 1rem;
  margin: 1.6rem 0;
}
.demo-kicker {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--faint); display: block;
  margin-bottom: 0.8rem;
}
#dropFig { display: block; width: 100%; height: auto; }

/* Slider snapped to the evaluated ratios, with the measured accuracy set
   large beside it. */
.drop-controls {
  display: flex; align-items: flex-end; gap: 1.7rem;
  margin-top: 1.1rem; flex-wrap: wrap;
}
.drop-controls .slider-wrap { flex: 1 1 240px; margin-top: 0; }
.slider-ticks {
  display: flex; justify-content: space-between; margin-top: 0.45rem;
  font-family: var(--mono); font-size: 0.6rem; color: var(--faint);
}
.slider-ticks span { cursor: pointer; transition: color .15s ease; }
.slider-ticks span:hover { color: var(--quiet); }
.slider-ticks span.on { color: var(--accent); font-weight: 600; }

.drop-readout { display: flex; align-items: baseline; gap: 0.65rem; flex: 0 0 auto; }
.drop-readout .acc {
  font-family: var(--sans); font-weight: 700; font-size: 2.5rem; line-height: 1;
  letter-spacing: -0.025em; color: var(--accent); font-variant-numeric: tabular-nums;
}
.drop-readout .acc-label {
  font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--faint); line-height: 1.6;
}
#attnFig { display: block; width: 100%; height: auto; max-width: 520px; margin: 0 auto; }

.controls { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.9rem; flex-wrap: wrap; }
.cbtn {
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: .05em;
  text-transform: uppercase; border: 1px solid #ddd; background: #fff;
  color: var(--quiet); border-radius: 6px; padding: 0.4em 0.8em; cursor: pointer;
  transition: all .15s ease;
}
.cbtn:hover { border-color: #bbb; color: var(--ink); }
.cbtn.is-active { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.stage { font-family: var(--mono); font-size: 0.72rem; color: var(--quiet); }
.stage b { color: var(--accent); font-weight: 600; }

.slider-wrap { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.9rem; }
.slider-scale {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--faint);
}
.slider-scale span:last-child { color: var(--accent); }
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 3px; border-radius: 3px;
  width: 100%; cursor: pointer;
  background: linear-gradient(90deg, var(--accent) var(--p,100%), #ececec var(--p,100%));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
}
.readout {
  font-family: var(--mono); font-size: 0.74rem; color: var(--quiet); margin-top: 0.6rem;
}
.readout b { color: var(--accent); font-weight: 600; }

/* Placeholder for a figure that has not been exported yet. */
.fig-pending {
  border: 1px dashed #dde2e7; border-radius: 6px; background: #fbfcfd;
  min-height: 150px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.3rem; padding: 1.2rem;
  text-align: center;
}
.fig-pending .t {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--faint);
}
.fig-pending .f { font-family: var(--mono); font-size: 0.68rem; color: #c3cbd2; }



/* --------------------------------------------------------------------------
   Showcase strip — patch-token visualizations at the head of the page
   -------------------------------------------------------------------------- */

.showcase { margin: 0.5rem 0 3rem; }

.showcase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 14px;
}

.tile figcaption {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 0.5rem;
  text-align: center;
}

.tile-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 4px;
  background: #000;
}
.tile-stage img,
.tile-stage video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}

/* The revealed layer is clipped rather than resized, so both images stay
   registered pixel-for-pixel as the divider moves. */
.cmp-b { clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0); }

.cmp-divider {
  position: absolute; top: 0; bottom: 0;
  left: var(--pos, 50%);
  width: 2px; margin-left: -1px;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 0 6px rgba(0,0,0,0.4);
  pointer-events: none;
}
.cmp-divider::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; background: rgba(255,255,255,0.95);
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.cmp-divider::before {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; z-index: 1;
  background:
    linear-gradient(90deg, transparent 7px, #226999 7px, #226999 8px, transparent 8px),
    linear-gradient(90deg, transparent 18px, #226999 18px, #226999 19px, transparent 19px);
}

/* A real range input drives the reveal: pointer, touch and keyboard for free. */
input[type=range].cmp-range {
  position: absolute; inset: 0;
  width: 100%; height: 100%; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: none; cursor: ew-resize; opacity: 0;
}
input[type=range].cmp-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 40px; height: 100%; border: 0; border-radius: 0;
  background: transparent; box-shadow: none; cursor: ew-resize;
}
input[type=range].cmp-range::-moz-range-thumb {
  width: 40px; height: 100%; border: 0; border-radius: 0;
  background: transparent; cursor: ew-resize;
}
input[type=range].cmp-range::-moz-range-track { background: none; height: 100%; }
input[type=range].cmp-range:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.tile-tag {
  position: absolute; bottom: 8px;
  font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: #fff;
  background: rgba(0,0,0,0.55); padding: 0.25em 0.6em; border-radius: 3px;
  pointer-events: none;
}
.tile-tag.l { left: 8px; }
.tile-tag.r { right: 8px; }

.showcase .caption { max-width: 780px; margin: 1rem auto 0; text-align: center; }

/* A comparison placed in the margin column keeps the same behaviour at
   whatever width the gutter (or, once collapsed, the body) allows. */
.margin .tile-stage { margin-bottom: 0.5rem; max-width: 420px; }

/* Tall media in a 300px gutter stacks via `clear: right`, so its height is
   charged against the prose beside it. Cap it so one item cannot outrun its
   own section and push the next full-width figure far down the page. */
.margin video, .margin .tile-stage { max-width: 245px; }

/* --------------------------------------------------------------------------
   Citation and footer
   -------------------------------------------------------------------------- */

.bibtex {
  background: var(--panel); border-radius: 8px; padding: 1.3rem 1.6rem;
  overflow-x: auto; margin: 1.2rem 0;
}
.bibtex pre {
  margin: 0; font-family: var(--mono); font-size: 0.74rem; line-height: 1.7;
  color: var(--quiet);
}

footer {
  border-top: 1px solid var(--rule);
  margin-top: 4rem; padding: 2rem 0 3.5rem;
}
footer h3 { margin-top: 0; }
footer p {
  font-family: var(--serif); font-size: 0.82rem; line-height: 1.6;
  color: var(--quiet); margin: 0 0 0.7rem;
}
footer a { color: var(--accent); }

/* --------------------------------------------------------------------------
   Collapse the gutter
   -------------------------------------------------------------------------- */

/* Wide screens: the gutter is laid out by script rather than by floats.
   `float + clear: right` made each item queue below the previous one, so tall
   media drifted away from its own paragraph and dragged the next full-width
   figure down with it. Positioned absolutely, the body flow is independent of
   how tall the margin content is. See layoutMargins() in figures.js. */
@media (min-width: 1081px) {
  .article.margins-positioned { position: relative; }
  .article.margins-positioned > .margin {
    position: absolute;
    right: 0;
    width: var(--margin-w);
    margin: 0;
  }
}

@media (max-width: 1080px) {
  .article > *:not(.full):not(.margin) { width: 100%; }

  .margin {
    float: none;
    width: 100%;
    margin: 1.6rem 0;
    padding-left: 1rem;
    border-left: 2px solid var(--rule);
  }
  .margin img, .margin video { max-width: 420px; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }

  /* Four frames across a narrow column would render each token at ~5px and
     the frame labels illegibly; keep a usable size and scroll instead. */
  .demo { overflow-x: auto; }
  #dropFig { min-width: 470px; }
  #attnFig { min-width: 440px; }
  .drop-readout .acc { font-size: 2.1rem; }
  .article { width: min(100% - 2rem, var(--total)); }
  .masthead { padding-top: 2.8rem; }
  .abstract { padding: 1.3rem 1.2rem; }
  .abstract p { text-align: left; }
  table { font-size: 0.8rem; }
  th, td { padding: 0.45rem 0.5rem; }
}
