* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    touch-action: manipulation;
}

.gameboy-container {
    width: 100%;
    max-width: 500px;
}

.gameboy {
    background: #e8e8e8;
    border-radius: 20px;
    padding: 30px 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.screen-section {
    background: #2d2d2d;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 30px;
}

#mainCanvas {
    width: 100%;
    max-width: 320px;
    height: auto;
    aspect-ratio: 160 / 144;
    display: block;
    margin: 0 auto;
    background: #9bbc0f;
    border-radius: 5px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.controls-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 20px;
}

.left-controls {
    flex: 1;
    display: flex;
    justify-content: flex-start;
}

.center-logo {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo {
    width: 100%;
    max-width: 150px;
    height: auto;
}

.right-controls {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.dpad-container {
    width: 120px;
    height: 120px;
}

.dpad {
    width: 100%;
    height: 100%;
    cursor: pointer;
    user-select: none;
}

.dpad-btn {
    fill: #333;
    transition: fill 0.1s;
}

.dpad-btn:active,
.dpad-btn.active {
    fill: #555;
}

.dpad-center {
    fill: #222;
}

.ab-buttons {
    display: flex;
    gap: 15px;
    align-items: center;
    transform: rotate(-20deg);
}

.game-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.1s;
    color: white;
}

.b-btn {
    background: #dc3545;
}

.b-btn:active {
    background: #c82333;
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.a-btn {
    background: #007bff;
}

.a-btn:active {
    background: #0056b3;
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.menu-section {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.menu-btn {
    padding: 8px 20px;
    background: #666;
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.1s;
}

.menu-btn:active {
    background: #555;
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.rom-section {
    text-align: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
}

.select-game-btn {
    width: 100%;
    padding: 15px 30px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 0 #1e7e34;
}

.select-game-btn:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #1e7e34;
}

.select-game-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #1e7e34;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 2px solid #eee;
}

.modal-header h2 {
    margin: 0;
    color: #333;
    font-size: 24px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 36px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 20px 25px;
    overflow-y: auto;
    flex: 1;
}

.filter-section {
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: #28a745;
}

.alphabet-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
}

.filter-btn {
    padding: 8px 12px;
    background: #f0f0f0;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
    min-width: 40px;
}

.filter-btn:hover {
    background: #e0e0e0;
    border-color: #28a745;
}

.filter-btn.active {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.game-list {
    max-height: 400px;
    overflow-y: auto;
    border: 2px solid #eee;
    border-radius: 8px;
    padding: 10px;
}

.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    background: #f9f9f9;
    border-radius: 8px;
    transition: all 0.2s;
}

.game-item:hover {
    background: #e8f5e9;
    transform: translateX(5px);
}

.game-name {
    flex: 1;
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

.load-btn {
    padding: 8px 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.load-btn:hover {
    background: #0056b3;
    transform: scale(1.05);
}

.load-btn:active {
    transform: scale(0.95);
}

.no-games {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: 16px;
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }
    
    .gameboy {
        padding: 20px 15px;
    }
    
    .dpad-container {
        width: 100px;
        height: 100px;
    }
    
    .game-btn {
        width: 50px;
        height: 50px;
        font-size: 16px;
    }
    
    .ab-buttons {
        gap: 10px;
    }
}

@media (max-width: 400px) {
    .dpad-container {
        width: 80px;
        height: 80px;
    }
    
    .game-btn {
        width: 45px;
        height: 45px;
        font-size: 14px;
    }
}
