body {
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #faf8ef;
    font-family: 'Arial', sans-serif; /* You can use your preferred font */
}

.container {
    width: fit-content; /* Adjust width based on content */
    margin: auto;
}

.game-area {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

.board-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 500px; /* Match board width */
    margin-bottom: 20px;
}

.button-new-game {
    background-color: #8f7a66; /* Color for the button */
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 18px;
}

.score-tab {
    background-color: #bbada0; /* Color for the score tab */
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-weight: bold;
    font-size: 18px;
    min-width: 100px; /* Adjust as needed */
    text-align: center;
}

#game-container {
    text-align: center;
    position: relative;
    display: inline-block;
}

.control-panel {
    background: #f3e6d4;
    border-radius: 10px;
    padding: 20px;
    width: 260px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.control-panel h2 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 22px;
    color: #776e65;
}

.control-section {
    margin-bottom: 20px;
}

.control-label {
    margin: 0 0 8px;
    font-weight: bold;
    color: #8f7a66;
}

.control-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    color: #776e65;
}

.control-option input[type="radio"] {
    accent-color: #8f7a66;
    margin-top: 3px;
}

.control-option small {
    font-size: 12px;
    color: #9b8b7f;
}

.control-option > span {
    min-width: 0;  /* let long option notes wrap inside the panel */
}

.control-option .option-note {
    display: block;
    margin-top: 2px;
    line-height: 1.35;
}

.button-auto-play {
    width: 100%;
    padding: 10px 16px;
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.button-auto-play:hover {
    background-color: #7c6956;
}

.button-auto-play.is-active {
    background-color: #5c9570;
}

.button-auto-play.is-active:hover {
    background-color: #4e815f;
}

.control-status {
    min-height: 24px;
    margin-top: 12px;
    font-size: 14px;
    color: #776e65;
}

.control-status.warning {
    color: #c46b47;
}

.control-status.success {
    color: #5c9570;
}

.control-status.info {
    color: #6b6b6b;
}

.grid {
    display: inline-block;
    position: relative;
    background-color: #bbada0;
    padding: 10px;
    border-radius: 10px;
    box-sizing: border-box;
}

.grid-row {
    display: flex;
}

.grid-cell {
    width: 90px;
    height: 90px;
    margin: 5px;
    border-radius: 5px;
    background: rgba(238, 228, 218, 0.35);
}

.tile-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    --tile-size: 90px;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 32px;
    border-radius: 5px;
    translate: var(--x, 0px) var(--y, 0px); /* separate from the pop animations, which use transform */
    transition: translate 0.18s ease-in-out;
    will-change: translate;
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
    z-index: 2;
}

.tile.tile-128,
.tile.tile-256,
.tile.tile-512 {
    font-size: 28px;
}

.tile.tile-1024,
.tile.tile-2048,
.tile.tile-super {
    font-size: 24px;
}

.tile-new {
    animation: tileAppear 0.2s ease;
}

.tile-merged {
    animation: tileMerge 0.25s ease;
}

@keyframes tileAppear {
    from {
        transform: scale(0.3);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes tileMerge {
    0% {
        transform: scale(0.85);
    }
    60% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Tile colors */
.tile.tile-2 {
    background-color: #eee4da;
    color: #776e65;
}

.tile.tile-4 {
    background-color: #ede0c8;
    color: #776e65;
}

.tile.tile-8 {
    background-color: #f2b179;
    color: #f9f6f2;
}

.tile.tile-16 {
    background-color: #f59563;
    color: #f9f6f2;
}

.tile.tile-32 {
    background-color: #f67c5f;
    color: #f9f6f2;
}

.tile.tile-64 {
    background-color: #f65e3b;
    color: #f9f6f2;
}

.tile.tile-128 {
    background-color: #edcf72;
    color: #f9f6f2;
}

.tile.tile-256 {
    background-color: #edcc61;
    color: #f9f6f2;
}

.tile.tile-512 {
    background-color: #edc850;
    color: #f9f6f2;
}

.tile.tile-1024 {
    background-color: #edc53f;
    color: #f9f6f2;
}

.tile.tile-2048 {
    background-color: #edc22e;
    color: #f9f6f2;
}

.tile.tile-super {
    background-color: #3c3a32;
    color: #f9f6f2;
}

@media (max-width: 900px) {
    body {
        align-items: flex-start;
    }

    .container {
        margin-top: 40px;
    }

    .game-area {
        flex-direction: column;
        align-items: center;
    }

    .control-panel {
        box-sizing: border-box;
        width: 100%;
        max-width: 500px;
    }

    .board-area {
        width: 100%;
        align-items: center;
    }

    .header {
        max-width: none;
    }
}


.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.5); /* Semi-transparent overlay */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 36px;
    color: #776e65;
    animation: fadeIn 0.5s;
    z-index: 3;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.new-game-button {
    padding: 10px;
    margin-top: 20px;
    border-radius: 5px;
    border: none;
    background-color: #8f7a66;
    color: white;
    font-size: 18px;
    cursor: pointer;
}

/* Phones: scale the board to the screen, with a 16px margin each side */
@media (max-width: 480px) {
    .container {
        box-sizing: border-box;
        width: 100%;
        padding: 0 16px 24px;
    }

    .grid-cell {
        width: calc((100vw - 92px) / 4);
        height: calc((100vw - 92px) / 4);
    }

    .tile { font-size: 26px; }
    .tile.tile-128, .tile.tile-256, .tile.tile-512 { font-size: 22px; }
    .tile.tile-1024, .tile.tile-2048, .tile.tile-super { font-size: 18px; }
}
