/* Gacha Animation Styles */

/* Overlay - covers the whole screen */
.gacha-animation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Solid background to hide interface */
    background: #0a0a14;
    z-index: 2000;
    display: none;
    /* Toggled by JS */
    align-items: center;
    justify-content: center;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding-bottom: 10vh;
}

/* Background Sparks Container (Behind Card) */
.gacha-card-sparks {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: -1;
    overflow: visible;
}

.card-spark {
    position: absolute;
    width: 4px;
    height: 40px;
    background: white;
    border-radius: 2px;
    transform-origin: center bottom;
    opacity: 0;
    /* animation handled inline/js or generic class */
}

.card-spark.gold {
    background: linear-gradient(to top, transparent, #ffd700, #fff);
    box-shadow: 0 0 10px #ffd700;
}

.card-spark.rainbow {
    background: linear-gradient(to top, transparent, #00ff88, #00d4ff, #ff00cc);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
}

@keyframes emitParticle {
    0% {
        transform: rotate(var(--angle)) translateY(0) scale(0);
        opacity: 0;
    }

    10% {
        opacity: 1;
        transform: rotate(var(--angle)) translateY(-20px) scale(1);
    }

    100% {
        transform: rotate(var(--angle)) translateY(calc(var(--dist) * -1)) scale(0);
        opacity: 0;
    }
}

.card-spark.infinite {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    /* Round particles */
    transform-origin: center center;
    /* Emit from center */
    /* Remove streak style for round particles */
    background: white;
}

.card-spark.infinite.gold {
    background: radial-gradient(circle, #fff 20%, #ffd700 60%, transparent 100%);
    box-shadow: 0 0 8px #ffd700;
}

.card-spark.infinite.rainbow {
    background: radial-gradient(circle, #fff 20%, #00d4ff 100%);
    box-shadow: 0 0 10px #00ff88, 0 0 20px #ff00cc;
}

.gacha-animation-overlay.active {
    display: flex;
    opacity: 1;
}

/* Container for the pack */
.gacha-pack-container {
    position: relative;
    width: 300px;
    height: 450px;
    max-width: 90vw;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

/* Glow behind the pack */
.gacha-pack-glow {
    position: absolute;
    width: 150%;
    height: 100%;
    background: radial-gradient(circle, rgba(108, 92, 231, 0.6) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.gacha-animation-overlay.active .gacha-pack-glow {
    opacity: 1;
}

/* The Pack Body */
.gacha-pack-body {
    position: relative;
    width: 100%;
    height: 100%;
    /* Start slightly scaled down */
    transform: scale(0.8);
    opacity: 0;
    z-index: 5;
    /* Ensure pack is above result initially */
}

/* Animation Phase 1: Appear */
.gacha-animation-overlay.active .gacha-pack-body {
    animation: packAppear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes packAppear {
    from {
        transform: scale(0.5) translateY(50px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Inner parts of the pack */
.pack-foil-left,
.pack-foil-right {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
    border: 2px solid #6c5ce7;
    overflow: hidden;
    z-index: 2;
}

.pack-foil-left {
    left: 0;
    border-radius: 15px 0 0 15px;
    border-right: none;
    transform-origin: left center;
}

.pack-foil-right {
    right: 0;
    border-radius: 0 15px 15px 0;
    border-left: none;
    transform-origin: right center;
}

/* Decorations on the pack */
.pack-decoration {
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
    background: repeating-linear-gradient(45deg,
            transparent,
            transparent 10px,
            rgba(108, 92, 231, 0.1) 10px,
            rgba(108, 92, 231, 0.1) 20px);
}

.pack-foil-right .pack-decoration {
    left: -100%;
}

/* Center Seam */
.pack-center-seam {
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 2px;
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(-50%);
    z-index: 3;
    box-shadow: 0 0 10px rgba(108, 92, 231, 0.5);
}

/* Logo Badge */
.pack-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, #fd79a8, #6c5ce7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 0 20px rgba(108, 92, 231, 0.8);
    z-index: 4;
    font-size: 32px;
    color: white;
}

/* Hint Text removed */

/* =========================================
   ANIMATION SEQUENCES TRIGGERED BY JS
   ========================================= */

/* Phase 2: Initial Shake (Anticipation) */
.gacha-pack-body.anim-shake {
    animation: packShake 0.4s ease-in-out infinite !important;
    opacity: 1 !important;
}

@keyframes packShake {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    25% {
        transform: scale(1.02) rotate(-2deg);
    }

    75% {
        transform: scale(1.02) rotate(2deg);
    }
}

/* Phase 2.5: Intense Trembling Before Burst */
.gacha-pack-body.anim-tremble {
    animation: packTremble 0.08s linear infinite !important;
    opacity: 1 !important;
}

@keyframes packTremble {

    0%,
    100% {
        transform: scale(1.05) translate(0, 0);
    }

    10% {
        transform: scale(1.05) translate(-3px, 2px);
    }

    20% {
        transform: scale(1.06) translate(4px, -2px);
    }

    30% {
        transform: scale(1.05) translate(-2px, 3px);
    }

    40% {
        transform: scale(1.07) translate(3px, -3px);
    }

    50% {
        transform: scale(1.06) translate(-4px, 1px);
    }

    60% {
        transform: scale(1.08) translate(2px, -2px);
    }

    70% {
        transform: scale(1.07) translate(-3px, 3px);
    }

    80% {
        transform: scale(1.09) translate(4px, -1px);
    }

    90% {
        transform: scale(1.08) translate(-2px, 2px);
    }
}

/* Glowing pulse during tremble */
.gacha-pack-body.anim-tremble .pack-logo {
    animation: logoPulse 0.2s ease-in-out infinite alternate;
}

@keyframes logoPulse {
    from {
        box-shadow: 0 0 20px rgba(108, 92, 231, 0.8);
    }

    to {
        box-shadow: 0 0 40px rgba(253, 121, 168, 1), 0 0 60px rgba(108, 92, 231, 0.9);
    }
}

/* Center seam glowing during tremble */
.gacha-pack-body.anim-tremble .pack-center-seam {
    animation: seamGlow 0.15s ease-in-out infinite alternate;
}

@keyframes seamGlow {
    from {
        background: rgba(255, 255, 255, 0.4);
        box-shadow: 0 0 10px rgba(108, 92, 231, 0.5);
    }

    to {
        background: rgba(255, 255, 255, 0.9);
        box-shadow: 0 0 25px rgba(253, 121, 168, 1), 0 0 40px rgba(108, 92, 231, 1);
    }
}

/* Phase 3: Flash (Removed per request) */

/* Phase 4: Open (Split Apart) */
.gacha-pack-body.anim-open .pack-logo {
    opacity: 0;
    transition: opacity 0.1s;
}

.gacha-pack-body.anim-open .pack-center-seam {
    opacity: 0;
}

.gacha-pack-body.anim-open .pack-foil-left {
    animation: splitLeft 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.gacha-pack-body.anim-open .pack-foil-right {
    animation: splitRight 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes splitLeft {
    to {
        transform: translateX(-150%) rotateY(-30deg);
        opacity: 0;
    }
}

@keyframes splitRight {
    to {
        transform: translateX(150%) rotateY(30deg);
        opacity: 0;
    }
}

/* =========================================
   RESULT CARD INTEGRATION
   ========================================= */

.gacha-result-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    /* Behind pack initially */
    transform: scale(0);
    opacity: 0;
}

/* Revealed State */
.gacha-animation-overlay.revealed .gacha-result-container {
    animation: cardReveal 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards 0.2s;
    z-index: 10;
}

@keyframes cardReveal {
    from {
        transform: scale(0.2);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Multi-gacha transitions */
.gacha-animation-overlay.revealed .gacha-result-container.anim-card-exit {
    animation: cardExit 0.3s cubic-bezier(0.55, 0.055, 0.675, 0.19) forwards !important;
}

@keyframes cardExit {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    40% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.gacha-animation-overlay.revealed .gacha-result-container.anim-card-enter {
    animation: cardEnter 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards !important;
}

@keyframes cardEnter {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Result Card Styles (Copied/Adapted from styles.css) */
.result-card {
    position: relative;
    width: 260px;
    height: auto;
    aspect-ratio: 2/3;
    border-radius: 12px;
    background: #1a1a2e;
    /* overflow: hidden; Removed */
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    border: 3px solid transparent;
    /* Colored dynamically */
    display: flex;
    /* Ensure it layout correctly */
    flex-direction: column;

    /* Enable 3D space for children */
    transform-style: preserve-3d;
}

.result-card .card-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    /* Allow 3D pop-out */
    border-radius: 9px;
    z-index: 1;
    transform: translateZ(0);
    transform-style: preserve-3d;
}

.result-card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    border-radius: 9px;
    overflow: hidden;
}

.result-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px;
    /* Smoother gradient */
    background: linear-gradient(to top,
            rgba(0, 0, 0, 0.9) 0%,
            rgba(0, 0, 0, 0.6) 40%,
            rgba(0, 0, 0, 0.3) 70%,
            transparent 100%);
    color: white;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;

    border-radius: 0 0 9px 9px;

    /* Lift overlay significantly HIGHER */
    transform: translateZ(60px);
    transform-style: preserve-3d;
    /* Ensure children can pop out further */
    pointer-events: none;
}

.result-rank {
    position: absolute;
    top: -3px;
    /* Align flush with inside of border to remove gap */
    right: -3px;
    font-size: 16px;
    font-weight: 800;
    padding: 4px 16px 6px 16px;
    border-radius: 0 12px 0 12px;
    /* Match card outer radius */
    background-color: #ffd700;
    /* Overridden in JS */
    color: white;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Removed pop out per request */
    transform: translateZ(0px);
    /* box-shadow: -5px 5px 10px rgba(0,0,0,0.5); Removed shadow */
}

.result-name {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 0;
    order: 1;
    /* Name first */
    /* Pop out text EVEN MORE */
    transform: translateZ(50px);
    text-shadow: 0 10px 20px rgba(0, 0, 0, 0.8);
    /* stronger shadow for height */
}

.result-collection {
    font-size: 13px;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
    order: 2;
    /* Collection second */
    /* Pop out slightly less than name */
    transform: translateZ(40px);
}

/* Hint at bottom of overlay */
.result-hint {
    margin-top: 80px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
    /* Let clicks pass through to overlay */
}

.gacha-animation-overlay.revealed .result-hint {
    opacity: 1;
    transition-delay: 1s;
}

/* Multi-card counter badge */
.gacha-counter {
    position: absolute !important;
    top: 20px !important;
    left: auto !important;
    right: 20px !important;
    transform: none !important;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    padding: 8px 24px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 20;
    letter-spacing: 2px;
    pointer-events: none;
}

/* Dynamic rank colors are now handled in JavaScript */

/* =========================================
   ENHANCED EFFECTS: Particles, Rainbow, Dynamic BG
   ========================================= */

/* Particles Container */
.gacha-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    overflow: visible;
}

/* Individual Particle */
.gacha-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    animation: particleFly 1s ease-out forwards;
}

.gacha-particle.star {
    width: 12px;
    height: 12px;
    background: radial-gradient(circle, #fff 0%, #ffd700 50%, transparent 70%);
    box-shadow: 0 0 10px #ffd700, 0 0 20px #ffd700;
}

.gacha-particle.spark {
    width: 6px;
    height: 6px;
    background: #fff;
    box-shadow: 0 0 8px #fff, 0 0 15px #6c5ce7;
}

.gacha-particle.burst {
    animation: particleBurst 0.8s ease-out forwards;
}

@keyframes particleFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 50px), var(--ty, -80px)) scale(0.3);
    }
}

@keyframes particleBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(0.5);
    }

    50% {
        opacity: 1;
        transform: translate(var(--tx, 100px), var(--ty, -50px)) scale(1.5);
    }

    100% {
        opacity: 0;
        transform: translate(calc(var(--tx, 100px) * 1.5), calc(var(--ty, -50px) * 1.5)) scale(0);
    }
}

/* Enhanced Bounce in Shake */
@keyframes packShakeBounce {

    0%,
    100% {
        transform: scale(1) rotate(0deg) translateY(0);
    }

    12.5% {
        transform: scale(1.02) rotate(-2deg) translateY(-5px);
    }

    25% {
        transform: scale(1.02) rotate(-2deg) translateY(0);
    }

    37.5% {
        transform: scale(1) rotate(0deg) translateY(-3px);
    }

    50% {
        transform: scale(1) rotate(0deg) translateY(0);
    }

    62.5% {
        transform: scale(1.02) rotate(2deg) translateY(-5px);
    }

    75% {
        transform: scale(1.02) rotate(2deg) translateY(0);
    }

    87.5% {
        transform: scale(1) rotate(0deg) translateY(-3px);
    }
}

/* Override shake with bounce */
.gacha-pack-body.anim-shake {
    animation: packShakeBounce 0.5s ease-in-out infinite !important;
    opacity: 1 !important;
}

/* =========================================
   DYNAMIC BACKGROUNDS BY RANK
   ========================================= */

/* S+ Rank - Rainbow Effect */
.gacha-animation-overlay.rank-splus {
    background: linear-gradient(135deg,
            rgba(255, 0, 128, 0.4) 0%,
            rgba(255, 165, 0, 0.4) 20%,
            rgba(255, 255, 0, 0.4) 40%,
            rgba(0, 255, 128, 0.4) 60%,
            rgba(0, 128, 255, 0.4) 80%,
            rgba(128, 0, 255, 0.4) 100%), #0a0a14;
    background-size: 400% 400%;
    animation: rainbowBg 3s ease infinite;
}

.gacha-animation-overlay.rank-splus .gacha-pack-glow {
    background: radial-gradient(circle,
            rgba(255, 215, 0, 0.8) 0%,
            rgba(255, 100, 150, 0.5) 40%,
            transparent 70%);
}

@keyframes rainbowBg {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* S Rank - Golden Glow */
.gacha-animation-overlay.rank-s {
    background: radial-gradient(ellipse at center,
            rgba(255, 215, 0, 0.3) 0%,
            rgba(255, 165, 0, 0.15) 30%,
            transparent 70%), #0a0a14;
}

.gacha-animation-overlay.rank-s .gacha-pack-glow {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.7) 0%, transparent 70%);
}

/* A Rank - Purple Glow */
.gacha-animation-overlay.rank-a {
    background: radial-gradient(ellipse at center,
            rgba(138, 43, 226, 0.2) 0%,
            transparent 60%), #0a0a14;
}

/* Flash Effect on Burst */
.gacha-flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 2001;
    pointer-events: none;
    opacity: 0;
}

.gacha-flash-overlay.active {
    animation: flashBurst 0.4s ease-out forwards;
}

@keyframes flashBurst {
    0% {
        opacity: 0.9;
    }

    100% {
        opacity: 0;
    }
}

/* =========================================
   UI ELEMENTS (Counter & Hint)
   ========================================= */

.gacha-counter {
    position: absolute;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    /* Explicit reset with !important to override potential cache/conflicts */
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;

    color: white;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
    z-index: 100;
    font-family: 'Outfit', sans-serif;
    display: flex;
    align-items: baseline;
    justify-content: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.result-hint {
    position: absolute;
    bottom: 60px;
    left: 0;
    width: 100%;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.5px;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}