/* Ensure no white background anywhere */
    html {
        background: #1a1a1a;
        margin: 0;
        padding: 0;
    }
    
    * { 
        box-sizing: border-box; 
    }
    
    body { 
        margin: 0; 
        padding: 0;
        width: 100%;
        height: 100%;
        background: #1a1a1a;
        background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
        color: white; 
        font-family: 'Arial', sans-serif;
        min-height: 100vh;
        overflow-x: hidden;
        position: relative;
    }
    
    /* Loading screen and game container styles */
    .loading-screen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: #1a1a1a;
        background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
        display: none;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 1000;
    }
    
    #game {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: #000;
        display: none;
        z-index: 2000;
    }

    .header {
        background: rgba(0,0,0,0.8);
        backdrop-filter: blur(10px);
        padding: 20px;
        text-align: center;
        border-bottom: 2px solid #333;
        position: sticky;
        top: 0;
        z-index: 100;
    }
        
    .header h1 {
        margin: 0;
        font-size: 2.5em;
        background: linear-gradient(45deg, #007AFF, #00D4FF);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .header .subtitle {
        margin: 5px 0 0 0;
        color: #888;
        font-size: 0.9em;
    }

    /* Filter Controls Section */
    .filter-section {
        background: rgba(0,0,0,0.6);
        backdrop-filter: blur(5px);
        padding: 15px;
        border-bottom: 1px solid #333;
        position: sticky;
        top: 87px; /* Adjust based on header height */
        z-index: 99;
    }

    /* Collapsible filter toggle button */
    .filter-toggle {
        display: none;
        background: #333;
        border: 2px solid #555;
        color: white;
        padding: 10px 15px;
        border-radius: 8px;
        cursor: pointer;
        width: 100%;
        margin-bottom: 10px;
        font-size: 14px;
        text-align: left;
        transition: all 0.3s ease;
    }

    .filter-toggle:hover {
        border-color: #007AFF;
        background: #444;
    }

    .filter-toggle::after {
        content: '▼';
        float: right;
        transition: transform 0.3s ease;
    }

    .filter-toggle.collapsed::after {
        transform: rotate(-90deg);
    }

    .filter-content {
        transition: all 0.3s ease;
    }

    .filter-content.collapsed {
        max-height: 0;
        overflow: hidden;
        opacity: 0;
    }

    /* Search Box */
    .search-container {
        position: relative;
        margin-bottom: 15px;
    }

    .search-box {
        width: 100%;
        padding: 12px 45px 12px 15px;
        background: #333;
        border: 2px solid #555;
        border-radius: 25px;
        color: white;
        font-size: 16px;
        outline: none;
        transition: all 0.3s ease;
    }

    .search-box:focus {
        border-color: #007AFF;
        box-shadow: 0 0 10px rgba(0,122,255,0.3);
    }

    .search-box::placeholder {
        color: #aaa;
    }

    .search-icon {
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: #aaa;
        font-size: 18px;
        pointer-events: none;
    }

    .clear-search {
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: #aaa;
        font-size: 20px;
        cursor: pointer;
        display: none;
        padding: 5px;
    }

    .clear-search:hover {
        color: #007AFF;
    }

    /* System Filter Dropdown */
    .system-filter {
        margin-bottom: 15px;
    }

    .system-filter select {
        width: 100%;
        padding: 12px 15px;
        background: #333;
        border: 2px solid #555;
        border-radius: 8px;
        color: white;
        font-size: 16px;
        cursor: pointer;
        outline: none;
    }

    .system-filter select:focus {
        border-color: #007AFF;
    }

    .system-filter option {
        background: #333;
        color: white;
        padding: 10px;
    }

    /* Alphabetical Filter Tabs */
    .alphabet-tabs {
        display: flex;
        justify-content: space-between;
        gap: 5px;
        margin-bottom: 10px;
        overflow-x: auto;
        padding: 5px 0;
        -webkit-overflow-scrolling: touch;
    }

    .alphabet-tab {
        flex: 1;
        min-width: 50px;
        padding: 10px 8px;
        background: #333;
        border: 2px solid #555;
        border-radius: 8px;
        text-align: center;
        cursor: pointer;
        transition: all 0.3s ease;
        font-size: 14px;
        font-weight: bold;
        white-space: nowrap;
    }

    .alphabet-tab:hover {
        background: #444;
        border-color: #007AFF;
    }

    .alphabet-tab.active {
        background: #007AFF;
        border-color: #007AFF;
        color: white;
        box-shadow: 0 0 10px rgba(0,122,255,0.4);
    }

    /* Results counter */
    .results-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 15px 0 10px 0;
        padding: 0 5px;
        font-size: 14px;
        color: #aaa;
    }

    .results-count {
        font-weight: bold;
    }

    .clear-filters {
        background: none;
        border: 1px solid #555;
        color: #aaa;
        padding: 5px 10px;
        border-radius: 15px;
        cursor: pointer;
        font-size: 12px;
        transition: all 0.3s ease;
    }

    .clear-filters:hover {
        border-color: #007AFF;
        color: #007AFF;
    }
        
    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 10px;
    }
        
    .system-section {
        margin: 20px 0;
    }
        
    .system-header {
        display: flex;
        align-items: center;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #444;
    }
        
    .system-icon {
        font-size: 2em;
        margin-right: 15px;
    }
        
    .system-name {
        font-size: 1.4em;
        font-weight: bold;
        color: #fff;
    }
        
    .system-count {
        margin-left: auto;
        background: #333;
        padding: 5px 12px;
        border-radius: 15px;
        font-size: 0.8em;
        color: #aaa;
    }

    /* Game grid and cards */
    .games-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 12px;
        margin-top: 20px;
    }

    .game-card {
        background: linear-gradient(145deg, #2a2a2a, #1e1e1e);
        border: 1px solid #333;
        border-radius: 8px;
        padding: 15px;
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
        min-height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .game-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
        transition: left 0.5s ease;
    }

    .game-card:hover {
        transform: translateY(-3px);
        border-color: #007AFF;
        box-shadow: 0 6px 20px rgba(0,122,255,0.3);
    }

    .game-card:hover::before {
        left: 100%;
    }

    .game-name {
        font-size: 0.95em;
        font-weight: bold;
        color: #fff;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        word-break: break-word;
        margin: 0;
    }

    /* Hide game details for clean look */
    .game-details,
    .game-region,
    .game-size,
    .game-filename {
        display: none !important;
    }

    /* No results message */
    .no-results {
        text-align: center;
        padding: 50px 20px;
        color: #666;
    }

    .no-results h3 {
        margin: 0 0 10px 0;
        color: #888;
    }

    .no-results p {
        margin: 0;
        font-size: 14px;
    }

    /* ============================== */
    /* LANDSCAPE MODE OPTIMIZATIONS */
    /* ============================== */

    /* Landscape mode for all devices */
    @media screen and (orientation: landscape) and (max-height: 500px) {
        
        /* Make header much more compact */
        .header {
            padding: 8px 15px;
        }
        
        .header h1 {
            font-size: 1.4em;
            margin: 0;
        }
        
        .header .subtitle {
            font-size: 0.7em;
            margin: 2px 0 0 0;
        }

        /* Show collapsible filter toggle */
        .filter-toggle {
            display: block;
        }

        /* Make filter section much more compact */
        .filter-section {
            padding: 8px 10px;
            top: 55px; /* Adjust for smaller header */
        }

        /* Horizontal layout for filters in landscape */
        .filter-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            align-items: start;
        }

        .search-container {
            grid-column: 1 / -1; /* Search takes full width */
            margin-bottom: 8px;
        }

        .search-box {
            padding: 8px 35px 8px 12px;
            font-size: 14px;
            border-radius: 20px;
        }

        .system-filter {
            margin-bottom: 8px;
        }

        .system-filter select {
            padding: 8px 12px;
            font-size: 14px;
        }

        /* Make alphabet tabs horizontal scrollable and smaller */
        .alphabet-tabs {
            margin-bottom: 8px;
            gap: 3px;
        }

        .alphabet-tab {
            min-width: 35px;
            padding: 6px 4px;
            font-size: 11px;
        }

        .results-info {
            grid-column: 1 / -1;
            margin: 8px 0 5px 0;
            font-size: 12px;
        }

        /* Make container more compact */
        .container {
            padding: 5px;
        }

        /* Compact system sections */
        .system-section {
            margin: 10px 0;
        }

        .system-header {
            margin-bottom: 8px;
            padding-bottom: 6px;
        }

        .system-icon {
            font-size: 1.2em;
            margin-right: 8px;
        }

        .system-name {
            font-size: 1em;
        }

        .system-count {
            font-size: 0.7em;
            padding: 2px 8px;
        }

        /* Smaller game cards in landscape */
        .games-grid {
            grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
            gap: 6px;
            margin-top: 8px;
        }

        .game-card {
            padding: 8px;
            min-height: 40px;
        }

        .game-name {
            font-size: 0.8em;
            line-height: 1.2;
            -webkit-line-clamp: 2;
        }
    }

    /* Mobile portrait - existing styles */
    @media (max-width: 768px) and (orientation: portrait) {
        .header {
            padding: 15px;
        }
        
        .header h1 {
            font-size: 1.8em;
        }

        .filter-section {
            padding: 10px;
            top: 77px;
        }

        .alphabet-tabs {
            gap: 3px;
        }

        .alphabet-tab {
            min-width: 45px;
            padding: 8px 6px;
            font-size: 12px;
        }
        
        .games-grid {
            grid-template-columns: 1fr 1fr 1fr !important;
            gap: 6px;
        }
        
        .game-card {
            padding: 8px;
            min-height: 45px;
            border-radius: 4px;
        }
        
        .game-name {
            font-size: 0.8em;
            line-height: 1.1;
        }

        .system-section {
            margin: 15px 0;
        }
        
        .system-header {
            margin-bottom: 8px;
        }
        
        .system-icon {
            font-size: 1.2em;
            margin-right: 8px;
        }
        
        .system-name {
            font-size: 1em;
        }
        
        .system-count {
            font-size: 0.7em;
            padding: 3px 8px;
        }

        .results-info {
            font-size: 12px;
            margin: 10px 0 5px 0;
        }
    }
        
    /* Loading and game styles remain the same */
    .loading-screen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.95);
        display: none;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 1000;
    }
        
    .loading-spinner {
        width: 50px;
        height: 50px;
        border: 3px solid #333;
        border-top: 3px solid #007AFF;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 20px;
    }
        
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
        
    .loading-bar {
        width: 300px;
        height: 20px;
        background: #333;
        border-radius: 10px;
        overflow: hidden;
        margin: 20px 0;
    }
        
    .loading-progress {
        height: 100%;
        background: linear-gradient(90deg, #007AFF, #00D4FF);
        width: 0%;
        transition: width 0.3s ease;
        position: relative;
    }
        
    .loading-progress::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        background-image: linear-gradient(
            -45deg,
            rgba(255, 255, 255, .2) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, .2) 50%,
            rgba(255, 255, 255, .2) 75%,
            transparent 75%,
            transparent
        );
        background-size: 50px 50px;
        animation: move 2s linear infinite;
    }
        
    @keyframes move {
        0% { background-position: 0 0; }
        100% { background-position: 50px 50px; }
    }
        
    .back-button {
        position: fixed;
        top: 20px;
        left: 20px;
        background: rgba(0,0,0,0.8);
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 25px;
        cursor: pointer;
        font-size: 14px;
        z-index: 2001;
        display: none;
        transition: all 0.3s ease;
    }
        
    .back-button:hover {
        background: rgba(0,122,255,0.8);
    }
        
    .stats {
        text-align: center;
        margin: 20px 0;
        color: #888;
    }
        
    .no-games {
        text-align: center;
        padding: 50px;
        color: #666;
    }

    /* Landscape requirement overlay */
    .landscape-required {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.95);
        display: none;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 5000;
        color: white;
        text-align: center;
    }

    .rotate-device {
        font-size: 4em;
        animation: rotateDevice 2s ease-in-out infinite;
        margin-bottom: 30px;
    }

    @keyframes rotateDevice {
        0%, 100% { transform: rotate(0deg); }
        25% { transform: rotate(15deg); }
        75% { transform: rotate(-15deg); }
    }

    .landscape-message {
        max-width: 300px;
        padding: 0 20px;
    }

    .landscape-message h2 {
        margin: 0 0 15px 0;
        font-size: 1.5em;
    }

    .landscape-message p {
        margin: 0;
        color: #ccc;
        line-height: 1.4;
    }

    @media screen and (orientation: landscape) {
        .landscape-required {
            display: none !important;
        }
    }

    /* ====================
    TABLET GAMEPAD FIX - CSS ADDITIONS
    ==================== */

    /* Tablet Portrait Mode (768px - 1024px) */
    @media screen and (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
        .header {
            padding: 12px 20px;
        }

        .header h1 {
            font-size: 2em;
        }

        .filter-section {
            padding: 12px 15px;
        }

        .games-grid {
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 15px;
        }

        .game-card {
            padding: 20px;
            min-height: 70px;
        }

        .game-name {
            font-size: 1em;
        }

        /* Ensure virtual gamepad elements are visible on tablets */
        .ejs-virtual-gamepad,
        .ejs-virtual-pad,
        .virtual-gamepad {
            display: block !important;
            visibility: visible !important;
            opacity: 1 !important;
        }
    }

    /* Tablet Landscape Mode (768px - 1366px) */
    @media screen and (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
        .header {
            padding: 10px 20px;
        }

        .header h1 {
            font-size: 1.6em;
        }

        .filter-section {
            padding: 10px 15px;
        }

        .filter-content {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 15px;
            align-items: start;
        }

        .search-container {
            grid-column: 1 / -1;
            margin-bottom: 10px;
        }

        .games-grid {
            grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
            gap: 12px;
            margin-top: 15px;
        }

        .game-card {
            padding: 15px;
            min-height: 60px;
        }

        .game-name {
            font-size: 0.9em;
        }

        /* Ensure virtual gamepad is visible and properly sized for tablet landscape */
        .ejs-virtual-gamepad,
        .ejs-virtual-pad,
        .virtual-gamepad {
            display: block !important;
            visibility: visible !important;
            opacity: 0.8 !important;
            z-index: 1000;
        }

        /* Make virtual gamepad buttons larger for tablets */
        .ejs-virtual-gamepad .ejs-virtual-pad-button {
            min-width: 60px !important;
            min-height: 60px !important;
            font-size: 16px !important;
        }

        .ejs-virtual-gamepad .ejs-virtual-pad-dpad {
            width: 120px !important;
            height: 120px !important;
        }
    }

    /* Force virtual gamepad visibility on all touch devices */
    @media (pointer: coarse) {
        .ejs-virtual-gamepad,
        .ejs-virtual-pad,
        .virtual-gamepad,
        [class*="virtual"],
        [class*="gamepad"],
        [id*="virtual"],
        [id*="gamepad"] {
            display: block !important;
            visibility: visible !important;
            opacity: 0.8 !important;
            pointer-events: auto !important;
        }
    }

    /* Specific EmulatorJS virtual gamepad overrides */
    .ejs-virtual-gamepad {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 999 !important;
        pointer-events: none !important;
    }

    .ejs-virtual-gamepad > * {
        pointer-events: auto !important;
    }

    /* iPad specific fixes */
    @media screen and (-webkit-min-device-pixel-ratio: 1) and (min-device-width: 768px) and (max-device-width: 1024px) {
        .ejs-virtual-gamepad,
        .virtual-gamepad {
            display: block !important;
            visibility: visible !important;
        }
    }



/* Save Notification Toast */
.save-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.save-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 0.95;
}

.save-toast.success {
    background: #4CAF50;
}

.save-toast.info {
    background: #2196F3;
}

.save-toast.error {
    background: #f44336;
}
