@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;700&display=swap');

:root {
    --laranja: #ff8a3d;
    --azul-ceu: #a5d8ff;
    --verde: #2ecc71;
    --vermelho: #ff7675;
    --roxo: #a29bfe;
    --amarelo-estrela: #f1c40f;

    --painel-borda: rgba(255,255,255,0.85);
    --sombra: 0 14px 30px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; }

html, body { overscroll-behavior: none; }

body {
    font-family: 'Fredoka', sans-serif;
    margin: 0;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
}

@supports (height: 100svh) { body { height: 100svh; } }

.controles-inferiores { transform: translateZ(0); will-change: transform; }

/* --- TELAS DE SOBREPOSIÇÃO --- */
.overlay {
    position: fixed; inset: 0; z-index: 200;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 15px;
    background: rgba(165, 216, 255, 0.4);
    backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
    transition: 0.5s; overflow-y: auto;
}

.card-info {
    background: white; border: 8px solid var(--laranja);
    border-radius: 40px; padding: 25px;
    max-width: 520px; width: min(95vw, 520px);
    box-shadow: var(--sombra); margin: auto;
}

/* --- MENU INICIAL: OPÇÕES --- */
.opcoes-container {
    background: rgba(0,0,0,0.03); border-radius: 20px;
    padding: 15px; margin-bottom: 15px; border: 2px dashed #ccc;
}
.titulo-secao { font-size: 1rem; color: var(--roxo); margin: 0 0 10px 0; font-weight: bold; }

.grid-botoes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 15px; }
.grid-botoes.tres { grid-template-columns: 1fr 1fr 1fr; margin-bottom: 0; }

.btn-opcao {
    background: white; border: 3px solid #eee; border-radius: 12px;
    padding: 8px 4px; font-family: 'Fredoka'; font-weight: bold; font-size: 0.90rem;
    cursor: pointer; color: #555; transition: 0.2s;
}
.btn-opcao.ativo { border-color: var(--laranja); background: #fff3eb; color: var(--laranja); transform: scale(1.05); }
.btn-opcao.modo-ativo { border-color: var(--roxo); background: #f0e6ff; color: var(--roxo); transform: scale(1.05); }

/* --- TOPO RESPONSIVO CENTRALIZADO --- */
.topo {
    width: 100%; padding: 12px 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    background: rgba(255, 255, 255, 0.92); z-index: 10;
    box-shadow: 0 8px 22px rgba(0,0,0,0.08); gap: 10px;
}
.topo-esquerda { justify-self: start; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.topo-direita { justify-self: end; text-align: right; }

.btn-sair, .btn-modo-voltar {
    text-decoration: none; color: white; padding: 8px 18px;
    border-radius: 50px; font-weight: bold; font-size: 0.9rem; margin: 2px;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; user-select: none;
}
.btn-sair { background: var(--vermelho); }
.btn-modo-voltar { background: var(--roxo); cursor: pointer; border: none; font-family: 'Fredoka'; }

/* BARRA DE PROGRESSO / TEMPO */
.area-progresso { justify-self: center; display: flex; flex-direction: column; align-items: center; width: 100%; min-width: 250px; }
.texto-progresso { font-size: 0.85rem; font-weight: bold; color: var(--roxo); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px; }
.progresso-container {
    width: 100%; max-width: 300px; height: 18px; background-color: #e1e8ed;
    border: 3px solid white; border-radius: 20px; overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1) inset, 0 2px 4px rgba(0,0,0,0.05);
}
.progresso-barra {
    height: 100%; width: 0%; background: var(--verde); border-radius: 20px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.5s;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.15);
}
.progresso-barra.urgente { background: var(--vermelho); animation: piscar 1s infinite; }

/* MELHORIA MOBILE: Deixa o topo em linha e ajusta tamanhos */
@media (max-width: 850px) {
    .topo { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; padding: 8px; justify-content: space-between; }
    .topo-esquerda { width: auto; order: 1; }
    .topo-direita { width: auto; order: 2; }
    .area-progresso { order: 3; width: 100%; margin-top: 5px; }
    .progresso-container { max-width: 100%; }
    .grid-botoes.tres { grid-template-columns: 1fr; }
}

/* --- ÁREA DO JOGO --- */
#game-container {
    margin-top: 8px; width: 100%; flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column; align-items: center; z-index: 5;
    overflow: auto; -webkit-overflow-scrolling: touch;
    /* Reduzindo o padding lateral para dar mais espaço ao tabuleiro */
    padding: 5px 5px calc(90px + env(safe-area-inset-bottom));
}

.painel-memoria {
    /* Aumentei de 720px para 960px para usar mais a lateral em monitores */
    width: min(98vw, 960px); 
    background: rgba(255, 255, 255, 0.92);
    border: 6px solid var(--painel-borda); border-radius: 20px;
    padding: clamp(10px, 2.5vw, 24px); 
    box-shadow: 0 16px 0 rgba(0,0,0,0.08); overflow: hidden;
}

.grid-memoria {
    --cols: 4; 
    /* Aumentei o tamanho máximo de 115px para 160px aqui também */
    --card-size: clamp(45px, 22vw, 160px); 
    --emoji-size: clamp(28px, 8vw, 65px); 
    --back-icon-size: clamp(32px, 12vw, 90px);
    display: grid; gap: clamp(6px, 1.5vw, 14px); 
    perspective: 1000px; width: 100%;
    grid-template-columns: repeat(var(--cols), var(--card-size));
    grid-auto-rows: var(--card-size); justify-content: center; align-items: center;
}

.carta {
    position: relative; transform-style: preserve-3d; transition: transform 0.45s cubic-bezier(.2,.9,.2,1);
    cursor: pointer; border-radius: 18px; width: var(--card-size); height: var(--card-size); touch-action: manipulation;
}
.carta:active { transform: scale(0.98); }
.carta.virada { transform: rotateY(180deg); }
.carta.combinada { cursor: default; }

.face {
    position: absolute; inset: 0; backface-visibility: hidden; display: flex; justify-content: center;
    align-items: center; font-size: var(--emoji-size); border-radius: 18px; box-shadow: 0 10px 18px rgba(0,0,0,0.10);
}
.face.costas {
    color: white; border: 3px solid rgba(255,255,255,0.95);
    background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.18), transparent 45%),
                radial-gradient(circle at 70% 75%, rgba(255,255,255,0.16), transparent 48%),
                linear-gradient(135deg, #6c5ce7 0%, #a29bfe 45%, #fd79a8 100%);
}
.icone-costas-img {
    width: var(--back-icon-size); height: auto; display: block;
    filter: drop-shadow(0 10px 18px rgba(0,0,0,0.28)); transform: translateY(-1px); pointer-events: none; user-select: none;
}
.face.frente { background: white; transform: rotateY(180deg); color: #333; border: 3px solid rgba(162, 155, 254, 0.9); }

.carta:not(.combinada):hover .face.costas { transform: translateY(-1px); }
.carta.combinada .face.frente { border-color: var(--verde); background: #e8f5e9; }

.carta.combinada.brilho { animation: brilhar 0.7s ease-out; z-index: 10; }
.carta.combinada.brilho .face.frente { box-shadow: 0 0 20px rgba(46, 204, 113, 0.6) inset, 0 0 30px rgba(46, 204, 113, 0.8); border-color: var(--verde); }

@keyframes brilhar {
    0% { transform: rotateY(180deg) scale(0.96); filter: brightness(1); }
    40% { transform: rotateY(180deg) scale(1.15); filter: brightness(1.2); }
    100% { transform: rotateY(180deg) scale(1); filter: brightness(1); }
}

.carta.erro { animation: shake 320ms ease; }
@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-5px); }
    50% { transform: rotateY(180deg) translateX(5px); }
    75% { transform: rotateY(180deg) translateX(-3px); }
}

/* --- STATUS INFERIOR --- */
.status-inferior {
    display: flex; gap: 20px; margin-top: 15px; background: rgba(255, 255, 255, 0.92);
    padding: 10px 24px; border-radius: 20px; box-shadow: 0 8px 16px rgba(0,0,0,0.08);
    font-weight: bold; font-size: 1.1rem; color: var(--roxo); border: 3px solid var(--painel-borda); justify-content: center;
    flex-wrap: wrap; text-align: center;
}
.status-inferior span { color: #333; }

/* --- ESTRELAS E CONFETES --- */
.estrelas-container { display: flex; justify-content: center; gap: 10px; margin: 15px 0; font-size: 3rem; }
.estrela { color: #ddd; transition: 0.5s; text-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.estrela.ganha { color: var(--amarelo-estrela); transform: scale(1.2) rotate(15deg); animation: popEstrela 0.5s ease backwards; }
@keyframes popEstrela { 0% { transform: scale(0) rotate(-45deg); opacity: 0; } 100% { transform: scale(1.2) rotate(15deg); opacity: 1; } }

.confete { position: fixed; top: -10px; width: 12px; height: 12px; z-index: 9999; animation: cairConfete linear forwards; }
@keyframes cairConfete { to { transform: translateY(110vh) rotate(720deg); } }

/* --- BOTÕES DIFICULDADE E MENUS --- */
.btn-dif {
    display: block; width: 100%; padding: 12px; margin: 8px 0; border: none; border-radius: 15px;
    color: white; font-size: 1.1rem; font-weight: bold; cursor: pointer; font-family: 'Fredoka'; box-shadow: 0 6px 0 rgba(0,0,0,0.12);
}
.btn-dif:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.12); }
.btn-verde { background: var(--verde); } .btn-laranja { background: var(--laranja); } .btn-vermelho { background: var(--vermelho); }

.controles-inferiores { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); right: calc(18px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 12px; z-index: 100; }
.btn-circular {
    width: 60px; height: 60px; border-radius: 50%; border: 4px solid white; cursor: pointer; font-size: 1.6rem;
    display: flex; align-items: center; justify-content: center; box-shadow: 0 12px 22px rgba(0,0,0,0.18); background: white; user-select: none;
}
.btn-som.ativo, .btn-musica.ativo { background: var(--verde); color: white; }

#toast {
    position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(0,0,0,0.75); color: white;
    padding: 10px 14px; border-radius: 14px; font-size: 0.95rem; z-index: 5000; opacity: 0; pointer-events: none; transition: opacity 220ms ease, transform 220ms ease; max-width: min(92vw, 520px);
}
#toast.mostrar { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* Tutorial e Textos Estilo Específico */
.lista-tutorial { color: #555; text-align: left; padding-left: 20px; line-height: 1.5; margin-top: 10px; font-size: 1rem; }
.lista-tutorial li { margin-bottom: 10px; }