:root {
  --text: #1c2024;
  --muted: #5b6470;
  --line: #e3e6ea;
  --bg: #ffffff;
  --bg-alt: #f6f7f9;
  --accent: #1f6feb;
  --pill: #22272e;
}

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

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

body {
  margin: 0;
  font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(100% - 2rem, 960px);
  margin-inline: auto;
}

.container.wide {
  width: min(100% - 2rem, 1320px);
}

/* ---------- hero ---------- */

.hero {
  padding: 2.75rem 0 1.5rem;
  text-align: center;
}

.title {
  margin: 0 0 1rem;
  font-size: clamp(1.65rem, 4.2vw, 2.85rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.authors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem 1.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 1.2rem;
}

.affiliation {
  margin: 0.4rem 0 0;
  font-size: 1.05rem;
}

.venue {
  margin: -0.35rem 0 0.9rem;
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 600;
}

.links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1.15rem;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.15rem;
  border-radius: 999px;
  background: var(--pill);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
}

.button:hover {
  background: #000;
  text-decoration: none;
}

.button svg {
  width: 1.15em;
  height: 1.15em;
  fill: currentColor;
  flex: none;
}

.button small {
  font-size: 0.85em;
  font-weight: 400;
}

.button.is-disabled,
.button.is-disabled:hover {
  background: #eceef1;
  color: #6b7280;
  cursor: default;
}

/* ---------- pipeline animation ---------- */

.teaser {
  padding: 0.5rem 0 2.75rem;
}

/* black, to match the background the ensemble video was rendered on */
.pipeline {
  --cyan: #19e0e0;
  --wire: #6b7682;
  /* feedback: kept dim so it does not compete with the forward flow */
  --grad: #8f4541;
  --flow-x: 1;
  --flow-y: 0;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3.2vw, 2.25rem) clamp(1rem, 3.2vw, 2.75rem);
  overflow: hidden;
  border-radius: 18px;
  background: #000;
  color: #eef2f5;
}

.pipeline-title {
  margin: 0 0 clamp(1.1rem, 2.6vw, 1.75rem);
  font-size: clamp(1.05rem, 2.4vw, 1.5rem);
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
}

.pipeline-title b {
  color: var(--cyan);
  font-weight: 700;
}

/* stages share one height: each picture centres itself in it, and the labels line up along the bottom */
.pipeline-flow {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: clamp(0.5rem, 1.3vw, 1rem);
}

/* room above the row for the guidance gradient arrow, once the script has drawn it */
.pipeline-flow.has-feedback {
  padding-top: 2.2rem;
}

.pipeline-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.pipeline-label {
  margin: 0;
  color: #98a2ad;
  font-size: 0.85rem;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
}

/* neural net */

.stage-net {
  flex: 0 1 17%;
}

.nn {
  display: block;
  width: 100%;
  height: auto;
  margin: auto 0;
  overflow: visible;
}

.nn path {
  fill: none;
}

.nn-edges path {
  stroke: #2c353e;
  stroke-width: 1;
}

/* the edges that carry a number stand out a little */
.nn-edges.is-weighted path {
  stroke: #56626e;
}

/* weights, written on those edges; the black outline blanks the lines behind the digits */
.nn-weights text {
  fill: #dfe5ea;
  stroke: #000;
  stroke-width: 3.5px;
  stroke-linejoin: round;
  paint-order: stroke;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.6s;
}

/* tinted like the gradient arrow while training is still moving them */
.nn-weights.is-updating text {
  fill: #cf8a85;
}

/* one short dash per edge, travelling towards the output */
.nn-signals path {
  stroke: var(--cyan);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-dasharray: 0.16 0.84;
  opacity: 0.8;
  animation: nn-signal 2.4s linear infinite;
}

.nn-signals path:nth-child(3n) {
  animation-delay: -0.8s;
}

.nn-signals path:nth-child(3n + 1) {
  animation-delay: -1.6s;
}

.nn-layer circle {
  fill: #031516;
  stroke: var(--cyan);
  stroke-width: 1.6;
  animation: nn-pulse 2.4s ease-in-out calc(var(--l) * 0.4s) infinite;
}

/* 3D output: the video, and the canvas that shows it as noise turning into structure */

.stage-sample {
  flex: 0 1 21%;
}

/* a little shorter than the video, whose top and bottom strips are always empty */
.sample {
  position: relative;
  width: 100%;
  aspect-ratio: 520 / 556;
  overflow: hidden;
}

.pipeline-video,
.sample-canvas {
  position: absolute;
  top: 50%;
  left: 0;
  display: block;
  width: 100%;
  height: auto;
  transform: translateY(-50%);
}

.sample-canvas {
  aspect-ratio: 260 / 310;
}

/* the protein sits left of the video's centre (its mass is at 43.5% of the width), so its label does too */
.stage-sample .pipeline-label {
  position: relative;
  left: -6.5%;
}

/* rendered image vs dataset image */

.pipeline-compare {
  display: flex;
  flex: 0 1 40%;
  align-items: stretch;
  gap: clamp(0.35rem, 0.9vw, 0.7rem);
  min-width: 0;
}

.shot {
  flex: 1 1 0;
}

.render-canvas,
.dataset {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: auto 0;
  border-radius: 5px;
  background: #868686;
}

/* the offset shadows make it one image off a stack */
.dataset {
  position: relative;
  box-shadow: 5px -5px 0 -1px #262b31, 10px -10px 0 -2px #16191d;
}

/* one 4x3 sprite; --c / --r pick the tile. The script shows them in turn; without it the first one stays up */
.dataset span {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  background: url("../images/cryoem_particles.png") calc(var(--c) * 100% / 3) calc(var(--r) * 50%) / 400% 300% no-repeat;
}

.dataset span:first-child {
  opacity: 1;
}

.compare {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  align-self: center;
  justify-content: center;
  width: 5.6rem;
  height: 2.6rem;
  /* centre on the images rather than on images + label */
  margin-bottom: 1.85rem;
}

.compare::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 7px;
  left: 7px;
  height: 2px;
  margin-top: -1px;
  background: var(--wire);
}

.compare i {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 12px;
  margin-top: -6px;
  background: var(--wire);
}

.compare i:first-child {
  left: 0;
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
}

.compare i:last-child {
  right: 0;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.pill {
  position: relative;
  z-index: 1;
  flex: none;
  padding: 0.26rem 0.7rem;
  border: 1.5px solid var(--wire);
  border-radius: 999px;
  background: #0b0e11;
  color: #c9d1d9;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

/* arrows */

.pipeline-arrow {
  position: relative;
  display: flex;
  flex: 1 1 0;
  align-items: center;
  align-self: center;
  min-width: 4.5rem;
  /* centre on the pictures rather than on pictures + label */
  margin-bottom: 1.85rem;
}

/* sits above its arrow, and may be wider than it */
.arrow-label {
  position: absolute;
  bottom: calc(50% + 0.8rem);
  left: 50%;
  transform: translateX(-50%);
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
}

.track {
  position: relative;
  flex: 1 1 0;
  height: 2.6rem;
}

.track::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 3px;
  margin-top: -1.5px;
  background: var(--cyan);
}

.track-out::before {
  right: 12px;
}

.track-out::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 17px;
  height: 20px;
  margin-top: -10px;
  background: var(--cyan);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

/* each atom spans its track, so translating it by 100% carries its dot from one end to the other */
.atom {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  animation: atom-travel 2s linear calc(var(--i) * 0.5s) infinite;
}

.atom::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #c4ffff;
  box-shadow: 0 0 8px var(--cyan);
}

/* feedback (guidance gradient and flow matching training): drawn by the script, dim red and dashed */
.feedback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.feedback-line {
  fill: none;
  stroke: var(--grad);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 5 7;
  animation: feedback-flow 1.4s linear infinite;
}

.feedback marker path {
  fill: var(--grad);
}

/* a shade lighter than the line so the word stays readable; the black outline blanks the dashes behind it */
.feedback text {
  fill: #a65a55;
  stroke: #000;
  stroke-width: 10px;
  stroke-linejoin: round;
  paint-order: stroke;
  font-size: 0.82rem;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
}

@keyframes feedback-flow {
  from {
    stroke-dashoffset: 12;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes nn-signal {
  from {
    stroke-dashoffset: 1;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes nn-pulse {
  0%,
  50%,
  100% {
    fill: #031516;
  }

  18% {
    fill: #0f8f90;
  }
}

@keyframes atom-travel {
  0% {
    opacity: 0;
    transform: translate(0, 0);
  }

  15%,
  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(var(--flow-x) * (100% - 16px)), calc(var(--flow-y) * (100% - 16px)));
  }
}

/* narrow screens: the pipeline runs top to bottom, ending in the image pair */
@media (max-width: 859px) {
  .pipeline {
    --flow-x: 0;
    --flow-y: 1;
  }

  .pipeline-flow {
    flex-direction: column;
    align-items: center;
  }

  /* the guidance gradient arrow runs under the image pair and up the right edge */
  .pipeline-flow.has-feedback {
    padding: 0 1.4rem 2.2rem;
  }

  .stage-net {
    flex: none;
    width: 11rem;
  }

  .stage-sample {
    flex: none;
    width: 15rem;
    max-width: 100%;
  }

  .pipeline-compare {
    flex: none;
    width: 100%;
    max-width: 24rem;
  }

  .pipeline-arrow {
    flex: none;
    flex-direction: column;
    min-width: 0;
    height: 4.6rem;
    margin-bottom: 0;
  }

  .arrow-label {
    top: 50%;
    bottom: auto;
    left: calc(50% + 1.2rem);
    transform: translateY(-50%);
    text-align: left;
  }

  .track {
    width: 2.6rem;
    height: auto;
  }

  .track::before {
    top: 0;
    right: auto;
    bottom: 0;
    left: 50%;
    width: 3px;
    height: auto;
    margin: 0 0 0 -1.5px;
  }

  .track-out::before {
    bottom: 12px;
  }

  .track-out::after {
    top: auto;
    right: auto;
    bottom: 0;
    left: 50%;
    width: 20px;
    height: 17px;
    margin: 0 0 0 -10px;
    clip-path: polygon(0 0, 100% 0, 50% 100%);
  }

  .atom::before {
    top: 0;
    left: 50%;
  }
}

/* ---------- videos ---------- */

.video-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.4rem 1.1rem;
}

@media (min-width: 860px) {
  .video-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.video-card {
  margin: 0;
}

.video-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f1f3f5;
}

.video-frame video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1532 / 720;
  object-fit: contain;
}

.video-missing {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.video-missing code {
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.video-card.is-missing .video-frame {
  border-style: dashed;
  border-color: #c5cad1;
}

.video-card.is-missing video {
  visibility: hidden;
}

.video-card.is-missing .video-missing {
  display: flex;
}

.video-card figcaption {
  margin-top: 0.5rem;
  text-align: center;
  line-height: 1.35;
}

.protein {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  font-weight: 600;
}

.protein-desc {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.video-caption {
  max-width: 820px;
  margin: 0 auto 1.6rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.97rem;
}

.video-caption strong {
  color: var(--text);
  font-weight: 700;
}

/* ---------- sections ---------- */

.section {
  padding: 3rem 0;
}

.section.alt {
  background: var(--bg-alt);
}

.section + .section:not(.alt) {
  border-top: 1px solid var(--line);
}

.section.alt + .section:not(.alt) {
  border-top: 0;
}

h2 {
  margin: 0 0 1.2rem;
  font-size: clamp(1.45rem, 3vw, 1.9rem);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
}

h3 {
  margin: 2.4rem 0 0.4rem;
  font-size: 1.2rem;
  font-weight: 600;
}

p {
  margin: 0 0 1rem;
}

.section p:last-child {
  margin-bottom: 0;
}

.math {
  font-family: "Cambria Math", "STIX Two Math", "Times New Roman", Times, serif;
  font-size: 1.06em;
  white-space: nowrap;
}

sub,
sup {
  font-size: 0.72em;
  line-height: 0;
}

@media (min-width: 720px) {
  .abstract {
    text-align: justify;
    hyphens: auto;
  }
}

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

.figure {
  margin: 1.4rem 0 0;
}

.figure-scroll {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
}

/* very wide strips stay legible on phones by scrolling sideways inside the figure */
.figure img.is-wide {
  min-width: 760px;
}

.figure figcaption {
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.55;
}

.figure figcaption strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- bibtex ---------- */

.bibtex {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.bibtex pre {
  margin: 0;
  padding: 1.1rem 1.2rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.6;
}

.copy-button {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-alt);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.copy-button:hover {
  background: #eceef1;
}

@media (max-width: 719px) {
  /* keep the copy button clear of the first line of the entry */
  .bibtex pre {
    padding-top: 2.9rem;
  }

  .video-missing code {
    font-size: 0.66rem;
  }
}

/* ---------- footer ---------- */

.footer {
  padding: 1.75rem 0 2.25rem;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.footer p {
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  /* static pipeline: the script shows the finished structure, and nothing travels along the arrows */
  .pipeline * {
    animation: none;
  }

  .nn-signals {
    display: none;
  }
}
