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

body { 
    margin: 0; 
    overflow: hidden; 
    font-family: 'Courier New', monospace;
    background: #8b956d;
    touch-action: none;
    /* Prevent iOS Safari from bouncing */
    position: fixed;
    width: 100%;
    height: 100%;
}

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

.gameboy-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for modern browsers */
    width: 100vw;
    background: linear-gradient(135deg, #8b956d 0%, #7a8660 100%);
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-top: max(10px, env(safe-area-inset-top));
}

.screen-section {
    flex: 1.5;
    background: #2f2f2f;
    border-radius: 20px;
    padding: 15px;
    box-shadow: 
        inset 0 4px 8px rgba(0, 0, 0, 0.3),
        0 2px 10px rgba(0, 0, 0, 0.2);
    margin-bottom: 15px;
    position: relative;
    min-height: 0; /* Allow flex item to shrink */
}

.screen-section::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 8px;
    background: #4a4a4a;
    border-radius: 4px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

canvas { 
    display: block; 
    width: 100%;
    height: 100%;
    border-radius: 10px;
    background: #000;
}

.controls-section {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 150px;
    min-height: 150px;
}

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

.dpad-button {
    position: absolute;
    background: linear-gradient(135deg, #6a6a6a 0%, #4a4a4a 100%);
    border: 2px solid #3a3a3a;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #ddd;
    box-shadow: 
        0 3px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    transition: all 0.1s ease;
}

.dpad-button:active, .dpad-button.pressed {
    background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.4),
        0 1px 2px rgba(0, 0, 0, 0.2);
}

.dpad-up, .dpad-down {
    width: 50px;
    height: 45px;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-up {
    top: 10px;
}

.dpad-down {
    bottom: 10px;
}

.dpad-left, .dpad-right {
    width: 45px;
    height: 50px;
    top: 50%;
    transform: translateY(-50%);
}

.dpad-left {
    left: 10px;
}

.dpad-right {
    right: 10px;
}

.dpad-center {
    width: 40px;
    height: 40px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2a2a2a;
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.action-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6a6a6a 0%, #4a4a4a 100%);
    border: 2px solid #3a3a3a;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 20px;
    color: #ddd;
    box-shadow: 
        0 3px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    transition: all 0.1s ease;
}

.action-button:active, .action-button.pressed {
    background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.4),
        0 1px 2px rgba(0, 0, 0, 0.2);
}

.button-label {
    position: absolute;
    bottom: -20px;
    font-size: 12px;
    color: #4a4a4a;
    font-weight: bold;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .gameboy-container {
        padding: 5px;
        padding-bottom: max(15px, env(safe-area-inset-bottom) + 10px);
    }
    
    .dpad-container {
        width: 140px;
        height: 140px;
    }
    
    .dpad-up, .dpad-down {
        width: 45px;
        height: 40px;
    }
    
    .dpad-left, .dpad-right {
        width: 40px;
        height: 45px;
    }
    
    .dpad-center {
        width: 35px;
        height: 35px;
    }
    
    .action-button {
        width: 55px;
        height: 55px;
        font-size: 18px;
    }
    
    .controls-section {
        height: 160px;
        min-height: 160px;
        padding: 0 15px;
    }
    
    .screen-section {
        margin-bottom: 10px;
        padding: 10px;
    }
}

@media (max-height: 700px) {
    .screen-section {
        flex: 1.2;
    }
    
    .controls-section {
        height: 170px;
        min-height: 170px;
    }
}

@media (max-height: 600px) {
    .gameboy-container {
        padding: 5px;
    }
    
    .screen-section {
        flex: 1;
        margin-bottom: 8px;
        padding: 8px;
    }
    
    .controls-section {
        height: 140px;
        min-height: 140px;
    }
    
    .dpad-container {
        width: 120px;
        height: 120px;
    }
    
    .dpad-up, .dpad-down {
        width: 40px;
        height: 35px;
    }
    
    .dpad-left, .dpad-right {
        width: 35px;
        height: 40px;
    }
    
    .dpad-center {
        width: 30px;
        height: 30px;
    }
    
    .action-button {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
}

/* Desktop wrapper responsive breakpoints */

/* Mobile: Keep current full-screen behavior */
@media (max-width: 768px) {
    .desktop-wrapper {
        padding: 0;
        background: #8b956d;
    }
    
    .gameboy-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
    }
}

/* Tablet: Medium constraint with subtle desktop context */
@media (min-width: 769px) and (max-width: 1024px) {
    body {
        background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    }
    
    .desktop-wrapper {
        background: transparent;
        padding: 40px;
        min-height: 100vh;
    }
    
    .gameboy-container {
        max-width: 500px;
        max-height: 700px;
        width: auto;
        height: auto;
        box-shadow: 
            0 20px 40px rgba(0, 0, 0, 0.3),
            0 10px 20px rgba(0, 0, 0, 0.2);
        border-radius: 25px;
    }
}

/* Desktop: Viewport-constrained Game Boy with proper proportions */
@media (min-width: 1025px) {
    body {
        background: 
            radial-gradient(circle at 30% 70%, rgba(139, 149, 109, 0.1) 0%, transparent 50%),
            linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    }
    
    .desktop-wrapper {
        background: transparent;
        padding: 60px;
        min-height: 100vh;
    }
    
    .gameboy-container {
        /* Larger desktop size while maintaining Game Boy proportions */
        width: min(420px, 26vw);
        
        /* Override mobile flex behavior */
        display: flex;
        flex-direction: column;
        
        /* Authentic Game Boy aspect ratio */
        aspect-ratio: 3/5;
        
        /* Ensure proper scaling */
        height: auto;
        max-height: 85vh;
        
        box-shadow: 
            0 25px 50px rgba(0, 0, 0, 0.4),
            0 15px 30px rgba(0, 0, 0, 0.3),
            inset 0 1px 0 rgba(255, 255, 255, 0.05);
        border-radius: 25px;
        position: relative;
    }
    
    /* Adjust internal proportions for desktop Game Boy layout */
    .gameboy-container .screen-section {
        flex: 3;
        min-height: 280px;
    }
    
    .gameboy-container .controls-section {
        flex: 0 0 200px;
        height: 200px;
        min-height: 200px;
    }
    
    /* Scale down D-pad and buttons for larger desktop size */
    .gameboy-container .dpad-container {
        width: 140px;
        height: 140px;
    }
    
    .gameboy-container .action-button {
        width: 55px;
        height: 55px;
        font-size: 18px;
    }
    
    /* Game Boy branding text */
    .gameboy-container::before {
        content: "GAME BOY";
        position: absolute;
        top: -40px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 12px;
        font-weight: bold;
        color: #666;
        letter-spacing: 2px;
        font-family: 'Courier New', monospace;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .gameboy-container {
            height: 100vh;
            height: -webkit-fill-available;
        }
    }
}

