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

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

.container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 20px;
    max-width: 900px;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

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

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 200px;
}

.score-board,
.level-board,
.lines-board {
    background: #f0f0f0;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.score-board h2,
.level-board h2,
.lines-board h2 {
    color: #667eea;
    font-size: 1.2em;
    margin-bottom: 10px;
}

#score,
#level,
#lines {
    font-size: 2em;
    font-weight: bold;
    color: #333;
}

.next-piece {
    background: #f0f0f0;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.next-piece h2 {
    color: #667eea;
    font-size: 1.2em;
    margin-bottom: 10px;
}

#nextCanvas {
    background: white;
    border: 2px solid #667eea;
    border-radius: 4px;
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1em;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

button:active {
    transform: translateY(0);
}

#pauseBtn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

#pauseBtn:hover {
    box-shadow: 0 5px 15px rgba(245, 87, 108, 0.4);
}

.game-board-container {
    position: relative;
}

#gameCanvas {
    border: 3px solid #333;
    border-radius: 8px;
    background: #1a1a1a;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.instructions {
    margin-top: 20px;
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
}

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

.instructions p {
    color: #666;
    margin: 5px 0;
    font-size: 0.95em;
}

/* Mobile Controls Base Styles */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
}

.control-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    pointer-events: auto;
    /* Enable clicks on buttons */
    align-items: flex-end;
    /* Align groups to the bottom */
}

.main-controls {
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    /* Limit width on larger screens */
    margin: 0 auto;
}

.arrow-group {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    /* Align to bottom */
}

.action-group {
    display: flex;
    flex-direction: column;
    /* Stack vertically */
    gap: 20px;
    align-items: center;
    padding-bottom: 5px;
    /* Slight padding to align with arrow keys visual weight */
}

.arrow-btn {
    width: 55px;
    height: 55px;
    /* Glassmorphism style */
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-weight: bold;
    font-size: 1.4em;
}

.control-btn {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.1s ease;
    flex-shrink: 0;
    /* Prevent button deformation */
}

.control-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 16px 0 rgba(31, 38, 135, 0.15);
}

.system-btns {
    display: none;
    /* Hide on mobile, use floating button instead */
}

.system-btn {
    width: 55px;
    height: 55px;
    /* Glassmorphism style */
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2em;
    border-radius: 50%;
    /* Slight adjustment to align visually with the larger rotate button */
}

.system-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

.rotate-btn {
    /* Glassmorphism style with slight purple tint */
    background: rgba(102, 126, 234, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 70px;
    height: 70px;
    font-size: 2em;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.3);
}

/* Floating Control Button Removed */

@media (max-width: 768px) {
    body {
        padding: 10px;
        align-items: flex-start;
        /* Allow scrolling if needed, but try to fit */
    }

    h1 {
        display: none;
        /* Hide title on mobile */
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        margin-bottom: 180px;
        /* Increased to accommodate taller vertical controls */
        /* Reduced for compact controls */
        gap: 10px;
    }

    .sidebar {
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        width: 100%;
        order: 1;
        /* Show at top */
        gap: 5px;
    }

    .game-board-container {
        order: 2;
        /* Show below sidebar */
        width: 100%;
        display: flex;
        justify-content: center;
    }

    #gameCanvas {
        width: auto;
        height: auto;
        max-height: 65vh;
        /* Increased height */
        max-width: 90vw;
        aspect-ratio: 1/2;
    }

    .score-board,
    .level-board,
    .lines-board,
    .next-piece {
        flex: 1;
        min-width: auto;
        padding: 5px;
        background: #f8f8f8;
    }

    .score-board h2,
    .level-board h2,
    .lines-board h2,
    .next-piece h2 {
        font-size: 0.7em;
        margin-bottom: 2px;
    }

    #score,
    #level,
    #lines {
        font-size: 1em;
    }

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

    /* Hide desktop buttons on mobile */
    .sidebar button {
        display: none;
    }

    .container {
        background: transparent;
        box-shadow: none;
        padding: 0;
        width: 100%;
    }

    .mobile-controls {
        display: flex;
        position: fixed;
        bottom: 40px;
        /* Lift up from bottom */
        left: 0;
        width: 100%;
        background: transparent;
        /* Remove background */
        padding: 0 20px;
        padding-bottom: env(safe-area-inset-bottom);
        z-index: 1000;
        justify-content: center;
        backdrop-filter: none;
        box-shadow: none;
        pointer-events: none;
        /* Allow clicks to pass through container */
    }

    .instructions {
        display: none;
    }
}