body {
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #202028;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: none; /* Prevent default touch actions like scrolling */
}

#game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding: 10px;
}

#stats {
    background-color: #000;
    padding: 20px;
    border: 2px solid #fff;
    min-width: 120px;
    font-size: 1.2rem;
    display: flex;
    flex-direction: column;
}

#stats div {
    margin-bottom: 10px;
}

#next-piece {
    margin-top: 20px;
    border-top: 1px solid #fff;
    padding-top: 10px;
    text-align: center;
}

#nextCanvas, #holdCanvas {
    margin-top: 10px;
    width: 100px;
    height: 100px;
    background-color: #000;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#canvas-wrapper {
    position: relative;
    overflow: hidden;
}

#canvas-wrapper::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.04), rgba(0, 255, 0, 0.01), rgba(0, 0, 118, 0.04));
    z-index: 5;
    background-size: 100% 4px, 3px 100%;
    pointer-events: none;
}

#canvas-wrapper::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: radial-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.2) 100%);
    z-index: 6;
    pointer-events: none;
}

canvas {
    background-color: #000;
    border: 2px solid #fff;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    display: block;
}

#tetrisCanvas {
    max-width: 80vw;
    max-height: 80vh;
    width: auto;
    height: auto;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

#overlay.hidden {
    display: none;
}

#overlay-text {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
}

#sub-text {
    font-size: 1rem;
    opacity: 0.8;
    text-align: center;
    padding: 0 10px;
}

/* Mobile Controls */
#mobile-controls {
    display: flex; /* Always visible for accessibility and testing */
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
    padding: 0 10px;
    box-sizing: border-box;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 15px;
    width: 100%;
}

.mobile-btn {
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px solid #fff;
    color: #fff;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 60px;
}

.mobile-btn:active {
    background-color: rgba(255, 255, 255, 0.3);
}

.mobile-btn.round {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    flex: 0 0 60px;
    padding: 0;
}

.mobile-btn.wide {
    width: 100%;
}

#pause-btn {
    margin-top: auto;
    padding: 10px;
    font-size: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        justify-content: flex-start;
        padding-top: 20px;
    }

    #game-container {
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 10px;
    }

    #stats {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        width: 100%;
        max-width: 320px; /* Match canvas width */
        box-sizing: border-box;
        padding: 10px;
        min-width: auto;
    }
    
    #stats div {
        margin-bottom: 0;
        margin-right: 10px;
    }

    #next-piece, #hold-piece {
        display: none; /* Hide next and hold pieces on very small screens */
        margin-top: 0;
        border-top: none;
        padding-top: 0;
    }

    #tetrisCanvas {
        width: 100%;
        max-width: 320px;
        height: auto;
    }

    #mobile-controls {
        display: flex;
        padding-bottom: 20px;
    }
    
    #pause-btn {
        margin-top: 0;
    }
}
