/* Piggy Chaos layer + piggy sprites and portraits. Transforms only; no layout-affecting animation. */

/* ---- sprites & portraits ------------------------------------------------------------------ */
.pig-sprite { position: absolute; left: 0; top: 0; pointer-events: none; }
.pig-frame { position: absolute; left: 0; top: 0; transform-origin: 50% 100%; }
.pig-frame > svg { display: block; width: 100%; height: 100%; overflow: visible; }
.pig-frame > img { display: block; width: 100%; height: 100%; -webkit-user-drag: none; user-select: none; }

.pig-portrait {
  position: relative; display: inline-block; flex: none; overflow: hidden; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #fffaf3 0%, #ffe6ec 55%, var(--pig-color, #f7a8b8) 130%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .75), 0 2px 6px rgba(80, 40, 30, .18);
}
.pig-portrait > svg { position: absolute; top: 4%; left: 0; width: 100%; height: 100%; }
.pig-portrait-img { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-repeat: no-repeat; }

/* ---- world layer --------------------------------------------------------------------------- */
.piggy-layer { pointer-events: none; overflow: visible; }
.piggy-layer.is-paused * { animation-play-state: paused !important; }

.piggy { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; will-change: transform; }
.piggy-shadow {
  position: absolute; left: -24px; top: -8px; width: 48px; height: 14px; border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(40, 20, 10, .32) 0%, rgba(40, 20, 10, .16) 55%, rgba(40, 20, 10, 0) 72%);
  transform-origin: 50% 50%;
}
.piggy-rig, .piggy-body { position: absolute; left: 0; top: 0; width: 0; height: 0; }
/* the parts the frame loop moves every frame get their own layers, so a walking pig is a compositor-only
   update (no repaint, no re-layerization of the whole page) */
.piggy-body { transform-origin: 0 0; will-change: transform; }
.piggy-shadow { will-change: transform, opacity; }
.piggy-hit {
  position: absolute; pointer-events: auto; cursor: grab; touch-action: none; border-radius: 45% 45% 40% 40%;
  -webkit-tap-highlight-color: transparent;
}
.piggy.is-held .piggy-hit { cursor: grabbing; }
.piggy.is-temp .piggy-hit { cursor: default; pointer-events: none; }
/* while the human decides: pigs over the hand, rivers or compass fade and let clicks through */
.piggy-rig, .piggy-shadow { transition: opacity .2s ease; }
.piggy.is-ghosted .piggy-rig, .piggy.is-ghosted .piggy-shadow { opacity: .35; }
.piggy.is-frozen .piggy-rig { opacity: .75; }
.piggy.is-ghosted .piggy-hit, .piggy.is-frozen .piggy-hit { pointer-events: none; }
.piggy-over { position: absolute; left: 0; top: 0; width: 0; height: 0; }

/* ---- emotes ---------------------------------------------------------------------------------- */
.piggy-emote {
  position: absolute; left: -17px; top: -34px; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  animation: piggy-emote-pop 1.4s cubic-bezier(.2, 1.4, .4, 1) both;
  transform-origin: 50% 100%;
}
.piggy-emote svg { width: 100%; height: 100%; overflow: visible; }
.piggy-emote .glyph {
  font: 900 26px/1 var(--font-display, "Baloo 2", "Arial Rounded MT Bold", system-ui, sans-serif);
  -webkit-text-stroke: 1px rgba(255, 255, 255, .9); paint-order: stroke fill;
  text-shadow: 0 2px 0 #fff, 0 -1px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff, 0 3px 4px rgba(0, 0, 0, .18);
}
.emote-bang .glyph { color: #ff4d4f; font-size: 30px; }
.emote-question .glyph { color: #4c7be0; }
.emote-zzz .glyph { color: #7d8fd6; font-size: 18px; letter-spacing: -1px; animation: piggy-zzz 2s ease-in-out infinite; }
.emote-nom .glyph { color: #d98a2b; font-size: 16px; }
@keyframes piggy-emote-pop {
  0% { transform: translateY(8px) scale(.2); opacity: 0; }
  14% { transform: translateY(-4px) scale(1.15); opacity: 1; }
  24% { transform: translateY(0) scale(1); }
  82% { transform: translateY(-3px) scale(1); opacity: 1; }
  100% { transform: translateY(-10px) scale(.9); opacity: 0; }
}
@keyframes piggy-zzz { 0%, 100% { transform: translate(0, 0) rotate(-6deg); } 50% { transform: translate(4px, -5px) rotate(6deg); } }

/* ---- speech bubble --------------------------------------------------------------------------- */
.piggy-bubble {
  position: absolute; left: 0; bottom: 6px; transform: translateX(-50%);
  max-width: 190px; width: max-content; padding: 5px 11px 6px;
  font: 700 15px/1.2 var(--font-body, "Baloo 2", "Nunito", "Trebuchet MS", system-ui, sans-serif);
  color: #5a2d36; background: #fffdf8; border: 2.5px solid var(--pig-color, #f39ab0); border-radius: 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .08), 0 4px 10px rgba(80, 40, 30, .16); white-space: normal; text-align: center;
  animation: piggy-bubble-in .32s cubic-bezier(.2, 1.5, .4, 1) both;
}
.piggy-bubble::after {
  content: ""; position: absolute; left: calc(50% + var(--tail-x, 0px) - 7px); bottom: -9px; width: 12px; height: 12px;
  background: #fffdf8; border-right: 2.5px solid var(--pig-color, #f39ab0); border-bottom: 2.5px solid var(--pig-color, #f39ab0);
  transform: rotate(45deg); border-bottom-right-radius: 3px;
}
.piggy-bubble.is-leaving { animation: piggy-bubble-out .25s ease-in both; }
@keyframes piggy-bubble-in { from { transform: translateX(-50%) translateY(6px) scale(.5); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes piggy-bubble-out { to { transform: translateX(-50%) translateY(-6px) scale(.8); opacity: 0; } }

/* ---- props: stolen flower, lucky coin, dust --------------------------------------------------- */
.piggy-prop { position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform; }
.piggy-flower {
  position: absolute; left: -10px; top: -28px; width: 20px; height: 27px; border-radius: 4px;
  background: linear-gradient(180deg, #fffdf5, #f1ead6); border: 1.5px solid #3f9a6c; box-shadow: 0 2px 0 #2e7a53;
  font: 700 13px/25px "Noto Serif SC", "PingFang SC", "Hiragino Sans GB", serif; color: #c2334a; text-align: center;
}
.piggy-coin {
  position: absolute; left: -16px; top: -32px; width: 32px; height: 32px; border-radius: 50%; pointer-events: auto; cursor: pointer;
  background: radial-gradient(circle at 38% 32%, #fff6b8 0%, #ffd54a 42%, #e0a011 78%, #b7780a 100%);
  box-shadow: inset 0 0 0 2px #fff1a0, 0 3px 0 #a86c05, 0 0 16px rgba(255, 214, 80, .8);
  font: 900 14px/32px system-ui, sans-serif; color: #a2620a; text-align: center;
  animation: piggy-coin-bob 1.6s ease-in-out infinite;
}
.piggy-coin::before, .piggy-coin::after {
  content: ""; position: absolute; width: 10px; height: 10px; background: #fff;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  -webkit-clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: piggy-twinkle 1.2s ease-in-out infinite;
}
.piggy-coin::before { left: -4px; top: -2px; }
.piggy-coin::after { right: -5px; bottom: 2px; animation-delay: .6s; }
@keyframes piggy-coin-bob { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-5px) rotate(6deg); } }
@keyframes piggy-twinkle { 0%, 100% { transform: scale(.3); opacity: .2; } 50% { transform: scale(1.2); opacity: 1; } }
.piggy-banner {
  position: absolute; left: -2px; top: -64px; width: 58px; height: 22px; border-radius: 3px 8px 8px 3px;
  background: linear-gradient(180deg, #ef4555, #c42538); color: #fff4c8; text-align: center;
  font: 800 12px/22px var(--font-display, "Baloo 2", system-ui, sans-serif); letter-spacing: .5px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .15); transform-origin: 0 50%; animation: piggy-flag 0.5s ease-in-out infinite alternate;
}
.piggy-banner::before { content: ""; position: absolute; left: -3px; top: -2px; width: 3px; height: 48px; background: #8a5a2b; border-radius: 2px; }
@keyframes piggy-flag { from { transform: skewY(-4deg); } to { transform: skewY(4deg); } }

.piggy-puff {
  position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fffaf0, #e8dcc6 70%, rgba(232, 220, 198, 0) 72%);
  animation: piggy-puff .6s ease-out both; pointer-events: none;
}
@keyframes piggy-puff { from { transform: var(--p, translate(0, 0)) scale(.3); opacity: .95; } to { transform: var(--q, translate(0, -10px)) scale(1.4); opacity: 0; } }

.piggy-dust { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.piggy-dust .cloud {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fffdf6, #efe3cc 65%, #e2d2b4 100%);
  box-shadow: 0 3px 0 rgba(120, 90, 50, .12); animation: piggy-cloud .5s ease-in-out infinite alternate;
}
.piggy-dust .bit { position: absolute; font: 900 18px/1 system-ui, sans-serif; color: #ffcf33; -webkit-text-stroke: 1px #d08a00; animation: piggy-bit .7s ease-out infinite; }
.piggy-dust .limb {
  position: absolute; width: 11px; height: 22px; margin: -11px 0 0 -5px; border-radius: 6px 6px 5px 5px;
  background: linear-gradient(180deg, #f7a8b9 0 72%, #5b3b33 72%); border: 1.5px solid #cf6f8b; transform-origin: 50% 0;
  transform: rotate(var(--r, 0deg)); animation: piggy-limb .22s ease-in-out infinite alternate; z-index: -1;
}
.piggy-dust .limb.tail { width: 14px; height: 14px; border-radius: 50%; background: none; border: 3px solid #e27d97; border-right-color: transparent; }
@keyframes piggy-limb { from { transform: rotate(var(--r, 0deg)) translateY(-3px); } to { transform: rotate(calc(var(--r, 0deg) + 24deg)) translateY(3px); } }
@keyframes piggy-cloud { from { transform: scale(.92) translateY(2px); } to { transform: scale(1.08) translateY(-3px); } }
@keyframes piggy-bit { from { transform: translate(0, 0) scale(.4); opacity: 1; } to { transform: translate(var(--dx, 10px), var(--dy, -24px)) scale(1.2); opacity: 0; } }

.piggy-heart-burst { position: absolute; left: 0; top: 0; pointer-events: none; }
.piggy-heart-burst span {
  position: absolute; left: -8px; top: -8px; width: 16px; height: 16px;
  animation: piggy-heart-fly 1.1s ease-out both;
}
.piggy-heart-burst svg { width: 100%; height: 100%; }
@keyframes piggy-heart-fly { from { transform: translate(0, 0) scale(.3); opacity: 1; } 70% { opacity: 1; } to { transform: translate(var(--dx, 0), var(--dy, -40px)) scale(1.1); opacity: 0; } }

/* ---- sneak tell, catch stamp, lucky coin ------------------------------------------------------ */
.piggy-threat {
  position: absolute; border-radius: 9px; pointer-events: none; transform-origin: 50% 100%;
  box-shadow: 0 0 0 3px rgba(255, 92, 138, .9), 0 0 16px 5px rgba(255, 92, 138, .55);
  background: rgba(255, 120, 160, .12);
  animation: piggy-threat .42s ease-in-out infinite alternate;
}
@keyframes piggy-threat {
  from { transform: rotate(-2.5deg); box-shadow: 0 0 0 3px rgba(255, 92, 138, .9), 0 0 10px 3px rgba(255, 92, 138, .4); }
  to { transform: rotate(2.5deg) translateY(-2px); box-shadow: 0 0 0 3px rgba(255, 92, 138, 1), 0 0 22px 7px rgba(255, 92, 138, .7); }
}

.piggy-stamp {
  position: absolute; padding: 8px 16px 7px; border: 3px solid #fff; border-radius: 12px; white-space: nowrap; pointer-events: none;
  background: #e8364f; color: #fff; letter-spacing: .04em;
  font: 900 24px/1 var(--font-display, "Baloo 2", system-ui, sans-serif);
  box-shadow: 0 5px 0 rgba(120, 20, 40, .35), 0 8px 18px rgba(0, 0, 0, .3);
  transform: translate(-50%, -50%) rotate(-6deg);
  animation: piggy-stamp 1.7s cubic-bezier(.2, 1.3, .4, 1) both;
}
@keyframes piggy-stamp {
  0% { transform: translate(-50%, -50%) rotate(-14deg) scale(2.2); opacity: 0; }
  14% { transform: translate(-50%, -50%) rotate(-4deg) scale(.94); opacity: 1; }
  22% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  82% { opacity: 1; }
  100% { transform: translate(-50%, -60%) rotate(-6deg) scale(1); opacity: 0; }
}

.piggy-prop.is-flying { transition: transform .6s cubic-bezier(.35, -.35, .55, 1); }
.piggy-prop.is-flying .piggy-coin { pointer-events: none; animation: none; }
.piggy-coin.is-carried { left: -13px; top: -34px; transform: scale(.8); pointer-events: none; animation: none; }
.piggy-lucky {
  position: absolute; pointer-events: none; transform: translate(-50%, -50%);
  font: 900 26px/1 var(--font-display, "Baloo 2", system-ui, sans-serif); color: #f2b705;
  -webkit-text-stroke: 1.5px #a86c05; paint-order: stroke fill;
  text-shadow: 0 2px 0 #fff, 0 -1px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff, 0 4px 8px rgba(0, 0, 0, .2);
  animation: piggy-lucky 1.3s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes piggy-lucky {
  0% { transform: translate(-50%, -30%) scale(.3); opacity: 0; }
  20% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -110%) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .piggy-emote, .piggy-bubble, .piggy-coin, .piggy-banner, .emote-zzz .glyph { animation-duration: .01s; animation-iteration-count: 1; }
}
/* the in-game Reduced motion setting (the world adds .is-reduced to its layer) */
.piggy-layer.is-reduced .piggy-emote, .piggy-layer.is-reduced .piggy-bubble, .piggy-layer.is-reduced .piggy-coin,
.piggy-layer.is-reduced .piggy-banner, .piggy-layer.is-reduced .emote-zzz .glyph, .piggy-layer.is-reduced .piggy-threat,
.piggy-layer.is-reduced .piggy-dust .cloud, .piggy-layer.is-reduced .piggy-dust .limb, .piggy-layer.is-reduced .piggy-dust .bit {
  animation-duration: .01s; animation-iteration-count: 1;
}
.piggy-layer.is-reduced .piggy-stamp, .piggy-layer.is-reduced .piggy-lucky { animation-name: piggy-fade; }
.piggy-layer.is-reduced .piggy-prop.is-flying { transition: none; }
@keyframes piggy-fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
