/* ============================================================
   SOCHOUSE — PET (Virtual Companion) v3
   Multi-sprite toggle (no swap = no loading delay)
   + Drag support
   ============================================================ */

.pet-layer {
    position: fixed;
    inset: 0;
    z-index: 60;
    pointer-events: none;
    overflow: hidden;
}

/* Container per pet */
.pet {
    position: absolute;
    width: 80px;
    height: 80px;
    transform-origin: center bottom;
    will-change: transform, top, left;
    pointer-events: auto;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    transition:
        left .8s cubic-bezier(.3, .7, .4, 1),
        top .8s cubic-bezier(.3, .7, .4, 1);
}

.pet.is-dragging {
    cursor: grabbing;
    transition: none !important;
    z-index: 100;
}

.pet.pet-fleeing {
    transition:
        left 1.6s cubic-bezier(.2, .8, .3, 1),
        top 1.6s cubic-bezier(.2, .8, .3, 1),
        opacity .5s ease 1.1s;
    opacity: 0;
    pointer-events: none;
}

.pet.pet-returning {
    transition:
        left 1.4s cubic-bezier(.2, .8, .3, 1),
        top 1.4s cubic-bezier(.2, .8, .3, 1),
        opacity .3s ease;
    opacity: 1;
}

/* ============================================================
   BODY — container yang dapet animasi
   ============================================================ */
.pet-body {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform-origin: center bottom;
    will-change: transform;
    filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.38));
}

/* ============================================================
   SPRITE STACK — 4 sprite layered, toggle opacity
   Semua di-render dari awal = ZERO loading saat swap
   ============================================================ */
.pet-sprite {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-position: center bottom;
    background-repeat: no-repeat;
    background-size: contain;
    opacity: 0;
    pointer-events: none;
    will-change: opacity;
    transition: opacity 0.06s linear;
}
.pet-sprite.is-active {
    opacity: 1;
}

/* Flip horizontal kalau menghadap ke kiri */
.pet.is-flipped .pet-body {
    transform: scaleX(-1);
}

/* ============================================================
   ANIMASI per STATE (diaplikasi ke .pet-body)
   ============================================================ */

.pet.is-idle .pet-body {
    animation: pet-breathe 2s ease-in-out infinite;
}
@keyframes pet-breathe {
    0%, 100% { transform: translateY(0) scaleY(1) scaleX(1); }
    40%      { transform: translateY(-3px) scaleY(1.04) scaleX(0.97); }
    70%      { transform: translateY(-1px) scaleY(1.01) scaleX(0.99); }
}

.pet.is-walk .pet-body {
    animation: pet-walk 0.4s ease-in-out infinite;
}
@keyframes pet-walk {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25%      { transform: translateY(-5px) rotate(-3.5deg); }
    50%      { transform: translateY(-2px) rotate(0deg); }
    75%      { transform: translateY(-5px) rotate(3.5deg); }
}
.pet.is-walk.is-flipped .pet-body {
    animation: pet-walk-flip 0.55s ease-in-out infinite;
}
@keyframes pet-walk-flip {
    0%, 100% { transform: scaleX(-1) translateY(0) rotate(0deg); }
    25%      { transform: scaleX(-1) translateY(-5px) rotate(3.5deg); }
    50%      { transform: scaleX(-1) translateY(-2px) rotate(0deg); }
    75%      { transform: scaleX(-1) translateY(-5px) rotate(-3.5deg); }
}

.pet.is-swim .pet-body {
    animation: pet-swim 0.3s ease-in-out infinite;
}
@keyframes pet-swim {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-6px) scale(1.03); }
}
.pet.is-swim.is-flipped .pet-body {
    animation: pet-swim-flip 0.4s ease-in-out infinite;
}
@keyframes pet-swim-flip {
    0%, 100% { transform: scaleX(-1) translateY(0) scale(1); }
    50%      { transform: scaleX(-1) translateY(-6px) scale(1.03); }
}

.pet.is-emote .pet-body {
    animation: pet-emote 0.9s cubic-bezier(.3, .7, .4, 1) 1;
}
@keyframes pet-emote {
    0%   { transform: translateY(0) scale(1) rotate(0deg); }
    15%  { transform: translateY(-10px) scale(1.18) rotate(-9deg); }
    30%  { transform: translateY(-12px) scale(1.22) rotate(9deg); }
    45%  { transform: translateY(-10px) scale(1.18) rotate(-7deg); }
    60%  { transform: translateY(-7px) scale(1.12) rotate(7deg); }
    80%  { transform: translateY(-4px) scale(1.06) rotate(-2deg); }
    100% { transform: translateY(0) scale(1) rotate(0deg); }
}

.pet.is-blink .pet-body {
    animation: pet-blink 0.15s ease-out 1;
}
@keyframes pet-blink {
    0%, 100% { transform: scaleY(1); }
    40%      { transform: scaleY(0.88) translateY(3px); }
}

/* DRAG — dangle (dipegang), squash-stretch lembut */
.pet.is-drag .pet-body {
    animation: pet-drag 0.6s ease-in-out infinite;
}
@keyframes pet-drag {
    0%, 100% { transform: rotate(-4deg) scale(1.02); }
    50%      { transform: rotate(4deg) scale(1.02); }
}
.pet.is-drag.is-flipped .pet-body {
    animation: pet-drag-flip 1s ease-in-out infinite;
}
@keyframes pet-drag-flip {
    0%, 100% { transform: scaleX(-1) rotate(4deg) scale(1.02); }
    50%      { transform: scaleX(-1) rotate(-4deg) scale(1.02); }
}

/* ============================================================
   SHADOW & BUBBLE
   ============================================================ */
.pet-shadow {
    position: absolute;
    left: 50%;
    bottom: -5px;
    width: 56px;
    height: 12px;
    margin-left: -28px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.34) 0%, transparent 70%);
    filter: blur(2px);
    pointer-events: none;
    animation: pet-shadow-pulse 3.2s ease-in-out infinite;
}
@keyframes pet-shadow-pulse {
    0%, 100% { transform: scaleX(1); opacity: 0.65; }
    50%      { transform: scaleX(0.85); opacity: 0.5; }
}

.pet-bubble {
    position: absolute;
    bottom: 10px;
    left: 50%;
    width: 5px;
    height: 5px;
    margin-left: -2.5px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.9), rgba(180, 220, 255, 0.4) 60%, transparent 100%);
    pointer-events: none;
    opacity: 0;
    will-change: transform, opacity;
}
.pet.is-walk .pet-bubble,
.pet.is-swim .pet-bubble {
    animation: pet-bubble-float 1.4s ease-out infinite;
}
.pet.is-swim .pet-bubble {
    animation-duration: 1s;
}
.pet-bubble:nth-child(1) { animation-delay: 0s;    left: 50%; }
.pet-bubble:nth-child(2) { animation-delay: 0.35s; left: 35%; }
.pet-bubble:nth-child(3) { animation-delay: 0.7s;  left: 65%; }
@keyframes pet-bubble-float {
    0%   { opacity: 0; transform: translateY(0) scale(0.6); }
    20%  { opacity: 0.85; transform: translateY(-8px) scale(1); }
    100% { opacity: 0; transform: translateY(-30px) scale(1.3); }
}

/* Hidden */
.pet.is-hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity .4s ease;
}

@media (prefers-reduced-motion: reduce) {
    .pet-body { animation: none !important; }
    .pet-bubble { display: none; }
}