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

html {
    height: 100%;
    overflow-x: hidden;
}

html, body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
    overflow-x: hidden;
}

.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    padding: 20px;
    max-width: 800px;
    width: 100%;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    font-size: 2.5rem;
    color: #333;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.score-item {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.score-item .label {
    font-weight: bold;
    margin-right: 5px;
}

.copyright {
    margin-top: 10px;
    font-size: 14px;
    color: #666;
    text-align: center;
    font-weight: 500;
}

.game-content {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

.game-board-container {
    position: relative;
    background: #222;
    border-radius: 10px;
    padding: 10px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    border: 2px solid #444;
    border-radius: 5px;
    background: #000;
    /* Performance optimizations for canvas */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    will-change: contents;
}

.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.game-over h2 {
    margin-bottom: 15px;
    color: #ff4444;
}

.hidden {
    display: none;
}

.game-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 200px;
}

.next-piece {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.next-piece h3 {
    margin-bottom: 10px;
    color: #333;
}

#nextCanvas {
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #000;
}

.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(45deg, #2196F3, #1976D2);
    color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.instructions {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    font-size: 14px;
}

.instructions h3 {
    margin-bottom: 10px;
    color: #333;
}

.control-info {
    margin-bottom: 10px;
}

.control-info p {
    margin: 2px 0;
}

.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 100;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 15px;
    backdrop-filter: blur(5px);
}

.mobile-top-controls {
    display: none;
}

.mobile-row {
    display: flex;
    gap: 10px;
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 10px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    background: linear-gradient(45deg, #FF9800, #F57C00);
    color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease; /* Faster, more specific transition */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    position: relative;
    z-index: 10;
    /* Performance optimizations */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.mobile-btn:active,
.mobile-btn.active-press {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    background: linear-gradient(45deg, #F57C00, #E65100);
    transition: all 0.1s ease; /* Faster transition */
}

.mobile-btn:hover {
    background: linear-gradient(45deg, #FFB74D, #FF9800);
}

/* Optimized active state for better performance */
.mobile-btn.active-press {
    will-change: transform; /* Optimize for animations */
}

.drop-btn {
    width: 120px;
    background: linear-gradient(45deg, #f44336, #d32f2f);
}

.drop-btn:active {
    background: linear-gradient(45deg, #d32f2f, #b71c1c);
}

.drop-btn:hover {
    background: linear-gradient(45deg, #ef5350, #f44336);
}

/* GameBoy Style Mobile Layout - Hidden by default, shown only on mobile */
.gameboy-container {
    display: none;
}

/* Desktop Layout - Default visible */
.desktop-layout {
    display: block;
}

/* Mobile Responsive - GameBoy Style */
@media (max-width: 768px) {
    body {
        align-items: center;
        padding: 8px;
        background: linear-gradient(135deg, #8B9DC3, #DFE9F3);
        min-height: 100vh;
    }

    .game-container {
        padding: 0;
        width: 100%;
        max-width: 380px;
        background: linear-gradient(145deg, #9BB0C1, #B8C5D1);
        border-radius: 25px;
        box-shadow:
            0 8px 32px rgba(0, 0, 0, 0.3),
            inset 0 2px 4px rgba(255, 255, 255, 0.2);
        border: 3px solid #7A8B9A;
    }

    .game-header {
        background: linear-gradient(145deg, #1A252F, #2C3E50);
        color: #FFFFFF;
        padding: 12px 20px;
        border-radius: 22px 22px 0 0;
        text-align: center;
        border-bottom: 3px solid #0F1419;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }

    .game-header h1 {
        font-size: 1.4rem;
        margin-bottom: 8px;
        font-family: 'Courier New', monospace;
        letter-spacing: 2px;
        text-shadow:
            0 2px 4px rgba(0, 0, 0, 0.8),
            0 0 10px rgba(255, 255, 255, 0.3);
        color: #FFFFFF;
        font-weight: bold;
    }

    .score-container {
        gap: 8px;
        margin-bottom: 6px;
        justify-content: center;
    }

    .score-item {
        padding: 4px 8px;
        font-size: 11px;
        background: rgba(0, 0, 0, 0.7);
        border-radius: 8px;
        font-family: 'Courier New', monospace;
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: #FFFFFF;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    }

    .copyright {
        font-size: 10px;
        margin-top: 4px;
        opacity: 0.8;
    }

    .game-content {
        padding: 0;
    }

    /* Show GameBoy container only on mobile */
    .gameboy-container {
        display: flex !important;
        flex-direction: column;
        gap: 0;
    }

    /* Hide desktop layout on mobile */
    .desktop-layout {
        display: none !important;
    }

    /* GameBoy Screen Area */
    .gameboy-screen {
        background: linear-gradient(145deg, #1A1A1A, #2D2D2D);
        padding: 15px;
        border-radius: 0 0 15px 15px;
        border: 3px solid #0F0F0F;
        position: relative;
    }

    .screen-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding: 8px;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 8px;
        border: 1px solid #333;
    }

    .next-piece-mini {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    .next-label {
        font-size: 10px;
        color: #00FF00;
        font-family: 'Courier New', monospace;
        font-weight: bold;
        text-shadow: 0 0 4px #00FF00;
    }

    #nextCanvas {
        border: 1px solid #333;
        border-radius: 4px;
        background: #000;
        width: 60px;
        height: 60px;
    }

    .control-buttons-mini {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .gameboy-btn.small {
        padding: 4px 8px;
        font-size: 10px;
        background: linear-gradient(145deg, #4A4A4A, #2A2A2A);
        color: #00FF00;
        border: 1px solid #666;
        border-radius: 4px;
        font-family: 'Courier New', monospace;
        font-weight: bold;
        text-shadow: 0 0 2px #00FF00;
        min-width: 35px;
    }

    .gameboy-btn.small:active {
        background: linear-gradient(145deg, #2A2A2A, #1A1A1A);
        transform: scale(0.95);
    }

    .game-board-container {
        display: flex;
        justify-content: center;
        margin: 0;
    }

    #gameCanvas {
        width: 280px;
        height: 420px;
        border: 2px solid #333;
        border-radius: 8px;
        box-shadow:
            inset 0 0 20px rgba(0, 0, 0, 0.8),
            0 0 10px rgba(0, 255, 0, 0.1);
    }

    /* GameBoy Controls */
    .gameboy-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px 25px;
        background: linear-gradient(145deg, #9BB0C1, #B8C5D1);
        border-radius: 0 0 22px 22px;
        padding-bottom: max(25px, env(safe-area-inset-bottom));
    }

    /* D-Pad Container */
    .dpad-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .dpad {
        position: relative;
        width: 150px;
        height: 150px;
        background: linear-gradient(145deg, #2C3E50, #34495E);
        border-radius: 50%;
        border: 3px solid #1A252F;
        box-shadow:
            0 4px 8px rgba(0, 0, 0, 0.3),
            inset 0 2px 4px rgba(255, 255, 255, 0.1);
    }

    .dpad-btn {
        position: absolute;
        background: linear-gradient(145deg, #34495E, #2C3E50);
        border: 2px solid #1A252F;
        color: #ECF0F1;
        font-size: 18px;
        font-weight: bold;
        cursor: pointer;
        transition: all 0.1s ease;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .dpad-up {
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 45px;
        height: 40px;
        border-radius: 10px 10px 5px 5px;
    }

    .dpad-left {
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 45px;
        border-radius: 10px 5px 5px 10px;
    }

    .dpad-right {
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 45px;
        border-radius: 5px 10px 10px 5px;
    }

    .dpad-down {
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 45px;
        height: 40px;
        border-radius: 5px 5px 10px 10px;
    }

    .dpad-center {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 30px;
        height: 30px;
        border-radius: 50%;
        background: linear-gradient(145deg, #1A252F, #2C3E50);
        pointer-events: none;
    }

    .dpad-btn:active {
        background: linear-gradient(145deg, #1A252F, #2C3E50);
        transform: translateX(-50%) scale(0.95);
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
    }

    .dpad-left:active {
        transform: translateY(-50%) scale(0.95);
    }

    .dpad-right:active {
        transform: translateY(-50%) scale(0.95);
    }

    .dpad-down:active {
        transform: translateX(-50%) scale(0.95);
    }

    .dpad-label {
        font-size: 10px;
        color: #2C3E50;
        font-family: 'Courier New', monospace;
        font-weight: bold;
        letter-spacing: 1px;
    }

    /* Action Buttons */
    .action-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .action-btn {
        width: 90px;
        height: 90px;
        border-radius: 50%;
        background: linear-gradient(145deg, #E74C3C, #C0392B);
        border: 3px solid #A93226;
        color: white;
        font-size: 14px;
        font-weight: bold;
        font-family: 'Courier New', monospace;
        cursor: pointer;
        transition: all 0.1s ease;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        box-shadow:
            0 4px 8px rgba(0, 0, 0, 0.3),
            inset 0 2px 4px rgba(255, 255, 255, 0.2);
    }

    .action-btn:active {
        background: linear-gradient(145deg, #C0392B, #A93226);
        transform: scale(0.95);
        box-shadow:
            0 2px 4px rgba(0, 0, 0, 0.3),
            inset 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .action-label {
        font-size: 10px;
        color: #2C3E50;
        font-family: 'Courier New', monospace;
        font-weight: bold;
        letter-spacing: 1px;
    }

    /* Hide desktop and old mobile controls */
    .desktop-controls,
    .mobile-top-controls,
    .mobile-controls {
        display: none;
    }
}

@media (max-width: 480px) {
    .game-container {
        max-width: 340px;
        border-radius: 20px;
    }

    .game-header h1 {
        font-size: 1.2rem;
        margin-bottom: 6px;
    }

    .score-container {
        gap: 6px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .score-item {
        padding: 3px 6px;
        font-size: 10px;
        min-width: 50px;
    }

    .gameboy-screen {
        padding: 12px;
    }

    .screen-info {
        padding: 6px;
        margin-bottom: 8px;
    }

    #nextCanvas {
        width: 50px;
        height: 50px;
    }

    .gameboy-btn.small {
        padding: 3px 6px;
        font-size: 9px;
        min-width: 30px;
    }

    #gameCanvas {
        width: 240px;
        height: 360px;
    }

    .gameboy-controls {
        padding: 15px 20px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

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

    .dpad-up, .dpad-down {
        width: 38px;
        height: 32px;
        font-size: 16px;
    }

    .dpad-left, .dpad-right {
        width: 32px;
        height: 38px;
        font-size: 16px;
    }

    .dpad-center {
        width: 20px;
        height: 20px;
    }

    .action-btn {
        width: 75px;
        height: 75px;
        font-size: 12px;
    }

    .dpad-label, .action-label {
        font-size: 9px;
    }
}

/* Desktop specific styles */
@media (min-width: 769px) {
    /* Hide mobile GameBoy layout */
    .gameboy-container {
        display: none !important;
    }

    /* Hide mobile controls */
    .mobile-top-controls {
        display: none !important;
    }

    .mobile-controls {
        display: none !important;
    }

    /* Show desktop controls */
    .desktop-controls {
        display: flex !important;
    }

    /* Reset desktop layout */
    .game-content {
        flex-direction: row;
        align-items: flex-start;
        gap: 30px;
    }

    .game-board-container {
        order: initial;
    }

    /* Reset desktop body and container styles */
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        align-items: center;
        padding: 20px;
    }

    .game-container {
        background: rgba(255, 255, 255, 0.95);
        border-radius: 20px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        border: none;
        max-width: 1000px;
        padding: 30px;
    }

    .game-header {
        background: transparent;
        color: #333;
        padding: 0;
        border-radius: 0;
        border-bottom: none;
        margin-bottom: 20px;
    }

    .game-header h1 {
        color: #2C3E50;
        text-shadow:
            0 2px 4px rgba(255, 255, 255, 0.8),
            0 1px 0 rgba(255, 255, 255, 1);
        font-family: 'Arial', sans-serif;
        font-size: 2.5rem;
        font-weight: bold;
    }

    .score-item {
        background: #f8f9fa;
        color: #333;
        border: 1px solid #dee2e6;
        font-family: 'Arial', sans-serif;
    }
}
