:root {
  --bg: #0b0b10;
  --surface: #14141b;
  --surface-2: #1d1d26;
  --text: #e6e6ea;
  --muted: #a1a1ab;
  --line: #2a2a34;
  --blue: #60a5fa;
  --violet: #a78bfa;
  --pink: #f472b6;
  --grad: linear-gradient(120deg, var(--blue) 0%, var(--violet) 50%, var(--pink) 100%);
  --accent: var(--pink);
  --accent-soft: rgba(244, 114, 182, .12);
  --accent-2: var(--blue);
  --accent-2-soft: rgba(96, 165, 250, .10);
  --link: #93c5fd;
  --emph: #c4b5fd;
  --code-bg: #101016;
  --cell-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .25);
  --radius: 14px;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
html { background: var(--bg); }
body {
  margin: 0;
  background: transparent;
  color: var(--text);
  font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}
/* Faint grid with a blue glow top-left and a pink glow bottom-right. */
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(720px circle at 0% 0%, rgba(96, 165, 250, .13), transparent 62%),
    radial-gradient(820px circle at 100% 100%, rgba(244, 114, 182, .11), transparent 62%),
    linear-gradient(rgba(167, 139, 250, .035) 1px, transparent 1px) 0 0 / 60px 60px,
    linear-gradient(90deg, rgba(167, 139, 250, .035) 1px, transparent 1px) 0 0 / 60px 60px;
}
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img, video { display: block; max-width: 100%; }
code { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 28px; } }

/* Shared WebGL canvas, drawn into each 3D cell's rectangle. */
#stage {
  position: fixed; inset: 0; width: 100vw; height: 100vh;
  z-index: 1; pointer-events: none;
}

/* ---------- nav ---------- */
.topnav {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav-inner { display: flex; align-items: center; gap: 20px; height: 52px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: -.02em; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 18px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a { color: var(--muted); font-size: 14px; white-space: nowrap; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
@media (max-width: 640px) { .brand { display: none; } .nav-links { margin-left: 0; } }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 72px 0 32px; }
.hero h1 {
  display: inline-block; font-weight: 800; letter-spacing: -.035em;
  font-size: clamp(44px, 8vw, 76px); line-height: 1.1; margin: 0; padding-bottom: .04em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero h1 + .tagline { margin-top: 6px; }
.tagline { font-size: clamp(18px, 2.4vw, 23px); font-weight: 500; letter-spacing: -.01em; color: var(--muted); margin: 12px 0 18px; }
.authors { margin: 0 0 22px; font-size: 16px; }
.links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: 500 15px/1 var(--sans); color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; cursor: pointer; transition: border-color .15s, background .15s;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn svg { width: 18px; height: 18px; }
.btn.pill { background: var(--grad); color: #fff; border-color: transparent; font-weight: 600; box-shadow: 0 6px 24px rgba(167, 139, 250, .25); }
.btn.pill:hover { opacity: .9; border-color: transparent; }
.btn.disabled { background: var(--surface-2); color: var(--muted); border-color: var(--line); cursor: default; }
.btn.disabled:hover { opacity: 1; border-color: var(--line); }
.btn em { font-style: normal; font-size: 12px; opacity: .8; }
.btn.small { font-size: 13px; padding: 7px 13px; }
.btn.ghost { background: transparent; }

/* ---------- sections ---------- */
section, section.wrap { padding-top: 72px; padding-bottom: 8px; }
.eyebrow { font-size: 12.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--violet); margin: 0 0 6px; }
h2 { font-weight: 700; font-size: clamp(24px, 3.4vw, 32px); letter-spacing: -.025em; margin: 0 0 12px; }
.lede { color: var(--muted); max-width: 860px; margin: 0 0 20px; }
.lede b { color: var(--emph); font-weight: 600; }

.teaser {
  width: 100%; height: auto; aspect-ratio: 16 / 9;
  border: 1px solid var(--line); border-radius: var(--radius); background: #03050a;
}
.intro { font-size: 17px; max-width: 900px; margin: 26px auto 0; }

.legend { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 0 0 8px; }
.legend div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.legend dt { font-weight: 600; font-size: 14px; }
.legend div:first-child { border-color: rgba(244, 114, 182, .35); background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--surface); }
.legend div:first-child dt { color: var(--accent); }
.legend dd { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.5; }

/* ---------- results ---------- */
.toolbar-wrap {
  position: sticky; top: 52px; z-index: 15;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  margin-top: 12px;
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding-top: 10px; padding-bottom: 10px; }
.control { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
.toolbar .seg { overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.toolbar .seg::-webkit-scrollbar { display: none; }
@media (max-width: 520px) { .toolbar .control-label { display: none; } .toolbar { gap: 8px; } }
.control-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.control.check { gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; margin-left: auto; }
.control.check input { accent-color: var(--accent); width: 16px; height: 16px; }
@media (max-width: 720px) { .control.check { margin-left: 0; } }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  font: 500 13px/1 var(--sans); color: var(--muted); background: none; border: 0;
  padding: 7px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.tiny { padding: 2px; width: 100%; }
.seg.tiny button { flex: 1; min-width: 0; font-size: 11px; padding: 5px 2px; overflow: hidden; text-overflow: ellipsis; }
.seg.tiny.placeholder { justify-content: center; align-items: center; font-size: 11px; color: var(--muted); min-height: 26px; }

.rows { display: flex; flex-direction: column; gap: 18px; padding-top: 20px; padding-bottom: 8px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.row.active { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.row-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.row-actions { display: flex; gap: 8px; }
.row.active .load { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.row-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.cell { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cell figcaption { display: flex; align-items: center; gap: 6px; min-height: 22px; }
.cell-title { font-size: 14px; font-weight: 600; }
.cell.ours { margin: -6px; padding: 6px; border-radius: 13px; background: rgba(244, 114, 182, .08); }
.cell.ours .cell-title { color: var(--accent); }
.tag { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 2px 6px; }
.cell.input figcaption { margin-bottom: 32px; }
@media (max-width: 760px) { .cell.input figcaption { margin-bottom: 0; } .cell.input .view { margin-top: 0; } }

.view {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--cell-bg); border: 1px solid var(--line);
  cursor: grab; touch-action: pan-y; user-select: none;
}
.cell.ours .view { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent); }
.cell.input .view { cursor: default; }
.view.dragging { cursor: grabbing; }
.view img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; transition: opacity .2s; }
.view.live img.preview { opacity: 0; }
.badge, .expand, .spinner { position: absolute; z-index: 2; }
.badge {
  left: 8px; bottom: 8px; font-size: 11px; font-weight: 500; color: #4b4741;
  background: rgba(255, 255, 255, .86); border: 1px solid #e4e0da; border-radius: 6px; padding: 1px 6px;
}
.expand {
  top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 8px; border: 1px solid #e4e0da;
  background: rgba(255, 255, 255, .9); color: #3a3631; font-size: 15px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
.view:hover .expand, .view:focus-within .expand, .expand:focus-visible { opacity: 1; }
@media (hover: none) { .expand { opacity: 1; } }
.spinner {
  inset: 0; margin: auto; width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(201, 58, 109, .2); border-top-color: #c93a6d;
  animation: spin .8s linear infinite; display: none;
}
.view.loading .spinner { display: block; }
.view.failed::after {
  content: 'Failed to load'; position: absolute; z-index: 2; inset: auto 0 34px; text-align: center; font-size: 12px; color: #a33;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------- static figures ---------- */
.figure-stack { display: flex; flex-direction: column; gap: 10px; }
.figure-stack img { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; }

.video-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.video-grid figure { margin: 0; }
.video-grid video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.video-grid figcaption { margin-top: 8px; font-size: 14.5px; }
.video-grid figcaption span { display: block; color: var(--muted); font-size: 13px; }

/* ---------- method figure ---------- */
.method-figure { margin: 0 0 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
.method-figure svg { display: block; width: 100%; min-width: 760px; height: auto; font-family: var(--sans); }
.m-stage { stroke-width: 1; }
.m-stage.s1 { fill: var(--accent-2-soft); stroke: rgba(96, 165, 250, .38); }
.m-stage.s2 { fill: var(--accent-soft); stroke: rgba(244, 114, 182, .38); }
.m-stage-num { font-size: 11.5px; font-weight: 700; letter-spacing: .12em; }
.m-stage-num.s1 { fill: var(--blue); }
.m-stage-num.s2 { fill: var(--pink); }
.m-stage-title { font-size: 21px; font-weight: 700; letter-spacing: -.02em; fill: var(--text); }
.m-stage-sub { font-size: 13px; fill: var(--muted); }
.m-box { fill: var(--surface); stroke: var(--line); stroke-width: 1; }
.m-box-title { font-size: 15px; font-weight: 600; fill: var(--text); }
.m-box-text { font-size: 12.5px; fill: var(--muted); }
.m-chips rect { fill: rgba(96, 165, 250, .1); stroke: rgba(96, 165, 250, .4); stroke-width: 1; }
.m-chips text { font-family: var(--mono); font-size: 10.5px; fill: var(--blue); }
.m-flow { fill: none; stroke: #8a8a96; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.m-loop { fill: none; stroke: var(--blue); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 4 4; }
.m-head { fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.m-head.flow { stroke: #8a8a96; }
.m-head.loop { stroke: var(--blue); }
.m-note { font-size: 11px; fill: var(--blue); font-weight: 600; letter-spacing: .02em; }
.m-out { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; fill: var(--muted); }
.m-caption { font-size: 12.5px; font-weight: 500; fill: var(--muted); }
.m-thumb-bg { fill: #fff; }
.m-thumb-line { fill: none; stroke: var(--line); stroke-width: 1; }
.m-steps circle { fill: #2a1724; stroke: var(--pink); stroke-width: 1.2; }
.m-step-n { font-size: 11.5px; font-weight: 700; fill: var(--pink); }
.m-rail { stroke: rgba(167, 139, 250, .3); stroke-width: 1.2; }

.method-notes { display: grid; gap: 16px 28px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.method-notes h3 { font-size: 17px; margin: 0 0 6px; }
.method-notes p { margin: 0; color: var(--muted); font-size: 15px; }
.method-notes b { color: var(--text); font-weight: 600; }

/* ---------- code ---------- */
.code-block { position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; }
.code-block pre { margin: 0; padding: 18px 20px; overflow-x: auto; font: 13.5px/1.65 var(--mono); }
.code-block code { font-size: inherit; }
.code-block .c { color: var(--muted); }
.copy {
  position: absolute; top: 10px; right: 10px; font: 500 12px/1 var(--sans); color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.copy:hover { color: var(--text); }

.footer { padding: 40px 16px 56px; color: var(--muted); font-size: 14px; text-align: center; }

/* ---------- modal ---------- */
dialog {
  width: min(1180px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(5, 5, 8, .7); backdrop-filter: blur(3px); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 10px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.modal-body { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 16px; padding: 0 20px 20px; min-height: 0; }
@media (max-width: 820px) { .modal-body { grid-template-columns: 1fr; overflow-y: auto; } }
.modal-view-wrap { position: relative; }
#modal-stage { position: absolute; inset: 0; width: 100%; height: calc(100% - 30px); pointer-events: none; z-index: 1; border-radius: 12px; }
#modal-view { aspect-ratio: auto; height: min(70vh, 720px); min-height: 300px; border-radius: 12px; }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; height: 22px; }
.modal-side { display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.modal-side .control { flex-direction: column; align-items: stretch; gap: 8px; }
.modal-side input[type=range] { width: 100%; accent-color: var(--accent); }
.parts-control { min-height: 0; flex: 1; }
.part-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: min(52vh, 520px); border: 1px solid var(--line); border-radius: 10px; }
.part-list li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: default; }
.part-list li:last-child { border-bottom: 0; }
.part-list li:hover { background: var(--surface-2); }
.swatch { width: 12px; height: 12px; border-radius: 4px; background: var(--line); flex: none; }
#modal-count { text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 4px; }

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .spinner { animation-duration: 2s; } }

#video { padding-top: 8px; }
