/* Carousel gallery — one phone, its reading footer, and the site viewer.
 *
 * Three surfaces, no overlay of its own:
 *   stage   the shared device frame (shared.css → .device) holding ONE capture;
 *   footer  the copy of the photo on the stage, the arrows and the filmstrip;
 *   viewer  the shipped lightbox (assets/js/lightbox.js), opened by the photo itself.
 *
 * The frame is paint and it never changes: only the capture inside its hole fades, one photo over
 * the one that is leaving (carousel.js lends the outgoing shot to `.device-screen`'s background for
 * the length of the fade). Fading the frame with it would blink the bezel on every step.
 *
 * The strip is the register: one thumb per capture, each carrying the photo it will put on the
 * stage. The footer's copy is three letter-morph slots (assets/js/text-morph.js), so a swap answers
 * with the same letters-in-motion the hero's headline uses.
 *
 * see DESIGN.md → The swap and Components · Buttons; docs/agents/ui.md → Gallery.
 */

.cg {
  /* The phone's own width: the frame's raster owns the ratio (shared.css → .device), so one number
     sizes the whole stage. */
  --cg-card-w: 11rem;
  /* The arriving capture's beat, in ms: the binder reads it for the fade and for the release of the
     borrowed frame. The leaving shot is the screen's background, so it does not fade — one beat,
     one number. */
  --cg-in: 240ms;
  /* Surface behind a capture while it decodes: the hole's own plate, never the page. */
  --cg-face: var(--surface-soft);
  position: relative;
  padding-block: var(--space-xl);
}

.cg-stage {
  display: flex;
  justify-content: center;
  /* The stage's height is the frame's, and the frame's is its ratio: nothing to reserve. */
  align-items: flex-start;
}

.cg-frame {
  display: block;
  width: var(--cg-card-w);
  /* One raster, no chrome: the phone IS the box (shared.css → .device owns the ratio and the hole). */
  --radius-device-screen: 0.75rem;
}

/* The capture in the hole. It is the only thing that fades. Every instance owns its own id prefix
   (`gallery-image`, `compare-image`), so the box is addressed by its place, never by one page's id. */
.cg-stage .device-screen > img {
  display: block;
  will-change: opacity;
}

/* The leaving shot is painted here for the length of the fade, sized exactly like the capture it
   replaces, so the phone never shows an empty hole and the bezel never moves. */
.cg-frame .device-screen {
  background-color: var(--cg-face);
  background-position: top center;
  background-size: cover;
  background-repeat: no-repeat;
}

/* ===== footer: the copy, the arrows, the filmstrip ========================== */

.cg-foot {
  display: grid;
  justify-items: center;
  gap: var(--space-md);
  padding-top: var(--space-lg);
  text-align: center;
}

.cg-copy {
  display: grid;
  align-content: start;
  gap: var(--space-3xs);
  /* A width, not just a cap: the footer centres its children, and a shrink-to-fit block whose only
     content is absolutely positioned measures zero — the morph's words then wrapped one per line. */
  width: min(100%, 46ch);
  min-height: 6rem;
}

/* Each line is a morph slot: its layers are absolutely centred, so the slot owns the width and the
   engine owns the height it reserves (shared.css → .morph-slot). */
.cg-copy > * {
  width: 100%;
}

.cg-eyebrow {
  margin: 0;
  color: var(--color-muted);
}

.cg-eyebrow:empty {
  display: none;
}

.cg-title {
  margin: 0;
  font-size: var(--fs-h4);
  line-height: var(--lh-heading);
  letter-spacing: var(--track-tight);
  text-wrap: balance;
}

.cg-body {
  margin: 0;
  color: var(--color-body);
  text-wrap: pretty;
}

.cg-body:empty {
  display: none;
}

.cg-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  max-width: 100%;
}

.cg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-circle);
  --r: var(--radius-circle);
  background: var(--surface-soft);
  color: var(--color-heading);
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out);
}

.cg-btn svg {
  width: 1rem;
  height: 1rem;
}

@media (hover: hover) {
  .cg-btn:hover {
    background: var(--color-border);
  }
}

.cg-strip {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  /* Wide enough for all seven thumbs at the desktop size, so the row reads as one list instead of a
     scroll; the window only bites on a phone. */
  max-width: min(100%, 28rem);
  padding: var(--space-3xs) var(--space-2xs);
  /* The strip is a window on the register, not a scroll: it centres the current thumb itself and
     never adds a second scrollbar to the page. */
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.cg-strip::-webkit-scrollbar {
  display: none;
}

/* A thumb is the same phone at chip size: the row reads as the register in miniature. The current
   one is the only one at full strength — a ring would paint a box, not a silhouette. The button is
   the 44px floor of DESIGN.md → Shapes; the phone inside it paints 36px, and the dim state scales
   that node, never the button: a transform on the button shrinks the hit area with the paint. */
.cg-thumb {
  flex: 0 0 auto;
  width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  cursor: pointer;
  /* On a white page the dimmed phones read as grey chips; the current one is the only black. */
  opacity: 0.35;
  /* Same rule as the stage, one size down: 4px is what a 33px screen needs. */
  --radius-device-screen: 0.25rem;
  transition: opacity var(--dur-base) var(--ease-out);
}

.cg-thumb > .device {
  transform: scale(0.94);
  transition: transform var(--dur-base) var(--ease-out);
}

.cg-thumb[aria-current="true"] {
  opacity: 1;
}

.cg-thumb[aria-current="true"] > .device {
  transform: none;
}

/* No hover ink here: a pointer resting on this row PINS its photo, so the thumb under the pointer
   is already the current one and full strength is its own answer. The outline is the only extra,
   and it belongs to the keyboard. */
.cg-thumb:focus-visible {
  outline: var(--focus-w) solid var(--focus-color);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  .cg {
    /* A phone reads the same one frame, a touch narrower: 46vw keeps the bezel inside the column
       with the footer's measure under it. */
    --cg-card-w: min(11rem, 46vw);
  }

  .cg-foot {
    gap: var(--space-sm);
    padding-top: var(--space-md);
  }

  .cg-copy {
    /* Three lines of body at the phone's measure, so the strip below never moves. */
    min-height: 7rem;
  }

  .cg-bar {
    gap: var(--space-2xs);
  }

  .cg-strip {
    max-width: 15rem;
  }

  .cg-thumb {
    width: 2.75rem;
    padding: 0 0.5rem;
  }
}

/* The hub's register is as wide as the column, and below 960px the floating prefs bar is fixed on
   the bottom-right (a 3.5rem box, a 1rem inset and a breath = 5rem of rail). On a narrow phone the
   next arrow landed under that pill at some scroll positions, so the register stacks over a centred
   arrow pair and both insets by the rail: the controls stay clear of the pill at every scroll, not
   just at the top of the section. Releases and the feed keep the one-row bar.
   Their register is narrower than the rail already, and those pages have no fixed rail of their own.
@media (max-width: 520px) {
  #gallery .cg-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    row-gap: var(--space-xs);
    justify-items: center;
    width: 100%;
    padding-inline: 5rem;
  }

  #gallery .cg-strip {
    grid-row: 1;
    grid-column: 1 / -1;
  }

  #gallery .cg-prev {
    grid-row: 2;
    grid-column: 1;
  }

  #gallery .cg-next {
    grid-row: 2;
    grid-column: 2;
  }
}

/* ===== an entry's instance: the same gallery, inside a media row ============ */
/* A release entry composes the same instance below its prose (`rl-media`, changelog.css) and so
   does a changelog entry (`.cl-panel-inner`, and that panel is narrower than a doc column). It
   takes the row's whole width and gives up the section's vertical breathing, because the stack
   above already owns the beat; the copy reads from the left under the phone instead of centred
   under the hub's hero-like stage. */
.rl-media .cg,
.cl-panel .cg {
  flex: 1 0 100%;
  padding-block: 0;
}

.rl-media .cg-foot {
  justify-items: center;
  padding-top: var(--space-md);
  text-align: center;
}

.cl-panel .cg-foot {
  justify-items: start;
  padding-top: var(--space-md);
  text-align: start;
}

.rl-media .cg-copy,
.cl-panel .cg-copy {
  width: min(100%, 62ch);
}

.rl-media .cg-bar {
  justify-content: center;
}

.cl-panel .cg-bar {
  justify-content: flex-start;
}

/* The panel is the narrowest surface the component lands on: its own row inset eats the width the
   arrows do not, so the register is what gives — it scrolls inside its own window rather than
   pushing the panel sideways. */
.cl-panel .cg-bar,
.cl-panel .cg-strip {
  max-width: 100%;
}

@media (max-width: 640px) {
  .rl-media .cg,
  .cl-panel .cg {
    /* A media row inside a document column has less room than a hub section, and
       the capture's `sizes` is the same 46vw: the hint never asks for a file the
       box cannot use. */
    --cg-card-w: min(9rem, 46vw);
  }

  .rl-media .cg-copy,
  .cl-panel .cg-copy {
    min-height: 7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cg-btn,
  .cg-thumb,
  .cg-thumb > .device,
  .cg-stage .device-screen > img {
    transition-duration: 0.01ms;
  }
}
