/* =====================================================
   CRAFT ANIMATION STYLES
   Mechanical Pack & Gear Theme
   Completely separate from gacha_anim.css
   ===================================================== */

/* =========================================
   1. OVERLAY BASE
   ========================================= */

.crafting-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a14;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.crafting-overlay.active {
    display: flex;
    opacity: 1;
}

/* =========================================
   2. CONTAINER & LAYOUT
   ========================================= */

.crafting-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* Status Text */
.crafting-status {
    position: absolute;
    top: 5%;
    text-align: center;
    z-index: 10;
    opacity: 1;
    transition: opacity 0.3s;
}

.crafting-status-text {
    font-size: 24px;
    font-weight: 700;
    color: #ff9500;
    text-shadow: 0 0 20px rgba(255, 149, 0, 0.5);
    margin-bottom: 8px;
}

.crafting-chance-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
}

#craft-chance-value {
    color: #4ade80;
    font-weight: 600;
}

/* Hide status during result */
.crafting-overlay.show-result .crafting-status {
    opacity: 0;
}

/* =========================================
   3. MECHANICAL PACK STRUCTURE
   ========================================= */

.craft-pack-container {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 450px;
    max-width: 90vw;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

.craft-pack-body {
    position: relative;
    width: 100%;
    height: 100%;
    transform: scale(0.8);
    opacity: 0;
    z-index: 5;
}

/* Pack Appear Animation */
.crafting-overlay.active .craft-pack-body {
    animation: craftPackAppear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes craftPackAppear {
    from {
        transform: scale(0.5) translateY(50px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* =========================================
   4. PACK HALVES - Industrial Metal Theme
   ========================================= */

.pack-half {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    overflow: hidden;
    z-index: 2;
}

.pack-half-left {
    left: 0;
    border-radius: 15px 0 0 15px;
    transform-origin: left center;
    background: linear-gradient(135deg,
            #2a2a35 0%,
            #1a1a22 40%,
            #252530 60%,
            #1f1f28 100%);
    border: 2px solid #ff6b00;
    border-right: none;
    box-shadow: inset -20px 0 40px rgba(0, 0, 0, 0.5);
}

.pack-half-right {
    right: 0;
    border-radius: 0 15px 15px 0;
    transform-origin: right center;
    background: linear-gradient(225deg,
            #2a2a35 0%,
            #1a1a22 40%,
            #252530 60%,
            #1f1f28 100%);
    border: 2px solid #ff6b00;
    border-left: none;
    box-shadow: inset 20px 0 40px rgba(0, 0, 0, 0.5);
}

/* Metal texture overlay */
.pack-half::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.02) 2px,
            rgba(255, 255, 255, 0.02) 4px);
    pointer-events: none;
}

/* Rivets decoration */
.pack-half::after {
    content: '';
    position: absolute;
    top: 20px;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle, #555 0%, #333 60%, #222 100%);
    border-radius: 50%;
    box-shadow:
        0 50px 0 #444,
        0 100px 0 #444,
        0 290px 0 #444,
        0 340px 0 #444;
}

.pack-half-left::after {
    left: 15px;
}

.pack-half-right::after {
    right: 15px;
}

/* =========================================
   5. CENTER SEAM GLOW
   ========================================= */

.pack-seam-glow {
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 4px;
    transform: translateX(-50%);
    z-index: 3;
    background: linear-gradient(to bottom,
            transparent 0%,
            rgba(255, 106, 0, 0.8) 20%,
            rgba(255, 149, 0, 1) 50%,
            rgba(255, 106, 0, 0.8) 80%,
            transparent 100%);
    box-shadow:
        0 0 10px rgba(255, 106, 0, 0.6),
        0 0 20px rgba(255, 106, 0, 0.4),
        0 0 40px rgba(255, 106, 0, 0.2);
    animation: seamPulse 1.5s ease-in-out infinite;
}

@keyframes seamPulse {

    0%,
    100% {
        opacity: 0.6;
        box-shadow:
            0 0 10px rgba(255, 106, 0, 0.4),
            0 0 20px rgba(255, 106, 0, 0.2);
    }

    50% {
        opacity: 1;
        box-shadow:
            0 0 15px rgba(255, 106, 0, 0.8),
            0 0 30px rgba(255, 106, 0, 0.5),
            0 0 50px rgba(255, 106, 0, 0.3);
    }
}

/* =========================================
   6. GEAR ICON
   ========================================= */

.pack-gear-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90px;
    height: 90px;
    background: radial-gradient(circle, #3a3a45 0%, #252530 60%, #1a1a22 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #ff6b00;
    box-shadow:
        0 0 20px rgba(255, 106, 0, 0.5),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    z-index: 4;
}

.gear-icon {
    font-size: 50px;
    color: #ff9500;
    text-shadow: 0 0 10px rgba(255, 149, 0, 0.5);
    animation: gearRotateSlow 4s linear infinite;
}

/* Slow rotation by default */
@keyframes gearRotateSlow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* =========================================
   7. FLYING CARDS (Stage 1) - Dramatic Top Entry
   ========================================= */

.crafting-cards {
    position: absolute;
    top: 45%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 6;
    pointer-events: none;
}

.craft-anim-card {
    position: absolute;
    width: 180px;
    height: auto;
    aspect-ratio: 2/3;
    background-size: cover;
    background-position: center;
    border-radius: 15px;
    border: 3px solid #6c5ce7;
    box-shadow:
        0 0 30px rgba(108, 92, 231, 0.7),
        0 10px 40px rgba(0, 0, 0, 0.5);
    transform: translate(-50%, -50%) translateY(-400px) scale(1.2);
    opacity: 0;
    transition: none;
}

.craft-anim-card.flying {
    animation: cardFlyFromTop 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes cardFlyFromTop {
    0% {
        transform: translate(-50%, -50%) translateY(-400px) scale(1.2) rotate(-5deg);
        opacity: 0;
    }

    20% {
        opacity: 1;
    }

    60% {
        transform: translate(-50%, -50%) translateY(0) scale(0.8) rotate(0deg);
        opacity: 1;
    }

    80% {
        transform: translate(-50%, -50%) translateY(0) scale(0.3) rotate(0deg);
        opacity: 0.8;
    }

    100% {
        transform: translate(-50%, -50%) translateY(0) scale(0) rotate(0deg);
        opacity: 0;
    }
}

/* =========================================
   8. PROCESSING PHASE (Stage 2)
   ========================================= */

.crafting-overlay.phase-processing .gear-icon {
    animation: gearRotateMedium 1.5s linear infinite;
}

@keyframes gearRotateMedium {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.crafting-overlay.phase-processing .pack-seam-glow {
    animation: seamPulse 0.8s ease-in-out infinite;
}

.crafting-overlay.phase-processing .pack-gear-container {
    box-shadow:
        0 0 30px rgba(255, 106, 0, 0.7),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Ensure pack stays visible during phases */
.crafting-overlay.phase-processing .craft-pack-body,
.crafting-overlay.shake .craft-pack-body {
    opacity: 1 !important;
}

/* =========================================
   9. SUSPENSE PHASE (Stage 3)
   ========================================= */

.crafting-overlay.phase-suspense .gear-icon {
    animation: gearRotateFast 0.3s linear infinite;
}

@keyframes gearRotateFast {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.crafting-overlay.phase-suspense .craft-pack-body {
    animation: packVibrate 0.05s linear infinite;
    opacity: 1 !important;
    position: relative;
}

/* Chromatic Aberration - RGB Color Split */
.crafting-overlay.phase-suspense .craft-pack-body::before,
.crafting-overlay.phase-suspense .craft-pack-body::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 15px;
    pointer-events: none;
    mix-blend-mode: screen;
    opacity: 0;
    animation: chromaticPulse 0.1s linear infinite;
}

/* Red channel - offset left */
.crafting-overlay.phase-suspense .craft-pack-body::before {
    background: rgba(255, 0, 0, 0.15);
    animation: chromaticRed 0.08s linear infinite;
}

/* Cyan channel - offset right */
.crafting-overlay.phase-suspense .craft-pack-body::after {
    background: rgba(0, 255, 255, 0.15);
    animation: chromaticCyan 0.08s linear infinite;
}

@keyframes chromaticRed {

    0%,
    100% {
        transform: translate(-3px, 0);
        opacity: 0.4;
    }

    25% {
        transform: translate(-5px, 1px);
        opacity: 0.6;
    }

    50% {
        transform: translate(-2px, -1px);
        opacity: 0.3;
    }

    75% {
        transform: translate(-4px, 0);
        opacity: 0.5;
    }
}

@keyframes chromaticCyan {

    0%,
    100% {
        transform: translate(3px, 0);
        opacity: 0.4;
    }

    25% {
        transform: translate(5px, -1px);
        opacity: 0.6;
    }

    50% {
        transform: translate(2px, 1px);
        opacity: 0.3;
    }

    75% {
        transform: translate(4px, 0);
        opacity: 0.5;
    }
}

@keyframes packVibrate {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    25% {
        transform: translate(-3px, 2px) scale(1.01);
    }

    50% {
        transform: translate(3px, -2px) scale(1);
    }

    75% {
        transform: translate(-2px, -3px) scale(1.01);
    }
}

.crafting-overlay.phase-suspense .pack-seam-glow {
    animation: seamIntense 0.2s ease-in-out infinite;
}

@keyframes seamIntense {

    0%,
    100% {
        opacity: 1;
        background: linear-gradient(to bottom,
                transparent 0%,
                rgba(255, 200, 0, 0.9) 20%,
                rgba(255, 255, 100, 1) 50%,
                rgba(255, 200, 0, 0.9) 80%,
                transparent 100%);
        box-shadow:
            0 0 20px rgba(255, 200, 0, 0.8),
            0 0 40px rgba(255, 149, 0, 0.5);
    }

    50% {
        opacity: 0.8;
    }
}

.crafting-overlay.phase-suspense .pack-gear-container {
    box-shadow:
        0 0 40px rgba(255, 200, 0, 0.9),
        0 0 60px rgba(255, 106, 0, 0.5),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Dynamic Zoom + Camera Shake during Suspense */
.crafting-overlay.phase-suspense .crafting-container {
    animation: suspenseZoomShake 1.2s ease-in forwards;
}

@keyframes suspenseZoomShake {
    0% {
        transform: scale(1) translate(0, 0);
    }

    20% {
        transform: scale(1.05) translate(-2px, 1px);
    }

    40% {
        transform: scale(1.08) translate(3px, -2px);
    }

    50% {
        transform: scale(1.10) translate(-3px, 2px);
    }

    60% {
        transform: scale(1.12) translate(4px, -1px);
    }

    70% {
        transform: scale(1.13) translate(-2px, -3px);
    }

    80% {
        transform: scale(1.14) translate(3px, 2px);
    }

    90% {
        transform: scale(1.15) translate(-4px, -2px);
    }

    100% {
        transform: scale(1.15) translate(0, 0);
    }
}

/* Aggressive shake overlay for intense vibration */
.crafting-overlay.phase-suspense::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    animation: cameraShake 0.05s linear infinite;
}

@keyframes cameraShake {
    0% {
        transform: translate(0, 0);
    }

    25% {
        transform: translate(-4px, 3px);
    }

    50% {
        transform: translate(4px, -4px);
    }

    75% {
        transform: translate(-3px, -3px);
    }

    100% {
        transform: translate(3px, 4px);
    }
}

/* Snap back on result */
.crafting-overlay.phase-result .crafting-container {
    animation: snapBack 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes snapBack {
    0% {
        transform: scale(1.15);
    }

    50% {
        transform: scale(0.95);
    }

    100% {
        transform: scale(1);
    }
}

/* Also support .shake class */
.crafting-overlay.shake .craft-pack-body {
    animation: packVibrate 0.05s linear infinite;
}

/* =========================================
   10. RESULT PHASE (Stage 4)
   ========================================= */

/* Success: Pack Bursts Open */
.crafting-overlay.phase-result.success .pack-half-left {
    animation: packBurstLeft 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.crafting-overlay.phase-result.success .pack-half-right {
    animation: packBurstRight 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes packBurstLeft {
    0% {
        transform: translateX(0) rotateY(0);
        opacity: 1;
    }

    100% {
        transform: translateX(-150%) rotateY(-30deg);
        opacity: 0;
    }
}

@keyframes packBurstRight {
    0% {
        transform: translateX(0) rotateY(0);
        opacity: 1;
    }

    100% {
        transform: translateX(150%) rotateY(30deg);
        opacity: 0;
    }
}

.crafting-overlay.phase-result.success .pack-seam-glow,
.crafting-overlay.phase-result.success .pack-gear-container {
    animation: centerFadeOut 0.3s ease-out forwards;
}

@keyframes centerFadeOut {
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.5);
    }
}

/* Fail: Gear Jams */
.crafting-overlay.phase-result.fail .gear-icon {
    animation: gearJam 0.3s ease-out forwards;
    color: #666;
    text-shadow: none;
}

@keyframes gearJam {
    0% {
        transform: rotate(0deg);
    }

    30% {
        transform: rotate(15deg);
    }

    60% {
        transform: rotate(-10deg);
    }

    80% {
        transform: rotate(5deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.crafting-overlay.phase-result.fail .craft-pack-body {
    animation: packDarken 0.5s ease-out forwards;
}

@keyframes packDarken {
    to {
        filter: brightness(0.4) saturate(0.3);
    }
}

.crafting-overlay.phase-result.fail .pack-seam-glow {
    animation: seamDie 0.4s ease-out forwards;
}

@keyframes seamDie {
    to {
        opacity: 0;
        background: transparent;
        box-shadow: none;
    }
}

.crafting-overlay.phase-result.fail .pack-gear-container {
    box-shadow: 0 0 10px rgba(100, 100, 100, 0.3);
    border-color: #555;
}

/* =========================================
   11. PARTICLES & SPARKS
   ========================================= */

.crafting-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    overflow: visible;
}

.craft-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
}

.craft-particle.spark {
    background: #ff9500;
    box-shadow: 0 0 8px #ff6b00, 0 0 15px #ff9500;
}

.craft-particle.energy {
    background: radial-gradient(circle, #fff 20%, #ff9500 60%, transparent 100%);
    box-shadow: 0 0 10px #ff6b00;
}

.craft-particle.success-burst {
    width: 12px;
    height: 12px;
    background: radial-gradient(circle, #fff 0%, #4ade80 50%, transparent 70%);
    box-shadow: 0 0 15px #4ade80;
}

/* Mechanical Sparks Container */
.mechanical-spark-system {
    position: absolute;
    top: 45%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 15;
    overflow: visible;
}

.mechanical-spark {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #ffaa00;
    border-radius: 50%;
    box-shadow: 0 0 6px #ff6b6b;
    /* Decreased shadow radius for performance */
    will-change: transform, opacity;
}

@keyframes sparkFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 50px), var(--ty, -50px)) scale(0.3);
    }
}

/* =========================================
   11.4 EPIC RESULT EFFECTS
   ========================================= */

/* SHOCKWAVE - expanding ring on success */
/* SHOCKWAVE - expanding ring on success */
.shockwave {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    overflow: visible;
    transform: translate(-50%, -50%) scale(0);
    pointer-events: none;
    opacity: 0;
    will-change: transform, opacity;
}

.shockwave.active {
    animation: shockwaveExpand 0.6s ease-out forwards;
}

@keyframes shockwaveExpand {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        transform: translate(-50%, -50%) scale(25);
        opacity: 0;
    }
}

/* Multiple shockwaves for more impact */
.shockwave.delay-1 {
    animation-delay: 0.1s;
}

.shockwave.delay-2 {
    animation-delay: 0.2s;
}

/* CONFETTI / STAR BURST particles */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    pointer-events: none;
    opacity: 0;
    will-change: transform, opacity;
}

.confetti.star {
    background: radial-gradient(circle, #fff 20%, #ffd700 60%, transparent 70%);
    border-radius: 50%;
    box-shadow: 0 0 10px #ffd700;
}

.confetti.sparkle {
    width: 6px;
    height: 16px;
    border-radius: 3px;
    background: linear-gradient(to bottom, transparent, var(--color, #fff), transparent);
    box-shadow: 0 0 8px var(--color, #fff);
}

.confetti.circle {
    border-radius: 50%;
    background: var(--color, #fff);
    box-shadow: 0 0 6px var(--color, #fff);
}

.confetti.active {
    animation: confettiBurst 1s ease-out forwards;
}

@keyframes confettiBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }

    30% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 100px), var(--ty, -150px)) rotate(var(--rot, 360deg)) scale(0.5);
    }
}

/* BROKEN GEARS - on fail */
.broken-gear {
    position: absolute;
    font-size: 20px;
    color: #666;
    pointer-events: none;
    opacity: 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.broken-gear.active {
    animation: brokenGearFly 1.2s ease-out forwards;
}

@keyframes brokenGearFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 80px), var(--ty, 120px)) rotate(var(--rot, 540deg)) scale(0.3);
    }
}

/* Gear fragment (half gear) */
.gear-fragment {
    position: absolute;
    width: 30px;
    height: 15px;
    background: linear-gradient(to bottom, #555 0%, #333 100%);
    border-radius: 15px 15px 0 0;
    pointer-events: none;
    opacity: 0;
    box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.5);
}

.gear-fragment.active {
    animation: fragmentFly 1s ease-out forwards;
}

@keyframes fragmentFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 60px), var(--ty, 100px)) rotate(var(--rot, 180deg));
    }
}

/* =========================================
   11.5 ADVANCED VFX PARTICLES
   ========================================= */

/* Mini Gears - fly out and rotate */
.mini-gear {
    position: absolute;
    font-size: 12px;
    color: #888;
    opacity: 0;
    pointer-events: none;
    text-shadow: 0 0 4px rgba(255, 150, 0, 0.5);
}

.mini-gear.flying {
    animation: miniGearFly 1.2s ease-out forwards;
}

@keyframes miniGearFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }

    50% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 80px), var(--ty, -100px)) rotate(720deg) scale(0.3);
    }
}

/* Steam/Smoke particles */
.steam-particle {
    position: absolute;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(200, 200, 200, 0.6) 0%, rgba(150, 150, 150, 0.3) 50%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    filter: blur(3px);
    opacity: 0;
}

.steam-particle.rising {
    animation: steamRise 1.5s ease-out forwards;
}

@keyframes steamRise {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.5);
    }

    20% {
        opacity: 0.7;
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 0), -80px) scale(2);
    }
}

/* Rank-colored sparks */
.rank-spark {
    position: absolute;
    width: 4px;
    height: 12px;
    border-radius: 2px;
    pointer-events: none;
    opacity: 0;
    will-change: transform, opacity;
}

.rank-spark.flying {
    animation: rankSparkFly 0.6s ease-out forwards;
}

@keyframes rankSparkFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(var(--rot, 0deg)) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--tx, 30px), var(--ty, -60px)) rotate(var(--rot, 0deg)) scale(0.5);
    }
}

/* Rank color variations - INPUT card colors */
.rank-spark.rank-c {
    background: linear-gradient(to top, transparent, #4ade80, #fff);
    box-shadow: 0 0 6px #4ade80;
}

.rank-spark.rank-b {
    background: linear-gradient(to top, transparent, #a855f7, #fff);
    box-shadow: 0 0 8px #a855f7;
}

.rank-spark.rank-a {
    background: linear-gradient(to top, transparent, #ef4444, #fff);
    box-shadow: 0 0 10px #ef4444;
}

.rank-spark.rank-s {
    background: linear-gradient(to top, transparent, #ffd700, #fff);
    box-shadow: 0 0 12px #ffd700;
}

.rank-spark.rank-splus {
    background: linear-gradient(to top, transparent, #ff6b6b, #ffd700, #fff);
    box-shadow: 0 0 15px #ff6b6b, 0 0 25px #ffd700;
}

/* Steam container positioned at seam */
.steam-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    z-index: 8;
    overflow: visible;
    pointer-events: none;
}

/* =========================================
   12. RESULT DISPLAY
   ========================================= */

.crafting-result {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    opacity: 0;
    pointer-events: none;
}

/* Show result when phase-result is active */
.crafting-overlay.phase-result .crafting-result {
    opacity: 1;
    pointer-events: auto;
}

/* Success Result */
.crafting-result-success {
    display: none;
}

.crafting-overlay.phase-result.success .crafting-result-success {
    display: block;
    animation: resultCardAppear 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes resultCardAppear {
    from {
        transform: scale(0.2);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.craft-result-card {
    width: 260px;
    height: auto;
    aspect-ratio: 2/3;
}

/* Fail Result */
.crafting-result-fail {
    display: none;
    text-align: center;
    color: #ff4444;
}

.crafting-overlay.phase-result.fail .crafting-result-fail {
    display: block;
    animation: failAppear 0.5s ease-out forwards;
}

@keyframes failAppear {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.fail-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: failPulse 1s ease-in-out infinite;
}

@keyframes failPulse {

    0%,
    100% {
        opacity: 0.8;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

.fail-text {
    font-size: 32px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 12px;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

.fail-subtext {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
}

.fail-smoke {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(50, 50, 50, 0.6) 0%, transparent 70%);
    animation: smokeRise 2s ease-out infinite;
    opacity: 0;
}

.crafting-overlay.fail .fail-smoke {
    opacity: 1;
}

@keyframes smokeRise {
    0% {
        transform: translateX(-50%) translateY(0) scale(1);
        opacity: 0.6;
    }

    100% {
        transform: translateX(-50%) translateY(-80px) scale(2);
        opacity: 0;
    }
}

/* =========================================
   13. OK BUTTON — Hidden (close by clicking anywhere)
   ========================================= */

.craft-ok-btn {
    display: none;
    position: absolute;
    bottom: 15%;
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 40px;
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px rgba(74, 222, 128, 0.4);
    z-index: 25;
}

.crafting-overlay.show-result .craft-ok-btn {
    opacity: 1;
    pointer-events: auto;
    animation: btnAppear 0.4s ease-out 0.3s both;
}

@keyframes btnAppear {
    from {
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.craft-ok-btn:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 25px rgba(74, 222, 128, 0.5);
}

.craft-ok-btn:active {
    transform: translateX(-50%) scale(0.98);
}

/* Fail state button color */
.crafting-overlay.fail .craft-ok-btn {
    background: linear-gradient(135deg, #666 0%, #444 100%);
    box-shadow: 0 4px 20px rgba(100, 100, 100, 0.3);
}

/* =========================================
   14. SKIP/CLOSE HINT
   ========================================= */

/* Skip/Close Hint */
.craft-skip-hint {
    position: absolute;
    bottom: 60px;
    /* Match gacha */
    top: auto;
    /* Reset top */
    left: 0;
    /* Match gacha */
    width: 100%;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    /* Match gacha */
    font-size: 14px;
    font-weight: 500;
    /* Match gacha */
    letter-spacing: 0.5px;
    /* Match gacha */
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    /* Match gacha */
    transform: none;
    /* Reset transform */
}

/* .crafting-overlay.can-skip .craft-skip-hint {
    opacity: 1;
} */

/* Keep hint visible on result (for "click to close") */
.crafting-overlay.show-result .craft-skip-hint {
    opacity: 1;
}

/* =========================================
   16. RANK BACKGROUNDS (Ported from Gacha)
   ========================================= */

/* S+ Rank - Rainbow Effect */
.crafting-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;
}

/* S Rank - Golden Glow */
.crafting-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;
}

/* A Rank - Purple Glow */
.crafting-overlay.rank-a {
    background: radial-gradient(ellipse at center,
            rgba(138, 43, 226, 0.2) 0%,
            transparent 60%), #0a0a14;
}

@keyframes rainbowBg {

    0%,
    100% {
        background-position: 0% 50%;
    }

}

/* Rank Glow Element (Center Hotspot) */
/* Result Container */
.crafting-result {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 450px;
    pointer-events: none;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
}

.craft-result-card {
    pointer-events: auto;
}

.craft-rank-glow {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.5s;
    /* Default glow (for B/C ranks) */
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 60%);
}

.crafting-overlay.show-result .craft-rank-glow {
    opacity: 1;
}

.crafting-overlay.rank-splus .craft-rank-glow {
    background: radial-gradient(circle,
            rgba(255, 215, 0, 0.8) 0%,
            rgba(255, 100, 150, 0.5) 40%,
            transparent 70%);
}

.crafting-overlay.rank-s .craft-rank-glow {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.7) 0%, transparent 70%);
}

/* A Rank - Purple Glow (New for uniformity) */
.crafting-overlay.rank-a .craft-rank-glow {
    background: radial-gradient(circle, rgba(138, 43, 226, 0.4) 0%, transparent 60%);
}

/* =========================================
   17. RESULT SPARKS & GOD RAYS (Ported from Gacha)
   ========================================= */

.craft-card-sparks {
    position: absolute;
    top: 45%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: -1;
    /* Behind card */
    overflow: visible;
}

.card-spark {
    position: absolute;
    width: 4px;
    height: 40px;
    background: white;
    border-radius: 2px;
    transform-origin: center bottom;
    opacity: 0;
}

.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%;
    transform-origin: center center;
    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;
}