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


#game-container {
    text-align: center;
    width: 100%;
    max-width: 480px;
    padding: 16px;
    box-sizing: border-box;
}

h1 {
    color: #776e65;
}


#score-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: bold;
    flex-wrap: wrap;
    gap: 8px;
}

#reverse-mode {
    color: red;
    font-weight: bold;
}

.hidden {
    display: none;
}


#board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
    gap: 10px;
    background-color: #bbada0;
    padding: 10px;
    border-radius: 10px;
    position: relative;
    width: 100%;
    max-width: 420px;
    aspect-ratio: 1 / 1;
    min-width: 220px;
    min-height: 220px;
    margin: 0 auto;
    box-sizing: border-box;
}

.cell {
    background-color: #cdc1b4;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5vw;
    font-weight: bold;
    color: #776e65;
    position: relative;
    min-width: 0;
    min-height: 0;
}

.tile {
    position: relative;
    width: 80%;
    height: 80%;
    box-sizing: border-box;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4vw;
    font-weight: bold;
    transition: transform 0.18s cubic-bezier(.4,1.4,.6,1), background 0.18s, box-shadow 0.18s;
    will-change: transform;
    min-width: 0;
    min-height: 0;
}

.tile-moving {
    z-index: 2;
}

.tile-merged {
    animation: merge-pop 0.22s cubic-bezier(.4,1.4,.6,1);
    z-index: 3;
}


@keyframes merge-pop {
    0% { transform: scale(1); box-shadow: 0 0 0 0 #fff0; }
    60% { transform: scale(1.18); box-shadow: 0 0 16px 2px #fff8; }
    100% { transform: scale(1); box-shadow: 0 0 0 0 #fff0; }
}

/* Responsividade para telas menores */
@media (max-width: 600px) {
    #game-container {
        max-width: 100vw;
        padding: 4vw;
    }
    #board {
        max-width: 98vw;
        min-width: 0;
        min-height: 0;
        aspect-ratio: 1 / 1;
    }
    .cell {
        font-size: 7vw;
    }
    .tile {
        font-size: 6vw;
    }
    h1 {
        font-size: 7vw;
    }
    #score-container {
        font-size: 5vw;
    }
    #combo-feedback {
        font-size: 5vw;
    }
    #restart, #how-to-play, #close-instructions {
        font-size: 5vw;
        padding: 2vw 4vw;
    }
    #instructions {
        max-width: 98vw;
        padding: 2vw;
    }
    #gameover-dialog {
        max-width: 98vw;
        padding: 2vw;
    }
}

@media (max-width: 400px) {
    #board {
        gap: 2vw;
        padding: 2vw;
    }
    .cell, .tile {
        font-size: 8vw;
    }
}

.tile-special-unstable {
    animation: unstable-shake 0.5s cubic-bezier(.4,1.4,.6,1) infinite alternate;
}
@keyframes unstable-shake {
    0% { transform: rotate(-2deg) scale(1.04); }
    100% { transform: rotate(2deg) scale(1.08); }
}

.tile-special-magnetic {
    animation: magnetic-pulse 0.7s cubic-bezier(.4,1.4,.6,1) infinite alternate;
}
@keyframes magnetic-pulse {
    0% { box-shadow: 0 0 0 0 #9c27b088; }
    100% { box-shadow: 0 0 16px 4px #9c27b088; }
}

/* Preview highlight antes de ativar efeito */
.cell-preview {
    box-shadow: inset 0 0 0 3px rgba(255,87,34,0.35);
    border-radius: 6px;
}
.tile-preview {
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* Explosão temporária (overlay) */
.explosion-effect {
    position: absolute;
    inset: 12% 12% 12% 12%;
    border-radius: 6px;
    background: radial-gradient(circle at 50% 40%, rgba(255,152,0,0.95), rgba(255,87,34,0.75) 40%, rgba(0,0,0,0) 70%);
    pointer-events: none;
    animation: explode-pop 420ms ease-out forwards;
}
@keyframes explode-pop {
    0% { transform: scale(0.6); opacity: 0.95; }
    60% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1.2); opacity: 0; }
}

/* Efeitos pós-ativação */
.tile-effect-magnetic {
    animation: magnetic-merge 420ms cubic-bezier(.2,.8,.2,1);
}
@keyframes magnetic-merge {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(156,39,176,0); }
    50% { transform: scale(1.18) rotate(-3deg); box-shadow: 0 0 22px 6px rgba(156,39,176,0.25); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(156,39,176,0); }
}

.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: 20px; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 20px; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 20px; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 18px; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 18px; }

.tile-special {
    font-size: 30px;
}

.tile-unstable { background-color: #ffeb3b; }
.tile-magnetic { background-color: #9c27b0; color: white; }


#combo-feedback {
    margin-top: 20px;
    font-size: 20px;
    color: #ff5722;
    font-weight: bold;
}

#special-legend {
    margin-top: 8px;
    padding: 12px;
    background: linear-gradient(180deg, #fffdfa, #f6f1ea);
    border: 1px solid #d6c9b8;
    border-radius: 8px;
    text-align: left;
    font-size: 14px;
    color: #333;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

#special-legend h4 {
    margin: 0 0 6px 0;
    font-size: 15px;
    color: #5b4b3b;
}

#special-legend p, #special-legend ul { margin: 6px 0; padding-left: 18px; }


#restart {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 16px;
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#restart:hover {
    background-color: #9f8a76;
}

#how-to-play {
    margin-bottom: 20px;
    padding: 10px 20px;
    font-size: 16px;
    background-color: #776e65;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#how-to-play:hover {
    background-color: #8f7a66;
}

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#modal-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

#instructions {
    background-color: white;
    border: 2px solid #bbada0;
    border-radius: 10px;
    padding: 20px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    width: 90%;
    margin: 0 auto;
}

#modal-overlay:not(.hidden) #instructions {
    transform: scale(1);
}

#instructions h2 {
    color: #776e65;
    margin-top: 0;
}

#instructions ul {
    margin: 10px 0;
    padding-left: 20px;
}

#close-instructions {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 16px;
    background-color: #776e65;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

#close-instructions:hover {
    background-color: #8f7a66;
}

#gameover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#gameover-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

#gameover-dialog {
    background-color: white;
    border: 2px solid #bbada0;
    border-radius: 10px;
    padding: 30px 24px 24px 24px;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    width: 90%;
}

#gameover-overlay:not(.hidden) #gameover-dialog {
    transform: scale(1);
}

#gameover-dialog h2 {
    color: #d32f2f;
    margin-top: 0;
}

#gameover-summary {
    margin: 18px 0 24px 0;
    font-size: 18px;
    color: #333;
}

#gameover-restart {
    padding: 10px 24px;
    font-size: 16px;
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
#gameover-restart:hover {
    background-color: #9f8a76;
}

/* Layout para telas largas em modo paisagem: board centralizado com informações nas laterais */
@media (min-width: 900px) and (orientation: landscape) {
    body {
        align-items: flex-start;
        padding: 40px 0;
    }
    #game-container {
        max-width: none;
        width: 100%;
        padding: 24px 40px;
        display: flex;
        flex-direction: column;
        align-items: center;
        box-sizing: border-box;
    }
    .layout {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 32px;
        width: 100%;
        max-width: 1400px;
        box-sizing: border-box;
    }
    .side {
        flex: 0 0 240px;
        max-width: 26%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    .side.left {
        align-items: flex-end;
        padding-right: 8px;
    }
    .side.right {
        align-items: flex-start;
        padding-left: 8px;
    }
    .center {
        flex: 0 1 520px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    #board {
        max-width: 620px;
        width: 100%;
        aspect-ratio: 1 / 1;
        padding: 14px;
        gap: 14px;
    }
     /* Aumenta o tamanho dos números nos tiles em telas grandes.
         Usa clamp() para escalar com a viewport mantendo limites razoáveis. */
     .cell { font-size: clamp(20px, 2.4vw, 56px); }
     .tile { font-size: clamp(18px, 2vw, 52px); }
    #score-container { text-align: right; }
    #combo-feedback { text-align: left; }
}