/* Basic body styling for centering and background */
/* This will apply to the body of this standalone HTML file */
body {
    font-family: 'Press Start 2P', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(to right, #ff69b4, #8a2be2); /* Pink and Blue gradient */
    color: #ffffff; /* White text */
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Container for the entire game */
.game-container {
    text-align: center;
    background-color: rgba(0, 0, 0, 0.8); /* More opaque dark background */
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(255, 105, 180, 0.5); /* Pink glow */
    border: 3px solid #ff69b4; /* Pink border */
    display: flex; /* Use flexbox for layout */
    flex-direction: column; /* Stack elements vertically */
    align-items: center; /* Center items horizontally */
    margin: 20px auto; /* Add margin and center the container */
    max-width: 700px; /* Keep max width */
    width: 100%; /* Ensure it takes full width up to max-width */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
}

h1 {
    color: #00ffff; /* Cyan title */
    margin-bottom: 15px;
    font-size: 2em;
}

.score-display {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #ffff00; /* Yellow score */
}

.game-area-wrapper {
    display: flex; /* Arrange game board and preview side-by-side */
    gap: 30px; /* Space between board and preview */
    align-items: flex-start; /* Align items to the top */
    margin-bottom: 20px;
}

#game-board {
    display: grid;
    /* Grid columns and rows will be set by JavaScript */
    border: 3px solid #00ffff; /* Cyan border for the board */
    background-color: #000000; /* Black background for the grid */
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.5); /* Cyan glow */
}

.grid-cell {
    width: 25px; /* Size of each block/cell */
    height: 25px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.1); /* Subtle grid lines */
}

/* Styling for different block colors */
.block {
    /* Base block style */
    border: 2px outset rgba(255, 255, 255, 0.3); /* 3D effect */
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

.block.i { background-color: #00ffff; } /* Cyan */
.block.j { background-color: #0000ff; } /* Blue */
.block.l { background-color: #ff7f00; } /* Orange */
.block.o { background-color: #ffff00; } /* Yellow */
.block.s { background-color: #00ff00; } /* Green */
.block.t { background-color: #800080; } /* Purple */
.block.z { background-color: #ff0000; } /* Red */

/* Next Piece Preview Styling */
.next-piece-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.next-piece-container h2 {
    font-size: 1.2em;
    margin-bottom: 10px;
    color: #00ff00; /* Green */
}

#next-piece-preview {
    display: grid;
    /* Grid size will be set by JS based on the largest piece (I-block is 4x4) */
    width: 100px; /* Fixed size for preview area */
    height: 100px;
    border: 2px dashed #ff00ff; /* Magenta dashed border */
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    box-shadow: 0 0 10px rgba(255, 0, 255, 0.5); /* Magenta glow */
    padding: 5px; /* Padding inside preview */
    box-sizing: border-box;
    margin-top: 5px;
}

/* Styling for cells within the next piece preview */
#next-piece-preview .grid-cell {
    width: 20px; /* Smaller size for preview cells */
    height: 20px;
    box-sizing: border-box; /* Include border/padding */
    border: 1px solid rgba(255, 255, 255, 0.05); /* Very subtle grid lines */
}


.controls {
    margin-top: 20px;
    font-size: 1em;
    color: #cccccc;
    display: flex; /* Use flexbox for controls */
    flex-direction: column; /* Stack control groups vertically */
    align-items: center; /* Center control groups */
}

.controls p {
    margin: 8px 0;
}

/* Hide mobile controls by default */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-top: 15px;
}

.mobile-controls-row {
    display: flex;
    gap: 15px; /* Space between left/right buttons */
    margin: 10px 0;
}

.control-button {
    font-family: 'Press Start 2P', cursive;
    background-color: #8a2be2; /* BlueViolet */
    color: white;
    padding: 10px 15px;
    font-size: 0.9em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    min-width: 80px; /* Ensure buttons have a minimum touch area */
    text-align: center;
}

.control-button:hover {
    background-color: #7b24d0; /* Darker BlueViolet */
}

.control-button:active {
    transform: scale(0.95);
}


button#start-button {
    font-family: 'Press Start 2P', cursive;
    background-color: #ff5722; /* Orange-red */
    color: white;
    padding: 12px 25px;
    font-size: 1.1em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 25px;
    transition: background-color 0.3s ease, transform 0.1s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

button#start-button:hover {
    background-color: #e64a19;
}

button#start-button:active {
     transform: scale(0.98);
}

#game-over-message {
    font-size: 2.5em;
    color: #ff0000; /* Red */
    margin-top: 30px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8);
}

.hidden {
    display: none;
}

/* Animation for clearing lines */
@keyframes line-clear-flash {
    0% { background-color: rgba(255, 255, 255, 0.8); } /* Bright flash */
    100% { background-color: transparent; } /* Fade to transparent */
}

.grid-cell.clearing {
    animation: line-clear-flash 0.3s ease-out forwards; /* Apply animation */
}

/* Media Query for Mobile Screens */
@media (max-width: 768px) {
    .game-area-wrapper {
        flex-direction: column; /* Stack board and preview vertically on small screens */
        align-items: center; /* Center them */
        gap: 20px; /* Reduce gap */
    }

    .keyboard-controls {
        display: none; /* Hide keyboard instructions on small screens */
    }

    .mobile-controls {
        display: flex; /* Show mobile controls on small screens */
        flex-wrap: wrap; /* Allow buttons to wrap */
        justify-content: center; /* Center buttons */
        gap: 10px; /* Adjust gap for wrapping */
    }

    .mobile-controls-row {
         flex-direction: row; /* Keep left/right in a row */
         gap: 15px;
         width: 100%; /* Allow row to take full width */
         justify-content: center; /* Center buttons in the row */
    }

    .control-button {
        font-size: 0.8em; /* Smaller button text */
        padding: 12px 15px; /* Larger touch area */
        min-width: 90px; /* Ensure a decent minimum width */
        text-align: center;
    }

    .game-container {
        padding: 15px; /* Reduce padding on the container */
        margin: 10px auto; /* Adjust margin */
    }

     h1 {
        font-size: 1.5em; /* Smaller title */
     }

     .score-display {
        font-size: 1.2em; /* Smaller score display */
     }

     #game-over-message {
        font-size: 1.8em; /* Smaller game over message */
     }
}

/* Specific adjustments for very small screens/portrait mode */
@media (max-width: 480px) {
     .game-area-wrapper {
        gap: 10px; /* Further reduce gap */
     }

     #game-board {
         /* Adjust board size for very small screens if needed */
         /* Example: transform: scale(0.8); transform-origin: top center; */
     }

     .next-piece-container {
         margin-top: 10px;
     }

     .control-button {
         font-size: 0.7em;
         padding: 10px 12px;
         min-width: 80px;
     }

     .mobile-controls-row {
         gap: 10px;
     }

     .game-container {
        padding: 10px;
        margin: 5px auto;
     }
}
