/* ============================================
   📱 MOBILE FIXES 2026 - Comprehensive
   OldGames.Games - Fevereiro 2026
   ============================================
   
   Fixes:
   - Emulator modal layout on mobile (sidebar, topbar, iframe)
   - Hero section overflow (side panels, bottom panels)
   - Navbar overflow on small screens
   - Game grids & cards responsive
   - Touch targets & interactions
   - iframe/frame compatibility
   ============================================ */

/* ============================================
   🎮 EMULATOR MODAL - MOBILE FIX
   The inline-styled sidebar & topbar need !important overrides
   ============================================ */

@media screen and (max-width: 768px) {

    /* --- Emulator Modal: fill the whole viewport --- */
    #emulatorModal {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 100000 !important;
        overflow: hidden !important;
    }

    /* --- Top Bar: compact for mobile --- */
    #emulatorTopBar {
        height: 48px !important;
        padding: 0 10px !important;
        gap: 6px !important;
        flex-wrap: nowrap !important;
    }

    /* Game cover in top bar */
    #emulatorGameCover {
        width: 32px !important;
        height: 32px !important;
        border-radius: 6px !important;
        border-width: 1px !important;
    }

    /* Game title - truncate but use available space */
    #emulatorGameTitle {
        font-size: 0.8rem !important;
        max-width: 35vw !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: block !important;
    }

    /* Console badge */
    #emulatorConsoleBadge {
        font-size: 0.6rem !important;
    }

    /* Viewers count - hide on mobile */
    #emulatorTopBar [style*="display: flex"][style*="gap: 4px"] {
        display: none !important;
    }

    /* Action buttons row in top bar - compact */
    .emu-action-btn {
        padding: 5px 8px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        font-size: 0.65rem !important;
    }

    /* Hide text labels on action buttons, keep SVG icons */
    .emu-action-btn span:not(:first-child) {
        display: none !important;
    }

    /* Hide the favorite text */
    #sidebarFavText {
        display: none !important;
    }

    /* Close button compact */
    .emu-close-btn {
        padding: 5px 10px !important;
        font-size: 0.7rem !important;
    }

    .emu-close-btn span:last-child {
        display: none !important;
    }

    /* Icon buttons */
    .emu-icon-btn {
        width: 32px !important;
        height: 32px !important;
    }

    /* Hide dividers in top bar on mobile */
    #emulatorTopBar > div > div[style*="width: 1px"] {
        display: none !important;
    }

    /* --- Main content area below top bar --- */
    #emulatorModal > div[style*="top: 56px"] {
        top: 48px !important;
        flex-direction: column !important;
    }

    /* --- SIDEBAR: Hide on mobile --- */
    #emulatorSidebar {
        display: none !important;
        width: 0 !important;
    }

    /* --- Game area: fill entire space --- */
    #emulatorGameArea {
        flex: 1 !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* --- Emulator iframe: fill game area --- */
    #emulatorFrame {
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !important;
        max-height: calc(100vh - 48px) !important;
        max-height: calc(100dvh - 48px) !important;
    }

    /* --- Loading state centered --- */
    #emulatorLoading {
        padding: 20px !important;
    }

    #emulatorLoading p {
        font-size: 0.9rem !important;
    }

    /* --- Toast notifications --- */
    .emu-toast {
        top: 56px !important;
        font-size: 0.8rem !important;
        padding: 8px 16px !important;
    }
}

/* Landscape emulator - even more compact */
@media screen and (max-width: 900px) and (orientation: landscape) {
    #emulatorTopBar {
        height: 40px !important;
        padding: 0 8px !important;
    }

    #emulatorGameCover {
        width: 28px !important;
        height: 28px !important;
    }

    #emulatorGameTitle {
        font-size: 0.75rem !important;
        max-width: 100px !important;
    }

    .emu-action-btn {
        padding: 4px 6px !important;
        min-width: 28px !important;
        min-height: 28px !important;
    }

    .emu-icon-btn {
        width: 28px !important;
        height: 28px !important;
    }

    #emulatorModal > div[style*="top: 56px"] {
        top: 40px !important;
    }

    #emulatorFrame {
        max-height: calc(100vh - 40px) !important;
        max-height: calc(100dvh - 40px) !important;
    }

    #emulatorSidebar {
        display: none !important;
        width: 0 !important;
    }
}

/* Tablet - sidebar as bottom sheet */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    #emulatorSidebar {
        width: 280px !important;
    }
}


/* ============================================
   🏠 HERO SECTION - MOBILE FIX
   Fix overflow of side panels and bottom panels
   ============================================ */

@media screen and (max-width: 768px) {

    /* Hero section - reduce min-height, add proper padding */
    .hero,
    #home {
        min-height: auto !important;
        padding: 80px 12px 30px !important;
        overflow: hidden !important;
    }

    /* Hero layout - remove negative margin that causes overlap */
    .hero-layout-vertical {
        margin-top: 0 !important;
        gap: 1rem !important;
    }

    /* Hero top row - stack vertically */
    .hero-top-row {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    /* Center content first */
    .hero-top-row .hero-content-centered {
        order: -1 !important;
        width: 100% !important;
        padding: 0 4px !important;
    }

    /* Hero title smaller */
    .hero-title {
        font-size: clamp(1.8rem, 8vw, 2.5rem) !important;
    }

    .hero-subtitle {
        font-size: 0.85rem !important;
    }

    /* Hero CTA - stack buttons */
    .hero-cta {
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .hero-cta .game-btn {
        width: 100% !important;
        max-width: 260px !important;
        font-size: 0.85rem !important;
        padding: 12px 20px !important;
    }

    /* Side panels - full width, shorter height */
    .hero-side-panel {
        flex: none !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 250px !important;
        min-height: auto !important;
    }

    .hero-side-panel .last-games-list,
    .hero-side-panel .top-players-list {
        max-height: 200px !important;
    }

    /* Bottom panels row - stack vertically */
    .hero-panels-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.8rem !important;
        width: 100% !important;
    }

    /* Each bottom panel - full width, reduced height */
    .hero-multiplayer-panel,
    .hero-live-panel,
    .hero-launcher-panel {
        flex: none !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: 200px !important;
        max-height: 260px !important;
    }

    /* Panel headers compact */
    .hero-panel-header {
        padding: 10px 14px !important;
        gap: 8px !important;
    }

    .hero-panel-title {
        font-size: 0.85rem !important;
        letter-spacing: 1px !important;
    }

    /* Hero badge */
    .hero-badge {
        font-size: 0.65rem !important;
        padding: 6px 14px !important;
    }

    /* Disable heavy canvas effects on mobile */
    .hero-canvas,
    #heroPlasmaCanvas,
    #heroLightningCanvas,
    #heroParticlesCanvas {
        display: none !important;
    }

    /* Reduce hero animated effects */
    .hero-orbs .orb {
        width: 60px !important;
        height: 60px !important;
        opacity: 0.3 !important;
    }

    /* Launcher panel header - compact */
    .hero-launcher-header {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .hero-download-btn {
        font-size: 0.7rem !important;
        padding: 4px 10px !important;
    }

    /* Multiplayer panel content */
    .hero-multiplayer-content,
    .hero-live-content,
    .hero-launcher-content {
        padding: 12px !important;
    }

    .hero-multiplayer-empty,
    .hero-live-empty,
    .hero-launcher-empty {
        padding: 16px 12px !important;
    }

    .hero-multiplayer-empty svg,
    .hero-live-empty svg,
    .hero-launcher-empty svg {
        width: 40px !important;
        height: 40px !important;
    }

    .hero-multiplayer-empty p,
    .hero-live-empty p,
    .hero-launcher-empty p {
        font-size: 0.85rem !important;
    }

    .hero-multiplayer-btn,
    .hero-live-start-btn {
        padding: 8px 16px !important;
        font-size: 0.8rem !important;
        min-height: 40px !important;
    }
}

@media screen and (max-width: 480px) {
    .hero-layout-vertical {
        margin-top: -60px !important;
    }

    .hero-side-panel {
        max-height: 220px !important;
    }

    .hero-multiplayer-panel,
    .hero-live-panel,
    .hero-launcher-panel {
        min-height: 180px !important;
        max-height: 230px !important;
    }

    /* Panel animation - disable floating on small screens */
    .hero-multiplayer-panel,
    .hero-live-panel,
    .hero-launcher-panel {
        animation: none !important;
    }
}


/* ============================================
   🧭 NAVBAR - MOBILE OVERFLOW FIX
   ============================================ */

@media screen and (max-width: 768px) {

    /* Navbar - compact layout */
    #navbar {
        padding: 6px 10px !important;
        gap: 6px !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        overflow: visible !important;
    }

    /* Logo smaller */
    #navbar .logo {
        font-size: 0.95rem !important;
        letter-spacing: -0.5px !important;
        gap: 4px !important;
        flex-shrink: 0 !important;
    }

    #navbar .logo .logo-icon {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.8rem !important;
    }

    /* Hide desktop nav links */
    .nav-menu {
        display: none !important;
    }

    /* Hide search on mobile navbar (accessible via menu) */
    #navbar .search-container {
        display: none !important;
    }

    /* Hide Discord & Coffee buttons */
    #navbar .discord-nav-btn,
    #navbar .coffee-nav-btn {
        display: none !important;
    }

    /* Navbar right area - minimal */
    .navbar-right-area {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        flex-shrink: 0 !important;
        margin-left: auto !important;
    }

    /* Subscribe button - icon only */
    .nav-subscribe-btn {
        padding: 6px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    .nav-subscribe-btn .subscribe-text,
    .nav-subscribe-btn .subscribe-badge {
        display: none !important;
    }

    /* Favorites - icon only */
    .nav-favorites-btn {
        padding: 6px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    .nav-favorites-btn .nav-fav-text {
        display: none !important;
    }

    /* Language selector - hide on mobile */
    .language-selector {
        display: none !important;
    }

    /* Auth button - compact */
    .auth-btn {
        padding: 6px 10px !important;
        font-size: 0.7rem !important;
        min-height: 36px !important;
        min-width: auto !important;
    }

    .auth-btn .auth-btn-icon {
        display: none !important;
    }

    /* User button - avatar only */
    .user-btn {
        padding: 4px !important;
        min-height: 36px !important;
        min-width: 36px !important;
    }

    .user-btn #userName {
        display: none !important;
    }

    .user-btn .user-avatar {
        width: 28px !important;
        height: 28px !important;
    }

    /* Admin toggle - small */
    .admin-toggle-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 1rem !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    /* Mobile Menu Button - prominent */
    .mobile-menu-btn {
        display: flex !important;
        width: 42px !important;
        height: 42px !important;
        min-width: 42px !important;
        min-height: 42px !important;
        font-size: 1.5rem !important;
        order: 999 !important;
        flex-shrink: 0 !important;
    }

    /* Profile dropdown positioning */
    .profile-dropdown {
        right: 10px !important;
        top: 55px !important;
        width: calc(100vw - 20px) !important;
        max-width: 300px !important;
    }
}

@media screen and (max-width: 400px) {
    /* Extra small - hide favorites & subscribe */
    .nav-favorites-btn,
    .nav-subscribe-btn {
        display: none !important;
    }

    .navbar-right-area {
        gap: 3px !important;
    }

    .auth-btn {
        padding: 4px 8px !important;
        font-size: 0.65rem !important;
    }
}


/* ============================================
   📱 MOBILE GAMES MODAL - FIX
   ============================================ */

@media screen and (max-width: 768px) {

    /* Mobile games modal - fullscreen */
    .mobile-games-modal {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 99000 !important;
        overflow: hidden !important;
        flex-direction: column !important;
    }

    .mobile-games-modal.active {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    /* Header */
    .mobile-games-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 12px 16px !important;
        background: rgba(10, 10, 15, 0.98) !important;
        border-bottom: 1px solid rgba(255, 45, 85, 0.2) !important;
        flex-shrink: 0 !important;
    }

    .mobile-games-title {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }

    .mobile-games-title h2 {
        font-size: 1.2rem !important;
    }

    .mobile-games-close {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        border-radius: 50% !important;
        background: rgba(255, 45, 85, 0.2) !important;
        border: 1px solid rgba(255, 45, 85, 0.4) !important;
        color: #FF2D55 !important;
        font-size: 1.2rem !important;
    }

    /* Search */
    .mobile-games-search {
        padding: 8px 16px !important;
        background: rgba(10, 10, 15, 0.95) !important;
        flex-shrink: 0 !important;
    }

    .mobile-games-search input {
        width: 100% !important;
        padding: 12px 16px !important;
        font-size: 16px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 10px !important;
        color: white !important;
        outline: none !important;
    }

    /* Games grid */
    .mobile-games-grid {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 12px !important;
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        align-content: start !important;
    }
}


/* ============================================
   📱 MOST PLAYED SECTION - MOBILE FIX
   ============================================ */

@media screen and (max-width: 768px) {
    .most-played-section {
        padding: 24px 12px !important;
    }

    .most-played-header {
        flex-direction: column !important;
        text-align: center !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
    }

    .mp-main-title {
        font-size: 1.3rem !important;
    }

    .mp-subtitle {
        font-size: 0.8rem !important;
    }

    .mp-stats-bar {
        justify-content: center !important;
        gap: 6px !important;
        flex-wrap: wrap !important;
    }

    .mp-stat-item {
        padding: 4px 8px !important;
        font-size: 0.65rem !important;
    }

    .most-played-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .most-played-card {
        border-radius: 10px !important;
    }

    .most-played-card-title {
        font-size: 0.75rem !important;
        padding: 6px 8px !important;
    }

    .most-played-card-info {
        padding: 6px 8px !important;
    }

    .mp-card-bottom-bar {
        padding: 6px 8px !important;
        gap: 6px !important;
    }

    .mp-bottom-play {
        font-size: 0.65rem !important;
        padding: 4px 8px !important;
        min-height: 28px !important;
    }
}

@media screen and (max-width: 480px) {
    .most-played-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
}


/* ============================================
   📺 CONSOLES SECTION - MOBILE FIX
   ============================================ */

@media screen and (max-width: 768px) {
    .consoles-section {
        padding: 24px 12px !important;
    }

    .consoles-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .console-item {
        padding: 14px 10px !important;
        min-height: auto !important;
        border-radius: 12px !important;
    }

    .console-icon-box {
        width: 56px !important;
        height: 56px !important;
        margin-bottom: 8px !important;
    }

    .console-title {
        font-size: 0.95rem !important;
    }

    .console-subtitle {
        font-size: 0.7rem !important;
    }

    .console-launch-btn {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        min-height: 38px !important;
    }
}

@media screen and (max-width: 400px) {
    .consoles-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .console-icon-box {
        width: 48px !important;
        height: 48px !important;
    }

    .console-title {
        font-size: 0.85rem !important;
    }
}


/* ============================================
   ⭐ FAVORITES SECTION - MOBILE FIX
   ============================================ */

@media screen and (max-width: 768px) {
    .favorites-section {
        padding: 24px 12px !important;
    }

    .favorites-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
}


/* ============================================
   📱 NEW MOBILE MENU - FIXES
   ============================================ */

@media screen and (max-width: 768px) {
    /* Ensure the new mobile menu covers everything */
    .new-mobile-menu {
        z-index: 90000 !important;
    }

    .new-mobile-menu.active {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: translateX(0) !important;
    }

    /* Links should be large and tappable */
    .new-mobile-link {
        min-height: 56px !important;
        padding: 16px 18px !important;
        font-size: 1rem !important;
    }

    /* Footer social buttons */
    .new-mobile-menu-footer {
        padding: 16px !important;
    }

    .new-mobile-social {
        min-height: 48px !important;
    }
}


/* ============================================
   🖼️ IFRAME / FRAME COMPATIBILITY
   Ensure all iframes scale properly on mobile
   ============================================ */

@media screen and (max-width: 768px) {
    iframe {
        max-width: 100vw !important;
        border: none !important;
    }

    /* Emulator iframe special handling */
    #emulatorFrame {
        width: 100% !important;
        height: 100% !important;
        position: relative !important;
    }

    /* Any video/embed iframes */
    .live-stream-video iframe,
    .video-container iframe {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 16/9 !important;
    }
}


/* ============================================
   🗄️ FOOTER - MOBILE FIX
   ============================================ */

@media screen and (max-width: 768px) {
    footer {
        padding: 24px 12px 40px !important;
    }

    .footer-content {
        flex-direction: column !important;
        gap: 16px !important;
        text-align: center !important;
    }

    .footer-links {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .footer-links a {
        padding: 8px !important;
        font-size: 0.85rem !important;
    }
}


/* ============================================
   🔔 TOASTS / NOTIFICATIONS - MOBILE
   ============================================ */

@media screen and (max-width: 768px) {
    .toast,
    .notification,
    .emu-toast,
    .alert-toast {
        left: 12px !important;
        right: 12px !important;
        max-width: calc(100vw - 24px) !important;
        font-size: 0.8rem !important;
        padding: 10px 14px !important;
        border-radius: 10px !important;
    }
}


/* ============================================
   🛡️ GENERAL MOBILE FIXES
   ============================================ */

@media screen and (max-width: 768px) {
    /* Prevent horizontal overflow */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* Ensure all sections don't overflow */
    section,
    .section,
    main {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* All images should be contained */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Fix any absolute positioned elements causing overflow */
    .hero::before,
    .hero::after {
        overflow: hidden !important;
    }

    /* Prevent text overflow */
    h1, h2, h3, h4, h5, h6 {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
}


/* ============================================
   🎯 TOUCH INTERACTION IMPROVEMENTS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Better active states for touch */
    .game-card:active,
    .console-card:active,
    .most-played-card:active,
    .console-item:active {
        transform: scale(0.97) !important;
        transition: transform 0.1s ease !important;
    }

    /* Remove all hover transforms on touch */
    .game-card:hover,
    .console-card:hover,
    .most-played-card:hover,
    .console-item:hover,
    .hero-multiplayer-panel:hover,
    .hero-live-panel:hover,
    .hero-launcher-panel:hover {
        transform: none !important;
    }

    /* All clickable elements need proper cursor and touch handling */
    a, button, [onclick], [role="button"],
    .game-card, .console-item, .console-launch-btn {
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(255, 45, 85, 0.15) !important;
        touch-action: manipulation !important;
    }
}


/* ============================================
   📱 VERY SMALL SCREENS (< 360px)
   ============================================ */

@media screen and (max-width: 360px) {
    #navbar {
        padding: 4px 6px !important;
    }

    #navbar .logo {
        font-size: 0.85rem !important;
    }

    .hero-title {
        font-size: 1.5rem !important;
    }

    .most-played-grid,
    .consoles-grid,
    .favorites-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }

    .console-item {
        padding: 10px 8px !important;
    }

    .console-icon-box {
        width: 40px !important;
        height: 40px !important;
    }

    .console-title {
        font-size: 0.8rem !important;
    }
}
