/* Loot Rewards & Backpack System */

/* ─── Backpack Icon ─── */
#backpack-icon {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #FFD700;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

#backpack-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

#backpack-icon:active {
    transform: scale(0.95);
}

#backpack-icon .coin-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    background: linear-gradient(45deg, #FFD700, #FFA500);
    color: #000;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 6px rgba(255, 165, 0, 0.6);
}

#backpack-icon.pulse {
    animation: backpackPulse 0.6s ease-out;
}

@keyframes backpackPulse {
    0% { transform: scale(1); box-shadow: 0 0 8px rgba(255, 215, 0, 0.3); }
    50% { transform: scale(1.25); box-shadow: 0 0 25px rgba(255, 215, 0, 0.8); }
    100% { transform: scale(1); box-shadow: 0 0 8px rgba(255, 215, 0, 0.3); }
}

/* ─── Inventory Panel ─── */
#inventory-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 5400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

#inventory-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

#inventory-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 380px;
    max-height: 600px;
    background: rgba(15, 15, 25, 0.95);
    border: 2px solid #FFD700;
    border-radius: 15px;
    z-index: 5500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

#inventory-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
}

.inventory-header h2 {
    margin: 0;
    font-size: 18px;
    letter-spacing: 3px;
    color: #FFD700;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

.inventory-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.inventory-close:hover {
    color: #fff;
}

.inventory-content {
    flex: 1;
    padding: 30px 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
    overflow-y: auto;
}

.inventory-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid rgba(255, 215, 0, 0.3);
}

.coin-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FFE44D, #FFD700 40%, #B8860B);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
    display: inline-block;
    flex-shrink: 0;
}

.inventory-coin-amount {
    font-size: 22px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

.inventory-coin-label {
    font-size: 12px;
    letter-spacing: 2px;
    color: #999;
}

/* ─── Present Box ─── */
.loot-present-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5000;
    pointer-events: none;
}

.present-box {
    width: 120px;
    height: 120px;
    position: relative;
    transform: scale(0);
    animation: presentBounceIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.present-box-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70%;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    border-radius: 4px;
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.2);
}

.present-box-top {
    position: absolute;
    top: 0;
    left: -5%;
    width: 110%;
    height: 35%;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    border-radius: 4px 4px 0 0;
    box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.15);
    transform-origin: center bottom;
}

.present-ribbon-v {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 18%;
    height: 100%;
    background: linear-gradient(90deg, #f1c40f, #f39c12);
}

.present-ribbon-h {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 100%;
    height: 18%;
    background: linear-gradient(180deg, #f1c40f, #f39c12);
}

.present-bow {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 20px;
    background: radial-gradient(ellipse, #f1c40f, #f39c12);
    border-radius: 50% 50% 20% 20%;
    box-shadow: 0 0 6px rgba(241, 196, 15, 0.6);
}

@keyframes presentBounceIn {
    0% { transform: scale(0) rotate(-10deg); }
    60% { transform: scale(1.1) rotate(3deg); }
    80% { transform: scale(0.95) rotate(-1deg); }
    100% { transform: scale(1) rotate(0deg); }
}

/* Wobble phase */
.present-box.wobble {
    animation: presentWobble 0.3s ease-in-out infinite;
}

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

/* Spin phase */
.present-box.spinning {
    animation: presentSpin 0.6s linear infinite;
}

@keyframes presentSpin {
    0% { transform: perspective(600px) rotateY(0deg); }
    100% { transform: perspective(600px) rotateY(360deg); }
}

/* Open phase */
.present-box.opening .present-box-top {
    animation: presentLidOpen 0.5s ease-out forwards;
}

.present-box.opening .present-box-bottom {
    animation: presentBottomDrop 0.5s ease-out forwards;
}

@keyframes presentLidOpen {
    0% { transform: rotate(0); opacity: 1; }
    100% { transform: translateY(-80px) rotate(-30deg); opacity: 0; }
}

@keyframes presentBottomDrop {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(40px); opacity: 0; }
}

/* ─── Glory Shine ─── */
.loot-glory {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.6) 0%, rgba(255, 165, 0, 0.2) 40%, transparent 70%);
    pointer-events: none;
    transition: transform 1s ease-out, opacity 0.5s;
    opacity: 0;
}

.loot-glory.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Pulsing rays */
.loot-glory::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 60%);
    animation: gloryPulse 1.5s ease-in-out infinite;
}

@keyframes gloryPulse {
    0%, 100% { transform: scale(0.9); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* Rarity color variants */
.loot-glory.rarity-common {
    background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, rgba(200, 200, 200, 0.15) 40%, transparent 70%);
}

.loot-glory.rarity-rare {
    background: radial-gradient(circle, rgba(30, 144, 255, 0.5) 0%, rgba(0, 0, 255, 0.15) 40%, transparent 70%);
}

.loot-glory.rarity-epic {
    background: radial-gradient(circle, rgba(218, 112, 214, 0.5) 0%, rgba(148, 0, 211, 0.15) 40%, transparent 70%);
}

.loot-glory.rarity-legendary {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.6) 0%, rgba(255, 165, 0, 0.2) 40%, transparent 70%);
}

/* ─── Coin Particles ─── */
.loot-coin {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FFE44D, #FFD700 40%, #B8860B);
    box-shadow: 0 0 6px rgba(255, 215, 0, 0.6);
    pointer-events: none;
    z-index: 5010;
}

.loot-coin.eject {
    animation: coinEject 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes coinEject {
    0% {
        transform: translate(0, 0) scale(0.3) rotate(0deg);
        opacity: 1;
    }
    30% {
        transform: translate(calc(var(--eject-x) * 0.8), calc(var(--eject-y) * 0.8)) scale(1.2) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--eject-x), var(--eject-y)) scale(1) rotate(360deg);
        opacity: 1;
    }
}

.loot-coin.fly-to-backpack {
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Coin Amount Text ─── */
.loot-amount-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 48px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.8), 0 0 30px rgba(255, 165, 0, 0.4);
    white-space: nowrap;
    pointer-events: none;
    z-index: 5020;
    animation: amountAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

.loot-amount-text.rarity-common { color: #fff; text-shadow: 0 0 10px rgba(255, 255, 255, 0.6); }
.loot-amount-text.rarity-rare { color: #1E90FF; text-shadow: 0 0 15px rgba(30, 144, 255, 0.8); }
.loot-amount-text.rarity-epic { color: #DA70D6; text-shadow: 0 0 15px rgba(218, 112, 214, 0.8); font-size: 54px; }
.loot-amount-text.rarity-legendary { color: #FFD700; text-shadow: 0 0 20px rgba(255, 215, 0, 1), 0 0 40px rgba(255, 165, 0, 0.6); font-size: 60px; }

.loot-amount-text.fly-to-backpack {
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Mobile Overrides ─── */
@media (max-width: 768px) {
    #backpack-icon {
        bottom: 20px;
        left: 15px;
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    #backpack-icon .coin-badge {
        min-width: 18px;
        height: 18px;
        font-size: 9px;
        top: -4px;
        right: -4px;
    }

    #inventory-panel {
        width: 90vw;
        max-width: 380px;
        max-height: 80vh;
    }

    .present-box {
        width: 80px;
        height: 80px;
    }

    .loot-glory {
        width: 280px;
        height: 280px;
    }

    .loot-coin {
        width: 18px;
        height: 18px;
    }

    .loot-amount-text {
        font-size: 36px;
    }

    .loot-amount-text.rarity-epic { font-size: 40px; }
    .loot-amount-text.rarity-legendary { font-size: 44px; }
}
