/* PiggyAnim — glossy gold piggy bank VFX (Hikari style). transform/opacity only. */
.piggy-anim {
  --pa-gold-1: #fff3b8;
  --pa-gold-2: #f6cf6a;
  --pa-gold-3: #d9a03a;
  --pa-gold-4: #9a6418;
  --pa-night: #0d0a1c;
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  font-family: 'Comfortaa', system-ui, sans-serif;
  font-weight: 700;
  color: var(--pa-gold-1);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  contain: layout style;
}

.piggy-anim * { box-sizing: border-box; }

.pa-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.05;
  display: grid;
  place-items: center;
  overflow: visible;
}

/* soft magical rays — fade within ~1.3× piggy, ≤40% opacity */
.pa-rays {
  position: absolute;
  left: 50%;
  top: 42%;
  /* piggy wrap ≈ 62% → 1.3× ≈ 80% of stage */
  width: 80%;
  height: 80%;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: 50% 50%;
  background: center / contain no-repeat url('../assets/ui/piggy/rays.svg');
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  filter: blur(2.2px) saturate(1.15);
  z-index: 1;
}
.piggy-anim.is-full .pa-rays {
  opacity: 0.4;
  animation: pa-rays-spin 16s linear infinite;
}
@keyframes pa-rays-spin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.pa-glow {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 70%;
  height: 70%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle, rgba(255, 230, 140, 0.55) 0%, rgba(255, 200, 80, 0.28) 40%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  will-change: opacity, transform;
  filter: blur(12px);
  z-index: 0;
}
.pa-glow-outer {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 210, 90, 0.22) 0%, transparent 65%);
  opacity: 0;
  pointer-events: none;
  filter: blur(16px);
  z-index: 0;
}
.piggy-anim.is-full .pa-glow,
.piggy-anim.is-full .pa-glow-outer {
  opacity: 1;
  animation: pa-glow-pulse 2.6s ease-in-out infinite;
}
.piggy-anim.is-full .pa-glow-outer {
  animation-name: pa-glow-outer-pulse;
}
@keyframes pa-glow-pulse {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(0.96); }
  50% { opacity: 0.85; transform: translate(-50%, -50%) scale(1.06); }
}
@keyframes pa-glow-outer-pulse {
  0%, 100% { opacity: 0.35; transform: translate(-50%, -50%) scale(0.98); }
  50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.05); }
}

.pa-piggy-wrap {
  position: relative;
  width: 62%;
  aspect-ratio: 1;
  z-index: 2;
  will-change: transform;
  transform-origin: 50% 70%;
}
.piggy-anim.is-bounce .pa-piggy-wrap {
  animation: pa-squash 280ms cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pa-squash {
  0% { transform: scale(1, 1); }
  35% { transform: scale(1.08, 0.88); }
  65% { transform: scale(0.94, 1.08); }
  100% { transform: scale(1, 1); }
}
.piggy-anim.is-shake .pa-piggy-wrap {
  animation: pa-shake 520ms ease-in-out;
}
.piggy-anim.is-full:not(.is-breaking):not(.is-shake) .pa-piggy-wrap {
  animation: pa-idle-shake 4.5s ease-in-out infinite;
}
@keyframes pa-idle-shake {
  0%, 78%, 100% { transform: rotate(0deg) translateX(0); }
  82% { transform: rotate(-3.5deg) translateX(-2px); }
  86% { transform: rotate(3.5deg) translateX(2px); }
  90% { transform: rotate(-2.5deg) translateX(-1px); }
  94% { transform: rotate(2deg) translateX(1px); }
  98% { transform: rotate(0deg) translateX(0); }
}
@keyframes pa-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  15% { transform: translateX(-6px) rotate(-4deg); }
  30% { transform: translateX(7px) rotate(5deg); }
  45% { transform: translateX(-7px) rotate(-5deg); }
  60% { transform: translateX(6px) rotate(4deg); }
  75% { transform: translateX(-3px) rotate(-2deg); }
}

.pa-piggy {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0;
  will-change: opacity;
  transition: opacity 0.45s ease;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55));
}
.pa-piggy.is-on { opacity: 1; }

/* glint sweep across piggy after stage change */
.pa-glint {
  position: absolute;
  inset: 0;
  border-radius: 40%;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  z-index: 3;
}
.pa-glint::before {
  content: '';
  position: absolute;
  top: -20%;
  left: -40%;
  width: 40%;
  height: 140%;
  background: linear-gradient(
    105deg,
    transparent 0%,
    rgba(255, 255, 255, 0) 35%,
    rgba(255, 255, 255, 0.55) 50%,
    rgba(255, 255, 255, 0) 65%,
    transparent 100%
  );
  transform: translateX(0) skewX(-18deg);
}
.piggy-anim.is-glint .pa-glint {
  opacity: 1;
}
.piggy-anim.is-glint .pa-glint::before {
  animation: pa-glint-sweep 0.7s ease-out forwards;
}
@keyframes pa-glint-sweep {
  from { transform: translateX(0) skewX(-18deg); }
  to { transform: translateX(320%) skewX(-18deg); }
}

/* coin slot target (invisible hit point near top of piggy) */
.pa-slot {
  position: absolute;
  left: 50%;
  top: 18%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
}

.pa-fill-wrap {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 4%;
  z-index: 3;
}
.pa-fill-track {
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #1c1009, #3b2412);
  box-shadow:
    0 0 0 1.5px var(--pa-gold-3),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 6px 12px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.pa-fill-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 42%),
    linear-gradient(90deg, #9a6418, #f6cf6a 45%, #fff3b8 70%, #d9a03a);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  will-change: width;
  transition: width 0.55s cubic-bezier(.2, .8, .2, 1);
}
.pa-fill-label {
  margin-top: 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--pa-gold-1);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  letter-spacing: 0.02em;
}

/* floating +N — upper-right of piggy, gold text + dark outline, no box */
.pa-float {
  position: absolute;
  left: 70%;
  top: 8%;
  transform: translate(0, 0);
  font-family: 'Comfortaa', system-ui, sans-serif;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  will-change: transform, opacity;
  color: #ffe27a;
  background: none;
  /* gold fill + dark outline (no box) */
  text-shadow:
    -1.5px -1.5px 0 #3a2008,
     1.5px -1.5px 0 #3a2008,
    -1.5px  1.5px 0 #3a2008,
     1.5px  1.5px 0 #3a2008,
    -1.5px  0 0 #3a2008,
     1.5px  0 0 #3a2008,
     0 -1.5px 0 #3a2008,
     0  1.5px 0 #3a2008,
     0 0 12px rgba(255, 200, 80, 0.7);
}
.pa-float.is-show {
  animation: pa-float-up 1.7s cubic-bezier(.2, .7, .2, 1) forwards;
}
@keyframes pa-float-up {
  0% { opacity: 0; transform: translate(0, 10px) scale(0.85); }
  10% { opacity: 1; transform: translate(0, 0) scale(1.06); }
  75% { opacity: 1; transform: translate(0, -30px) scale(1); }
  100% { opacity: 0; transform: translate(0, -54px) scale(0.98); }
}

/* flying coins + particles live in layer */
.pa-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 4;
  perspective: 600px;
  transform-style: preserve-3d;
}
.pa-coin {
  position: absolute;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  background: center / contain no-repeat;
  will-change: transform, opacity;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
  z-index: 5;
  transform-style: preserve-3d;
}
.pa-trail {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff3b8 0%, #f6cf6a 40%, transparent 70%);
  pointer-events: none;
  will-change: transform, opacity;
  z-index: 4;
  filter: blur(0.3px);
}
.pa-spark {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  background: center / contain no-repeat;
  will-change: transform, opacity;
  pointer-events: none;
  z-index: 6;
}
.pa-flash {
  position: absolute;
  inset: 10% 8% 20% 8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 245, 200, 0.95) 0%, rgba(255, 200, 80, 0.45) 35%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 7;
  will-change: opacity, transform;
}
.piggy-anim.is-flash .pa-flash {
  animation: pa-flash 0.55s ease-out forwards;
}
@keyframes pa-flash {
  0% { opacity: 0; transform: scale(0.4); }
  30% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1.45); }
}

.pa-crack {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(125deg, transparent 46%, rgba(255, 255, 255, 0.55) 49%, transparent 52%),
    linear-gradient(55deg, transparent 48%, rgba(255, 230, 160, 0.4) 50%, transparent 53%);
  mix-blend-mode: screen;
  will-change: opacity;
}
.piggy-anim.is-crack .pa-crack {
  animation: pa-crack-flash 0.45s ease-out forwards;
}
@keyframes pa-crack-flash {
  0% { opacity: 0; }
  40% { opacity: 1; }
  100% { opacity: 0; }
}

/* balance counter (demo / break target) */
.pa-balance {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #3b2412, #1c1009);
  box-shadow:
    0 0 0 1.5px var(--pa-gold-3),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 6px 14px rgba(0, 0, 0, 0.45);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}
.pa-balance img {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.5));
}
.pa-balance b {
  font-size: 22px;
  font-weight: 800;
  color: var(--pa-gold-1);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}
.pa-balance.is-bump {
  animation: pa-bump 280ms cubic-bezier(.2, .9, .3, 1.25);
}
@keyframes pa-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .piggy-anim.is-full .pa-rays,
  .piggy-anim.is-full .pa-glow,
  .piggy-anim.is-full .pa-piggy-wrap {
    animation: none !important;
  }
}


/* Compact win-panel badge: float stays inside, no top crop */
.piggy-anim.is-compact .pa-float {
  left: 50%;
  top: auto;
  bottom: 10%;
  right: auto;
  transform: translate(-50%, 0);
  font-size: 22px;
}
.piggy-anim.is-compact .pa-float.is-show {
  animation: pa-float-compact 1.5s cubic-bezier(.2, .7, .2, 1) forwards;
}
@keyframes pa-float-compact {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -18px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(0.98); }
}
.piggy-anim.is-compact .pa-balance,
.piggy-anim.is-compact .pa-fill-wrap { display: none; }
.piggy-anim.is-compact .pa-stage { aspect-ratio: 1 / 1; }
.piggy-anim.is-compact .pa-coin { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
