body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #faf8ef;
    color: #776e65;
    margin: 0;
}

.game-container {
    text-align: center;
}

.score-container {
    font-size: 1.5em;
    margin-bottom: 15px;
}

.grid-container {
    position: relative; /* Needed for game-over overlay */
    width: 400px; /* Adjust size as needed */
    height: 400px; /* Adjust size as needed */
    margin: 0 auto; /* Center the grid */
}

#game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px; /* Spacing between cells */
    background-color: #bbada0; /* Grid background */
    border-radius: 6px;
    padding: 10px;
    box-sizing: border-box; /* Include padding in width/height */
    width: 100%;
    height: 100%;
}

.grid-cell {
    background-color: rgba(238, 228, 218, 0.35); /* Empty cell color */
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em; /* Default font size */
    font-weight: bold;
    box-sizing: border-box;
    /* Transition for smoother appearance (optional) */
    /* transition: all 0.1s ease-in-out; */
}

/* Tile Styles - Add more as needed */
.tile {
    color: #776e65; /* Default text color */
}

.tile-2 { background-color: #eee4da; }
.tile-4 { background-color: #ede0c8; }
.tile-8 { background-color: #f2b179; color: #f9f6f2; }
.tile-16 { background-color: #f59563; color: #f9f6f2; }
.tile-32 { background-color: #f67c5f; color: #f9f6f2; }
.tile-64 { background-color: #f65e3b; color: #f9f6f2; }
.tile-128 { background-color: #edcf72; color: #f9f6f2; font-size: 1.8em; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 1.8em; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 1.8em; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 1.5em; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 1.5em; }
/* Higher tiles */
.tile-4096 { background-color: #3c3a32; color: #f9f6f2; font-size: 1.5em; }
.tile-8192 { background-color: #3c3a32; color: #f9f6f2; font-size: 1.5em; }


#game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(238, 228, 218, 0.73); /* Semi-transparent overlay */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    z-index: 10; /* Make sure it's on top */
    text-align: center;
}

#game-over h2 {
    font-size: 3em;
    color: #776e65;
    margin: 0;
}
#game-over p {
     font-size: 1.5em;
     margin-top: 10px;
}

#try-again-button, #reset-button {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 1.2em;
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
#try-again-button:hover, #reset-button:hover {
     background-color: #9f8b77;
}

.hidden {
    display: none !important; /* Use !important to override other display properties */
}

.instructions {
    margin-top: 15px;
    font-size: 0.9em;
    color: #776e65;
}

/* NEW: On-screen Control Button Styles */
.controls-container {
    margin-top: 25px;
    display: grid;
    grid-template-columns: repeat(3, 65px); /* Adjust button size */
    grid-template-rows: repeat(2, 65px);    /* Adjust button size */
    gap: 8px;
    justify-content: center; /* Center the grid */
    /* Hide on larger screens if desired (optional) */
    /* @media (min-width: 768px) {
        display: none;
    } */
}

.control-button {
    font-size: 1.8em;
    font-weight: bold;
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: flex; /* For centering text */
    justify-content: center;
    align-items: center;
    /* Prevent text selection on rapid taps */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    /* Improve tap feedback on touch devices */
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
}

.control-button:hover {
    background-color: #9f8b77;
}
.control-button:active { /* Style for when button is pressed */
    background-color: #776e65;
}


/* Position individual buttons within the grid */
#button-up { grid-column: 2 / 3; grid-row: 1 / 2; }
#button-left { grid-column: 1 / 2; grid-row: 2 / 3; }
#button-down { grid-column: 2 / 3; grid-row: 2 / 3; }
#button-right { grid-column: 3 / 4; grid-row: 2 / 3; }


/* Optional: Slightly smaller controls on very small screens */
@media (max-width: 420px) {
    .controls-container {
        grid-template-columns: repeat(3, 55px);
        grid-template-rows: repeat(2, 55px);
        gap: 5px;
    }
    .control-button {
        font-size: 1.5em;
    }
}