:root {
  --bg: #ffffff;
  --paper: #fafaf8;
  --ink: #1a1c20;
  --ink-2: #474b53;
  --muted: #80848c;
  --rule: #e7e6e1;
  --rule-strong: #1a1c20;
  --accent: #23489c;
  --agent: #3a5ba9;
  --memory: #7d4fb3;
  --wm: #4b8a2c;
  --confirmed: #12805a;
  --imagined: #e0780f;
  --dropped: #d23a3a;
  --path: #1d1f24;
  --ok: #3a9a6c;
  --minor: #dba227;
  --major: #cf4848;
  --radius: 6px;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 60px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, video { display: block; max-width: 100%; }
video { background: #111; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
b { font-weight: 600; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 28px; }
.wrap.mid { max-width: 1140px; }
.wrap.narrow { max-width: 760px; }

.label {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}

/* ---------- top nav ---------- */
.topnav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topnav-inner {
  max-width: 1140px; margin: 0 auto; padding: 0 28px;
  height: 48px; display: flex; align-items: center; gap: 24px;
}
.brand { font-family: var(--serif); font-weight: 600; font-size: 18px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.topnav-links { display: flex; gap: 22px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav-links::-webkit-scrollbar { display: none; }
.topnav-links a { color: var(--ink-2); font-size: 13.5px; white-space: nowrap; }
.topnav-links a:hover { color: var(--ink); text-decoration: none; }

/* ---------- table of contents: a floating box on wide screens; the top nav takes over below 1240 px ---------- */
.toc { display: none; }
@media (min-width: 1240px) {
  body { padding-left: 250px; }
  html { scroll-padding-top: 28px; }
  .topnav { display: none; }
  .toc {
    display: block; position: fixed; left: 28px; top: 50%; transform: translateY(-50%); z-index: 40;
    width: 204px; padding: 18px 12px 12px; background: #fff;
    border: 1px solid var(--rule); border-radius: 14px;
    box-shadow: 0 12px 32px rgba(20, 22, 28, .08), 0 2px 6px rgba(20, 22, 28, .05);
  }
  .toc-brand {
    display: block; font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--ink);
    padding: 0 10px 12px; margin-bottom: 8px; border-bottom: 1px solid var(--rule);
  }
  .toc-brand:hover { text-decoration: none; }
  .toc ol { list-style: none; margin: 0; padding: 0; }
  .toc li a {
    display: block; padding: 7px 10px; border-radius: 8px;
    color: var(--ink-2); font-size: 15px; line-height: 1.35; transition: background .15s, color .15s;
  }
  .toc li a:hover { color: var(--ink); background: var(--paper); text-decoration: none; }
  .toc li a.on { color: var(--accent); background: rgba(35, 72, 156, .08); font-weight: 500; }
}

/* ---------- hero ---------- */
.hero { padding: 72px 0 56px; text-align: center; border-bottom: 1px solid var(--rule); }
.title {
  font-family: var(--serif); font-size: clamp(44px, 6.4vw, 68px); font-weight: 600;
  letter-spacing: -.015em; line-height: 1.05;
}
.title-sub {
  font-family: var(--serif); font-size: clamp(20px, 2.6vw, 27px); font-weight: 400; color: var(--ink-2);
  margin: 12px auto 0; max-width: 760px; line-height: 1.35;
}
.u { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 5px; text-decoration-color: var(--imagined); }
.authors { margin: 30px auto 4px; max-width: 860px; font-size: 16.5px; line-height: 2; }
.author { margin: 0 10px; white-space: nowrap; }
.author a { color: var(--ink); border-bottom: 1px solid #c9ccd4; }
.author a:hover { text-decoration: none; color: var(--accent); border-bottom-color: var(--accent); }
.authors sup { font-size: 10.5px; color: var(--muted); margin-left: 1px; }
.affils { color: var(--ink-2); margin: 0; font-size: 15px; }
.affils span { margin: 0 12px; white-space: nowrap; }
.affils sup { font-size: 10px; color: var(--muted); margin-right: 2px; }

.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 28px 0 0; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: var(--radius);
  color: var(--ink); font-size: 14.5px; font-weight: 500;
  border: 1px solid #d5d5cf; background: #fff; transition: border-color .15s, background .15s;
}
.btn:hover { text-decoration: none; border-color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn.is-soon { color: var(--muted); cursor: default; }
.btn.is-soon:hover { border-color: #d5d5cf; }
.soon { font-size: 11px; color: var(--muted); font-style: italic; font-family: var(--serif); }

/* input → output composition, used by the teaser and the gallery */
.teaser { margin: 0; text-align: left; }
.teaser-grid { display: grid; grid-template-columns: 250px 72px minmax(0, 1fr); align-items: start; }
.teaser-in { display: flex; flex-direction: column; gap: 22px; padding-top: 2px; }
.io-block img { width: 100%; border-radius: var(--radius); aspect-ratio: 832 / 480; object-fit: cover; }
.instr { font-family: var(--serif); font-size: 17.5px; line-height: 1.5; margin: 0; color: var(--ink); }
.teaser-arrow {
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted);
  padding-top: 70px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.teaser-arrow svg { width: 40px; height: 16px; }
.teaser-out { min-width: 0; }

.player { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--rule); background: #111; }
.player video { width: 100%; aspect-ratio: 832 / 480; }

/* ---------- video controls ---------- */
.vctl {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: #fff; color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--rule);
}
.vctl button {
  appearance: none; border: 0; background: transparent; color: inherit; cursor: pointer;
  font: inherit; padding: 2px 6px; border-radius: 4px; display: inline-flex; align-items: center;
}
.vctl button:hover { background: #f0f0ec; color: var(--ink); }
.vctl button svg { width: 14px; height: 14px; }
.vctl .rate.on { color: var(--ink); font-weight: 600; background: #f0f0ec; }
.vctl input[type=range] { flex: 1; min-width: 40px; accent-color: var(--ink); height: 3px; }
.vctl .time { min-width: 76px; text-align: right; }

/* ---------- sections ---------- */
.section { padding: 84px 0; border-bottom: 1px solid var(--rule); }
.section h2 { font-family: var(--serif); font-size: clamp(27px, 3.2vw, 34px); letter-spacing: -.01em; line-height: 1.2; }
.section-head { margin-bottom: 36px; }
.section-head p { max-width: 760px; }
.section-head p { color: var(--ink-2); margin: 14px 0 0; font-size: 16.5px; }
.lead { font-size: 17px; color: var(--ink-2); margin: 16px 0 0; }
.lead b { color: var(--ink); }
.note { color: var(--muted); font-size: 14.5px; margin: 28px 0 0; max-width: 760px; }
.small { font-size: 13.5px; }
.muted { color: var(--muted); }
details summary { cursor: pointer; font-weight: 500; color: var(--ink-2); }
details summary:hover { color: var(--ink); }
h2.centered { text-align: center; }
.abstract { margin-top: 18px; }
.abstract p { color: var(--ink-2); font-family: var(--serif); font-size: 16px; line-height: 1.6; text-align: justify; hyphens: auto; }
.subsection { margin-top: 72px; }
.subsection.first { margin-top: 0; }
.subsection.tight { margin-top: 36px; }
.subsection h3 { font-family: var(--serif); font-size: 23px; margin-bottom: 18px; }
.subsection > p { color: var(--ink-2); margin: 10px 0 22px; max-width: 760px; }
.caption { color: var(--muted); font-size: 13.5px; margin: 10px 0 0; max-width: 760px; }

.figure { margin: 0; }
.figure img { width: 100%; }

/* ---------- gallery (in the hero) ---------- */
.gallery-stage { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 40px; align-items: start; }
.gallery-info { display: flex; flex-direction: column; gap: 22px; }
.gallery-text h3 { font-family: var(--serif); font-size: 22px; line-height: 1.2; }
.gallery-meta { margin: 2px 0 16px; color: var(--muted); font-size: 13px; }
.gallery-gist { font-family: var(--serif); font-size: 17px; margin: 0; line-height: 1.5; }
.gallery-gist::before { content: "“"; } .gallery-gist::after { content: "”"; }
.gallery-video { min-width: 0; }
.full-instr { margin-top: 12px; font-size: 13.5px; }
.full-instr summary { font-size: 13px; }
.full-instr p { color: var(--ink-2); margin: 8px 0 0; font-size: 13.5px; line-height: 1.6; }
.gallery-thumbs { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 14px; margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--rule); }
.thumb {
  appearance: none; border: 0; background: none; padding: 0; cursor: pointer;
  text-align: left; font: inherit; color: var(--ink-2);
}
.thumb img { width: 100%; aspect-ratio: 832 / 480; object-fit: cover; border-radius: 4px; opacity: .72; transition: opacity .15s; outline: 2px solid transparent; outline-offset: 2px; }
.thumb:hover img { opacity: 1; }
.thumb span { display: block; padding-top: 7px; font-size: 13px; font-weight: 500; line-height: 1.3; }
.thumb small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.thumb[aria-selected=true] img { opacity: 1; outline-color: var(--ink); }
.thumb[aria-selected=true] span { color: var(--ink); }

/* ---------- method ---------- */
.components { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 0 0 40px; }
.component { border-left: 3px solid; padding: 2px 0 2px 18px; }
.component.agent { border-color: var(--agent); }
.component.wm { border-color: var(--wm); }
.component h3 { font-family: var(--serif); font-size: 21px; margin-bottom: 6px; }
.component p { margin: 0; color: var(--ink-2); font-size: 15.5px; }

/* ---------- loop steps ---------- */
.steps { list-style: none; padding: 0; margin: 40px 0 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px; }
.steps li { border-top: 1px solid var(--rule-strong); padding-top: 14px; }
.steps h3 { font-family: var(--serif); font-size: 18px; margin: 4px 0 8px; }
.steps p { margin: 0; color: var(--ink-2); font-size: 14.5px; line-height: 1.6; }
.step-n { font-family: var(--serif); font-size: 14px; color: var(--muted); }
.steps li:nth-child(3) { border-top-color: var(--wm); }
.steps li:nth-child(1), .steps li:nth-child(2), .steps li:nth-child(4) { border-top-color: var(--agent); }
.tag { font-size: 13px; font-weight: 600; white-space: nowrap; }
.tag.confirmed { color: var(--confirmed); }
.tag.imagined { color: var(--imagined); }

/* ---------- replay ---------- */
.replay {
  display: grid; gap: 28px 36px;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-areas: "left right" "journey right";
  align-items: start;
}
.replay-left { grid-area: left; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.replay-right { grid-area: right; min-width: 0; }
.replay-video { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--rule); }
.replay-video video { width: 100%; aspect-ratio: 832 / 480; }

.timeline { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 3px; }
.tl-chunk {
  appearance: none; border: 0; cursor: pointer; font: inherit; padding: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; background: transparent; color: var(--muted);
}
.tl-bar { height: 6px; border-radius: 1px; background: var(--ink); opacity: .14; position: relative; overflow: hidden; }
.tl-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ink); }
.tl-chunk span { font-size: 10.5px; text-align: center; font-variant-numeric: tabular-nums; }
.tl-chunk.on .tl-bar { opacity: .55; }
.tl-chunk.on span { color: var(--ink); font-weight: 600; }

.io { display: flex; gap: 12px; align-items: baseline; padding-top: 6px; }
.io .label { margin: 0; flex: none; }
.io-text { font-family: var(--serif); font-size: 16px; line-height: 1.5; }

.plan-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.plan-head h3 { font-size: 14.5px; font-weight: 600; }
.plan-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px solid; margin-right: 5px; vertical-align: 3px; }
.lg.confirmed { border-color: var(--confirmed); }
.lg.imagined { border-color: var(--imagined); border-top-style: dashed; }
.lg.dropped { border-color: var(--dropped); border-top-style: dotted; }
.lg.path { border-color: var(--path); }
.plan-legend .hint { flex-basis: 100%; font-size: 11.5px; }
.plan {
  position: relative; background: #edece7; border-radius: var(--radius); border: 1px solid var(--rule); overflow: hidden;
  aspect-ratio: 936 / 864;
}
.plan img, .plan svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.plan img { opacity: 1; }
.plan-caption { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
.plan-tip {
  position: absolute; z-index: 3; pointer-events: none; max-width: 260px;
  background: #fff; color: var(--ink); font-size: 12px; line-height: 1.45; padding: 8px 10px; border-radius: 4px;
  border: 1px solid var(--rule); box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
}
.plan-tip b { display: block; font-weight: 600; margin-bottom: 2px; }
.plan-tip em { font-style: normal; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.plan-scale { display: none; }

svg .el { vector-effect: non-scaling-stroke; transition: opacity .3s; }
svg .el.confirmed { stroke: var(--confirmed); }
svg .el.imagined { stroke: var(--imagined); stroke-dasharray: 6 4; }
svg .el.dropped { stroke: var(--dropped); stroke-dasharray: 2 4; fill: none !important; }
svg .el.hit { cursor: help; }
svg .el.fresh { animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0% { stroke-width: 6; } 100% { stroke-width: 2; } }

.journey { grid-area: journey; min-width: 0; }
.journey summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; }
.journey summary::-webkit-details-marker { display: none; }
.journey summary .label { margin: 0; flex: none; }
.journey summary .label::after { content: "▸"; display: inline-block; margin-left: 6px; transition: transform .15s; }
.journey[open] summary .label::after { transform: rotate(90deg); }
.journey-now { font-size: 13.5px; color: var(--ink); font-weight: 500; line-height: 1.45; }
.journey-now::before { content: "▶ "; color: var(--agent); font-size: 11px; }
.journey[open] .journey-now { display: none; }
.journey .stages { margin-top: 8px; }
.stages { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.stages li { display: grid; grid-template-columns: 18px 1fr; gap: 6px; padding: 5px 0; color: var(--ink-2); line-height: 1.45; }
.stages li i { font-style: normal; font-size: 11px; text-align: center; padding-top: 2px; }
.stages li.done { color: var(--muted); }
.stages li.done i { color: var(--ok); }
.stages li.active { color: var(--ink); font-weight: 500; }
.stages li.active i { color: var(--agent); }
.stages li.skipped { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0, 0, 0, .25); }

/* ---------- tabs ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 26px; margin-bottom: 24px; border-bottom: 1px solid var(--rule); }
.tab {
  appearance: none; font: inherit; font-size: 14.5px; cursor: pointer; background: none;
  border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 0 0 9px; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected=true] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }

.video-frame { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--rule); background: #111; margin: 0 auto 0 0; }
.video-frame video { width: 100%; }

/* ---------- AgiWorld-WM: camera-controlled generation ---------- */
.i2v-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.i2v-grid video { cursor: pointer; }
.i2v-cell { position: relative; }
.i2v-cell .inset {
  position: absolute; left: 8px; top: 8px; width: 21%; aspect-ratio: 832 / 480; object-fit: cover;
  border: 1.5px solid rgba(255, 255, 255, .95); border-radius: 4px; box-shadow: 0 3px 10px rgba(0, 0, 0, .35); pointer-events: none;
}

/* ---------- AgiWorld-WM comparison ---------- */
.scene-thumbs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.cmp-frame { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--rule); background: #111; }
.cmp-video { position: relative; }
.cmp-video video { width: 100%; aspect-ratio: 1280 / 720; }
.q {
  position: absolute; font-size: 12px; font-weight: 600; color: #fff; padding: 2px 8px; border-radius: 4px;
  background: rgba(20, 22, 28, .62); pointer-events: none;
}
.q.tl { left: 8px; top: 8px; } .q.tr { left: calc(50% + 8px); top: 8px; }
.q.bl { left: 8px; top: calc(50% + 8px); } .q.br { left: calc(50% + 8px); top: calc(50% + 8px); }
.q.ours { background: rgba(18, 128, 90, .9); }

/* ---------- bibtex ---------- */
#bibtex { border-bottom: 0; padding-bottom: 96px; }
.bib { position: relative; margin-top: 18px; }
.bib pre {
  margin: 0; padding: 18px 20px; background: var(--paper); color: var(--ink); border-radius: var(--radius);
  border: 1px solid var(--rule); font: 13px/1.65 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.copy {
  position: absolute; right: 10px; top: 10px; appearance: none; cursor: pointer;
  font: 500 12px var(--sans); color: var(--ink-2); background: #fff;
  border: 1px solid var(--rule); border-radius: 4px; padding: 3px 10px;
}
.copy:hover { color: var(--ink); border-color: #c8c8c2; }


/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .gallery-thumbs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .replay { grid-template-columns: minmax(0, 1fr); grid-template-areas: "left" "right" "journey"; }
  .replay-right { max-width: 560px; }
  .steps { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .teaser-grid { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .teaser-in { flex-direction: row; gap: 18px; align-items: flex-start; }
  .teaser-in .io-block:first-child { width: 42%; flex: none; }
  .teaser-arrow { display: none; }
  .gallery-stage { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .gallery-info { flex-direction: row; gap: 18px; }
  .gallery-info .io-block { width: 42%; flex: none; }
  .gallery-video { order: -1; }
}
@media (max-width: 640px) {
  .wrap, .topnav-inner { padding: 0 16px; }
  .topnav-links { gap: 16px; }
  .brand { display: none; }
  .hero { padding: 44px 0 36px; }
  .authors { font-size: 15px; }
  .author { margin: 0 6px; }
  .affils span { display: block; margin: 0; }
  .links { margin-bottom: 36px; }
  .instr, .gallery-gist { font-size: 16px; }
  .section { padding: 60px 0; }
  .section-head p, .lead { font-size: 16px; }
  .gallery-thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .scene-thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .i2v-grid { grid-template-columns: 1fr; }
  .q { font-size: 10px; padding: 1px 5px; }
  .steps { grid-template-columns: 1fr; gap: 22px; }
  .components { grid-template-columns: 1fr; gap: 20px; }
  .timeline span { font-size: 9px; }
  .io { flex-direction: column; gap: 4px; }
  .vctl { gap: 4px; padding: 6px 6px; }
  .vctl .time { min-width: 0; }
}
