/**
 * Shimeji Pet Styles
 * 시메지 스타일 펫 애니메이션
 */

/* 시메지 컨테이너 */
.shimeji-pet {
    position: fixed;
    z-index: 99999;
    width: 80px;
    height: 80px;
    cursor: grab;
    user-select: none;
    pointer-events: auto;
    image-rendering: pixelated;
    overflow: visible;
}

.shimeji-pet.widget-mode {
    position: absolute;
}

.shimeji-pet img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.shimeji-pet .pet-accessory {
    position: absolute;
    top: 50%;
    left: 50%;
    width: fit-content;
    height: fit-content;
    max-width: 80px;
    max-height: 80px;
    margin-top: -40px;
    margin-left: -40px;
    object-fit: contain;
    image-rendering: pixelated;
    pointer-events: none;
}

/* 방향 전환 */
.shimeji-pet.facing-left .shimeji-inner {
    transform: scaleX(-1);
}

.shimeji-inner {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ============================
   기본 상태 - idle
   ============================ */
.shimeji-pet.state-idle .shimeji-inner {
    animation: shimeji-idle 2s ease-in-out infinite;
}

@keyframes shimeji-idle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* ============================
   걷기 - walk
   ============================ */
.shimeji-pet.state-walk .shimeji-inner {
    animation: shimeji-walk 0.4s ease-in-out infinite;
}

@keyframes shimeji-walk {
    0%, 100% {
        transform: rotate(-5deg) translateY(0);
    }
    25% {
        transform: rotate(5deg) translateY(-3px);
    }
    50% {
        transform: rotate(-5deg) translateY(0);
    }
    75% {
        transform: rotate(5deg) translateY(-3px);
    }
}

/* ============================
   앉기 - sit
   ============================ */
.shimeji-pet.state-sit .shimeji-inner {
    animation: shimeji-sit 1.5s ease-in-out infinite;
}

@keyframes shimeji-sit {
    0%, 100% {
        transform: scaleY(0.9) translateY(4px);
    }
    50% {
        transform: scaleY(0.85) translateY(6px);
    }
}

/* ============================
   점프 - jump
   ============================ */
.shimeji-pet.state-jump .shimeji-inner {
    animation: shimeji-jump 0.6s ease-out forwards;
}

@keyframes shimeji-jump {
    0% {
        transform: scaleY(0.8) scaleX(1.1);
    }
    30% {
        transform: scaleY(1.2) scaleX(0.9) translateY(-30px);
    }
    50% {
        transform: scaleY(1.1) translateY(-40px);
    }
    70% {
        transform: scaleY(1.2) scaleX(0.9) translateY(-30px);
    }
    100% {
        transform: scaleY(0.9) scaleX(1.05) translateY(0);
    }
}

/* ============================
   달리기 - run
   ============================ */
.shimeji-pet.state-run .shimeji-inner {
    animation: shimeji-run 0.2s ease-in-out infinite;
}

@keyframes shimeji-run {
    0%, 100% {
        transform: rotate(-8deg) translateY(-2px) scaleX(1.1);
    }
    50% {
        transform: rotate(8deg) translateY(-2px) scaleX(1.1);
    }
}

/* ============================
   잠자기 - sleep
   ============================ */
.shimeji-pet.state-sleep .shimeji-inner {
    animation: shimeji-sleep 3s ease-in-out infinite;
}

@keyframes shimeji-sleep {
    0%, 100% {
        transform: scaleY(0.95) rotate(-2deg);
    }
    50% {
        transform: scaleY(0.9) rotate(2deg);
    }
}

/* 잠자기 이펙트 (Zzz) */
.shimeji-pet.state-sleep::after {
    content: 'z';
    position: absolute;
    top: -10px;
    right: -5px;
    font-size: 14px;
    color: var(--primary-color, #39ff14);
    text-shadow: 0 0 5px currentColor;
    animation: shimeji-zzz 1s ease-in-out infinite;
}

@keyframes shimeji-zzz {
    0%, 100% {
        opacity: 0.3;
        transform: translateY(0) scale(0.8);
    }
    50% {
        opacity: 1;
        transform: translateY(-5px) scale(1);
    }
}

/* ============================
   떨어지기 - fall
   ============================ */
.shimeji-pet.state-fall .shimeji-inner {
    animation: shimeji-fall 0.15s ease-in-out infinite;
}

@keyframes shimeji-fall {
    0%, 100% {
        transform: rotate(-10deg) scaleX(1.2);
    }
    50% {
        transform: rotate(10deg) scaleX(1.2);
    }
}

/* ============================
   기어오르기 - climb (선택)
   ============================ */
.shimeji-pet.state-climb .shimeji-inner {
    animation: shimeji-climb 0.4s ease-in-out infinite;
}

@keyframes shimeji-climb {
    0%, 100% {
        transform: translateY(0) rotate(-5deg);
    }
    50% {
        transform: translateY(-5px) rotate(5deg);
    }
}

/* ============================
   매달리기 - hang (선택)
   ============================ */
.shimeji-pet.state-hang .shimeji-inner {
    animation: shimeji-hang 1s ease-in-out infinite;
    transform-origin: top center;
}

@keyframes shimeji-hang {
    0%, 100% {
        transform: rotate(-15deg);
    }
    50% {
        transform: rotate(15deg);
    }
}

/* ============================
   드래그 - dragging (핵심)
   ============================ */
.shimeji-pet.state-dragging {
    cursor: grabbing;
}

.shimeji-pet.state-dragging .shimeji-inner {
    animation: shimeji-dangle 0.4s ease-in-out infinite;
    transform-origin: top center;
}

@keyframes shimeji-dangle {
    0%, 100% {
        transform: scaleY(1.3) scaleX(0.85) rotate(-5deg);
    }
    25% {
        transform: scaleY(1.25) scaleX(0.9) rotate(8deg);
    }
    50% {
        transform: scaleY(1.35) scaleX(0.8) rotate(-8deg);
    }
    75% {
        transform: scaleY(1.25) scaleX(0.9) rotate(5deg);
    }
}

/* ============================
   착지 - land
   ============================ */
.shimeji-pet.state-land .shimeji-inner {
    animation: shimeji-land 0.3s ease-out forwards;
}

@keyframes shimeji-land {
    0% {
        transform: scaleY(0.6) scaleX(1.3);
    }
    50% {
        transform: scaleY(1.1) scaleX(0.95);
    }
    100% {
        transform: scaleY(1) scaleX(1);
    }
}

/* ============================
   시메지 활성화 버튼
   ============================ */
.pet-shimeji-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--primary-color, #39ff14);
    color: var(--primary-color, #39ff14);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.pet-shimeji-toggle:hover {
    background: var(--primary-color, #39ff14);
    color: #000;
}

.pet-shimeji-toggle.active {
    background: var(--primary-color, #39ff14);
    color: #000;
}

.pet-shimeji-toggle i {
    font-size: 14px;
}

/* ============================
   모드 전환 버튼
   ============================ */
.pet-shimeji-mode {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--primary-color, #39ff14);
    color: var(--primary-color, #39ff14);
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.shimeji-pet:hover .pet-shimeji-mode {
    opacity: 1;
}

.pet-shimeji-mode:hover {
    background: var(--primary-color, #39ff14);
    color: #000;
}

/* ============================
   페이지 모드 시 그림자
   ============================ */
.shimeji-pet.page-mode {
    filter: drop-shadow(0 0 10px var(--primary-color, #39ff14));
}

/* ============================
   복귀 애니메이션
   ============================ */
.shimeji-pet.returning {
    transition: all 0.5s ease-out;
}

/* ============================
   탈출 애니메이션
   ============================ */
@keyframes shimeji-escape {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
}

.shimeji-pet.escaping {
    animation: shimeji-escape 0.5s ease-out forwards;
}

/* ============================
   시메지 설정 탭
   ============================ */
.pet-shimeji-settings {
    padding: 15px;
}

.pet-shimeji-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pet-shimeji-option:last-child {
    border-bottom: none;
}

.pet-shimeji-option label {
    color: #aaa;
    font-size: 12px;
}

.pet-shimeji-option select,
.pet-shimeji-option input[type="range"] {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #444;
    color: #fff;
    padding: 5px 10px;
    font-size: 11px;
}

.pet-shimeji-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 15px;
}

.pet-shimeji-action-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #444;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.pet-shimeji-action-toggle:hover {
    border-color: #666;
    color: #999;
}

.pet-shimeji-action-toggle.active {
    border-color: var(--primary-color, #39ff14);
    background: rgba(57, 255, 20, 0.2);
    color: var(--primary-color, #39ff14);
    box-shadow: 0 0 8px rgba(57, 255, 20, 0.4);
}

.pet-shimeji-action-toggle i {
    font-size: 16px;
}

.pet-shimeji-action-toggle span {
    font-size: 9px;
    text-transform: uppercase;
}

/* ============================
   말풍선 - Speech Bubble
   ============================ */
.shimeji-speech-bubble {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--primary-color, #39ff14);
    border-radius: 8px;
    padding: 8px 12px;
    color: #fff;
    font-size: 11px;
    line-height: 1.4;
    width: max-content;
    max-width: 300px;
    min-width: 80px;
    text-align: center;
    white-space: pre-wrap;
    word-break: break-word;
    z-index: 1;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
    animation: shimeji-bubble-appear 0.3s ease-out;
}

/* 말풍선 꼬리 */
.shimeji-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--primary-color, #39ff14);
}

.shimeji-speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid rgba(0, 0, 0, 0.9);
    z-index: 1;
}

/* 말풍선 등장 애니메이션 */
@keyframes shimeji-bubble-appear {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* 말풍선 사라짐 애니메이션 */
.shimeji-speech-bubble.hiding {
    animation: shimeji-bubble-hide 0.3s ease-in forwards;
}

@keyframes shimeji-bubble-hide {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px) scale(0.8);
    }
}

/* 매달리기 상태에서 말풍선 위치 조정 (아래로) */
.shimeji-pet.state-hang .shimeji-speech-bubble {
    bottom: auto;
    top: calc(100% + 8px);
}

.shimeji-pet.state-hang .shimeji-speech-bubble::after {
    bottom: auto;
    top: -6px;
    border-top: none;
    border-bottom: 6px solid var(--primary-color, #39ff14);
}

.shimeji-pet.state-hang .shimeji-speech-bubble::before {
    bottom: auto;
    top: -4px;
    border-top: none;
    border-bottom: 5px solid rgba(0, 0, 0, 0.9);
}
