:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #f43f5e;
    --accent: #10b981;
    --bg-dark: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #252542;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border: #27273f;
    --gradient-1: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
    --gradient-2: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);
    --radius: 16px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 26, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    gap: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-family: 'Press Start 2P', cursive;
    font-size: 14px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav {
    display: flex;
    gap: 32px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
    position: relative;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gradient-1);
    border-radius: 1px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.search-box {
    position: relative;
}

.search-box-placeholder {
    width: 240px;
}

.search-box input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 16px 10px 40px;
    color: var(--text-primary);
    font-size: 14px;
    width: 240px;
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.lang-switch {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.lang-select {
    background: transparent;
    border: none;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    font-family: 'Inter', sans-serif;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a1a1aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.lang-select:hover {
    color: var(--text-primary);
}

.lang-select:focus {
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.lang-select option {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 8px 16px;
}

.hero {
    padding: 80px 0 60px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
    pointer-events: none;
}

.hero-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 36px;
    margin-bottom: 16px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.4;
}

.hero-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

.categories-section {
    padding: 20px 0;
}

.category-tabs {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.category-tab {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 24px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.category-tab:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--primary);
}

.category-tab.active {
    background: var(--gradient-1);
    border-color: transparent;
    color: white;
}

.games-section {
    padding: 40px 0 80px;
}

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

.game-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid var(--border);
}

.game-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-glow);
    border-color: var(--primary);
}

.game-card:hover .game-thumbnail img {
    transform: scale(1.05);
}

.game-thumbnail {
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--bg-dark);
    position: relative;
}

.game-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.game-thumbnail .placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-dark) 100%);
}

.game-category-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.game-info {
    padding: 20px;
}

.game-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.game-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    overflow: hidden;
}

.game-play-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 16px;
    background: var(--gradient-1);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
}

.game-play-btn:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.history-section {
    padding: 20px 0 40px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.history-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.history-clear-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-clear-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--primary);
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.history-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid var(--border);
}

.history-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
    border-color: var(--primary);
}

.history-thumbnail {
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--bg-dark);
    position: relative;
}

.history-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.history-card:hover .history-thumbnail img {
    transform: scale(1.05);
}

.history-thumbnail .placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-dark) 100%);
}

.history-category-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-info {
    padding: 12px;
}

.history-game-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 11px;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    .history-title {
        font-size: 18px;
    }

    .history-info {
        padding: 10px;
    }

    .history-game-title {
        font-size: 12px;
    }
}

.footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 40px 0;
    text-align: center;
}

.recommended-games {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 1px solid var(--border);
    margin-left: 20px;
    margin-right: 20px;
}

.recommended-header {
    margin-bottom: 20px;
}

.recommended-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.recommended-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.recommended-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid var(--border);
}

.recommended-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
    border-color: var(--primary);
}

.recommended-thumbnail {
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--bg-dark);
    position: relative;
}

.recommended-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.recommended-card:hover .recommended-thumbnail img {
    transform: scale(1.05);
}

.recommended-thumbnail .placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-dark) 100%);
}

.recommended-category-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.recommended-info {
    padding: 8px;
}

.recommended-game-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .recommended-games {
        margin-left: 10px;
        margin-right: 10px;
    }

    .recommended-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 10px;
    }

    .recommended-header h3 {
        font-size: 16px;
    }

    .recommended-info {
        padding: 6px;
    }

    .recommended-game-title {
        font-size: 10px;
    }
}

.play-page {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

.disclaimer {
    color: var(--text-muted);
    font-size: 12px;
}

.play-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.play-header {
    flex-shrink: 0;
}

.play-controls {
    display: flex;
    gap: 12px;
}

.control-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 20px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.play-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 0;
}

.emulator-container {
    width: 100%;
    max-width: 960px;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.game-info-panel {
    width: 100%;
    max-width: 960px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 20px;
    overflow: hidden;
}

.game-info-header {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 16px;
}

.game-info-thumbnail {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg-dark);
}

.game-info-meta {
    flex: 1;
}

.game-info-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.game-info-details {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.game-info-year,
.game-info-category,
.game-info-rating {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-dark);
    padding: 4px 10px;
    border-radius: 4px;
}

.game-info-rating {
    color: #fbbf24;
}

.game-info-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
    transition: transform 0.3s;
}

.game-info-toggle.collapsed {
    transform: rotate(-90deg);
}

.game-info-content {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.game-info-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-top: none;
}

.game-info-description {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 16px 0 0 0;
}

.emulator-container iframe,
.emulator-container #game {
    width: 100%;
    height: 100%;
    border: none;
}

@media (max-width: 768px) {
    body.play-page-active {
        overflow: hidden;
        height: 100vh;
        width: 100vw;
        position: fixed;
    }

    .play-page .header,
    .play-page .footer,
    .play-page .game-info-panel,
    .play-page .controls-panel {
        display: none !important;
    }

    .play-main {
        padding: 0;
        height: 100vh;
        width: 100vw;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        background: #000;
        overflow: hidden;
    }

    .emulator-container {
        flex: 1;
        width: 100vw;
        max-width: none;
        border-radius: 0;
        aspect-ratio: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #000;
        padding-top: 60px;
        box-sizing: border-box;
    }

    .emulator-container #game {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .emulator-container canvas {
        max-width: 100% !important;
        max-height: 100% !important;
        object-fit: contain;
    }
}

.mobile-back-btn {
    display: none;
}

@media (max-width: 768px) {
    .mobile-back-btn {
        display: block;
        position: fixed;
        top: 8px;
        left: 16px;
        z-index: 10000;
        background: rgba(15, 15, 26, 0.9);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        padding: 10px 16px;
        color: white;
        font-size: 14px;
        font-weight: 600;
        transition: all 0.2s;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        cursor: pointer;
        font-family: inherit;
    }

    .mobile-back-btn:hover {
        background: rgba(99, 102, 241, 0.9);
        border-color: rgba(99, 102, 241, 0.8);
        transform: scale(1.05);
    }

    .mobile-back-btn:active {
        transform: scale(0.98);
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-wrap: wrap;
        height: auto;
        padding: 16px 0;
        gap: 16px;
    }

    .nav {
        order: 3;
        width: 100%;
        justify-content: center;
        gap: 24px;
    }

    .search-box input {
        width: 180px;
    }

    .hero-title {
        font-size: 20px;
    }

    .hero-subtitle {
        font-size: 14px;
    }

    .category-tabs {
        gap: 8px;
    }

    .category-tab {
        padding: 8px 16px;
        font-size: 13px;
    }

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

    .play-controls {
        display: none;
    }
}

@media (max-width: 480px) {
    .logo-text {
        font-size: 11px;
    }

    .search-box {
        display: none;
    }

    .games-grid {
        grid-template-columns: 1fr;
    }
}

.controls-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    min-width: 280px;
    max-width: 320px;
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.controls-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.controls-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: transform 0.3s;
}

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

.controls-content {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
}

.controls-content.collapsed {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

.control-section {
    margin-bottom: 16px;
}

.control-section:last-child {
    margin-bottom: 0;
}

.control-section h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    margin: 0 0 10px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.key-grid {
    display: grid;
    gap: 8px;
}

.key-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    padding: 6px 10px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--text-primary);
}

.key-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

.mobile-tip {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

@media (max-width: 768px) {
    .controls-panel {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        min-width: auto;
    }

    .mobile-controls {
        display: block;
    }
}

@media (min-width: 769px) {
    .mobile-controls {
        display: none;
    }
}

.virtual-gamepad {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 35vh;
    min-height: 220px;
    max-height: 320px;
    background: linear-gradient(to top, rgba(15, 15, 26, 0.95), rgba(15, 15, 26, 0.8));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    /* Safari support */
    z-index: 9999;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px 15px calc(15px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.virtual-gamepad.visible {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 5px;
}

.gamepad-left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.dpad {
    position: relative;
    width: 150px;
    height: 150px;
}

.dpad-btn {
    position: absolute;
    width: 52px;
    height: 52px;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.95);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.1);
    transition: all 0.05s ease-out;
}

.dpad-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    pointer-events: none;
}

.dpad-btn.pressed {
    background: var(--primary);
    border-color: var(--primary-light);
    transform: scale(0.9) !important;
    box-shadow: 0 0 25px rgba(99, 102, 241, 0.6);
}

.dpad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.dpad-right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.gamepad-center {
    display: flex;
    flex-direction: column;
    gap: 15px;
    justify-content: center;
    align-items: center;
    height: 100%;
    opacity: 0.8;
}

.gamepad-btn {
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 9px;
    font-family: 'Press Start 2P', cursive;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.gamepad-btn.pressed {
    background: var(--primary);
    color: white;
    transform: scale(0.92);
    box-shadow: 0 0 15px var(--primary);
}

.gamepad-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.buttons-container {
    position: relative;
    width: 160px;
    height: 120px;
}

.gamepad-a,
.gamepad-b {
    position: absolute;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    font-family: 'Press Start 2P', cursive;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6), inset 0 2px 2px rgba(255, 255, 255, 0.2);
    transition: all 0.05s ease-out;
}

.gamepad-a {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    border: 3px solid rgba(255, 255, 255, 0.3);
    right: 0;
    bottom: 0;
}

.gamepad-b {
    background: linear-gradient(135deg, #4b5563, #374151);
    border: 3px solid rgba(255, 255, 255, 0.3);
    left: 0;
    top: 0;
}

.gamepad-a.pressed {
    background: #ef4444;
    transform: scale(0.9);
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.8), 0 0 30px rgba(239, 68, 68, 0.4);
}

.gamepad-b.pressed {
    background: #6b7280;
    transform: scale(0.9);
    box-shadow: 0 2px 10px rgba(107, 114, 128, 0.8), 0 0 30px rgba(255, 255, 255, 0.2);
}

@media (max-width: 540px) {

    /* Standard mobile portrait optimization */
    .virtual-gamepad {
        height: 38vh;
        max-height: 350px;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .dpad {
        width: 130px;
        height: 130px;
    }

    .dpad-btn {
        width: 44px;
        height: 44px;
    }

    .buttons-container {
        width: 140px;
        height: 110px;
    }

    .gamepad-a,
    .gamepad-b {
        width: 60px;
        height: 60px;
        font-size: 15px;
    }

    .gamepad-btn {
        padding: 8px 12px;
        font-size: 8px;
    }
}

/* Landscape mode optimization - Game screen on top, controls on sides if space allows, or overlay */
@media (orientation: landscape) and (max-width: 932px) {
    .virtual-gamepad.visible {
        height: 100vh;
        max-height: none;
        background: transparent;
        border-top: none;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        padding: 20px calc(20px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
        pointer-events: none;
    }

    .gamepad-left,
    .gamepad-right,
    .gamepad-center {
        pointer-events: auto;
    }

    .gamepad-left {
        width: 180px;
        height: 180px;
        justify-content: center;
    }

    .gamepad-right {
        width: 180px;
        height: 180px;
        justify-content: center;
    }

    .gamepad-center {
        flex-direction: row;
        gap: 20px;
        margin-bottom: 10px;
        background: rgba(15, 15, 26, 0.4);
        padding: 5px 15px;
        border-radius: 20px;
        backdrop-filter: blur(10px);
    }

    .dpad {
        width: 160px;
        height: 160px;
    }

    .buttons-container {
        width: 160px;
        height: 120px;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .virtual-gamepad {
        padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px));
    }

    .dpad {
        width: 115px;
        height: 115px;
    }

    .dpad-btn {
        width: 38px;
        height: 38px;
    }

    .buttons-container {
        width: 120px;
        height: 100px;
    }

    .gamepad-a,
    .gamepad-b {
        width: 54px;
        height: 54px;
    }
}

@media (min-width: 769px) {
    .virtual-gamepad {
        display: none !important;
    }
}

.loading-games {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    grid-column: 1 / -1;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(99, 102, 241, 0.2);
    border-left: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-games p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Pagination & Discovery Section */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
    flex-wrap: wrap;
}

.pagination-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
}

.pagination-link:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.pagination-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.discovery-section {
    margin: 40px 0 20px 0;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.discovery-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
}

.discovery-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.discovery-tag {
    padding: 6px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s ease;
}

.discovery-tag:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.mobile-play-shell {
    display: none;
}

.mobile-home-bar {
    display: flex;
    justify-content: flex-start;
    padding: max(12px, env(safe-area-inset-top, 0px)) 16px 0;
}

.mobile-home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(10, 14, 24, 0.82);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
    cursor: pointer;
}

.mobile-back-btn {
    display: none !important;
}

@media (max-width: 768px) {
    .play-page {
        min-height: 100dvh;
        height: 100dvh;
        background:
            radial-gradient(circle at top, rgba(99, 102, 241, 0.18), transparent 34%),
            linear-gradient(180deg, #0b1220 0%, #05070d 100%);
    }

    body.play-page-active {
        overflow: hidden;
        height: 100dvh;
        width: 100vw;
        position: fixed;
    }

    .play-page .header,
    .play-page .footer,
    .play-page .game-info-panel,
    .play-page .controls-panel,
    .play-page .game-seo-block,
    .play-page .discovery-section,
    .play-page .recommended-games {
        display: none !important;
    }

    .mobile-play-shell {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 10dvh;
        z-index: 10001;
        pointer-events: none;
    }

    .mobile-home-bar {
        height: 100%;
        pointer-events: auto;
        align-items: center;
        padding: max(8px, env(safe-area-inset-top, 0px)) 16px 0;
    }

    .play-main {
        height: 100dvh;
        width: 100%;
        padding: 10dvh 0 calc(40dvh + env(safe-area-inset-bottom, 0px));
        display: block;
        background: transparent;
        overflow: hidden;
    }

    .play-main > .container {
        width: 100%;
        height: 50dvh;
        max-width: none !important;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
    }

    .emulator-container {
        width: 100%;
        max-width: none;
        height: 100%;
        margin: 0;
        border-radius: 0;
        border: none;
        background:
            radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 55%),
            #000;
        box-shadow: none;
        overflow: hidden;
    }

    .emulator-container #game,
    .emulator-container iframe,
    .emulator-container > div {
        width: 100%;
        height: 100%;
    }

    .emulator-container canvas {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        object-fit: contain;
    }

    .virtual-gamepad {
        display: none;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: calc(40dvh + env(safe-area-inset-bottom, 0px));
        min-height: 0;
        max-height: none;
        padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
        background:
            linear-gradient(180deg, rgba(3, 6, 12, 0) 0%, rgba(3, 6, 12, 0.76) 18%, rgba(3, 6, 12, 0.98) 100%);
        border-top: none;
        box-sizing: border-box;
        z-index: 10000;
    }

    .virtual-gamepad.visible {
        display: grid;
        grid-template-columns: minmax(120px, 1fr) auto minmax(120px, 1fr);
        align-items: end;
        gap: 12px;
    }

    .gamepad-left,
    .gamepad-center,
    .gamepad-right {
        height: 100%;
    }

    .gamepad-left {
        justify-content: flex-start;
        align-items: flex-end;
    }

    .gamepad-right {
        justify-content: flex-end;
        align-items: flex-end;
    }

    .gamepad-center {
        justify-content: center;
        gap: 12px;
        opacity: 1;
        padding-bottom: 4px;
    }

    .dpad {
        width: min(36vw, 148px);
        height: min(36vw, 148px);
    }

    .dpad-btn {
        width: min(11vw, 52px);
        height: min(11vw, 52px);
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.14);
    }

    .dpad-center {
        width: min(10vw, 44px);
        height: min(10vw, 44px);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.04);
    }

    .buttons-container {
        width: min(40vw, 168px);
        height: min(30vw, 128px);
    }

    .gamepad-a,
    .gamepad-b {
        width: min(17vw, 72px);
        height: min(17vw, 72px);
    }

    .gamepad-btn {
        min-width: 88px;
        padding: 10px 14px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.88);
        font-size: 8px;
    }

    #gameClickOverlay {
        border-radius: 0 !important;
    }
}

@media (max-width: 420px) {
    .virtual-gamepad {
        padding-left: 12px;
        padding-right: 12px;
    }

    .virtual-gamepad.visible {
        gap: 8px;
    }

    .gamepad-btn {
        min-width: 78px;
        padding: 9px 12px;
    }
}
