/* REFERENCE
 * - ui/overlay/mote-tools.js (HELD_ITEMS these rules pose: tuoppi,
 *   puumiekka, finflag)
 * - ui/companion/mote-work.css (work-tool pattern this mirrors; reuses
 *   its mh-wrist-lag + mh-rock-chop keyframes)
 * - ui/mote-animation/mote-anim-roll.css (generic mh-hat-settle these
 *   per-hat physics rules override for the new hats)
 *
 * Idle HOLD poses + accents for cosmetic held items, and per-hat landing
 * physics. Design laws (perspective panel 2026-07-11): each prop has its
 * own mass model and event rate — mug acts every 9s, sword poises at
 * 4.8s, flag waves always at 1.9s (periods avoid the 3.4-3.7s band that
 * would beat against the hand bob). POLICY: the tuoppi never touches the
 * mouth — a hoist is a gesture, drinking is a platform classification.
 */

/* ── Tuoppi: one-handed hold at the body's SIDE (Ville: not in front of
   the face) — mug beside the right hull edge; free hand keeps its bob ── */
.pg-mote--hold-tuoppi .mote-tool {
  visibility: visible;
  transform: translate(78px, 60px) rotate(-4deg);
}
.pg-mote--hold-tuoppi .mote-hand--r {
  animation: mh-mug-hand 9s ease-in-out infinite;
  transform: translate(-4.5px, 0) rotate(-6deg);
}
.pg-mote--hold-tuoppi .mt-tuoppi { animation: mh-mug-tilt 9s ease-in-out infinite; }

@keyframes mh-mug-hand {
  0%, 100% { transform: translate(-4.5px, 0) rotate(-6deg); }
  45%      { transform: translate(-4.5px, -0.9px) rotate(-6deg); }
  82%, 88% { transform: translate(-3.5px, -3px) rotate(-6deg); }   /* small admire lift */
  95%      { transform: translate(-4.5px, -0.5px) rotate(-6deg); }
}
@keyframes mh-mug-tilt { /* wrist-only foam slosh — rotation about the grip */
  0%, 78%, 100% { transform: translate(0, 0) rotate(0deg); }
  82%, 88%      { transform: translate(0.5px, -2px) rotate(-10deg); }
  95%           { transform: translate(0, -0.3px) rotate(-1deg); }
}

/* Cheers one-shot (JS adds .pg-mote--cheers, removes on animationend):
   the whole toolarm hoists, so the free hand joins the toast. */
.pg-mote--cheers .mote-toolarm { animation: mh-cheers 900ms cubic-bezier(0.34, 1.56, 0.64, 1) 1; }
@keyframes mh-cheers {
  0%   { transform: translate(0, 0) rotate(0deg); }
  35%  { transform: translate(0, -6px) rotate(7deg); }
  60%  { transform: translate(0, -5px) rotate(6deg); }   /* hold the toast */
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ── Puumiekka: two-handed kid-grip, fencer's poise (no bob — swords
   poise, they don't float). Tip lags the arm 150ms = blade mass. ── */
.pg-mote--hold-puumiekka .mote-hand { animation: none; }
.pg-mote--hold-puumiekka .mote-tool {
  visibility: visible;
  transform: translate(74px, 58px) rotate(22deg);
}
.pg-mote--hold-puumiekka .mote-hand--r { transform: translate(-8.5px, -2px) rotate(20deg); }
.pg-mote--hold-puumiekka .mote-hand--l { transform: translate(59px, 4.3px) rotate(20deg); }
.pg-mote--hold-puumiekka .mote-toolarm { animation: mh-sword-ready 4.8s ease-in-out infinite; }
.pg-mote--hold-puumiekka .mt-puumiekka { animation: mh-sword-poise 4.8s ease-in-out -150ms infinite; }

@keyframes mh-sword-ready {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  30%      { transform: translate(0, -0.7px) rotate(-2.5deg); }
  62%      { transform: translate(0.4px, 0) rotate(1.5deg); }
}
@keyframes mh-sword-poise {
  0%, 100% { transform: rotate(0deg); }
  30%      { transform: rotate(-1.2deg); }
  62%      { transform: rotate(0.8deg); }
}

/* Flourish one-shot: apex at the house 60% mark; reuses the work-file
   wrist-lag and body-rock keyframes (both stylesheets load together). */
.pg-mote--flourish .mote-toolarm { animation: mh-flourish 1.3s 1; }
.pg-mote--flourish .mt-puumiekka { animation: mh-wrist-lag 1.3s 1; }
.pg-mote--flourish .mote-body-anim { animation: mh-rock-chop 1.3s 1; }
@keyframes mh-flourish {
  0%   { transform: translate(0, 0) rotate(0deg);          animation-timing-function: ease-in-out; }
  42%  { transform: translate(0, -1px) rotate(-44deg);     animation-timing-function: linear; }
  50%  { transform: translate(0, -1px) rotate(-47deg);     animation-timing-function: cubic-bezier(0.7, 0, 1, 0.6); }
  60%  { transform: translate(7px, 1px) rotate(58deg);     animation-timing-function: ease-out; }
  70%  { transform: translate(7.5px, 1.5px) rotate(64deg); animation-timing-function: ease-in-out; }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ── Finflag: one-handed display hold — cloth breaks the crown line.
   Pole leads (5.7s = 3×1.9s, gust lands on the same cloth phase), cloth
   follows. scaleX squeeze at extremes = length conservation (cloth, not
   cardboard). ── */
.pg-mote--hold-finflag .mote-hand--r {
  animation: none;
  transform: translate(-10.5px, -8px) rotate(10deg);
}
.pg-mote--hold-finflag .mote-tool {
  visibility: visible;
  transform: translate(72px, 52px) rotate(12deg);
}
.pg-mote--hold-finflag .mt-finflag { animation: mh-pole-sway 5.7s ease-in-out infinite; }
.pg-mote--hold-finflag .mt-flag-c1 { animation: mh-cloth 1.9s ease-in-out infinite; }

@keyframes mh-pole-sway {
  0%, 100% { transform: rotate(-2deg); }
  40%      { transform: rotate(2.5deg); }
  60%, 68% { transform: rotate(4.5deg); }  /* the gust */
  84%      { transform: rotate(0.5deg); }
}
@keyframes mh-cloth {
  0%, 100% { transform: rotate(-3deg) scaleX(1); }
  50%      { transform: rotate(3deg) scaleX(0.95); }
}

/* ── Per-hat landing physics (needs the identity-transform hat rig):
   duration ∝ fit looseness, overshoot ∝ softness, delay ∝ air gap. ── */
.pg-mote--landing .mote-hat--lippis { animation: mh-hat-settle-stiff 300ms cubic-bezier(0.3, 1.4, 0.6, 1); }
@keyframes mh-hat-settle-stiff {
  0%   { transform: translate(0, -2px) rotate(1deg); }
  60%  { transform: translate(0, 0.5px) rotate(-0.5deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
.pg-mote--landing .mote-hat--pipo { animation: mh-hat-settle-soft 420ms cubic-bezier(0.34, 1.4, 0.64, 1); }
@keyframes mh-hat-settle-soft {
  0%   { transform: translate(0, -3px) rotate(2.5deg); }
  55%  { transform: translate(0, 1px) rotate(-1.5deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
.pg-mote--landing .mote-hat--cowboy { animation: mh-hat-settle-cowboy 550ms cubic-bezier(0.25, 1.1, 0.5, 1) 40ms backwards; }
@keyframes mh-hat-settle-cowboy {
  0%   { transform: translate(0, -4.5px) rotate(-3deg); }
  45%  { transform: translate(0, 1.5px) rotate(2deg); }
  70%  { transform: translate(0, -0.6px) rotate(-1deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ── Held items ride along on rolls: the ball spins, the floating hands
   and prop glide with it — hats already spin with the ball (Ville:
   "pyörivät esineen kanssa oletuksena"). Beats the base roll-hide. ── */
.pg-mote--rolling[class*="pg-mote--hold-"] .mote-hands { opacity: 1; }

/* headphones: spring-clamped to the skull — barely moves. Stiffest. */
.pg-mote--landing .mote-hat--headphones { animation: mh-hat-settle-clamp 260ms cubic-bezier(0.3, 1.3, 0.6, 1); }
@keyframes mh-hat-settle-clamp {
  0%   { transform: translate(0, -1.5px) rotate(0.5deg); }
  65%  { transform: translate(0, 0.4px) rotate(-0.3deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
/* viking: rigid metal clonk — big drop, one firm bounce. */
.pg-mote--landing .mote-hat--viking { animation: mh-hat-settle-clonk 380ms cubic-bezier(0.28, 1.5, 0.5, 1); }
@keyframes mh-hat-settle-clonk {
  0%   { transform: translate(0, -3.5px) rotate(-1.5deg); }
  55%  { transform: translate(0, 1.4px) rotate(0.8deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
/* flower: near-massless flutter — extra rotational wobble, air gap. */
.pg-mote--landing .mote-hat--flower { animation: mh-hat-settle-flutter 480ms cubic-bezier(0.34, 1.45, 0.62, 1) 20ms backwards; }
@keyframes mh-hat-settle-flutter {
  0%   { transform: translate(0, -2.8px) rotate(2.5deg); }
  45%  { transform: translate(0, 0.9px) rotate(-1.8deg); }
  72%  { transform: translate(0, -0.4px) rotate(0.9deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ── Reduced motion: static held poses survive, all motion dies. ── */
@media (prefers-reduced-motion: reduce) {
  .pg-mote--hold-tuoppi .mote-hand--r,
  .pg-mote--hold-tuoppi .mt-tuoppi,
  .pg-mote--cheers .mote-toolarm,
  .pg-mote--hold-puumiekka .mote-toolarm,
  .pg-mote--hold-puumiekka .mt-puumiekka,
  .pg-mote--flourish .mote-toolarm,
  .pg-mote--flourish .mt-puumiekka,
  .pg-mote--flourish .mote-body-anim,
  .pg-mote--hold-finflag .mt-finflag,
  .pg-mote--hold-finflag .mt-flag-c1,
  .pg-mote--landing .mote-hat--lippis,
  .pg-mote--landing .mote-hat--pipo,
  .pg-mote--landing .mote-hat--cowboy,
  .pg-mote--landing .mote-hat--headphones,
  .pg-mote--landing .mote-hat--viking,
  .pg-mote--landing .mote-hat--flower { animation: none !important; }
}
