/* Chapters 2 (#problem), 6 (#robots), 7 (#examples), 8 (#code) and the footer. Loaded after site.css. */

/* Wide container for videos and the gallery: up to 1280 px, with a side margin that grows with the
   window so wide media never runs to the edge of a laptop screen. Text stays in .wrap. */
.mx-wide {
  width: min(100% - 2 * max(var(--gutter), 4vw), 1280px);
  margin-inline: auto;
}

/* Captions and credits under wide media start at the text column's left edge, like the headings. */
.mx-wide > .caption,
.mx-wide > .rb-credit {
  margin-left: calc((100% - min(100vw - 2 * var(--gutter), 1080px)) / 2);
}

/* ---------- Chapters 2 and 4: enlarging the wide animal videos (media.js) ---------- */

/* Phones held upright only (below 700 px; wider screens show the clips large enough): a round button in
   the clip's top-right corner, and the clip itself is tappable. */
.video-enlarge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(232, 232, 237, 0.78);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  color: var(--text);
  cursor: pointer;
}
.video-enlarge svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* On phones the two buttons sit in a row under the clip's bottom-right corner, off the picture. */
@media (max-width: 699px) {
  .can-enlarge {
    overflow: visible;
    margin-bottom: 44px;
    cursor: zoom-in;
  }
  .can-enlarge > video { border-radius: inherit; }
  .can-enlarge > .video-toggle,
  .can-enlarge > .video-enlarge {
    top: auto;
    bottom: -40px;
    width: 32px;
    height: 32px;
    opacity: 1;
  }
  .can-enlarge > .video-toggle { right: 0; }
  .can-enlarge > .video-enlarge { display: grid; right: 40px; }
  .can-enlarge > .video-toggle svg,
  .video-enlarge svg { width: 12px; height: 12px; }
  .can-enlarge + .caption { margin-top: 0; }
}

/* Lightbox on a narrow upright screen: a wide clip is turned sideways to fill the screen's height. */
.lightbox.is-turned { overflow: hidden; }
.lightbox.is-turned .lightbox-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform: translate(-50%, -50%) rotate(90deg);
}
.lightbox.is-turned .lightbox-frame video {
  width: min(100vh - 128px, (100vw - 2 * var(--gutter)) * var(--r, 1.7778));
  width: min(100svh - 128px, (100vw - 2 * var(--gutter)) * var(--r, 1.7778));
}
.lightbox.is-turned .lightbox-label {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  bottom: 20px;
  font-size: 15px;
}
/* A phone held sideways: little height, so the label gives its room to the clip. */
@media (max-height: 500px) {
  .lightbox { padding: 12px var(--gutter); }
  .lightbox-label { display: none; }
  .lightbox-frame video {
    width: min(100vw - 2 * var(--gutter) - 112px, (100vh - 24px) * var(--r, 1.7778), 1400px);
    width: min(100vw - 2 * var(--gutter) - 112px, (100svh - 24px) * var(--r, 1.7778), 1400px);
  }
}

/* ---------- Chapter 6: one dance, six robots ---------- */

.rb-sub { margin-top: clamp(80px, 10vw, 136px); }
.rb-body { margin-top: clamp(28px, 3.5vw, 48px); }

.rb-six {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px 12px;
}
.rb-cell .video-label { margin-bottom: 8px; }
.rb-human { grid-column: 1 / -1; }
.rb-human .video-label { font-size: 17px; }
.rb-robot .media-frame,
.rb-clip .media-frame { border-radius: 12px; }
/* The renders have a white sky, which disappears into a white chapter; a hairline keeps the frame. */
.mx-frame { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.07); }
.chapter-alt .mx-frame { box-shadow: none; }

@media (min-width: 900px) {
  /* The human in the middle column, three robots on each side. */
  .rb-six {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
    grid-template-rows: repeat(3, auto);
    align-items: center;
    gap: clamp(18px, 2vw, 26px) clamp(18px, 2vw, 28px);
  }
  /* The human sits in the middle of the three rows beside it. */
  .rb-human { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
  .rb-r1, .rb-r2, .rb-r3 { grid-column: 1; }
  .rb-r4, .rb-r5, .rb-r6 { grid-column: 3; }
  .rb-r1, .rb-r4 { grid-row: 1; }
  .rb-r2, .rb-r5 { grid-row: 2; }
  .rb-r3, .rb-r6 { grid-row: 3; }
}

/* ---------- Chapter 6: two dancers on the Unitree G1 ---------- */

.rb-table { display: grid; gap: 28px; }
.rb-head p,
.rb-name p,
.rb-kept p { margin: 0; }

.rb-head {
  display: flex;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}
.rb-head .rb-d1,
.rb-head .rb-d2,
.rb-col-blank { display: none; }

.rb-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px 16px;
}
.rb-name { grid-column: 1; grid-row: 1; }
.rb-kept { grid-column: 2; grid-row: 1; }
.rb-clip { grid-column: 1 / -1; }
.rb-row-label {
  text-wrap: balance;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.rb-name .rb-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}
.rb-kept {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 88px;
}
.rb-value {
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.rb-kept .rb-ref {
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.6;
}
.rb-track { width: 88px; height: 6px; }
/* A short bar still shows as a dot. */
.rb-track .bar-fill { min-width: 6px; }

/* Phones and tablets: a Dancer 1 / Dancer 2 switch (media.js), four clips at a time. */
.rb-switch {
  display: flex;
  width: max-content;
  max-width: 100%;
  margin: 0 0 28px;
  padding: 3px;
  border-radius: 980px;
  background: var(--surface);
}
.rb-switch[hidden] { display: none; }
.rb-switch-button {
  min-height: 34px;
  padding: 0 20px;
  border: 0;
  border-radius: 980px;
  background: transparent;
  color: var(--muted);
  font: 600 15px/1 var(--font);
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}
.rb-switch-button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
@media (max-width: 899px) {
  .rb-table.is-switchable[data-dancer="1"] .rb-clip.rb-d2,
  .rb-table.is-switchable[data-dancer="2"] .rb-clip.rb-d1 { display: none; }
}

@media (min-width: 900px) {
  .rb-switch,
  .rb-switch[hidden] { display: none; }
  .rb-table { gap: clamp(14px, 1.6vw, 20px); }
  .rb-head,
  .rb-row {
    display: grid;
    grid-template-columns: minmax(170px, 1.2fr) minmax(0, 2fr) minmax(0, 2fr) minmax(120px, 0.7fr);
    column-gap: clamp(16px, 1.8vw, 24px);
    align-items: center;
  }
  .rb-head { font-size: 15px; }
  .rb-head .rb-d1,
  .rb-head .rb-d2,
  .rb-col-blank { display: block; }
  .rb-head .rb-d1,
  .rb-head .rb-d2 { color: var(--text); }
  .rb-name,
  .rb-kept,
  .rb-clip { grid-column: auto; grid-row: auto; }
  .rb-kept { align-items: flex-start; }
  .rb-value { font-size: clamp(24px, 1rem + 1vw, 32px); }
  .rb-track { width: 100%; max-width: 120px; }
}

.rb-body > .caption { margin-top: 20px; }
.rb-credit {
  margin: 14px 0 0;
  max-width: 48em;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Chapter 7: gallery ---------- */

.gx-grid {
  --n: 2;
  --gap: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 28px var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}
.gx-item { flex: 0 0 calc((100% - (var(--n) - 1) * var(--gap)) / var(--n)); min-width: 0; }
@media (min-width: 640px) { .gx-grid { --n: 4; --gap: 18px; } }
@media (min-width: 1240px) {
  .gx-grid { --n: 7; --gap: 18px; }
  /* Seven narrow columns: a slightly smaller label keeps every label to two lines. */
  .gx-grid .gx-label { font-size: 14px; }
}

.gx-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.gx-button:focus-visible { outline: none; }
.gx-button:focus-visible .gx-still { outline: 2px solid var(--accent); outline-offset: 3px; }
.gx-still {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.35s ease, transform 0.35s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.gx-still img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gx-button:hover .gx-still {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.09);
}
.gx-play {
  position: absolute;
  left: 50%;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 10px;
  border-radius: 980px;
  background: rgba(29, 29, 31, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: background-color 0.25s ease;
}
.gx-play svg { width: 10px; height: 10px; fill: currentColor; }
.gx-button:hover .gx-play { background: var(--accent-text); }
.gx-label {
  display: block;
  min-height: 2.6em;
  margin-top: 12px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.005em;
  text-wrap: balance;
}
.gx-caption { margin-top: clamp(32px, 4vw, 48px); }

@media (max-width: 560px) {
  .gx-label { font-size: 14px; margin-top: 10px; }
  .gx-play { bottom: 10px; }
}

/* ---------- Chapter 8: code, guides, button ---------- */

/* The copy button sits beside the code rather than above it, so a one-line block stays one line high.
   Lines keep their breaks (wrapped Python reads wrongly) and scroll sideways inside the block. */
.cx-code pre {
  margin-right: 64px;
  padding-top: 4px;
  font-size: 14px;
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
}
.cx-code + .cx-code { margin-top: 14px; }
.cx-comment { color: var(--muted); }
.cx-cards { margin-top: clamp(40px, 5vw, 64px); }
.cx-cards .card-link { overflow-wrap: anywhere; }
.cx-cta { margin: clamp(40px, 5vw, 64px) 0 0; }

/* The citation block: on wider screens its text starts at the same inset as the code blocks above. */
@media (min-width: 561px) {
  #cite .code-block pre { margin-right: 64px; padding-top: 4px; }
}

@media (max-width: 560px) {
  /* Phones: the copy button goes above the code, which then has the block's full width. */
  .cx-code pre {
    margin-right: 0;
    padding-top: 30px;
    font-size: 13px;
  }
  /* The install line is one shell command, so it may wrap; the Python keeps its lines. */
  #code-install {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  /* A block cut off on the right fades out there, to show that it scrolls sideways (site.js). */
  .cx-code pre.is-cut {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
  }
  .cx-cards .card { min-height: 0; gap: 14px; }
}

/* ---------- Footer ---------- */

.ft-wrap .footer-list li + li { margin-top: 4px; }
.ft-wrap {
  display: grid;
  gap: 8px;
}
.footer .ft-licence {
  margin: 8px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
@media (min-width: 760px) {
  .ft-wrap {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    column-gap: clamp(40px, 5vw, 72px);
  }
  .ft-licence { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .gx-still,
  .gx-play,
  .rb-switch-button { transition: none; }
  .gx-button:hover .gx-still { transform: none; }
}
