* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

.game-container {
    text-align: center;
    max-width: 540px;
    width: 100%;
    padding: 20px;
}

.header {
    margin-bottom: 20px;
}

h1 {
    font-size: 48px;
    color: #776e65;
    margin-bottom: 10px;
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

.score, .moves {
    font-size: 24px;
    color: #776e65;
    background-color: #bbada0;
    padding: 10px 20px;
    border-radius: 3px;
    color: white;
}

.new-game-btn {
    background-color: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 10px 20px;
    font-size: 18px;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.new-game-btn:hover {
    background-color: #9f8a76;
}

.grid-container {
    position: relative;
    background-color: #bbada0;
    border-radius: 6px;
    width: 450px;
    height: 450px;
    margin: 0 auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
}

.grid-cell {
    background-color: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 3px;
    font-size: 48px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: left 0.15s ease-in-out, top 0.15s ease-in-out, transform 0.15s ease-in-out;
    line-height: 1;
    z-index: 10;
}

.tile-2 { background-color: #eee4da; color: #776e65; }
.tile-4 { background-color: #ede0c8; color: #776e65; }
.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: 40px; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 40px; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 40px; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 32px; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 32px; }

.tile-new {
    animation: appear 0.2s ease-in-out;
    z-index: 20;
}

.tile-merged {
    animation: merge 0.2s ease-in-out;
    z-index: 30;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes merge {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.73);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.game-over-text {
    font-size: 72px;
    color: #776e65;
    font-weight: bold;
}

.instructions {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 999;
    transition: opacity 0.3s ease-out;
}

.instructions p {
    color: white;
    font-size: 36px;
    text-align: center;
    line-height: 1.5;
    margin: 10px 0;
}

.instructions.hidden {
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 600px) {
    .grid-container {
        width: 320px;
        height: 320px;
        gap: 8px;
        padding: 8px;
    }
    
    .tile {
        width: 70px;
        height: 70px;
        font-size: 32px;
        transition: left 0.15s ease-in-out, top 0.15s ease-in-out, transform 0.15s ease-in-out;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 28px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 24px;
    }
    
    h1 {
        font-size: 36px;
    }
    
    .score, .moves {
        font-size: 18px;
        padding: 8px 16px;
    }
}