* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

/* Adicione isto ao body para evitar comportamento de "puxar para atualizar" no mobile */
body {
    font-family: 'Poppins', sans-serif;
    background-color: #faf8ef;
    color: #776e65;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    flex-direction: column;
    overscroll-behavior: none; 
}

.container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative; /* Importante para os modais */
}

header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    align-items: center;
}

.heading h1 {
    font-size: 48px;
    font-weight: 700;
    color: #776e65;
    line-height: 1;
}

.heading p {
    font-size: 14px;
}

.scores {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.score-box {
    background: #bbada0;
    padding: 5px 15px;
    border-radius: 5px;
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    min-width: 80px;
}

.score-box span {
    display: block;
    font-size: 20px;
}

/* Botões do Topo */
.top-buttons {
    display: flex;
    gap: 5px;
}

button {
    background: #8f7a66;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

button:hover {
    background: #7f6a56;
}

button.btn-help {
    background: #e6c55f; /* Cor diferente para Ajuda */
    color: #fff;
}

/* O TABULEIRO */
#board {
    width: 400px;
    height: 400px;
    background-color: #bbada0;
    border: 6px solid #bbada0;
    border-radius: 6px;
    display: flex;
    flex-wrap: wrap;
    position: relative;
    /* BLOQUEIA O SCROLL DO NAVEGADOR DENTRO DO JOGO */
    touch-action: none;
}

.tile {
    width: 90px;
    height: 90px;
    border: 5px solid transparent;
    margin: 3.5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    font-weight: bold;
    color: #776e65;
    background-color: #cdc1b4;
    border-radius: 5px;
}

/* Cores dos Números */
.x2 { background-color: #eee4da; color: #776e65; }
.x4 { background-color: #ede0c8; color: #776e65; }
.x8 { background-color: #f2b179; color: #f9f6f2; }
.x16 { background-color: #f59563; color: #f9f6f2; }
.x32 { background-color: #f67c5f; color: #f9f6f2; }
.x64 { background-color: #f65e3b; color: #f9f6f2; }
.x128, .x256, .x512 { background-color: #edcf72; color: #f9f6f2; font-size: 30px; }
.x1024, .x2048 { background-color: #edc53f; color: #f9f6f2; font-size: 24px; }
.x4096 { background-color: black; color: white; font-size: 24px; }

/* MODAIS (Game Over e Ajuda) - CORREÇÃO AQUI */
.modal-overlay {
    position: absolute;
    background: rgba(238, 228, 218, 0.9); /* Fundo semi-transparente */
    width: 100%;
    height: 100%;
    top: 0; 
    left: 0;
    display: none; /* Padrão: ESCONDIDO */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 6px;
    text-align: center;
    padding: 20px;
    animation: fadeIn 0.3s;
}

/* Classe para mostrar o modal */
.modal-overlay.show {
    display: flex; 
}

.modal-overlay h2 {
    font-size: 30px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #776e65;
}

.modal-overlay ul {
    text-align: left;
    margin-bottom: 20px;
    list-style: none;
    font-size: 16px;
    color: #555;
}

.modal-overlay li {
    margin-bottom: 8px;
}

.adsense-container {
    margin-top: 20px;
    width: 100%;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Responsividade Mobile */
@media (max-width: 450px) {
    #board {
        width: 320px;
        height: 320px;
    }
    .tile {
        width: 72px;
        height: 72px;
        font-size: 28px;
        margin: 2px;
    }
    .heading h1 { font-size: 36px; }
    .heading p { display: none; } /* Esconde subtítulo no mobile pra economizar espaço */
}
