/* ================================================= */
/*   COMPLETE MOBILE OVERHAUL FOR ELEMENTAL WORKSHOP */
/*   Optimized for iPhone 13 and similar devices     */
/* ================================================= */

/* Base Mobile Layout (max-width: 768px) */
@media (max-width: 768px) {
    
    /* ======================== */
    /*    VIEWPORT & BODY       */
    /* ======================== */
    body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        touch-action: manipulation; /* Prevent double-tap zoom */
        -webkit-touch-callout: none; /* Disable callout on long press */
        user-select: none;
    }
    
    #game-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        height: -webkit-fill-available; /* iOS Safari fix */
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    /* ======================== */
    /*    MOBILE HEADER         */
    /* ======================== */
    .game-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 50px !important;
        min-height: 50px !important;
        max-height: 50px !important;
        z-index: 1000 !important;
        background: linear-gradient(180deg, 
            rgba(20, 20, 30, 0.98) 0%, 
            rgba(15, 15, 25, 0.98) 100%) !important;
        border-bottom: 2px solid rgba(255, 215, 0, 0.3) !important;
        padding: 5px 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }
    
    /* Show mobile-only elements */
    .mobile-only {
        display: flex !important;
    }
    
    /* Mobile header icons container */
    .mobile-header-icons {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        height: 100% !important;
    }
    
    /* Mobile buttons */
    .mobile-icon-btn {
        width: 38px !important;
        height: 38px !important;
        padding: 6px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
        transition: all 0.2s ease !important;
        cursor: pointer !important;
    }
    
    .mobile-icon-btn:active {
        transform: scale(0.95) !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }
    
    .mobile-btn-icon {
        width: 24px !important;
        height: 24px !important;
    }
    
    /* Mobile discoveries badge */
    .mobile-discoveries-badge {
        position: absolute !important;
        top: 2px !important;
        right: 2px !important;
        width: 12px !important;
        height: 12px !important;
        background: rgba(255, 87, 34, 0.9) !important;
        border-radius: 50% !important;
        font-size: 8px !important;
        color: white !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* ======================== */
    /*    ELEMENTAL BELTS       */
    /* ======================== */
    .elements-container {
        position: fixed !important;
        top: 50px !important; /* Exactly below mobile header */
        left: 0 !important;
        right: 0 !important;
        height: 260px !important; /* 4 belts at 65px each */
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 5px !important;
        background: linear-gradient(135deg, 
            rgba(10, 10, 20, 0.95) 0%, 
            rgba(5, 5, 15, 0.98) 100%) !important;
        z-index: 100 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
    }
    
    /* Element group (belt row) */
    .element-group {
        display: flex !important;
        align-items: center !important;
        margin-bottom: 2px !important;
        padding: 4px 3px !important;
        min-height: 62px !important;
        height: 62px !important;
        max-height: 62px !important;
        border-radius: 12px !important;
        position: relative !important;
        flex-shrink: 0 !important;
    }
    
    /* Core element (left side) */
    .core-element-integrated {
        width: 55px !important;
        height: 55px !important;
        min-width: 55px !important;
        margin-right: 8px !important;
        margin-left: 3px !important;
        border: 2px solid !important;
        position: sticky !important;
        left: 5px !important;
        z-index: 100 !important;
        background: radial-gradient(circle, 
            rgba(255, 255, 255, 0.03) 0%, 
            rgba(255, 255, 255, 0.02) 50%, 
            transparent 100%) !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), inset 0 1px 2px rgba(255, 255, 255, 0.03) !important;
    }
    
    .core-element-integrated img {
        width: 48px !important; /* Increased by 20% */
        height: 48px !important;
    }
    
    .core-element-name {
        font-size: 9px !important;
        padding: 1px 5px !important;
        bottom: -3px !important;
    }
    
    /* Scrollable belt container */
    .kinetic-scroll-container {
        flex: 1 !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
        padding: 5px 10px 5px 0 !important;
        
        /* Hide scrollbar but keep functionality */
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
    }
    
    .kinetic-scroll-container::-webkit-scrollbar {
        display: none !important;
    }
    
    /* Belt elements container */
    .kinetic-physics {
        display: flex !important;
        gap: 10px !important;
        padding-right: 15px !important;
    }
    
    /* Derived elements in belt */
    .derived-element {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        background: radial-gradient(circle, 
            rgba(255, 255, 255, 0.02) 0%, 
            transparent 70%) !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), inset 0 1px 2px rgba(255, 255, 255, 0.02) !important;
        position: relative !important;
        transition: transform 0.2s ease !important;
    }
    
    .derived-element img {
        width: 42px !important; /* Increased by 20% */
        height: 42px !important;
    }
    
    .derived-element:active {
        transform: scale(0.9) !important;
    }
    
    /* Tier rings adjustment for mobile */
    .derived-element::before,
    .derived-element::after {
        display: none !important; /* Hide complex animations on mobile */
    }
    
    /* Simple tier indicator for mobile */
    .derived-element[data-tier]::after {
        content: attr(data-tier) !important;
        position: absolute !important;
        top: 2px !important;
        right: 2px !important;
        width: 16px !important;
        height: 16px !important;
        border-radius: 50% !important;
        font-size: 10px !important;
        font-weight: bold !important;
        color: white !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        pointer-events: none !important;
    }
    
    .derived-element[data-tier="0"]::after { background: #757575 !important; }
    .derived-element[data-tier="1"]::after { background: #87ceeb !important; }
    .derived-element[data-tier="2"]::after { background: #98d8c8 !important; }
    .derived-element[data-tier="3"]::after { background: #ffd700 !important; }
    .derived-element[data-tier="4"]::after { background: #ff9f40 !important; }
    .derived-element[data-tier="5"]::after { background: #e74c3c !important; }
    .derived-element[data-tier="6"]::after { background: #ffd700 !important; } /* Golden for mythical */
    
    /* Visual scroll indicators */
    .kinetic-scroll-container::after {
        content: '' !important;
        position: absolute !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 30px !important;
        background: linear-gradient(90deg, 
            transparent 0%, 
            rgba(10, 10, 20, 0.9) 100%) !important;
        pointer-events: none !important;
        z-index: 50 !important;
    }
    
    /* ======================== */
    /*    WORKSHOP/FORGE AREA   */
    /* ======================== */
    .workshop-area {
        position: fixed !important;
        top: 315px !important; /* 50px header + 260px belts + 5px padding */
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: auto !important;
        background: 
            radial-gradient(ellipse at center, 
                rgba(255, 215, 0, 0.08) 0%, 
                transparent 50%),
            url('../images/table.png') center center / cover no-repeat,
            linear-gradient(180deg, 
                rgba(92, 51, 23, 0.92) 0%, 
                rgba(63, 35, 16, 0.95) 40%,
                rgba(41, 23, 10, 0.98) 100%) !important;
        border-top: 3px solid rgba(255, 215, 0, 0.5) !important;
        border-radius: 25px 25px 0 0 !important;
        padding: 20px 15px !important;
        z-index: 50 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        box-shadow: 
            0 -8px 25px rgba(0, 0, 0, 0.6),
            inset 0 3px 6px rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Workshop title */
    .workshop-title {
        position: absolute !important;
        top: 10px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        color: rgba(255, 215, 0, 0.9) !important;
        font-size: 13px !important;
        font-weight: bold !important;
        text-transform: uppercase !important;
        letter-spacing: 2px !important;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8) !important;
        z-index: 10 !important;
    }
    
    /* Combination zone - HORIZONTAL LAYOUT */
    .combination-zone {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 20px !important;
        width: 100% !important;
        height: 100% !important;
        padding: 35px 15px 15px 15px !important;
        position: relative !important;
    }
    
    /* Drop slots for mobile - SIDE BY SIDE */
    .drop-slot {
        width: 100px !important;
        height: 100px !important;
        background: 
            radial-gradient(circle at center, 
                rgba(0, 0, 0, 0.5) 0%, 
                rgba(41, 23, 10, 0.7) 40%,
                rgba(63, 35, 16, 0.5) 100%) !important;
        border: 3px solid rgba(255, 215, 0, 0.4) !important;
        border-radius: 18px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
        transition: all 0.3s ease !important;
        box-shadow: 
            inset 0 3px 10px rgba(0, 0, 0, 0.6),
            0 3px 6px rgba(255, 215, 0, 0.15) !important;
    }
    
    /* Position slots on left and right */
    .drop-slot[data-slot="1"] {
        order: 1 !important;
    }
    
    .drop-slot[data-slot="2"] {
        order: 3 !important;
    }
    
    .drop-slot.drag-over {
        border-color: rgba(255, 215, 0, 0.8) !important;
        background: radial-gradient(circle at center, 
            rgba(255, 215, 0, 0.2) 0%, 
            rgba(41, 23, 10, 0.6) 100%) !important;
        transform: scale(1.05) !important;
    }
    
    .drop-slot.has-element {
        background: radial-gradient(circle at center, 
            rgba(255, 215, 0, 0.1) 0%, 
            rgba(41, 23, 10, 0.7) 100%) !important;
    }
    
    /* Slot placeholder text */
    .slot-placeholder {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        color: rgba(255, 215, 0, 0.4) !important;
        pointer-events: none !important;
    }
    
    .slot-top-text {
        font-size: 10px !important;
        font-weight: bold !important;
        letter-spacing: 1px !important;
        margin-bottom: 2px !important;
    }
    
    .slot-bottom-text {
        font-size: 8px !important;
        opacity: 0.7 !important;
    }
    
    /* Elements in slots */
    .slot-element {
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        position: relative !important;
    }
    
    .slot-element img {
        width: 60px !important;
        height: 60px !important;
        filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.6)) brightness(1.05) !important;
    }
    
    /* Combine button (swirl) - CENTERED BETWEEN SLOTS */
    .swirl-container {
        width: 60px !important;
        height: 60px !important;
        position: relative !important;
        cursor: pointer !important;
        transition: transform 0.3s ease !important;
        order: 2 !important; /* Place between the two slots */
        margin: 0 5px !important;
    }
    
    .swirl-container:active {
        transform: scale(0.9) !important;
    }
    
    #combine-btn {
        width: 100% !important;
        height: 100% !important;
        background: radial-gradient(circle, 
            rgba(255, 215, 0, 0.4) 0%, 
            rgba(255, 152, 0, 0.3) 40%,
            rgba(255, 193, 7, 0.1) 100%) !important;
        border: 3px solid rgba(255, 215, 0, 0.6) !important;
        border-radius: 50% !important;
        position: relative !important;
        overflow: hidden !important;
        box-shadow: 
            0 0 20px rgba(255, 215, 0, 0.3),
            inset 0 0 10px rgba(255, 215, 0, 0.2) !important;
    }
    
    #combine-btn:not(:disabled):active {
        background: radial-gradient(circle, 
            rgba(255, 215, 0, 0.5) 0%, 
            rgba(255, 152, 0, 0.4) 100%) !important;
    }
    
    #combine-btn:disabled {
        opacity: 0.3 !important;
        cursor: not-allowed !important;
    }
    
    /* Swirl animation when active */
    #combine-btn.combining::before {
        content: '' !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        width: 200% !important;
        height: 200% !important;
        background: conic-gradient(
            from 0deg,
            transparent 0deg,
            rgba(255, 215, 0, 0.6) 60deg,
            transparent 120deg,
            rgba(255, 152, 0, 0.6) 180deg,
            transparent 240deg,
            rgba(255, 215, 0, 0.6) 300deg,
            transparent 360deg
        ) !important;
        transform: translate(-50%, -50%) !important;
        animation: swirlRotate 1s linear infinite !important;
    }
    
    @keyframes swirlRotate {
        from { transform: translate(-50%, -50%) rotate(0deg); }
        to { transform: translate(-50%, -50%) rotate(360deg); }
    }
    
    /* ======================== */
    /*    TOUCH OPTIMIZATIONS   */
    /* ======================== */
    
    /* Improve touch targets */
    .derived-element,
    .core-element-integrated,
    .drop-slot,
    .mobile-icon-btn,
    #combine-btn {
        -webkit-tap-highlight-color: transparent !important;
        touch-action: manipulation !important;
    }
    
    /* Visual feedback for touches */
    .derived-element:active,
    .core-element-integrated:active {
        opacity: 0.7 !important;
    }
    
    /* Prevent accidental selections */
    * {
        -webkit-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
    }
    
    /* ======================== */
    /*    TOOLTIP ADJUSTMENTS   */
    /* ======================== */
    .game-tooltip {
        max-width: 250px !important;
        font-size: 11px !important;
        padding: 8px 10px !important;
        pointer-events: none !important;
        z-index: 9999 !important;
    }
    
    /* Hide tooltips on touch devices */
    @media (hover: none) and (pointer: coarse) {
        .game-tooltip {
            display: none !important;
        }
    }
    
    /* ======================== */
    /*    LANDSCAPE MODE        */
    /* ======================== */
    @media (max-width: 950px) and (max-height: 450px) and (orientation: landscape) {
        .game-header {
            height: 40px !important;
            min-height: 40px !important;
            padding: 3px 8px !important;
        }
        
        .elements-container {
            top: 42px !important;
            height: 175px !important; /* Compressed 4 belts */
            padding: 3px !important;
        }
        
        .element-group {
            height: 42px !important;
            min-height: 42px !important;
            margin-bottom: 1px !important;
        }
        
        .core-element-integrated {
            width: 40px !important;
            height: 40px !important;
            min-width: 40px !important;
        }
        
        .core-element-integrated img {
            width: 30px !important;
            height: 30px !important;
        }
        
        .derived-element {
            width: 38px !important;
            height: 38px !important;
            min-width: 38px !important;
        }
        
        .derived-element img {
            width: 28px !important;
            height: 28px !important;
        }
        
        .workshop-area {
            top: 220px !important; /* 42px header + 175px belts + 3px padding */
            height: calc(100vh - 220px) !important;
            min-height: 140px !important;
            padding: 10px !important;
        }
        
        .drop-slot {
            width: 85px !important;
            height: 85px !important;
        }
        
        .slot-element img {
            width: 60px !important;
            height: 60px !important;
        }
        
        .swirl-container {
            width: 45px !important;
            height: 45px !important;
        }
        
        .combination-zone {
            gap: 10px !important;
            padding: 20px 8px 8px 8px !important;
        }
    }
}

/* ================================ */
/*   IPHONE 13 SPECIFIC (390x844)  */
/* ================================ */
@media (max-width: 430px) and (max-height: 950px) {
    
    /* Adjust for notch and home indicator */
    .game-header {
        padding-top: env(safe-area-inset-top, 5px) !important;
        height: calc(50px + env(safe-area-inset-top, 0px)) !important;
    }
    
    .elements-container {
        top: calc(50px + env(safe-area-inset-top, 0px)) !important;
        height: 255px !important; /* 4 belts for iPhone 13 */
    }
    
    .workshop-area {
        top: calc(305px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
        height: calc(100vh - 305px - env(safe-area-inset-top, 0px)) !important;
        min-height: calc(200px + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    /* Smaller elements for compact screen */
    .element-group {
        height: 62px !important;
        min-height: 62px !important;
        margin-bottom: 2px !important;
    }
    
    .core-element-integrated {
        width: 55px !important;
        height: 55px !important;
        min-width: 55px !important;
    }
    
    .core-element-integrated img {
        width: 48px !important; /* Increased by 20% */
        height: 48px !important;
    }
    
    .derived-element {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
    }
    
    .derived-element img {
        width: 38px !important;
        height: 38px !important;
    }
    
    /* Compact workshop with horizontal layout */
    .drop-slot {
        width: 100px !important;
        height: 100px !important;
    }
    
    .slot-element img {
        width: 70px !important;
        height: 70px !important;
    }
    
    .swirl-container {
        width: 55px !important;
        height: 55px !important;
    }
    
    .combination-zone {
        gap: 15px !important;
        padding: 30px 10px 10px 10px !important;
    }
}

/* ================================ */
/*   SMOOTH SCROLLING & PHYSICS    */
/* ================================ */
.kinetic-scroll-container {
    scroll-snap-type: none !important; /* Disable snap for smoother scrolling */
}

/* Removed scroll-snap-align for smoother free scrolling */

/* Momentum scrolling */
.elements-container,
.kinetic-scroll-container {
    -webkit-overflow-scrolling: touch !important;
    overflow-scrolling: touch !important;
}

/* ================================ */
/*   PERFORMANCE OPTIMIZATIONS      */
/* ================================ */
@media (max-width: 768px) {
    /* Reduce animation complexity */
    * {
        animation-duration: 0.2s !important;
    }
    
    /* Disable complex shadows */
    .derived-element,
    .core-element-integrated {
        box-shadow: none !important;
    }
    
    /* Use GPU acceleration */
    .kinetic-scroll-container,
    .elements-container,
    .derived-element,
    .core-element-integrated {
        will-change: transform !important;
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
    }
    
    /* Reduce blur effects */
    .workshop-area {
        backdrop-filter: none !important;
    }
}

/* ================================ */
/*   GESTURE HINTS                  */
/* ================================ */
.kinetic-scroll-container::before {
    content: '←  Swipe to scroll  →' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    color: rgba(255, 255, 255, 0.2) !important;
    font-size: 11px !important;
    font-style: italic !important;
    pointer-events: none !important;
    opacity: 0 !important;
    transition: opacity 0.3s !important;
}

.kinetic-scroll-container:empty::before {
    opacity: 1 !important;
}

/* Show drop hint in empty slots */
.drop-slot:not(.has-element)::after {
    content: 'Drop Here' !important;
    position: absolute !important;
    bottom: 8px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    color: rgba(255, 215, 0, 0.3) !important;
    font-size: 9px !important;
    font-weight: bold !important;
    letter-spacing: 0.5px !important;
    pointer-events: none !important;
}

/* Visual connection lines between slots and combine button */
.combination-zone::before,
.combination-zone::after {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    height: 2px !important;
    background: linear-gradient(90deg, 
        rgba(255, 215, 0, 0.2) 0%, 
        rgba(255, 215, 0, 0.4) 50%,
        rgba(255, 215, 0, 0.2) 100%) !important;
    transform: translateY(-50%) !important;
    pointer-events: none !important;
}

.combination-zone::before {
    left: calc(25% + 45px) !important;
    width: calc(25% - 70px) !important;
}

.combination-zone::after {
    right: calc(25% + 45px) !important;
    width: calc(25% - 70px) !important;
}

/* Plus signs between elements - REMOVED for cleaner look */
/* .drop-slot[data-slot="1"]::before {
    content: '+' !important;
    position: absolute !important;
    right: -25px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: rgba(255, 215, 0, 0.5) !important;
    font-size: 24px !important;
    font-weight: bold !important;
    pointer-events: none !important;
    z-index: 5 !important;
} */

/* Equals sign after combine button - REMOVED for cleaner look */
/* .swirl-container::after {
    content: '=' !important;
    position: absolute !important;
    right: -20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: rgba(255, 215, 0, 0.5) !important;
    font-size: 24px !important;
    font-weight: bold !important;
    pointer-events: none !important;
    z-index: 5 !important;
} */

/* Result indicator (appears during combination) */
.workshop-area::after {
    content: '?' !important;
    position: absolute !important;
    bottom: 25px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 40px !important;
    height: 40px !important;
    border: 2px dashed rgba(255, 215, 0, 0.3) !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: rgba(255, 215, 0, 0.4) !important;
    font-size: 20px !important;
    font-weight: bold !important;
    opacity: 0.5 !important;
    pointer-events: none !important;
}

.workshop-area.combining::after {
    animation: pulseResult 1s ease-in-out infinite !important;
}

@keyframes pulseResult {
    0%, 100% { 
        opacity: 0.3;
        transform: translateX(-50%) scale(0.9);
    }
    50% { 
        opacity: 0.7;
        transform: translateX(-50%) scale(1.1);
    }
}