/**
 * Treasure Chest Celebration - Cat opens chest animation
 * Triggered at 10+ WebCom calls
 *
 * @version 1.4.0
 */

/* ===== Overlay Container ===== */
.treasure-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at bottom, rgba(20, 10, 30, 0.9) 0%, rgba(0, 0, 0, 0.95) 100%);
    z-index: 99998;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 100px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    overflow: hidden;
}

.treasure-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ===== Ground/Floor ===== */
.treasure-ground {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100px;
    background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1a 100%);
    border-top: 3px solid #2d2d44;
}

.treasure-ground::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 0;
    width: 100%;
    height: 2px;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 50px,
        #2d2d44 50px,
        #2d2d44 52px
    );
}

/* ===== Sparkle Background ===== */
.treasure-sparkles {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.treasure-sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fbbf24;
    border-radius: 50%;
    opacity: 0;
    animation: sparkle-twinkle 2s ease-in-out infinite;
}

@keyframes sparkle-twinkle {
    0%, 100% { opacity: 0; transform: scale(0.5); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* ===== Scene Container ===== */
.treasure-scene {
    position: relative;
    width: 400px;
    height: 300px;
    z-index: 10;
}

/* ===== Treasure Chest ===== */
.treasure-chest {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 100px;
}

/* Chest Base */
.chest-base {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 120px;
    height: 60px;
    background: linear-gradient(180deg, #92400e 0%, #78350f 50%, #451a03 100%);
    border-radius: 8px;
    border: 3px solid #fbbf24;
    box-shadow:
        inset 0 -10px 20px rgba(0,0,0,0.3),
        0 5px 20px rgba(0,0,0,0.5);
}

/* Chest metal bands */
.chest-base::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 5px;
    right: 5px;
    height: 8px;
    background: linear-gradient(180deg, #fbbf24 0%, #b45309 100%);
    border-radius: 2px;
}

.chest-base::after {
    content: '';
    position: absolute;
    bottom: 10px;
    left: 5px;
    right: 5px;
    height: 8px;
    background: linear-gradient(180deg, #fbbf24 0%, #b45309 100%);
    border-radius: 2px;
}

/* Chest Lock */
.chest-lock {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 25px;
    background: linear-gradient(180deg, #fbbf24 0%, #d97706 100%);
    border-radius: 3px 3px 10px 10px;
    border: 2px solid #92400e;
    z-index: 5;
}

.chest-lock::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: #451a03;
    border-radius: 50%;
}

/* Chest Lid */
.chest-lid {
    position: absolute;
    bottom: 55px;
    left: 0;
    width: 120px;
    height: 50px;
    background: linear-gradient(180deg, #b45309 0%, #92400e 50%, #78350f 100%);
    border-radius: 60px 60px 0 0;
    border: 3px solid #fbbf24;
    border-bottom: none;
    transform-origin: bottom center;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: inset 0 10px 20px rgba(251, 191, 36, 0.2);
}

/* Lid metal band */
.chest-lid::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 10px;
    right: 10px;
    height: 8px;
    background: linear-gradient(180deg, #fbbf24 0%, #b45309 100%);
    border-radius: 2px;
}

/* Lid opened state */
.treasure-chest.open .chest-lid {
    transform: rotateX(-120deg);
}

/* Gold inside chest (visible when open) */
.chest-gold {
    position: absolute;
    bottom: 30px;
    left: 15px;
    right: 15px;
    height: 30px;
    background: linear-gradient(180deg, #fde047 0%, #fbbf24 50%, #d97706 100%);
    border-radius: 5px 5px 0 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.5);
}

.treasure-chest.open .chest-gold {
    opacity: 1;
}

/* Chest glow when opening */
.treasure-chest.open::after {
    content: '';
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 100px;
    background: radial-gradient(ellipse, rgba(251, 191, 36, 0.6) 0%, transparent 70%);
    animation: chest-glow 1s ease-out;
}

@keyframes chest-glow {
    0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
    50% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) scale(2); }
}

/* ===== Cat ===== */
.treasure-cat {
    position: absolute;
    bottom: 0;
    left: -80px;
    width: 70px;
    height: 80px;
    transition: left 2s ease-in-out;
}

.treasure-cat.walking {
    animation: cat-bounce 0.3s ease-in-out infinite;
}

.treasure-cat.arrived {
    left: calc(50% - 100px);
}

.treasure-cat.happy {
    animation: cat-happy 0.5s ease-in-out infinite;
}

@keyframes cat-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

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

/* Cat Body */
.cat-body {
    position: absolute;
    bottom: 10px;
    left: 15px;
    width: 40px;
    height: 35px;
    background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
    border-radius: 50% 50% 45% 45%;
    border: 2px solid #c2410c;
}

/* Cat Head */
.cat-head {
    position: absolute;
    bottom: 35px;
    left: 10px;
    width: 50px;
    height: 45px;
    background: linear-gradient(180deg, #fb923c 0%, #f97316 100%);
    border-radius: 50% 50% 45% 45%;
    border: 2px solid #c2410c;
}

/* Cat Ears */
.cat-ear {
    position: absolute;
    top: -12px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 18px solid #f97316;
}

.cat-ear.left {
    left: 5px;
    transform: rotate(-15deg);
}

.cat-ear.right {
    right: 5px;
    transform: rotate(15deg);
}

.cat-ear::after {
    content: '';
    position: absolute;
    top: 5px;
    left: -5px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #fecaca;
}

/* Cat Eyes */
.cat-eyes {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
}

.cat-eye {
    width: 12px;
    height: 14px;
    background: white;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
}

.cat-eye::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 6px;
    height: 8px;
    background: #1f2937;
    border-radius: 50%;
    animation: eye-look 3s ease-in-out infinite;
}

@keyframes eye-look {
    0%, 100% { transform: translateX(0); }
    30% { transform: translateX(2px); }
    60% { transform: translateX(-2px); }
}

/* Cat happy eyes (when chest opens) */
.treasure-cat.happy .cat-eye::after {
    width: 10px;
    height: 6px;
    top: 6px;
    left: 1px;
    border-radius: 0 0 50% 50%;
    background: #1f2937;
    animation: none;
}

/* Cat Nose */
.cat-nose {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 6px;
    background: #ec4899;
    border-radius: 50% 50% 40% 40%;
}

/* Cat Mouth */
.cat-mouth {
    position: absolute;
    top: 27px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 6px;
    border: 2px solid #c2410c;
    border-top: none;
    border-radius: 0 0 50% 50%;
    background: transparent;
}

/* Cat Whiskers */
.cat-whiskers {
    position: absolute;
    top: 24px;
    width: 100%;
}

.cat-whisker {
    position: absolute;
    width: 15px;
    height: 2px;
    background: #c2410c;
}

.cat-whisker.left-1 { left: -5px; top: 0; transform: rotate(-10deg); }
.cat-whisker.left-2 { left: -7px; top: 5px; transform: rotate(0deg); }
.cat-whisker.left-3 { left: -5px; top: 10px; transform: rotate(10deg); }
.cat-whisker.right-1 { right: -5px; top: 0; transform: rotate(10deg); }
.cat-whisker.right-2 { right: -7px; top: 5px; transform: rotate(0deg); }
.cat-whisker.right-3 { right: -5px; top: 10px; transform: rotate(-10deg); }

/* Cat Tail */
.cat-tail {
    position: absolute;
    bottom: 20px;
    left: 48px;
    width: 8px;
    height: 35px;
    background: linear-gradient(90deg, #f97316 0%, #ea580c 100%);
    border-radius: 4px;
    transform-origin: bottom center;
    transform: rotate(30deg);
    border: 2px solid #c2410c;
}

.treasure-cat.walking .cat-tail,
.treasure-cat.happy .cat-tail {
    animation: tail-wag 0.3s ease-in-out infinite alternate;
}

@keyframes tail-wag {
    0% { transform: rotate(20deg); }
    100% { transform: rotate(45deg); }
}

/* Cat Legs */
.cat-legs {
    position: absolute;
    bottom: 0;
    left: 15px;
    width: 40px;
    display: flex;
    justify-content: space-between;
}

.cat-leg {
    width: 10px;
    height: 15px;
    background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
    border-radius: 0 0 5px 5px;
    border: 2px solid #c2410c;
    border-top: none;
}

.treasure-cat.walking .cat-leg:nth-child(1),
.treasure-cat.walking .cat-leg:nth-child(4) {
    animation: leg-walk-a 0.3s ease-in-out infinite;
}

.treasure-cat.walking .cat-leg:nth-child(2),
.treasure-cat.walking .cat-leg:nth-child(3) {
    animation: leg-walk-b 0.3s ease-in-out infinite;
}

@keyframes leg-walk-a {
    0%, 100% { height: 15px; }
    50% { height: 10px; }
}

@keyframes leg-walk-b {
    0%, 100% { height: 10px; }
    50% { height: 15px; }
}

/* Cat Paw (for tapping) */
.cat-paw {
    position: absolute;
    bottom: 40px;
    right: -20px;
    width: 15px;
    height: 20px;
    background: #f97316;
    border-radius: 50% 50% 40% 40%;
    border: 2px solid #c2410c;
    opacity: 0;
    transform: rotate(-30deg);
}

.treasure-cat.tapping .cat-paw {
    opacity: 1;
    animation: paw-tap 0.4s ease-in-out 2;
}

@keyframes paw-tap {
    0%, 100% { transform: rotate(-30deg) translateY(0); }
    50% { transform: rotate(-10deg) translateY(10px); }
}

/* ===== Flying Coins ===== */
.treasure-coins {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.treasure-coin {
    position: absolute;
    width: 25px;
    height: 25px;
    background: linear-gradient(135deg, #fde047 0%, #fbbf24 50%, #d97706 100%);
    border-radius: 50%;
    border: 3px solid #b45309;
    opacity: 0;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

.treasure-coin::after {
    content: '€';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    font-weight: bold;
    color: #92400e;
}

.treasure-coin.fly {
    animation: coin-fly 2s ease-out forwards;
}

@keyframes coin-fly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) rotate(720deg) scale(0.5);
    }
}

/* ===== Message ===== */
.treasure-message {
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    text-align: center;
    opacity: 0;
    z-index: 100;
}

.treasure-message.show {
    animation: message-pop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes message-pop {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.treasure-message-calls {
    font-size: 80px;
    font-weight: 900;
    background: linear-gradient(180deg, #fde047 0%, #fbbf24 50%, #d97706 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px rgba(251, 191, 36, 0.6));
    line-height: 1;
}

.treasure-message-text {
    font-size: 32px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    margin-top: 10px;
}

/* ===== Close Button ===== */
.treasure-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000;
}

.treasure-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.treasure-close::before,
.treasure-close::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: white;
}

.treasure-close::before { transform: rotate(45deg); }
.treasure-close::after { transform: rotate(-45deg); }

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .treasure-scene {
        transform: scale(0.7);
    }

    .treasure-message-calls {
        font-size: 50px;
    }

    .treasure-message-text {
        font-size: 24px;
    }
}
