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

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

.container {
    width: 500px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 80px;
    font-weight: bold;
    color: #776e65;
}

.score-container {
    position: relative;
    background: #bbada0;
    padding: 15px 25px;
    font-size: 25px;
    height: 60px;
    line-height: 30px;
    font-weight: bold;
    border-radius: 3px;
    color: white;
    text-align: center;
}

.score-addition {
    position: absolute;
    right: 30px;
    color: rgba(119, 110, 101, 0.9);
    font-size: 25px;
    line-height: 25px;
    font-weight: bold;
    animation: score-animation 0.8s ease-in-out;
    z-index: 100;
}

@keyframes score-animation {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px);
    }
}

.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    width: 500px;
    height: 500px;
    padding: 15px;
    margin-bottom: 20px;
    box-sizing: border-box;
    border: 5px solid #bbada0;
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.game-message.game-over {
    display: flex;
    opacity: 1;
    animation: fade-in 0.8s ease;
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.game-message p {
    font-size: 60px;
    font-weight: bold;
    margin-bottom: 30px;
    animation: message-pop 0.5s ease 0.3s both;
}

@keyframes message-pop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.retry-button {
    background: #8f7a66;
    border-radius: 3px;
    padding: 10px 20px;
    color: white;
    text-decoration: none;
    cursor: pointer;
    font-weight: bold;
    animation: button-pop 0.5s ease 0.5s both;
}

@keyframes button-pop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.grid-container {
    position: absolute;
    z-index: 1;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    display: grid;
    grid-template-columns: repeat(4, 106.25px);
    grid-template-rows: repeat(4, 106.25px);
    grid-gap: 15px;
}

.grid-row {
    display: contents;
}

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

.tile-container {
    position: absolute;
    z-index: 2;
    top: 15px;
    left: 15px;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    display: grid;
    grid-template-columns: repeat(4, 106.25px);
    grid-template-rows: repeat(4, 106.25px);
    grid-gap: 15px;
}

.tile {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 3px;
    font-size: 55px;
    font-weight: bold;
    text-align: center;
    line-height: 106.25px;
    transition: all 0.15s ease-in-out;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 10;
    grid-column: var(--grid-column);
    grid-row: var(--grid-row);
}

.tile-1 {
    background: #eee4da;
    color: #776e65;
    border: 2px solid #d8d0c8;
}

.tile-2 {
    background: #ede0c8;
    color: #776e65;
    border: 2px solid #d8c8a0;
}

.tile-3 {
    background: #f2b179;
    color: white;
    border: 2px solid #e09a60;
}

.tile-6 {
    background: #f59563;
    color: white;
    border: 2px solid #e07e4a;
}

.tile-12 {
    background: #f67c5f;
    color: white;
}

.tile-24 {
    background: #f65e3b;
    color: white;
}

.tile-48 {
    background: #edcf72;
    color: white;
}

.tile-96 {
    background: #edcc61;
    color: white;
}

.tile-192 {
    background: #edc850;
    color: white;
}

.tile-384 {
    background: #edc53f;
    color: white;
}

.tile-768 {
    background: #edc22e;
    color: white;
}

.tile-1536 {
    background: #3c3a32;
    color: white;
}

.tile-3072 {
    background: #3c3a32;
    color: white;
}

.instructions {
    text-align: center;
    margin-top: 20px;
    line-height: 1.5;
}

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

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

@keyframes move {
    0% {
        transform: translate(0, 0) scale(1);
    }
    50% {
        transform: translate(var(--move-x, 0), var(--move-y, 0)) scale(1.05);
    }
    100% {
        transform: translate(0, 0) scale(1);
    }
}

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

.tile-merged {
    animation: pop 0.2s ease;
}

.tile-moved {
    animation: move 0.15s ease-in-out;
}

/* Media queries per dispositivi mobili */
@media screen and (max-width: 520px) {
    .container {
        width: 100%;
        padding: 10px;
        box-sizing: border-box;
    }
    
    h1 {
        font-size: 50px;
    }
    
    .score-container {
        padding: 10px 15px;
        font-size: 18px;
        height: 45px;
        line-height: 25px;
    }
    
    .game-container {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
        padding: 10px;
    }
    
    .grid-container {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        grid-gap: 10px;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(4, 1fr);
    }
    
    .grid-cell {
        width: 100%;
        height: 0;
        padding-bottom: 100%;
    }
    
    .tile-container {
        top: 10px;
        left: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
        grid-gap: 10px;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(4, 1fr);
    }
    
    .tile {
        font-size: 35px;
        line-height: normal;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .game-message p {
        font-size: 40px;
    }
    
    .instructions {
        font-size: 14px;
        margin-top: 15px;
    }
}

/* Media queries per dispositivi molto piccoli */
@media screen and (max-width: 350px) {
    h1 {
        font-size: 40px;
    }
    
    .score-container {
        padding: 8px 12px;
        font-size: 16px;
        height: 40px;
        line-height: 24px;
    }
    
    .tile {
        font-size: 28px;
    }
    
    .game-message p {
        font-size: 32px;
    }
} 