.chest-opening-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100vw;
    height: 100vh;
    color: white;
    overflow: hidden;
}

.chest-animation {
    text-align: center;
    animation: chestBounce 2s ease-in-out;
}

.chest-icon {
    font-size: 120px;
    margin-bottom: 20px;
    animation: chestShake 0.5s ease-in-out infinite alternate;
}

.chest-rarity {
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.chest-rewards {
    text-align: center;
    animation: fadeIn 0.5s ease-in-out;
}

.reward-items-display {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin: 30px 0;
}

.chest-animation-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 400px;
    height: 400px;
    margin-bottom: 20px;
}

#confettiCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* --- STATES --- */

/* INITIAL STATE */
.chest-opening-container.initial .chest-box {
    cursor: pointer;
    text-align: center;
    animation: pulsate 1.5s ease-in-out infinite;
}

.chest-opening-container.initial .chest-icon {
    font-size: 150px;
}

.chest-opening-container.initial .click-to-open-text {
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    color: white;
}

.chest-opening-container.initial .chest-rewards {
    display: none;
}

.chest-opening-container.initial #chestCloseBtn {
    display: none;
}


/* OPENED STATE */
.chest-opening-container.opened .chest-box {
    animation: shrinkOut 0.5s ease-in forwards;
}

.chest-opening-container.opened .chest-rewards {
    position: absolute;
    text-align: center;
    width: 100%;
}

.chest-opening-container.opened .chest-rarity {
    color: white;
    font-size: 28px;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
    opacity: 0;
    animation: fadeIn 0.5s 0.3s ease-out forwards;
}

.chest-opening-container.opened .reward-items-display {
    display: flex;
    gap: 30px;
    justify-content: center;
}

.reward-display {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 150px;
    opacity: 0;
}

.chest-opening-container.opened .reward-display:nth-child(1) {
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) 0.5s forwards;
}

.chest-opening-container.opened .reward-display:nth-child(2) {
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) 0.7s forwards;
}

.reward-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.reward-name {
    color: white;
    font-size: 16px;
    font-weight: bold;
    opacity: 0;
}

.chest-opening-container.opened .reward-name {
    animation: fadeIn 0.5s 1.5s forwards;
}

#chestCloseBtn {
    opacity: 0;
}
.chest-opening-container.opened #chestCloseBtn {
    animation: fadeIn 0.5s 2s forwards;
}

/* --- KEYFRAMES --- */
@keyframes chestBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes chestShake {
    0% { transform: rotate(-2deg); }
    100% { transform: rotate(2deg); }
}

@keyframes pulsate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes shrinkOut {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(0); opacity: 0; }
}

@keyframes bounceIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}