/* MM-14 + MM-16 — living pieces: the breath half of the one animation system (piece-life.js owns the
 * policy, clock and strip player; design in Vault docs/ludo/mm-16-living-pieces.md).
 *
 * Presentation only. The breath uses the individual `translate` / `scale` / `rotate` CSS properties,
 * which compose on top of the figure's fixed `transform` (experience.css / board-skins.css set it
 * !important), so no existing scale rule and no engine-written token-body transform is changed.
 * Figures are pointer-events:none; hit areas never move. Transform-only: nothing here triggers layout.
 *
 * One rule per figure: a figure playing its set's frame strip ([data-life-strip]) is alive through the
 * strip and the breath steps aside; every other figure breathes with its set's temperament.
 *
 * Stills: the animating rules only exist under prefers-reduced-motion: no-preference AND when the body
 * has neither .calm (in-app Reduced Motion) nor .performance-mode — so either setting stops it fully. */

/* Timing vocabulary — mirrored by LudoPieceLife.timing. */
:root {
  --life-breath-ms: 3400ms;
  --life-ease-breath: cubic-bezier(.45, 0, .55, 1);
  --life-ease-settle: cubic-bezier(.2, .8, .3, 1.2);
  --life-quick-ms: 140ms;
  --life-stride-ms: 520ms;
  --life-settle-ms: 240ms;
}

/* Temperaments (set personality). Defaults = steady (Arena Originals and any unknown set).
 * Two scales per set, because the surfaces differ in size:
 * - board (--life-lift in SVG units, --life-sx/--life-sy): a board figure is small, so it needs a large
 *   share of its own height. Steady IS the MM-14 live fix (#165: lift 3, 1.03/1.075 — track ~3.3 px,
 *   base ~4.1 px travel); every other set's top travel (lift + stretch) is at least steady's, so no set
 *   falls back to the old ~1 px lifts that read as still (mentat live QA, board 1095).
 * - HTML (--life-lift-pct in % of the figure, --life-hsx/--life-hsy): home squad, match setup. The Locker
 *   stage and the Locker grid thumbnails run the same tokens x --life-locker-k (1.6) through mm14-locker-idle — its
 *   figures sit small on a tilted floor, so #165 gave it ~1.6x the home breath (3.5%, 1.02/1.05). */
:root, .life-steady {
  --life-period: 3400ms; --life-lift: 3px; --life-sx: 1.03; --life-sy: 1.075;
  --life-lift-pct: 2.2%; --life-hsx: 1.012; --life-hsy: 1.034; --life-sway: 0deg;
  --life-locker-k: 1.6;
}
/* Holo Squad hovers: slower, higher, almost no squash — a projection, not a body. */
.warrior-figure[data-life-set="holo-squad"], .set-holo-squad, img[data-piece-set="holo-squad"] {
  --life-period: 4200ms; --life-lift: 4.5px; --life-sx: 1.01; --life-sy: 1.035;
  --life-lift-pct: 4.6%; --life-hsx: 1.006; --life-hsy: 1.012; --life-sway: 0deg;
}
/* Shadow Ops is coiled: a quicker breath, more squash than lift, with a slight weight shift. */
.warrior-figure[data-life-set="shadow-ops"], .set-shadow-ops, img[data-piece-set="shadow-ops"] {
  --life-period: 2800ms; --life-lift: 3px; --life-sx: 1.04; --life-sy: 1.09;
  --life-lift-pct: 2%; --life-hsx: 1.025; --life-hsy: 1.045; --life-sway: 1.2deg;
}
/* Arena Legends is heroic: its idle strip is its life; this breath is only its fallback. */
.warrior-figure[data-life-set="arena-legends"], .set-arena-legends, img[data-piece-set="arena-legends"] {
  --life-period: 3600ms; --life-lift: 3.4px; --life-sx: 1.032; --life-sy: 1.08;
  --life-lift-pct: 2.6%; --life-hsx: 1.014; --life-hsy: 1.04; --life-sway: 0deg;
}

/* Board amplitude (MM-14 live-QA fix, mentat board 1095): the first cut moved a board piece by only
 * ~1-2 CSS px (a track piece ~1 px), which ran but read as still — live QA measured 0 changed points.
 * A board figure is small, so its breath needs a larger share of its own height than the big home squad
 * figures: ~3-4 CSS px of lift plus a squash-and-stretch about the feet (transform-origin 50% 88%).
 * A base piece sits on a larger token body, so it scales the set's breath by --life-base-lift-k /
 * --life-base-scale-k (0.5 / 0.67: steady gives #165's base values, lift 1.5, 1.02/1.05). */
@keyframes mm14-piece-idle {
  0%, 100% { translate: 0 0; scale: 1 1; rotate: 0deg; }
  25% { rotate: calc(var(--life-sway) * -1); }
  50% {
    translate: 0 calc(var(--life-lift) * var(--life-base-lift-k, 1) * -1);
    scale: calc(1 + (var(--life-sx) - 1) * var(--life-base-scale-k, 1)) calc(1 + (var(--life-sy) - 1) * var(--life-base-scale-k, 1));
    rotate: 0deg;
  }
  75% { rotate: var(--life-sway); }
}

/* The home page squad and match setup figures are HTML <img>s: same breath, sized in %. */
@keyframes mm14-stage-idle {
  0%, 100% { translate: 0 0; scale: 1 1; rotate: 0deg; }
  25% { rotate: calc(var(--life-sway) * -1); }
  50% { translate: 0 calc(var(--life-lift-pct) * -1); scale: var(--life-hsx) var(--life-hsy); rotate: 0deg; }
  75% { rotate: var(--life-sway); }
}

/* The Locker stage (and Locker grid thumbnail) figures are smaller and seen through the stage's tilted floor, so the home % breath
 * moved them too little to register (live QA: 0 changed points). Same rhythm and set, larger share. */
@keyframes mm14-locker-idle {
  0%, 100% { translate: 0 0; scale: 1 1; rotate: 0deg; }
  25% { rotate: calc(var(--life-sway) * -1); }
  50% {
    translate: 0 calc(var(--life-lift-pct) * var(--life-locker-k) * -1);
    scale: calc(1 + (var(--life-hsx) - 1) * var(--life-locker-k)) calc(1 + (var(--life-hsy) - 1) * var(--life-locker-k));
    rotate: 0deg;
  }
  75% { rotate: var(--life-sway); }
}

/* An <img> playing a strip shows one frame through object-position (piece-life.js); it keeps the
 * frame's aspect ratio and stands on the bottom edge exactly where the still stood. */
img[data-life-strip] { height: auto !important; object-fit: cover !important; align-self: end; }
/* The match setup hero is sized by max-height with width:auto; a strip keeps the same square footprint. */
.match-setup-hero-art img[data-life-strip] { height: 132px !important; width: auto !important; max-height: 132px; }

/* Home page squad (Clement, board 1084: "I want the pieces on the home page to be animated also").
 * styles.css already floated each .lobby-character container, but that float ignored in-app Reduced
 * Motion and Performance Mode. It is retired here so the home squad runs the one MM-14 idle below,
 * which both settings fully still. The container keeps its static translateX(-50%) placement. */
#screen-lobby .lobby-character { animation: none; }

@media (prefers-reduced-motion: no-preference) {
  /* Inactive pieces on the board sit still at rest size (Clement 2026-12-02: no board breathing or CSS
   * motion; pieces come alive when acting). Home page, Match Setup and Locker keep their living idle below. */

  body:not(.calm):not(.performance-mode) .locker-stage-figure img:not([data-life-strip]) {
    transform-origin: 50% 100%;
    animation: mm14-locker-idle var(--life-period) var(--life-ease-breath) infinite;
  }
  body:not(.calm):not(.performance-mode) .locker-stage-piece.team-yellow .locker-stage-figure img { animation-delay: -850ms; }
  body:not(.calm):not(.performance-mode) .locker-stage-piece.team-red .locker-stage-figure img { animation-delay: -1700ms; }
  body:not(.calm):not(.performance-mode) .locker-stage-piece.team-green .locker-stage-figure img { animation-delay: -2550ms; }

  /* Locker grid (MM-16 follow-up, mentat live QA 2026-11-27): every piece-set thumbnail is alive, not
   * only the selected tile. The grid is where players browse sets to buy, so a set must look like it
   * lives before it is tapped. Cheap by construction: transform-only individual properties on four
   * small <img>s per tile, no strip decode, no layout; the same shared-clock breath as the Locker stage
   * (mm14-locker-idle is pinned in piece-life.js), so a re-rendered grid resumes its phase. The figures
   * are ~30 px tall, so they use the stage's larger share (x --life-locker-k) to register at all; each
   * set keeps its temperament through the .set-<id> tokens on .locker-piece-roster. */
  body:not(.calm):not(.performance-mode) .locker-item .locker-piece-roster img {
    transform-origin: 50% 100%;
    animation: mm14-locker-idle var(--life-period) var(--life-ease-breath) infinite;
  }
  body:not(.calm):not(.performance-mode) .locker-item .locker-piece-slot.team-yellow img { animation-delay: -850ms; }
  body:not(.calm):not(.performance-mode) .locker-item .locker-piece-slot.team-red img { animation-delay: -1700ms; }
  body:not(.calm):not(.performance-mode) .locker-item .locker-piece-slot.team-green img { animation-delay: -2550ms; }

  /* Match setup: the hero figure is alive; in the colour row only the selected swatch breathes. */
  body:not(.calm):not(.performance-mode) .match-setup-hero-art img:not([data-life-strip]),
  body:not(.calm):not(.performance-mode) .match-setup-colour.is-selected .match-setup-swatch img {
    transform-origin: 50% 100%;
    animation: mm14-stage-idle var(--life-period) var(--life-ease-breath) infinite;
  }

  body:not(.calm):not(.performance-mode) #screen-lobby .lobby-character img:not([data-life-strip]) {
    transform-origin: 50% 100%;
    animation: mm14-stage-idle var(--life-period) var(--life-ease-breath) infinite;
  }
  body:not(.calm):not(.performance-mode) #screen-lobby .lobby-character-yellow img { animation-delay: -850ms; }
  body:not(.calm):not(.performance-mode) #screen-lobby .lobby-character-red img { animation-delay: -1700ms; }
  body:not(.calm):not(.performance-mode) #screen-lobby .lobby-character-green img { animation-delay: -2550ms; }
}
