body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background: #000;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.container {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.background {
    position: relative;
    width: 100%;
    max-width: 550px;
    height: 100%;
    overflow: hidden;
}

.background .bg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

.fafa {
    position: absolute;
    top: 3%;
    left: 50%;
    transform: translateX(-50%);
    width: 30%;
    z-index: 1;
    animation: fafaGlow 4s ease-in-out infinite alternate;
}

/* Glowing shadow animation */
@keyframes fafaGlow {
    0% {
        filter: drop-shadow(0 0 5px #a0f3e241) drop-shadow(0 0 10px #00ff9963) drop-shadow(0 0 20px #00ffcc65);
        transform: translateX(-50%) scale(1);
    }

    50% {
        filter: drop-shadow(0 0 10px #f08fe838) drop-shadow(0 0 20px #f385e148) drop-shadow(0 0 30px #f484f848);
        transform: translateX(-50%) scale(1.03);
    }

    70% {
        filter: drop-shadow(0 0 5px #7c96ec52) drop-shadow(0 0 10px #9f7dfc44) drop-shadow(0 0 20px #8c97fd50);
        transform: translateX(-50%) scale(1);
    }
}

.box {
    position: absolute;
    top: 14%;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    z-index: 1;
}

.reward {
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    z-index: 1;
}

.chest-grid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 300px;
    gap: 10px;
    justify-items: center;
    align-items: center;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chest-grid img {
    width: 80%;
    height: 70%;
    object-fit: cover;
}
.chest-grid .vs{
    width: 40%;
    height: 40%;
    object-fit: cover;
}

/* Wind-blown flag animation for dragon and tiger */
@keyframes windWave {
    0% {
        transform: skewY(0deg) rotateZ(0deg) translateX(0);
    }
    20% {
        transform: skewY(3deg) rotateZ(2deg) translateX(2px);
    }
    40% {
        transform: skewY(-1deg) rotateZ(-1deg) translateX(-1px);
    }
    60% {
        transform: skewY(2deg) rotateZ(1.5deg) translateX(1px);
    }
    80% {
        transform: skewY(-2deg) rotateZ(-1.5deg) translateX(-2px);
    }
    100% {
        transform: skewY(0deg) rotateZ(0deg) translateX(0);
    }
}

@keyframes windWaveReverse {
    0% {
        transform: skewY(0deg) rotateZ(0deg) translateX(0);
    }
    20% {
        transform: skewY(-3deg) rotateZ(-2deg) translateX(-2px);
    }
    40% {
        transform: skewY(1deg) rotateZ(1deg) translateX(1px);
    }
    60% {
        transform: skewY(-2deg) rotateZ(-1.5deg) translateX(-1px);
    }
    80% {
        transform: skewY(2deg) rotateZ(1.5deg) translateX(2px);
    }
    100% {
        transform: skewY(0deg) rotateZ(0deg) translateX(0);
    }
}

.chest-grid .dragon {
    animation: windWave 4s ease-in-out infinite;
    transform-origin: left center;
    transition: transform 0.1s ease-out;
}

.chest-grid .tiger {
    animation: windWaveReverse 4s ease-in-out infinite;
    transform-origin: right center;
    transition: transform 0.1s ease-out;
}

.box-grid{
    position: absolute;
    top: 73%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 300px;
    gap: 30px;
    justify-items: center;
    align-items: center;
    z-index: 1; /* sits behind cards */
    display: flex;
    justify-content: center;
    align-items: center;
}
.box-grid img {
    width: 70%;
    height: 70%;
    object-fit: cover;
    flex: 0 0 auto;
}
.box-grid .boxdragon{
    width: 70%;
    height: 70%;
    object-fit: cover;
}
.box-grid .boxtiger{
    width: 70%;
    height: 70%;
    object-fit: cover;
    transition: filter 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

/* Border glow effect for tiger box */
@keyframes boxBorderGlow {
    0% {
        filter: drop-shadow(0 0 8px rgba(255, 200, 0, 0.6)) 
                drop-shadow(0 0 15px rgba(255, 165, 0, 0.7))
                drop-shadow(0 0 25px rgba(255, 140, 0, 0.5));
        box-shadow: 0 0 5px rgba(255, 200, 0, 0.5),
                    inset 0 0 10px rgba(255, 200, 0, 0.3);
    }
    50% {
        filter: drop-shadow(0 0 5px rgba(255, 200, 0, 0.9)) 
                drop-shadow(0 0 25px rgba(255, 140, 0, 0.8));
        box-shadow: 0 0 5px rgba(255, 200, 0, 0.7),
                    inset 0 0 15px rgba(255, 200, 0, 0.5);
    }
   
}

#boxtiger.glowing {
    animation: boxBorderGlow 1.5s ease-in-out infinite;
    filter: drop-shadow(0 0 5px rgba(255, 200, 0, 0.7)) 
            drop-shadow(0 0 10px rgba(255, 165, 0, 0.8))
            drop-shadow(0 0 20px rgba(255, 140, 0, 0.6));
    box-shadow: 0 0 12px rgba(255, 200, 0, 0.6),
                inset 0 0 2px rgba(255, 200, 0, 0.4);
}

/* Box light effect animation */
@keyframes boxLightGlow {
    0% {
        filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)) 
                drop-shadow(0 0 20px rgba(255, 200, 0, 0.7))
                drop-shadow(0 0 30px rgba(255, 165, 0, 0.6));
    }
    50% {
        filter: drop-shadow(0 0 15px rgba(255, 215, 0, 1)) 
                drop-shadow(0 0 30px rgba(255, 200, 0, 0.9))
                drop-shadow(0 0 45px rgba(255, 165, 0, 0.8));
    }
    100% {
        filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)) 
                drop-shadow(0 0 20px rgba(255, 200, 0, 0.7))
                drop-shadow(0 0 30px rgba(255, 165, 0, 0.6));
    }
}

#boxdragon.light-effect,
#boxtiger.light-effect {
    animation: boxLightGlow 1.5s ease-in-out infinite;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)) 
            drop-shadow(0 0 20px rgba(255, 200, 0, 0.7))
            drop-shadow(0 0 30px rgba(255, 165, 0, 0.6));
}

/* Cards overlay the boxes and stay centered on each box */
.cards-grid{
    position: absolute;
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 50%;
    z-index: 3; /* above boxes */
    pointer-events: none; /* clicks pass through to boxes if needed */
}
.cards-grid img{
    width: 30%;
    height: auto;
    object-fit: contain;
    display: block;
    flex: 0 0 auto;
    position: relative;
    pointer-events: auto; /* Enable clicks on card images */
    cursor: pointer; /* Show pointer cursor on hover */
}
.cards-grid .cards1{
    width: 25%;
    height: auto;
    object-fit: contain;
    /* Center the card on the dragon box */
    transform: translateX(0);
    pointer-events: auto; /* Enable clicks */
    cursor: pointer;
    transition: transform 0.6s ease-in-out, filter 0.3s ease-in-out;
    transform-style: preserve-3d;
    position: relative;
}
.cards-grid .cards2{
    width: 25%;
    height: auto;
    object-fit: contain;
    /* Center the card on the tiger box */
    transform: translateX(0);
    pointer-events: auto; /* Enable clicks */
    cursor: pointer;
    transition: transform 0.6s ease-in-out, filter 0.3s ease-in-out;
    transform-style: preserve-3d;
    position: relative;
}

/* Card flip animation */
@keyframes cardFlip {
    0% {
        transform: rotateY(0deg) scale(1);
    }
    50% {
        transform: rotateY(90deg) scale(0.9);
    }
    100% {
        transform: rotateY(0deg) scale(1);
    }
}

.cards-grid .cards1.flipping,
.cards-grid .cards2.flipping {
    animation: cardFlip 0.6s ease-in-out;
    transform-style: preserve-3d;
}


/* Popup overlay - centered */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.4s ease, visibility 0.4s ease, background 0.4s ease;
    backdrop-filter: blur(0px);
}

.popup.show {
    visibility: visible;
    opacity: 1;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0.2px);
}

/* Popup content container - centered */
.popup-content {
    position: relative;
    background: transparent;
    border: none;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 350px;
    max-height: 90%;
    transform: scale(0) rotate(-10deg);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.popup.show .popup-content {
    animation: popupEntrance 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Popup image style */
.popup-content .popup-image {
    max-width: 100%;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 0 20px rgba(255, 200, 0, 0.5))
            drop-shadow(0 0 40px rgba(255, 165, 0, 0.4));
    animation: popupPulse 2s ease-in-out infinite;
    animation-delay: 0.8s;
}

/* Enhanced popup entrance animation */
@keyframes popupEntrance {
    0% {
        transform: scale(0) rotate(-15deg) translateY(-50px);
        opacity: 0;
        filter: blur(10px);
    }
    50% {
        transform: scale(1.15) rotate(5deg) translateY(0);
        opacity: 0.9;
        filter: blur(2px);
    }
    70% {
        transform: scale(0.95) rotate(-2deg) translateY(0);
        opacity: 1;
        filter: blur(0px);
    }
    85% {
        transform: scale(1.05) rotate(1deg) translateY(0);
        opacity: 1;
        filter: blur(0px);
    }
    100% {
        transform: scale(1) rotate(0deg) translateY(0);
        opacity: 1;
        filter: blur(0px);
    }
}

/* Continuous pulse animation for popup image */
@keyframes popupPulse {
    0%, 100% {
        transform: scale(1);
        filter: drop-shadow(0 0 20px rgba(255, 200, 0, 0.5))
                drop-shadow(0 0 40px rgba(255, 165, 0, 0.4));
    }
    50% {
        transform: scale(1.02);
        filter: drop-shadow(0 0 25px rgba(255, 200, 0, 0.7))
                drop-shadow(0 0 50px rgba(255, 165, 0, 0.6));
    }
}

/* Coin rain container - centered */
.coin-rain {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 550px;
    height: 100vh;
    pointer-events: none;
    z-index: 1001;
    overflow: hidden;
}

/* Individual coin styles */
.coin {
    position: absolute;
    width: 40px;
    height: 40px;
    background-image: url('./images/coin.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    animation: coinFall linear forwards;
}

/* Coin rain animation */
@keyframes coinFall {
    0% {
        transform: translateY(-100px) translateX(0) rotate(0deg) scale(0.5);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    50% {
        transform: translateY(calc(50vh)) translateX(var(--drift, 0px)) rotate(360deg) scale(1);
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(calc(100vh + 100px)) translateX(calc(var(--drift, 0px) * 2)) rotate(720deg) scale(1);
        opacity: 0;
    }
}

/* Varied coin sizes and speeds */
.coin.small {
    width: 30px;
    height: 30px;
    animation: coinFall 3s linear forwards;
}

.coin.medium {
    width: 40px;
    height: 40px;
    animation: coinFall 4s linear forwards;
}

.coin.large {
    width: 50px;
    height: 50px;
    animation: coinFall 5s linear forwards;
}

/* ---------- Responsive for Mobile Devices ---------- */

/* iPhone 14 Pro Max / 430px wide */
@media (max-width: 440px) {
    .fafa {
        width: 35%;
        top: 5%;
    }

    .box {
        top: 15%;
        width: 60%;
    }


    .chest-grid {
        top: 50%;
        max-width: 350px;
        gap: 8px;
    }

    .chest-grid img {
        width: 150px;
    }
    .box-grid{
        top: 70%;
        max-width: 280px;
    }
    .box-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid{
        top: 68%;
        max-width: 280px;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    
    
}

/* iPhone 14 Pro / 428px */
@media (max-width: 428px) {
    .fafa {
        width: 40%;
        top: 5%;
    }
 
    .chest-grid {
        top: 45%;
        max-width: 350px;
        gap: 8px;
    }

    .chest-grid img {
        width: 190px;
    }
    .chest-grid .vs{
        width: 30%;
        height: 30%;
        object-fit: cover;
    }
    .box-grid{
        top: 70%;
        max-width: 280px;
    }
    .box-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid{
        top: 68%;
        max-width: 280px;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
}

/* iPhone 13 / 414px */
@media (max-width: 414px) {
    .fafa {
        width: 40%;
        top: 5%;
    }

    
    .chest-grid {
        top: 45%;
        max-width: 350px;
        gap: 8px;
    }

    .chest-grid img {
        width: 150px;
    }
    .chest-grid .vs{
        width: 30%;
        height: 30%;
        object-fit: cover;
    }

    .box-grid{
        top: 70%;
        max-width: 280px;
    }
    .box-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid{
        top: 68%;
        max-width: 280px;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
}

/* iPhone 12 Mini / 390px */
@media (max-width: 390px) {
    .fafa {
        width: 30%;
        top: 5%;
    }

    .chest-grid {
        top: 45%;
        max-width: 350px;
        gap: 8px;
    }

    .chest-grid img {
        width: 190px;
    }
    .chest-grid .vs{
        width: 30%;
        height: 30%;
        object-fit: cover;
    }
    .box-grid{
        top: 71%;
        max-width: 250px;
    }
    .box-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid{
        top: 68%;
        max-width: 280px;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
}

/* Galaxy S21 / 360px */
@media (max-width: 360px) {
    .fafa {
        width: 30%;
        top: 5%;
    }
    .chest-grid {
        top: 45%;
        max-width: 350px;
        gap: 8px;
    }

    .chest-grid img {
        width: 150px;
    }
    .chest-grid .vs{
        width: 30%;
        height: 30%;
        object-fit: cover;
    }
    .box-grid{
        top: 70%;
        max-width: 220px;
    }
    .box-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid{
        top: 68%;
        max-width: 230px;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
    .cards-grid img {
        width: 60%;
        height: 60%;
        object-fit: cover;
    }
}