/* ============================================
   ANIMATIONS
   ============================================ */


/* highlight current player */
@keyframes pulseShadow {
    0% {
        box-shadow: var(--glow) 0 0 0 .25em;
    }

    50% {
        box-shadow: var(--glow) 0 0 0 .5em;
    }

    100% {
        box-shadow: var(--glow) 0 0 0 .25em;
    }
}

/* the breath of the glow of the player on turn (.player.current::before in linotte.css): a block behind the box that swells from
   .25em to .5em outside it (the box is about 110 x 80 px: .25em more on each side is a scale of about 1.065 by 1.085) */
@keyframes glowBreath {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.065, 1.085); }
}

@keyframes spinOut {
  0% {
    transform: rotate(0deg);
  }

  40% {
    transform: rotate(20deg);
  }

  65% {
    transform: rotate(11deg);
  }

  82% {
    transform: rotate(14deg);
  }

  100% {
    transform: rotate(12deg);
  }
}

@keyframes springOut {
  0% {
    transform: translate(0, 0) scale(1);
  }

  10% {
    transform: translate(-4%, 6%) scale(0.88);
  }

  26% {
    transform: translate(28%, -48%) scale(2.45);
  }

  40% {
    transform: translate(17%, -29%) scale(1.65);
  }

  54% {
    transform: translate(24%, -40%) scale(2.15);
  }

  66% {
    transform: translate(19.5%, -33.5%) scale(1.82);
  }

  78% {
    transform: translate(21.5%, -36.8%) scale(1.98);
  }

  88% {
    transform: translate(20.2%, -34.6%) scale(1.86);
  }

  94% {
    transform: translate(20.1%, -34.2%) scale(1.82);
  }

  100% {
    transform: translate(20%, -34%) scale(1.8);
  }
}

/* Tap feedback below (piece in/out, die, call, button) is deliberately
   quiet: one small move, transform and opacity only, timed by the --tap /
   --state tokens in linotte.css. The easing comes from the rule using it. */

/* piece placement: grows in from a little smaller, one slight overshoot */
@keyframes bounceIn {
  /* The 2.7.0 placement: the piece pops in from small with a few
     settling bounces (restored on the user's request). */
  0%, 20%, 40%, 60%, 80%, to {
    animation-timing-function: cubic-bezier(.215, .61, .355, 1);
  }

  0% {
    opacity: 0;
    transform: scale(.3);
  }

  20% {
    transform: scale(1.1);
  }

  40% {
    transform: scale(.9);
  }

  60% {
    opacity: 1;
    transform: scale(1.03);
  }

  80% {
    transform: scale(.97);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* piece removed: shrinks a touch while it fades */
@keyframes bounceOut {
  /* The 2.7.0 removal: the piece swells and fades out. */
  0% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0;
    transform: scale(2);
  }

  to {
    opacity: 0;
    transform: scale(1);
  }
}

/* die (and option) selection: a short press. The ring itself is a plain
   style on .selected in linotte.css, so nothing stays filled afterwards. */
@keyframes bounceDie {
  /* The 2.7.0 selection bounce: in, out, settle. The ring itself is a
     plain style on .selected (linotte.css), so nothing stays filled. */
  40%, 60%, 80%, to {
    animation-timing-function: cubic-bezier(.215, .61, .355, 1);
  }

  40% {
    transform: scale(.9);
  }

  60% {
    transform: scale(1.1);
  }

  80% {
    transform: scale(.95);
  }

  to {
    transform: scale(1);
  }
}

/* the same press, on the wrapper around a die (see .wrapDie in linotte.css) */
@keyframes bounceDieWrap {
  /* The 2.7.0 selection bounce: in, out, settle. The ring itself is a
     plain style on .selected (linotte.css), so nothing stays filled. */
  40%, 60%, 80%, to {
    animation-timing-function: cubic-bezier(.215, .61, .355, 1);
  }

  40% {
    scale: .9;
  }

  60% {
    scale: 1.1;
  }

  80% {
    scale: .95;
  }

  to {
    scale: 1;
  }
}

/* clock top tile */
@keyframes flipTop {
  to {
    transform: rotateX(-180deg);
  }
}

/* clock bottom tile */
@keyframes flipBottom {
  from {
    transform: scale(1.1, 0.8) rotateX(180deg);
  }

  to {
    transform: rotateX(0deg);
  }
}

/* call selection: a small lift as it lights up */
@keyframes bounceCall {
  /* The 2.7.0 call: it swells as it lights up, then settles. */
  40%, 60%, 80%, to {
    animation-timing-function: cubic-bezier(.215, .61, .355, 1);
  }

  40% {
    transform: scale(.9);
  }

  60% {
    transform: scale(1.3);
  }

  80% {
    transform: scale(.97);
  }

  to {
    transform: scale(1);
  }
}


/* button press: a slight push in */
@keyframes bounceButton {
  50% {
    transform: scale(.95);
  }

  to {
    transform: scale(1);
  }
}

/* fairy trail: the piece on a tile hops the instant the spark reaches it
   (see shared/fairyTrail.js's onWaypoint callback, wired in linotte.js).
   Classic cartoon squash-and-stretch: a quick squash as it leaves the
   ground, stretched tall at the peak, a squash again on landing. This is
   applied via .piece-jump to the WRAPPER (.wrapPiece), never to .piece
   itself (see jumpPiece() in linotte.js) -- .piece carries its own
   per-instance rotate()+translate() from applyTidyness()'s "scattered
   pieces" look as an inline transform, and a running animation on
   `transform` fully overrides that element's transform for its duration,
   so animating .piece directly used to snap that rotation away and back
   -- a real, visible spin, not just a look. .wrapPiece's own leftover
   transform (scale(1) from the bounceIn placement animation) is a true
   identity, so taking it over here and handing it back is silent. */
/* Every value the jump shape depends on is a CSS variable with a fallback --
   these fallbacks were tuned live in fairy-playground.html (duration 0.66s,
   height -14%, squash/stretch intensity 1.8x) and carried back here as the
   real gameplay values. A debug page can still override them on a single
   wrapper via inline style, or globally on :root, to live-tune the jump
   without touching this file. */
@keyframes pieceJump {
  0% {
    transform: translateY(0) scale(1, 1);
  }

  20% {
    transform: translateY(var(--jump-windup, 1.75%)) scale(var(--jump-squash-out-x, 1.144), var(--jump-squash-out-y, 0.892));
  }

  50% {
    transform: translateY(var(--jump-height, -14%)) scale(var(--jump-stretch-x, 0.91), var(--jump-stretch-y, 1.108));
  }

  80% {
    transform: translateY(var(--jump-windup, 1.75%)) scale(var(--jump-squash-in-x, 1.09), var(--jump-squash-in-y, 0.928));
  }

  100% {
    transform: translateY(0) scale(1, 1);
  }
}

.piece-jump {
  animation-name: pieceJump;
  animation-duration: var(--jump-duration, 0.66s);
  animation-timing-function: cubic-bezier(.45, 0, .2, 1);
  animation-iteration-count: 1;
}

/* Touching a placed piece: a soft jelly wobble, chosen by the user on a
   test page ("I", 840ms, 65%). The piece stays on its base (transform-origin
   at the bottom) and squashes and stretches in waves that die out, like a
   dense jelly. The fairy-trail jump above is a celebration and keeps its
   own size and timing. */
@keyframes pieceTapJelly {
  0%   { transform: none; }
  15%  { transform: scale(1.0858, 0.922); }
  30%  { transform: scale(0.9376, 1.0702); }
  45%  { transform: scale(1.039, 0.9649); }
  60%  { transform: scale(0.9805, 1.0195); }
  75%  { transform: scale(1.0098, 0.9922); }
  100% { transform: none; }
}

.piece-jump.piece-tap {
  animation-name: pieceTapJelly;
  animation-duration: 840ms;
  animation-timing-function: cubic-bezier(.3, .6, .4, 1);
  transform-origin: 50% 95%;
}

/* Player info table: the pieces-remaining and points numbers pop when
   they change (see popStat() in linotte.js) -- pieces pop immediately
   when a placement commits; points pop only once the fairy trail's extra
   hop off the board (see celebratePoints() in linotte.js) actually lands
   on the points number -- the trail itself is what visually travels
   there, this is just the number reacting to its arrival.
   A single spring-ish (back-out) easing curve drives the whole bounce
   instead of hand-placed undershoot keyframes -- CSS re-applies the
   timing function to EACH segment (0->50 and 50->100) independently, so
   it naturally overshoots past 1.4 on the way up and past 1 on the way
   back down by itself, which reads as a springy "boing" rather than the
   more mechanical, evenly-eased 4-point version this replaced. */
@keyframes statPop {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.4);
  }

  100% {
    transform: scale(1);
  }
}

.stat-pop {
  display: inline-block;
  animation: statPop 700ms cubic-bezier(.34, 1.56, .64, 1);
}

/* The piece count ticks over like an odometer/counter widget instead of
   popping in place: the old value (a temporary clone, see tickStat() in
   linotte.js -- a single text node can't show two values sliding past
   each other at once) slides up and out while the live element's new
   value slides in from below to take its spot. */
@keyframes statTickOut {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  100% {
    transform: translateY(-120%) scale(0.7);
    opacity: 0;
  }
}

.stat-tick-out {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  /* Above the game, below every menu and panel (options 50, home 60...):
     a piece or point that changes while the menu is open must not show
     on top of it. */
  z-index: 44;
  animation: statTickOut 480ms cubic-bezier(.4, 0, .2, 1) forwards;
}

/* The incoming value slides up AND pops -- overshooting past full size as
   it arrives, then settling -- instead of a plain linear slide, so landing
   in place has some bounce to it rather than just stopping dead. */
@keyframes statTickIn {
  0% {
    transform: translateY(120%) scale(0.6);
    opacity: 0;
  }

  60% {
    transform: translateY(0) scale(1.6);
    opacity: 1;
  }

  80% {
    transform: translateY(0) scale(0.85);
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.stat-tick-in {
  display: inline-block;
  animation: statTickIn 620ms cubic-bezier(.34, 1.56, .64, 1);
}

/* The winner popup's final score (see showWinnerPopup() in linotte.js,
   which also counts the number itself up to that value while this plays)
   pops in with a spring overshoot rather than just appearing. */
@keyframes winnerPointsReveal {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }

  60% {
    transform: scale(1.15);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.winner-points-reveal {
  animation: winnerPointsReveal 600ms cubic-bezier(.34, 1.56, .64, 1);
}

/* A looping light sweep across the score text (see .winner-points-shine in
   linotte.css for the gradient + text-clip setup this animates) -- runs
   continuously the whole time the popup is up, independent of the one-shot
   pop-in above since it lives on a separate inner element. */
/* A shimmer sweep: the narrow bright band in .winner-points-shine's
   gradient's bright band (see linotte.css, now spanning 30%-70% of the
   gradient) sits fully clear of the visible glyph area at both 120% and
   -20% -- confirmed by sampling the actual rendered text at several
   positions, not just assumed from the numbers -- so at rest the text
   just reads as solid gold. It crosses the visible area during 0%->60% of
   the cycle (a good deal slower than an earlier, much quicker 0%->35%
   version); 60%->100% holds at the same (again off-screen) position,
   which is what makes it read as an occasional slow glide with a pause,
   rather than a fast, constant sweep. */
@keyframes winnerPointsShimmer {
  0% {
    background-position: 120% 0;
  }

  60% {
    background-position: -20% 0;
  }

  100% {
    background-position: -20% 0;
  }
}

.winner-points-shine {
  animation: winnerPointsShimmer 3.6s ease-in-out infinite;
}

/* A "+N" that pops up right at the points number and rises/fades in
   place, see showPlusPopup(). Fixed positioning + a viewport coordinate
   set from JS, since it needs to sit above the player info table
   regardless of that table's own layout. */
@keyframes statPlusFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.8);
  }

  15% {
    opacity: 1;
    transform: translate(-50%, -0.3em) scale(1.15);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -1.6em) scale(1);
  }
}

.stat-plus-popup {
  position: fixed;
  /* Detached from the player box's own font-size chain (appended straight
     to <body>), so it needs its own size -- matched to roughly double
     .textPlayer.t2's 4vw (see linotte.css) so it actually reads clearly
     next to the number instead of blending into the UI at body size. */
  font-size: 8vw;
  white-space: nowrap;
  color: #ffea00;
  font-weight: bold;
  text-shadow: 0 0 .15em rgba(0, 0, 0, .7), 0 0 .3em rgba(0, 0, 0, .4);
  pointer-events: none;
  z-index: 44; /* above the game, below every menu (see .stat-tick-out) */
  animation: statPlusFloat 900ms ease-out forwards;
}
