/* Fusion System Styles */

/* CRITICAL OVERRIDES FOR VISIBILITY */
/* Fusion Container */
.fusion-container {
    width: 100%;
    max-width: 1200px;
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    text-align: center;
    position: relative;
    z-index: 200;
}

.fusion-machine {
    background: linear-gradient(135deg, rgba(20, 20, 25, 0.95) 0%, rgba(10, 10, 15, 0.98) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid #444;
    border-top: 4px solid #ffd700;
    border-bottom: 4px solid #b8860b;
    border-radius: 20px;
    padding: 30px 40px;
    width: 90%;
    max-width: 900px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), inset 0 0 50px rgba(255, 215, 0, 0.05);
    display: flex;
    flex-direction: column;
    margin-bottom: 50px;
    position: relative;
    /* overflow: hidden; Removed to allow core to pop out */
}

/* New Header Styles inside Machine */
.fusion-header-panel {
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.1), transparent);
    width: 100%;
    padding: 10px 0;
    margin-bottom: 40px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.fusion-title {
    font-size: 3.5rem;
    background: linear-gradient(180deg, #fff 0%, #ffd700 50%, #e6ac00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
    text-transform: uppercase;
    letter-spacing: 5px;
    margin: 0;
    font-weight: 900;
    font-family: 'Kanit', sans-serif;
    line-height: 1.2;
}

.fusion-divider {
    height: 3px;
    width: 100px;
    background: #ffd700;
    margin: 10px 0;
    border-radius: 2px;
    box-shadow: 0 0 10px #ffd700;
}

.fusion-subtitle {
    color: #a0a0a0;
    font-size: 1.1rem;
    margin: 0;
    font-family: 'Kanit', sans-serif;
    letter-spacing: 1px;
}

.slots-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.fusion-slot {
    width: 100px;
    height: 100px;
    border: 2px dashed #555;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.fusion-slot:hover {
    border-color: #ffd700;
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 5px 15px rgba(255, 215, 0, 0.2);
    background: rgba(50, 50, 50, 0.6);
}

.fusion-slot.filled {
    border: 2px solid #ffd700;
    background: radial-gradient(circle, rgba(60, 60, 60, 1) 0%, rgba(20, 20, 20, 1) 100%);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

.slot-placeholder {
    font-size: 3rem;
    color: #444;
    line-height: 1;
    font-weight: bold;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
}

.fusion-slot:hover .slot-placeholder {
    color: #ffd700;
}

.slot-item-img {
    width: 85%;
    height: 85%;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
}

.fusion-core {
    width: 150px;
    height: 150px;
    margin: 0 30px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.core-img {
    width: 100%;
    height: 100%;
    z-index: 2;
    filter: drop-shadow(0 0 15px #ff4e00);
    animation: pulse 3s infinite ease-in-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 10px #ff4e00);
    }

    50% {
        transform: scale(1.08);
        filter: drop-shadow(0 0 30px #ffd700);
    }

    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 10px #ff4e00);
    }
}

/* Controls */
.fusion-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    margin-top: 20px;
}

.success-rate-box {
    font-size: 1.4rem;
    font-weight: 600;
    color: #fff;
    background: #1a1a1a;
    padding: 12px 30px;
    border-radius: 30px;
    border: 1px solid #333;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

#rate-display {
    color: #555;
    font-size: 1.8rem;
    font-weight: 800;
    min-width: 80px;
    text-align: right;
    transition: color 0.3s;
}

.btn-fuse {
    background: linear-gradient(180deg, #ff4e00 0%, #b30000 100%);
    border: none;
    padding: 16px 100px;
    font-size: 2rem;
    color: white;
    font-family: 'Kanit', sans-serif;
    font-weight: 900;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    text-transform: uppercase;
    box-shadow: 0 6px 0 #800000, 0 15px 20px rgba(0, 0, 0, 0.4);
    letter-spacing: 2px;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.btn-fuse::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(to bottom right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0) 100%);
    transform: rotate(45deg);
    transition: transform 0.5s;
}

.btn-fuse:hover::after {
    transform: rotate(45deg) translate(50%, 50%);
}

.btn-fuse:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #800000, inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.btn-fuse:disabled {
    background: #333;
    color: #666;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    text-shadow: none;
    filter: none;
    opacity: 0.7;
}

.btn-fuse:hover:not(:disabled) {
    background: linear-gradient(180deg, #ff6a00 0%, #cc0000 100%);
    box-shadow: 0 6px 0 #800000, 0 0 40px #ff4e00;
}

/* Inventory Drawer */
.inventory-drawer {
    position: fixed;
    bottom: -450px;
    /* Start hidden */
    left: 0;
    width: 100%;
    height: 400px;
    background: rgba(18, 18, 20, 0.98);
    border-top: 4px solid #ffd700;
    transition: bottom 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.9);
}

.inventory-drawer.open {
    bottom: 0;
}

.drawer-header {
    padding: 15px 40px;
    background: linear-gradient(90deg, #1a1a1a, #2a2a2a);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffd700;
    border-bottom: 1px solid #444;
}

.drawer-header h3 {
    margin: 0;
    font-size: 1.5rem;
    text-transform: uppercase;
}

.close-drawer {
    background: none;
    border: none;
    font-size: 2.5rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.close-drawer:hover {
    color: #ff4e00;
    transform: rotate(90deg);
}

.inventory-grid {
    padding: 30px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 20px;
    height: 100%;
}

.inv-item {
    width: 90px;
    height: 90px;
    border: 1px solid #444;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background: #252525;
    border-radius: 8px;
    position: relative;
    transition: all 0.2s;
}

.inv-item:hover {
    border-color: #ffd700;
    background: #333;
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.inv-item img {
    width: 75%;
    height: 75%;
    object-fit: contain;
}

/* Rate Info Card (Side Panel) */
.fusion-info-card {
    position: absolute;
    right: 0;
    /* Align to right edge of container */
    top: 100px;
    width: 220px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid #ffd700;
    border-radius: 10px;
    padding: 15px;
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
    font-family: 'Kanit', sans-serif;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.level-tag {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 10px;
    background: #000;
    padding: 2px 6px;
    border-radius: 4px;
    color: #ffd700;
    border: 1px solid #333;
    font-weight: bold;
}

/* ANIMATIONS FOR FUSION PROCESS */
/* ... (retaining existing animations) ... */
@keyframes shake-and-glow {
    0% {
        transform: translate(0, 0) scale(1);
        filter: brightness(1);
    }

    10% {
        transform: translate(-2px, -2px) scale(0.95);
        filter: brightness(1.2);
    }

    20% {
        transform: translate(2px, 2px) scale(0.95);
        filter: brightness(1.4);
    }

    30% {
        transform: translate(-3px, 3px) scale(0.9);
        filter: brightness(1.6);
        opacity: 1;
    }

    40% {
        transform: translate(3px, -3px) scale(0.9);
        filter: brightness(1.8);
        opacity: 0.8;
    }

    50% {
        transform: translate(-4px, 0px) scale(0.8);
        filter: brightness(2.0);
        opacity: 0.6;
    }

    80% {
        transform: translate(4px, 0px) scale(0.5);
        filter: brightness(5.0);
        opacity: 0;
    }

    100% {
        transform: translate(0, 0) scale(0);
        opacity: 0;
    }
}

@keyframes core-overload {
    0% {
        transform: scale(1) rotate(0deg);
        filter: drop-shadow(0 0 10px #ff4e00);
    }

    20% {
        transform: scale(1.2) rotate(10deg);
        filter: drop-shadow(0 0 20px #ffd700);
    }

    40% {
        transform: scale(1.4) rotate(-10deg);
        filter: drop-shadow(0 0 40px #ffd700);
    }

    50% {
        transform: scale(1.5) rotate(0deg);
        filter: drop-shadow(0 0 60px orange) brightness(2);
    }

    80% {
        transform: scale(1.8) rotate(5deg);
        filter: drop-shadow(0 0 100px white) brightness(5);
    }

    100% {
        transform: scale(2) rotate(0deg);
        filter: drop-shadow(0 0 200px white) brightness(10);
    }
}

@keyframes magic-swirl {
    0% {
        transform: rotate(0deg) scale(0.5);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: rotate(720deg) scale(2);
        opacity: 0;
    }
}

/* Classes applied during fusion */
.fusing .fusion-slot[data-slot] {
    animation: shake-and-glow 1.8s ease-in forwards;
    border-color: white;
}

.fusing .fusion-core .core-img {
    animation: core-overload 2s cubic-bezier(0.5, 0, 1, 1) forwards;
}

/* Magic Circle Overlay Effect */
/* === EXTREME FUSION EFFECTS (100x MODE) === */

/* 1. MAGIC CIRCLE: SUPER COMPACT REACTOR */
.magic-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 600px;
    /* Massive size */
    height: 600px;
    transform: translate(-50%, -50%) scale(0);
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
    /* Complex energy field */
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, rgba(255, 215, 0, 0.4) 20%, rgba(255, 69, 0, 0) 60%);
    mix-blend-mode: screen;
}

/* Rotating Runes/Rings */
.magic-circle::before {
    content: '';
    position: absolute;
    top: 10%;
    bottom: 10%;
    left: 10%;
    right: 10%;
    border-radius: 50%;
    border: 10px dashed #ffd700;
    box-shadow: 0 0 50px #ffd700, inset 0 0 50px #ffd700;
    opacity: 0.8;
}

.magic-circle::after {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: 25%;
    right: 25%;
    border-radius: 50%;
    border: 15px double #fff;
    border-left-color: transparent;
    border-right-color: transparent;
    filter: blur(2px);
    box-shadow: 0 0 80px white;
}

/* GOD RAYS (Third layer via child if possible, but we use pseudo on core for now) */

/* 2. SLOT ENERGY BEAMS */
.fusing .fusion-slot {
    border-color: #fff !important;
    background: #fff !important;
    box-shadow: 0 0 50px #ffd700 !important;
    z-index: 20;
}

.fusing .fusion-slot::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 200px;
    /* Reach the core */
    height: 10px;
    background: linear-gradient(90deg, #fff, transparent);
    z-index: -1;
    transform-origin: center left;
    filter: drop-shadow(0 0 10px gold);
    animation: beam-shoot 0.5s infinite alternate;
    opacity: 0;
}

/* Adjust beam direction based on slot position */
.fusing .fusion-slot[data-slot="1"]::after,
.fusing .fusion-slot[data-slot="2"]::after {
    left: 100%;
    transform: translateY(-50%);
    animation: beam-shoot-right 0.2s infinite;
}

.fusing .fusion-slot[data-slot="3"]::after,
.fusing .fusion-slot[data-slot="4"]::after,
.fusing .fusion-slot[data-slot="5"]::after {
    right: 100%;
    transform: translateY(-50%) rotate(180deg);
    animation: beam-shoot-left 0.2s infinite;
}

/* 3. ANIMATION TRIGGERS */
.fusing .magic-circle {
    animation: extreme-implode 2s cubic-bezier(0.7, 0, 0.3, 1) forwards;
}

.fusing .magic-circle::before {
    animation: spin-violent 2s cubic-bezier(0.5, 0, 1, 1) forwards;
}

.fusing .magic-circle::after {
    animation: spin-violent-reverse 2s cubic-bezier(0.5, 0, 1, 1) forwards;
}

.fusing .fusion-machine {
    animation: machine-rumble 2s ease-in-out forwards;
}

.fusing .core-img {
    animation: core-meltdown 2s steps(10) forwards !important;
}

/* 4. KEYFRAMES */

/* Implosion: Huge growth then rapid collapse to black hole */
@keyframes extreme-implode {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    10% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    60% {
        transform: translate(-50%, -50%) scale(1.5);
        filter: hue-rotate(0deg) brightness(2);
    }

    80% {
        transform: translate(-50%, -50%) scale(0.1);
        filter: hue-rotate(180deg) brightness(5);
        opacity: 1;
    }

    90% {
        transform: translate(-50%, -50%) scale(30);
        opacity: 1;
        filter: brightness(100);
        background: white;
    }

    /* FLASH BANG */
    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

@keyframes spin-violent {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(1080deg);
        border-width: 50px;
        border-style: solid;
    }
}

@keyframes spin-violent-reverse {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(-1080deg);
        border-width: 20px;
    }
}

@keyframes beam-shoot-right {
    0% {
        width: 0;
        opacity: 0;
    }

    50% {
        width: 300px;
        opacity: 1;
        background: linear-gradient(90deg, #fff, gold);
    }

    100% {
        width: 300px;
        opacity: 0.5;
        background: linear-gradient(90deg, transparent, #fff);
    }
}

@keyframes beam-shoot-left {
    0% {
        width: 0;
        opacity: 0;
    }

    50% {
        width: 300px;
        opacity: 1;
        background: linear-gradient(90deg, #fff, gold);
    }

    100% {
        width: 300px;
        opacity: 0.5;
        background: linear-gradient(90deg, transparent, #fff);
    }
}

/* Machine Shake */
@keyframes machine-rumble {
    0% {
        transform: translate(0, 0);
    }

    10% {
        transform: translate(-5px, 5px);
    }

    20% {
        transform: translate(5px, -5px) rotate(1deg);
    }

    30% {
        transform: translate(-10px, 0px) rotate(-1deg);
        filter: invert(0);
    }

    40% {
        transform: translate(10px, 0px);
        filter: invert(0.1);
    }

    50% {
        transform: translate(0px, 15px) scale(1.02);
        filter: invert(0.2);
    }

    60% {
        transform: translate(0px, -15px) scale(1.05);
        filter: contrast(2) brightness(1.5);
    }

    70% {
        transform: translate(20px, 20px) rotate(5deg);
        background-color: #330000;
    }

    80% {
        transform: translate(-20px, -20px) rotate(-5deg);
        background-color: #fff;
    }

    90% {
        transform: translate(0, 0) scale(1.1);
        filter: contrast(5) brightness(10);
    }

    100% {
        transform: translate(0, 0);
        filter: none;
    }
}

/* Core turning into a sun */
@keyframes core-meltdown {
    0% {
        filter: drop-shadow(0 0 10px red);
    }

    50% {
        filter: drop-shadow(0 0 100px gold) brightness(3) sepia(1);
        transform: scale(1.5) rotate(720deg);
    }

    100% {
        filter: drop-shadow(0 0 500px white) brightness(10) contrast(2);
        transform: scale(0.1);
    }
}

/* Full Screen Flash */
.fusion-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: hard-light;
}

.fusing-flash-anim {
    animation: flash-bang 3s ease-out forwards;
}

@keyframes flash-bang {
    0% {
        opacity: 0;
    }

    20% {
        opacity: 0.5;
        background: gold;
    }

    40% {
        opacity: 1;
        background: white;
    }

    100% {
        opacity: 0;
    }
}

/* === ENHANCED RARITY VISIBILITY === */

/* Rarity Tag - High Contrast */
.rarity-tag {
    position: absolute;
    top: 0;
    right: 0;
    padding: 3px 8px;
    /* Larger padding */
    font-size: 11px;
    /* Larger font */
    font-weight: 900;
    text-transform: uppercase;
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    border-bottom-left-radius: 8px;
    box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.5);
    /* Stronger shadow */
    z-index: 5;
    letter-spacing: 0.5px;
    border-left: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

/* Item Border by Rarity */
.inv-item {
    position: relative;
    border: 2px solid #555;
    /* Default border */
    transition: transform 0.2s, box-shadow 0.2s;
}

/* Specific Rarity Styles (Tag Background + Item Border) */

/* COMMON */
.rarity-tag.common {
    background: #6c757d;
}

.inv-item:has(.rarity-tag.common) {
    border-color: #6c757d;
}

/* UNIQUE */
.rarity-tag.unique {
    background: #007bff;
}

.inv-item:has(.rarity-tag.unique) {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

/* RARE - FIXED VISIBILITY */
.rarity-tag.rare {
    background: #00ff00;
    /* Neon Green */
    color: #000;
    /* Black Text for Contrast */
    text-shadow: none;
    /* Remove shadow for readability on bright bg */
    border: 1px solid #fff;
}

.inv-item:has(.rarity-tag.rare) {
    border-color: #00ff00;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.4);
}

/* LEGEND */
.rarity-tag.legend {
    background: linear-gradient(45deg, #ffd700, #ffca00);
    color: #000;
    text-shadow: none;
    border: 1px solid #fff;
}

.inv-item:has(.rarity-tag.legend) {
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

/* ULTIMATE */
.rarity-tag.ultimate {
    background: #dc3545;
    border: 1px solid #ffaaaa;
}

.inv-item:has(.rarity-tag.ultimate) {
    border-color: #dc3545;
    box-shadow: 0 0 8px rgba(220, 53, 69, 0.5);
}

/* mystic */
.rarity-tag.mystic {
    background: linear-gradient(45deg, #9400d3, #da70d6);
    box-shadow: 0 0 10px #9400d3;
    border: 1px solid #fff;
}

.inv-item:has(.rarity-tag.mystic) {
    border-color: #da70d6;
    box-shadow: 0 0 15px rgba(148, 0, 211, 0.6);
    animation: rarity-pulse 2s infinite;
}

@keyframes rarity-pulse {
    0% {
        box-shadow: 0 0 5px #9400d3;
    }

    50% {
        box-shadow: 0 0 15px #da70d6;
    }

    100% {
        box-shadow: 0 0 5px #9400d3;
    }
}