:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f4;
  --ink: #16171a;
  --ink-2: #4a4d55;
  --ink-3: #5c6069;
  --rule: #e4e4e0;
  --accent: #e0662b;
  --accent-soft: #fbeee6;
  --slot: #1b1c1f;
  --todo: #b7791f;
  --todo-bg: #fff8e6;
  --radius: 10px;
  --wrap: 760px;
  --wrap-wide: 1160px;
  --font: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111214; --bg-soft: #1a1b1e; --ink: #ececec; --ink-2: #b9bcc3; --ink-3: #8a8e97;
  --rule: #2a2b30; --accent: #f08a52; --accent-soft: #2b1f18; --slot: #000; --todo: #e3b25a; --todo-bg: #2a2416;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.65 var(--font); -webkit-font-smoothing: antialiased; }
img, video { max-width: 100%; height: auto; display: block; }
a { color: inherit; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: var(--wrap-wide); margin: 0 auto; padding: 0 16px; }

/* Sticky nav */
.site-nav { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule); }
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 52px; gap: 16px; }
.brand { font-weight: 700; text-decoration: none; letter-spacing: .02em; }
.nav-right { display: flex; align-items: center; gap: 18px; min-width: 0; }
.nav-links { display: flex; gap: 22px; list-style: none; margin: 0; padding: 0; font-size: 14px; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a { text-decoration: none; color: var(--ink-2); white-space: nowrap; }
.nav-links a.active, .nav-links a:hover { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--bg-soft);
  color: var(--ink-2);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: scale(1.06);
}
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .theme-icon-sun { display: none; }
.theme-toggle .theme-icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none; }

/* Hero */
.hero { text-align: center; padding: 56px 16px 24px; }
.hero h1 { font-size: clamp(28px, 4.4vw, 46px); font-weight: 700; letter-spacing: -.01em; }
.h1-line { display: block; }
.byline { margin: 18px 0 0; color: var(--ink-2); }
.affiliation { margin: 6px 0 0; color: var(--ink-2); }
.hero-note { max-width: 560px; margin: 16px auto 0; font-size: 14px; line-height: 1.55; color: var(--ink-3); }

/* Sections */
.section { padding: 56px 16px; }
.section + .section { border-top: 1px solid var(--rule); }
.eyebrow { display: block; width: 28px; height: 3px; background: var(--accent); margin-bottom: 14px; }
.section h2 { font-size: 26px; margin-bottom: 18px; }
.section h3 { font-size: 19px; margin: 36px 0 12px; }
.kicker { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
.prose { max-width: var(--wrap); }
.prose p { margin: 0 0 14px; color: var(--ink-2); }
.prose ul { color: var(--ink-2); padding-left: 20px; }
.prose li { margin-bottom: 8px; }
.center { margin-left: auto; margin-right: auto; }

figure { margin: 0; }
figcaption { font-size: 14px; color: var(--ink-3); margin-top: 10px; line-height: 1.55; }
figcaption strong { color: var(--ink-2); }

/* Media slots */
.slot { position: relative; }
.media-frame { position: relative; display: block; background: var(--slot); border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.slot[data-aspect="4/3"] .media-frame { aspect-ratio: 4 / 3; }
.slot[data-aspect="1/1"] .media-frame { aspect-ratio: 1 / 1; }
.media-frame > img, .media-frame > video { width: 100%; height: 100%; object-fit: cover; }
.media-frame > video { position: absolute; inset: 0; }
/* Keep the poster visible until the clip has data; a missing clip never blacks it out. */
.media-frame > video { opacity: 0; transition: opacity .2s; }
.slot.is-loaded .media-frame > video { opacity: 1; }
.slot-tag { position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px); font: 600 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: #fff; background: rgba(0,0,0,.65); border: 1px dashed rgba(255,255,255,.5); padding: 5px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.slot.is-loaded .slot-tag { display: none; }
.slot-label { position: absolute; left: 10px; top: 10px; font-size: 12px; font-weight: 600; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 6px; }
.speed-badge { position: absolute; right: 10px; top: 10px; font-size: 12px; font-weight: 700; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 6px; }
.clip-open { display: inline-block; font-size: 13px; margin-top: 6px; color: var(--accent); }

/* Step chips */
.steps { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 12px 0 0; }
.step-chip {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  font: 500 13px var(--font);
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.step-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.step-chip:active {
  transform: scale(0.97);
}
.step-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.step-chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #b64a18;
}
:root[data-theme="dark"] .step-chip.is-active {
  color: var(--accent);
}
.step-chip.is-active .step-time {
  color: #b64a18;
}
:root[data-theme="dark"] .step-chip.is-active .step-time {
  color: var(--accent);
}
.step-time { font-variant-numeric: tabular-nums; color: var(--ink-3); }

/* Grids */
.grid-2, .grid-3, .grid-4 { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.lead { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.lead-side { display: grid; gap: 16px; align-content: start; }
.stack > * + * { margin-top: 14px; }
.fig-img { background: #fff; border-radius: var(--radius); padding: 10px; border: 1px solid var(--rule); }
.fig-img img { margin: 0 auto; }
.spacer { margin-top: 28px; }

/* Specs */
.spec { width: 100%; border-collapse: collapse; font-size: 14px; }
.spec caption { text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); padding-bottom: 8px; }
.spec th, .spec td { text-align: left; padding: 7px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.spec th { font-weight: 500; color: var(--ink-2); padding-right: 16px; }
.spec td { text-align: right; font-variant-numeric: tabular-nums; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stat { min-width: 0; background: var(--bg-soft); border: 1px solid var(--rule); border-radius: 8px; padding: 10px clamp(8px, 1vw, 12px); }
.stat b { display: block; font-size: clamp(13px, 1.25vw, 16px); font-variant-numeric: tabular-nums; white-space: nowrap; overflow-wrap: normal; }
@media (max-width: 400px) { .stat b { white-space: normal; overflow-wrap: anywhere; } }
.stat span { font-size: 12px; color: var(--ink-3); }

/* Equations and tables */
.eq { max-width: 100%; overflow-x: auto; padding: 6px 0; margin: 8px 0 14px; }
details.table-block { margin-top: 24px; border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; }
details.table-block summary { cursor: pointer; font-weight: 600; }
.table-scroll { overflow-x: auto; }
table.paper { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 14px 0; }
table.paper caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
table.paper th, table.paper td { border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: left; vertical-align: top; }
table.paper thead th { border-bottom: 2px solid var(--ink-3); }
.table-note { font-size: 12.5px; color: var(--ink-3); }

/* Carousel */
.carousel { position: relative; }
.carousel-track { display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; border-radius: var(--radius); }
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track > .slot { scroll-snap-align: start; }
.carousel-controls { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.carousel-controls button { font: 600 16px var(--font); width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--rule); background: var(--bg-soft); color: var(--ink); cursor: pointer; }
.carousel-count { font-variant-numeric: tabular-nums; color: var(--ink-3); font-size: 14px; }

/* TODO blocks: visible reminders for the authors */
.todo { border: 2px dashed var(--todo); background: var(--todo-bg); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; color: var(--ink-2); font-size: 14px; }
.todo h4 { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--todo); margin-bottom: 6px; }
.todo ul { margin: 0; padding-left: 18px; }

.site-footer { border-top: 1px solid var(--rule); padding: 28px 16px 40px; text-align: center; color: var(--ink-3); font-size: 14px; }

@media (max-width: 860px) {
  .lead, .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .grid-4.sim { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-links { gap: 14px; }
  .brand { display: none; }
}
@media (max-width: 560px) {
  .grid-2, .grid-4.sim { grid-template-columns: minmax(0, 1fr); }
  /* Wide figure strips stay legible: scroll inside the card instead of shrinking. */
  .wide-strip { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .fig-img.wide-strip img { width: auto; max-width: none; height: 220px; }
  .section { padding: 40px 16px; }
}

.principle img { width: 100%; height: auto; }
.velocity img { width: 100%; height: 340px; object-fit: contain; }
@media (max-width: 560px) { .velocity img { height: auto; } }

/* Short text snippets */
.snippet { font-size: 15.5px; line-height: 1.6; color: var(--ink-2); margin: 0 0 20px; }
.todo.snippet { border-style: dashed; margin: 0 0 20px; }
.todo.snippet p { margin: 0; font-style: italic; }

/* 3D Robot Model Viewer */
.viewer-3d-figure {
  margin: 0;
}
.model-viewer-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(640px, 85vh);
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: grab;
  touch-action: pan-y;
}
.model-viewer-frame:active { cursor: grabbing; }
#robot-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}
#robot-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.viewer-hint-badge {
  position: absolute;
  left: 14px;
  top: 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--bg-soft) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  border: 1px solid var(--rule);
  z-index: 5;
  white-space: nowrap;
  max-width: calc(100% - 28px);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0.35s ease;
}
.viewer-hint-badge svg {
  flex-shrink: 0;
  opacity: 0.85;
}
.viewer-hint-badge span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.viewer-hint-badge.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
}
.viewer-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 16px 0 12px;
  flex-wrap: wrap;
}
.viewer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 500 13px var(--font);
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 7px 15px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.viewer-btn:hover {
  background: color-mix(in srgb, var(--bg-soft) 70%, var(--accent-soft));
  border-color: var(--accent);
  color: var(--accent);
}
.viewer-btn:active { transform: scale(0.97); }
.viewer-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.viewer-btn.is-paused {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.viewer-btn .btn-icon { font-size: 11px; line-height: 1; }

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.3s ease;
  z-index: 10;
}
.viewer-loading.is-loaded {
  opacity: 0;
  pointer-events: none;
}
.viewer-loading .spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: viewer-spin 0.75s linear infinite;
}
@keyframes viewer-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .model-viewer-frame {
    aspect-ratio: 4 / 3;
    max-height: min(480px, 75vh);
  }
  .viewer-hint-badge {
    top: 10px;
    left: 10px;
    padding: 4px 10px;
    font-size: 11px;
    max-width: calc(100% - 20px);
  }
  .viewer-hint-badge svg {
    width: 12px;
    height: 12px;
  }
  .viewer-controls {
    gap: 6px;
    margin: 12px 0 8px;
  }
  .viewer-btn {
    padding: 6px 11px;
    font-size: 12px;
    gap: 5px;
  }
}

@media (max-width: 440px) {
  .viewer-controls {
    gap: 5px;
  }
  .viewer-btn {
    padding: 5px 9px;
    font-size: 11px;
  }
  .viewer-btn .btn-icon {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .viewer-loading .spinner {
    animation: none;
  }
  .viewer-btn {
    transition: none;
  }
  .viewer-hint-badge {
    transition: none;
  }
}

/* Fig. 3 simulation clip labels (under each clip, clear of the in-video speed readout) */
.sim-label { margin: 8px 0 0; text-align: center; font-size: 15px; color: var(--ink-2); }
.sim-label strong { color: var(--ink); font-weight: 700; }

/* Additional trials: one video and three photos in a uniform 4:3 grid */
.gallery { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.gallery-photo { aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden; background: var(--slot); }
.gallery-photo img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item figcaption { margin-top: 8px; text-align: center; }
@media (max-width: 860px) { .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .gallery { grid-template-columns: minmax(0, 1fr); } }
.clip-note { position: absolute; right: 10px; bottom: 10px; margin: 0; z-index: 2; font-size: 12px; font-weight: 600; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 6px; pointer-events: none; }
