/* Mobile Responsive Enhancements for Touch Navigation */
* {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    #sphere-canvas {
        touch-action: none !important;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    body {
        overflow: hidden;
        overscroll-behavior: none;
    }
    
    .content-window {
        width: 95vw !important;
        max-height: 80vh;
        max-width: 95vw;
        left: 2.5vw !important;
        top: 10vh !important;
    }
    
    .content-window.mobile-view {
        left: 2.5vw !important;
        top: 10vh !important;
        width: 95vw !important;
        height: 80vh !important;
        max-width: 95vw !important;
        max-height: 80vh !important;
    }
    
    .node-label {
        font-size: 0.65rem;
        padding: 6px 10px;
        pointer-events: auto;
    }
    
    #gesture-hints {
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: calc(100vw - 20px);
        font-size: 0.7rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .quick-link {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
    
    .link-grid {
        grid-template-columns: 1fr;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    .metric-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

@media (max-width: 480px) {
    .content-window {
        width: 98vw !important;
        left: 1vw !important;
        max-height: 85vh;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .glitch-title {
        font-size: 1.25rem;
    }
    
    .window-content {
        padding: 16px;
    }
}

/* Mobile Performance & UX Fixes */
@media (max-width: 768px) {
    /* Force loading screen to hide */
    #loading-screen {
        display: flex !important;
        z-index: 10000 !important;
    }
    
    #loading-screen.hidden {
        opacity: 0 !important;
        pointer-events: none !important;
        visibility: hidden !important;
    }
    
    /* Canvas should be touchable */
    #sphere-canvas {
        touch-action: none !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }
    
    /* Content windows - smaller and centered */
    .content-window {
        position: fixed !important;
        width: 94vw !important;
        max-width: 94vw !important;
        min-height: auto !important;
        max-height: 80vh !important;
        left: 3vw !important;
        top: 8vh !important;
        margin: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px !important;
    }
    
    .content-window.active {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* If no 3D, show simplified content */
    body.no-webgl .content-window {
        display: block !important;
    }
    
    /* HUD hidden on mobile for full experience */
    .hud-overlay {
        display: none !important;
    }
    
    /* Gesture hints at bottom */
    #gesture-hints {
        position: fixed !important;
        bottom: 8px !important;
        left: 5vw !important;
        right: 5vw !important;
        width: 90vw !important;
        font-size: 0.7rem !important;
        padding: 8px 12px !important;
        background: rgba(0,0,0,0.8) !important;
        border-radius: 8px !important;
        z-index: 100 !important;
    }
    
    /* Node labels smaller on mobile */
    .node-label {
        font-size: 0.65rem !important;
        padding: 6px 10px !important;
        transform: translate(-50%, -50%) scale(0.9) !important;
    }
    
    /* Quick links better touch targets */
    .quick-link {
        min-height: 48px !important;
        padding: 12px 16px !important;
        font-size: 0.9rem !important;
        margin: 4px 0 !important;
    }
    
    /* Stats grid 2 columns on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    /* Iframes in windows scrollable */
    .genesis-content iframe,
    .store-content iframe,
    .vps-content iframe {
        min-height: 50vh !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Window header fixed on mobile */
    .window-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
    }
    
    /* Window controls larger for touch */
    .close-btn, .minimize-btn, .maximize-btn {
        min-width: 36px !important;
        min-height: 36px !important;
    }
}

@media (max-width: 480px) {
    .content-window {
        width: 96vw !important;
        left: 2vw !important;
        top: 6vh !important;
        max-height: 85vh !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .glitch-title {
        font-size: 1.3rem !important;
    }
    
    .window-content {
        padding: 12px !important;
    }
    
    .link-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Emergency: always ensure loading screen can be dismissed */
@keyframes forceHideLoader {
    0%, 80% { opacity: 1; }
    100% { opacity: 0; pointer-events: none; }
}

body.loaded #loading-screen {
    animation: forceHideLoader 0.5s ease forwards;
}


/* Emergency touch fix - ensure canvas is interactive */
#sphere-canvas {
    touch-action: none !important;
    -webkit-touch-callout: default;
    -webkit-user-select: none;
    user-select: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
}

/* Ensure content windows are above canvas */
.content-window {
    z-index: 200 !important;
}

/* Loading screen must be above everything */
#loading-screen {
    z-index: 10000 !important;
}
