/* ===========================================================================
   carousel.css — the Melancholy Love character wheel. Added 2026-07-27.

   Three panels visible: one in focus, one either side, turned away on a wheel.

   WHY A ROTATION IS HONEST HERE, WHEN IT WAS NOT FOR THE CHARACTER SELECTOR.
   The selector deliberately avoids faux-3D because faking a turnaround implies
   the reader is seeing the character's other side, and no turnaround art
   exists. This is a different claim: the flat sheets are arranged on a wheel
   and the WHEEL turns. Nothing pretends a drawing has a back. rotateY is
   applied to the panel, never to imply depth inside the artwork.

   NO AUTOPLAY, EVER. Advance is user-driven only — buttons, keyboard, or clicking a
   neighbour. A portfolio piece that slides away while someone is still
   looking at it is worse than no carousel at all.

   FAIL-VISIBLE, same contract as reveal.js and character-select.js. The track
   is a plain grid of 12 figures until js/carousel.js adds .js-carousel, and
   the controls are built by that script rather than sitting dead in markup.
   Script dies -> the reader gets the gallery this replaced.
   =========================================================================== */

/* --- Without JS: the grid it was ----------------------------------------- */
.carousel__track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr));
  gap: var(--space-m) var(--space-s);
  margin: 0;
  padding: 0;
  list-style: none;
}

.carousel__item { margin: 0; }

.carousel__figure {
  display: block;
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius-media);
  background: color-mix(in srgb, var(--color-text) 6%, transparent);
}

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

.carousel__cap {
  margin-top: var(--space-3xs);
  color: var(--color-text-muted);
}

/* ===========================================================================
   WITH JS — the wheel
   =========================================================================== */

.js-carousel .carousel { margin-top: var(--space-l); }

.js-carousel .carousel__stage {
  position: relative;
  /* The sheets are all 1920x1080, so the stage locks to a ratio derived from
     them and never resizes as panels move through it.

     THE RATIO IS NOT 1920/1080. That was the bug: it sized the stage as though
     a sheet spanned the full width, but a panel is only 62% wide (see
     .carousel__item below), so the artwork drew at 714x402 inside a 1152x648
     box and sat at the top of it — measured, 246px of dead cream below the
     wheel, which was the largest unexplained gap on the page.

     Derivation, so this stays correct if the 62% ever changes:
       panel height = width * 0.62 * (1080/1920)
       stage ratio  = 1 / (0.62 * 1080/1920) = 1920 / (1080 * 0.62) = 1920/669.6
     Keep this in step with the width in .carousel__item and with the mobile
     override at the foot of this file. */
  aspect-ratio: 1920 / 669.6;
  /* The wheel only reads as a wheel with perspective. Without it, rotateY is
     an affine squash and the effect collapses into a horizontal scale. */
  perspective: 1400px;
  perspective-origin: 50% 50%;
  overflow: hidden;
  /* Claims horizontal drags for the swipe handler in carousel.js while leaving
     vertical page scrolling entirely to the browser. Doing it declaratively
     here means the JS listeners can stay passive and can never stall the
     scroller. */
  touch-action: pan-y;
}

.js-carousel .carousel__track {
  display: block;
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.js-carousel .carousel__item {
  position: absolute;
  top: 0;
  /* 62% wide, centred: the focused panel dominates while still leaving a
     neighbour visible on each side. */
  left: 19%;
  width: 62%;
  transform-origin: 50% 50%;
  /* --step IS THE PANEL PITCH, and it is a token because TWO owners need it.
     CSS uses it to place the panels; js/carousel.js reads it back off this
     element to convert pointer pixels into panels during a drag. Hard-coding
     54% here and 54 in the script meant the mobile override below (a different
     pitch) silently made the drag track at the wrong rate. One value, read by
     both, and the breakpoint only has to change it once. */
  --step: 0.54;
  /* Everything else is driven from --off (signed distance from focus) and
     --dist (its absolute value), written per frame by js/carousel.js. Both are
     FRACTIONAL now, so the wheel can rest anywhere between two panels. */
  transform:
    translateX(calc(var(--off, 0) * var(--step) * 100%))
    translateZ(calc(var(--dist, 0) * -170px))
    rotateY(calc(var(--off, 0) * -34deg))
    scale(calc(1 - var(--dist, 0) * 0.14));
  /* --dim is the per-step dimming, lifted to a custom property so the
     neighbour hover below can ease it back without redeclaring the whole
     opacity expression (or fighting it from a child element, where a nested
     opacity multiplies and can never brighten). */
  opacity: calc(1 - var(--dist, 0) * var(--dim, 0.55));
  z-index: calc(10 - var(--dist, 0));
  pointer-events: none;
}

/* --- Attribute contract, rewritten 2026-08-10 ---------------------------
   `--off` and `--dist` are now FRACTIONAL — carousel.js drives a continuous
   wheel position so the panels can follow a finger. That split what used to
   be one `data-hidden` flag into two, because the two jobs it was doing now
   change at different moments:

     data-far    purely visual, keyed on FRACTIONAL distance
     data-focus  pointer + semantics, keyed on ROUNDED distance

   Keying pointer-events on the fractional value would make a panel flicker
   between clickable and inert as it slid past the halfway mark mid-drag. */

/* The opacity expression above already fades a panel out by about dist 1.8.
   This is only a hard cut so a far panel can never bleed at the stage edge. */
.js-carousel .carousel__item[data-far="true"] { opacity: 0; }

/* The focused panel stays interactive: it carries the link to the full-size
   sheet. Everything further out is inert so it cannot swallow a click. */
.js-carousel .carousel__item[data-focus="true"] { pointer-events: auto; }

/* Neighbours are clickable, so the wheel can be turned by grabbing the thing
   you want — which is how a physical wheel behaves. */
.js-carousel .carousel__item[data-neighbour="true"] {
  pointer-events: auto;
  cursor: pointer;
}

/* While a drag is live the reader is holding the wheel, so say so on desktop
   and stop a drag from starting a text selection inside the artwork. */
.js-carousel .carousel__stage[data-dragging] {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

.js-carousel .carousel__figure { height: 100%; background: none; }
.js-carousel .carousel__img { height: 100%; object-fit: contain; }
/* The static caption stays hidden in the wheel — .carousel__caption below
   shows the focused panel's text instead — but it REMAINS IN THE MARKUP and in
   the accessibility tree, because it is how a screen reader reaches Ruby's
   description of the sheet it is currently on. Do not delete it. */
.js-carousel .carousel__cap { display: none; }

/* --- Caption -------------------------------------------------------------
   The twelve captions run one to three sentences, so this needs a stable box: without min-height the controls
   above would jump every time the wheel turned onto a longer or shorter one —
   the same class of defect as the label width fixed above. */
.carousel__caption {
  max-width: var(--measure);
  margin: var(--space-m) auto 0;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--step-small);
  text-wrap: pretty;
  min-height: calc(3 * 1.6em);
}

@media (prefers-reduced-motion: no-preference) {
  .carousel__caption { transition: opacity 260ms var(--ease-out); }
}

/* --- Controls ------------------------------------------------------------
   Rebuilt 2026-07-28. What was wrong, measured on the live page:

   1. The row is full-bleed (1152px) but the controls were laid out from its
      left edge, so a small cluster sat in the bottom-left corner of an
      otherwise empty rule while the wheel above it was centred. Nothing lined
      up with anything.
   2. THE NEXT BUTTON MOVED AS YOU PAGED. prev sat at x=64 and next at x=234,
      with a variable-width label between them — measured from 70px ("Niamh")
      to 142px ("Vampire hunter 2"). Advancing the wheel therefore slid the
      next button up to 72px sideways, so a reader clicking through the roster
      was chasing the control. That did more to make these read as generic
      plugin leftovers than the arrow shapes did.
   3. The counter was proportional, so 1/12 -> 11/12 shifted again.

   Fixed by centring the group under the stage and giving the label a
   min-width wider than the longest label it will ever hold, with tabular
   figures. min-width rather than a fixed width so unexpected future content
   still fits — it just costs the stability back, which is the right way round.

   NO DISABLED STATE, DELIBERATELY. The wheel wraps (carousel.js offsetOf takes
   the shortest way round a ring), so neither button is ever a dead end. A
   greyed-out arrow here would be a lie about the component. */
.carousel__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-s);
  margin-top: var(--space-m);
}

.carousel__btn {
  flex: 0 0 auto;
  /* 2.75rem -> 3.5rem, 2026-07-28. 44px was the accessible minimum and nothing
     more, which under a 1152px wheel of full-bleed artwork read as two small
     utility buttons parked below the work rather than as part of it. 56px
     carries the scale of the thing it drives, and puts the hit area
     comfortably past the minimum instead of exactly on it. */
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  border: 1.5px solid currentColor;
  border-radius: var(--radius-pill);
  background: none;
  color: inherit;
  display: grid;
  place-items: center;
  line-height: 1;
}

/* A real stroked arrow, not U+2190. Satoshi has no arrow glyph, so the old
   text entities fell back to a system font and rendered hairline against this
   1.5px ring — see the note on .icon in base.css. stroke-width 2 on a 24-unit
   viewBox at 20px resolves to ~1.7px, which is the ring weight. */
.carousel__arrow {
  width: 1.65rem;
  height: 1.65rem;
  display: block;
  /* Direction and nudge travel as custom properties so the hover transform can
     compose both instead of clobbering the rotation. */
  transform: translateX(0) rotate(var(--arrow-rotate, 0deg));
}

.carousel__btn--prev .carousel__arrow { --arrow-rotate: 180deg; --arrow-nudge: -2px; }
.carousel__btn--next .carousel__arrow { --arrow-rotate: 0deg;   --arrow-nudge: 2px; }

.carousel__label {
  color: var(--color-text-muted);
  margin: 0;
  /* The two numbers are the whole reason for tabular figures: without them
     "1 / 12" and "11 / 12" set to different widths and the buttons twitch. */
  font-variant-numeric: tabular-nums;
  /* Wider than the longest label (142px measured, "Vampire hunter 2"), so the
     buttons hold still across all twelve. */
  min-width: 12rem;
  text-align: center;
}

.carousel__name { color: var(--color-text); font-weight: var(--fw-bold); }

/* ===========================================================================
   MOTION
   ===========================================================================
   THE PANEL TRANSITION IS GONE, AND MUST NOT COME BACK. Removed 2026-08-10.

   It used to be `transition: transform 620ms, opacity 480ms` on
   .carousel__item. carousel.js now integrates the wheel position itself — a
   spring, so the wheel can be grabbed mid-flight and can carry a flick's
   velocity into the settle. A CSS transition on top of that means two owners
   easing the same property: the script writes a value it has already eased,
   and the transition then eases toward THAT, so every panel lags its own
   animation by the transition duration.

   This is the same trap css/statement-field.css documents for the glyph
   field, and it has the same resolution — the per-frame integration IS the
   easing. Reduced motion is handled in the script (it jumps straight to the
   target), not here.

   620ms was also simply too slow for a control the reader pressed. Apple
   ships ~0.4s for a reposition; the spring below settles in about that. */

@media (prefers-reduced-motion: no-preference) {
  /* 260ms -> 200ms. These are input-driven, so they answer the press rather
     than performing for it. */
  .carousel__btn {
    transition: background-color 200ms var(--ease-out),
                color 200ms var(--ease-out),
                border-color 200ms var(--ease-out),
                transform 200ms var(--ease-out);
  }
  .carousel__arrow { transition: transform 260ms var(--ease-enter); }
}

@media (hover: hover) {
  .carousel__btn:hover {
    background: var(--color-text);
    color: var(--color-bg);
    border-color: var(--color-text);
  }
  /* The arrow leads out of the button, matching the pill hover in motion.css
     layer 4 so the two arrow treatments on the page behave the same way.
     rotate() is composed in or the prev arrow would flip east mid-hover. */
  .carousel__btn:hover .carousel__arrow {
    transform: translateX(var(--arrow-nudge, 0)) rotate(var(--arrow-rotate, 0deg));
  }

  /* A neighbour panel is clickable (it turns the wheel) and carries
     cursor:pointer, but gave no visual response at all — a hand cursor over
     something that looked inert. Easing --dim from 0.55 to 0.25 lifts it from
     45% to 75% opacity: clearly reachable, still plainly not the focused
     panel. */
  .js-carousel .carousel__item[data-neighbour="true"]:hover { --dim: 0.25; }
}

/* Pressed state. Without this the button recolours on hover and then does
   nothing at all on the click itself, which is the specific thing that makes a
   control feel unresponsive. Kept outside the reduced-motion query on purpose:
   base.css flattens the duration there, so it becomes an instant state change
   rather than a missing one. */
.carousel__btn:active { transform: scale(0.94); }

/* --- Mobile: flatten the wheel and give the artwork the screen -----------
   At small widths a 34deg turn on a 62%-wide panel throws the neighbours
   almost entirely off-stage, and the perspective cost buys nothing anyone can
   see. The wheel becomes a gentler slide instead.

   PANEL WIDTH 76% -> 92%, 2026-08-10. Measured at a 390px viewport: a
   character sheet was drawing at 269x151 inside a 354px stage. Ruby's sheets
   carry several expression studies each; at 151px tall those are not readable,
   and the character SELECTOR directly below — same screen, same artwork class
   — was giving them 354x246. The wheel was the worst place on the site to see
   the work it exists to show.

   At 92% the sheet draws 326x183: 47% more image area, with about 8% of the
   next panel still peeking at each edge. Full width was the other option and
   was rejected — the peek is the only remaining "there is more" cue at rest,
   now that the flattened wheel has no perspective to imply depth.

   Derivation, kept in step with the desktop note above:
     stage ratio = 1920 / (1080 * 0.92) = 1920/993.6 */
@media (max-width: 47.99rem) {
  .js-carousel .carousel__stage {
    perspective: none;
    aspect-ratio: 1920 / 993.6;
  }
  .js-carousel .carousel__item {
    left: 4%;
    width: 92%;
    /* Panels sit shoulder to shoulder with a sliver of overlap. carousel.js
       reads this to scale the drag, so it must stay a --step. */
    --step: 0.96;
    transform:
      translateX(calc(var(--off, 0) * var(--step) * 100%))
      scale(calc(1 - var(--dist, 0) * 0.1));
  }
}
