body {
    font-family: 'Arial', sans-serif;
    text-align: center;
    background-color: #f0f0f0;
    color: #333;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    box-sizing: border-box; /* Prevent overflow issues */
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 10px;
    justify-content: center;
    margin: 20px auto;
    max-width: 100%; /* Ensure it fits in mobile */
    width: 440px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    background-color: #fff;
    padding: 15px; /* Reduced padding for smaller screens */
}

/* Grid Cell: Responsive Scaling */
.grid-cell {
    width: 100%;
    aspect-ratio: 1; /* Ensures square cells on any screen */
    background-color: #ddd;
    font-size: calc(10px + 1vw); /* Adjust font size dynamically */
    line-height: normal;
    text-align: center;
    border-radius: 5px;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    transition: background-color 0.3s, transform 0.3s ease-in-out;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* Prevent overflow issues */
}

/* Dynamic colors based on the value */
.grid-cell[data-value="5"] {
    background-color: #e35518;
    color: #fff;
}

.grid-cell[data-value="10"] {
    background-color: #f79846;
    color: #fff;
}

.grid-cell[data-value="20"] {
    background-color: #f5c219;
    color: #fff;
}

.grid-cell[data-value="40"] {
    background-color: #ffb84d;
    color: #fff;
}

.grid-cell[data-value="80"] {
    background-color: #ff9f2f;
    color: #fff;
}

.grid-cell[data-value="160"] {
    background-color: #ff6f00;
    color: #fff;
}

.grid-cell[data-value="320"] {
    background-color: #ff4500;
    color: #fff;
}

.grid-cell[data-value="640"] {
    background-color: #e63946;
    color: #fff;
}

.grid-cell[data-value="1280"] {
    background-color: #d32f2f;
    color: #fff;
}

.grid-cell[data-value="2560"] {
    background-color: #c2185b;
    color: #fff;
}

.grid-cell[data-value="5120"] {
    background-color: #8e24aa;
    color: #fff;
}

.grid-cell[data-value="10240"] {
    background-color: #7b1fa2;
    color: #fff;
}

.grid-cell:empty {
    background-color: #ddd;
}

#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#game-container {
    display: none;
}

#gameOver {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #f39c12;
    border: none;
    color: white;
    border-radius: 5px;
    transition: background-color 0.3s, transform 0.3s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: #e67e22;
    transform: scale(1.05);
}

button:active {
    transform: scale(1);
}

#score, #highScore {
    font-size: 24px;
    margin-top: 20px;
    font-weight: bold;
    color: #333;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}

/* Left and Right Controls */
/* Top Controls: Adjust spacing */
#top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 480px;
    padding: 5px;
    margin-top: 10px;
    gap: 10px; /* Adds consistent spacing */
}

#left-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

#right-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#pauseGame, #aboutGame {
    font-size: 16px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    #grid-container {
        width: 95%;
        padding: 10px;
    }

    .grid-cell {
        font-size: 16px;
    }

    #score, #highScore {
        font-size: 20px;
    }

    button {
        padding: 8px 16px;
        font-size: 14px;
    }

    #pauseGame, #aboutGame {
        font-size: 14px;
    }
}

/* Very Small Screens (Under 400px) */
@media (max-width: 400px) {
    #grid-container {
        grid-gap: 5px;
    }

    .grid-cell {
        font-size: 14px;
    }

    button {
        padding: 6px 10px;
        font-size: 12px;
    }

    #score, #highScore {
        font-size: 16px;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    padding-top: 60px;
}

/* Adjust Modal for Mobile */
.modal-content {
    width: 90%;
    padding: 15px;
    font-size: 14px;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

@media (max-width: 600px) {
    .modal-content {
        width: 90%;
    }
}
