/* Mobile-First Game Boy Emulator Design */
:root {
    /* Game Boy Green Palette */
    --gb-screen-green: #9BBD0F;
    --gb-screen-dark: #8BAC0F;
    --gb-screen-light: #B8D862;
    --gb-darkest: #0f380f;
    
    /* UI Colors */
    --ui-dark: #1a1a1a;
    --ui-darker: #0f0f0f;
    --ui-light: #2a2a2a;
    --ui-accent: #4a4a4a;
    --ui-text: #ffffff;
    --ui-text-dim: rgba(255, 255, 255, 0.6);
    
    /* Control Colors */
    --control-bg: #2c2c2c;
    --control-shadow: rgba(0, 0, 0, 0.5);
    --control-highlight: rgba(255, 255, 255, 0.1);
    --control-pressed: #1a1a1a;
    
    /* Button specific */
    --btn-a: #e74c3c;
    --btn-b: #f39c12;
    --btn-start: #27ae60;
    --btn-select: #3498db;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--ui-darker);
    color: var(--ui-text);
    display: flex;
    flex-direction: column;
    touch-action: none;
}

/* Game Selection Menu - Full Screen */
.game-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--ui-darker);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.menu-header {
    padding: env(safe-area-inset-top) 20px 20px;
    padding-top: max(env(safe-area-inset-top), 40px);
    background: linear-gradient(to bottom, var(--ui-dark), transparent);
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.menu-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--gb-screen-green);
    margin-bottom: 5px;
    letter-spacing: -1px;
}

.menu-subtitle {
    font-size: 14px;
    color: var(--ui-text-dim);
    font-weight: 400;
}

.game-options {
    flex: 1;
    padding: 0 15px 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    align-content: start;
}

.game-option {
    background: var(--ui-light);
    border: none;
    border-radius: 16px;
    padding: 20px 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.game-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gb-screen-green);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.game-option:active {
    transform: scale(0.95);
    background: var(--ui-accent);
}

.game-option:hover::before {
    transform: scaleX(1);
}

.game-icon {
    font-size: 48px;
    margin-bottom: 12px;
    filter: grayscale(0.3);
}

.game-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ui-text);
    margin-bottom: 4px;
    line-height: 1.2;
}

.game-description {
    font-size: 11px;
    color: var(--ui-text-dim);
    font-weight: 400;
}

/* Main Game Layout - NO SHELL, just functional */
.gameboy-shell {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--ui-darker);
}

/* Screen Section - Takes up available space */
.gameboy-top {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) 0 0;
    background: #000;
    position: relative;
}

/* Minimal Header */
.gameboy-header {
    position: absolute;
    top: env(safe-area-inset-top);
    left: 0;
    right: 0;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

.power-led {
    width: 8px;
    height: 8px;
    background: #00ff00;
    border-radius: 50%;
    box-shadow: 0 0 10px #00ff00;
}

.game-info {
    font-size: 12px;
    color: var(--ui-text-dim);
    text-align: center;
}

/* Screen Area - Full Width */
.screen-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #000;
}

.screen-housing {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen-bezel {
    position: relative;
    width: 100%;
    max-width: 500px;
    background: var(--gb-darkest);
    border-radius: 8px;
    padding: 2px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Game Canvas - Responsive */
#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 160 / 144;
    background: var(--gb-screen-green);
    border-radius: 6px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Controls Section - Fixed at Bottom */
.gameboy-bottom {
    background: var(--ui-dark);
    padding: 25px 15px env(safe-area-inset-bottom);
    padding-bottom: max(env(safe-area-inset-bottom), 25px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

/* Controls Container */
.controls-layout {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Top row container for D-pad and Action buttons */
.controls-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

/* D-Pad - Left Side */
.left-controls {
    /* No grid needed, flexbox handles it */
}

.dpad {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto;
}

.dpad-center {
    position: absolute;
    top: 40px;
    left: 40px;
    width: 40px;
    height: 40px;
    background: var(--control-bg);
    border-radius: 4px;
    pointer-events: none;
}

.dpad-btn {
    position: absolute;
    background: var(--control-bg);
    border: none;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 
        0 2px 8px var(--control-shadow),
        inset 0 1px 0 var(--control-highlight);
}

.dpad-up {
    top: 0;
    left: 40px;
    width: 40px;
    height: 48px;
    border-radius: 8px 8px 0 0;
}

.dpad-down {
    bottom: 0;
    left: 40px;
    width: 40px;
    height: 48px;
    border-radius: 0 0 8px 8px;
}

.dpad-left {
    left: 0;
    top: 40px;
    width: 48px;
    height: 40px;
    border-radius: 8px 0 0 8px;
}

.dpad-right {
    right: 0;
    top: 40px;
    width: 48px;
    height: 40px;
    border-radius: 0 8px 8px 0;
}

.dpad-arrow {
    color: var(--ui-text-dim);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.dpad-btn:active,
.dpad-btn.pressed {
    background: var(--control-pressed);
    transform: scale(0.95);
    box-shadow: 
        0 1px 3px var(--control-shadow),
        inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Center Area - START/SELECT */
.center-controls {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.system-btn {
    background: var(--control-bg);
    border: none;
    border-radius: 30px;
    padding: 12px 32px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--ui-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.1s ease;
    box-shadow: 
        0 2px 8px var(--control-shadow),
        inset 0 1px 0 var(--control-highlight);
}

.start-btn {
    background: var(--btn-start);
    color: white;
}

.select-btn {
    background: var(--btn-select);
    color: white;
}

.system-btn:active,
.system-btn.pressed {
    transform: scale(0.95);
    box-shadow: 
        0 1px 3px var(--control-shadow),
        inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Action Buttons - Right Side */
.right-controls {
    /* No grid needed, flexbox handles it */
}

.action-buttons {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto;
}

.action-btn {
    position: absolute;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 20px;
    color: white;
    transition: all 0.1s ease;
    box-shadow: 
        0 3px 10px var(--control-shadow),
        inset 0 -2px 4px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 var(--control-highlight);
}

.btn-a {
    background: var(--btn-a);
    left: 10px;
    bottom: 20px;
}

.btn-b {
    background: var(--btn-b);
    right: 5px;
    top: 25px;
}

.action-btn:active,
.action-btn.pressed {
    transform: scale(0.92);
    box-shadow: 
        0 1px 5px var(--control-shadow),
        inset 0 3px 6px rgba(0, 0, 0, 0.4);
}

/* Menu Controls - Bottom Row */
.modern-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
    padding: 0 20px;
}

.menu-btn {
    background: var(--ui-accent);
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--ui-text);
    transition: all 0.1s ease;
    box-shadow: 0 2px 6px var(--control-shadow);
}

.menu-btn:active {
    transform: scale(0.95);
    background: var(--ui-light);
}

.menu-btn.compact {
    padding: 8px 12px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.1);
    min-width: 40px;
}

/* Remove all decorative elements */
.nintendo-branding,
.screen-label,
.speaker-grille,
.shell-details,
.cartridge-slot {
    display: none !important;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--ui-darker);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 3px solid var(--ui-accent);
    border-top: 3px solid var(--gb-screen-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-text {
    font-size: 14px;
    color: var(--ui-text-dim);
    font-weight: 500;
}

/* Game UI Overlay for Tetris */
.game-ui {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    pointer-events: none;
}

.score-panel {
    background: rgba(0, 0, 0, 0.8);
    padding: 12px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(155, 189, 15, 0.3);
}

.score-item {
    margin-bottom: 8px;
    text-align: right;
}

.score-item:last-child {
    margin-bottom: 0;
}

.score-item .label {
    font-size: 10px;
    color: var(--ui-text-dim);
    margin-bottom: 2px;
    font-weight: 500;
}

.score-item .value {
    font-size: 16px;
    color: var(--gb-screen-green);
    font-weight: 700;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

/* Modals - Modern Style */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 20px;
}

.modal-content {
    background: var(--ui-light);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--ui-text);
    margin-bottom: 20px;
    text-align: center;
}

.modal-close-btn {
    display: block;
    margin: 20px auto 0;
    background: var(--gb-screen-green);
    color: var(--ui-darker);
    border: none;
    border-radius: 25px;
    padding: 12px 32px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* Form Styling */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ui-text-dim);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    background: var(--ui-dark);
    border: 2px solid var(--ui-accent);
    border-radius: 10px;
    color: var(--ui-text);
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--gb-screen-green);
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    .gameboy-shell {
        flex-direction: row;
    }
    
    .gameboy-top {
        flex: 1;
        padding: 0;
    }
    
    .gameboy-header {
        display: none;
    }
    
    .gameboy-bottom {
        width: auto;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }
    
    .controls-layout {
        grid-template-columns: auto auto;
        grid-template-rows: auto auto auto;
        max-width: none;
    }
    
    .left-controls {
        grid-column: 1;
        grid-row: 1 / 3;
    }
    
    .right-controls {
        grid-column: 2;
        grid-row: 1 / 3;
    }
    
    .center-controls {
        grid-column: 1 / -1;
        grid-row: 3;
        margin-top: 10px;
    }
    
    .modern-controls {
        display: none;
    }
}

/* iPhone X and newer safe areas */
@supports (padding: max(0px)) {
    .menu-header {
        padding-top: max(env(safe-area-inset-top), 40px);
    }
    
    .gameboy-bottom {
        padding-bottom: max(env(safe-area-inset-bottom), 15px);
    }
}

/* High contrast mode for better visibility */
@media (prefers-contrast: high) {
    .dpad-btn,
    .action-btn,
    .system-btn {
        border: 2px solid var(--ui-text);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Game Message Notifications */
.game-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--ui-light);
    color: var(--gb-screen-green);
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 10001;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(0);
    }
}