@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;700&display=swap');

:root {
  --azul-ceu: #87CEEB;
  --laranja: #ff9800;
  --btn-vermelho: #ff7675;
  --btn-vermelho-escuro: #c0392b;
  --btn-verde: #2ecc71;
  --btn-verde-escuro: #1e8449;
  --btn-azul: #0984e3;
  --btn-azul-escuro: #074b83;
  --azul-tile: #6c5ce7;
  --azul-tile-escuro: #4834d4;
  --cinza: #2d3436;
}

body {
  font-family: 'Fredoka', sans-serif;
  margin: 0;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.intro-blur {
  filter: blur(20px);
  transition: filter .8s;
}

/* Cabeçalho Novo Centralizado */
header {
  background: rgba(255,255,255,.95);
  width: 100%;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 15px rgba(0,0,0,.1);
  box-sizing: border-box;
  position: relative; /* Necessário para a centralização absoluta do título */
}

.header-grupo-botoes {
  display: flex;
  gap: 10px;
  z-index: 2; /* Fica acima do título se houver sobreposição em telas muito pequenas */
}

.header-hud {
  display: flex;
  gap: 15px;
  align-items: center;
  z-index: 2;
}

#info-nivel {
  color: var(--azul-tile);
  font-weight: bold;
  font-size: 1.2rem;
  text-align: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 1;
}

/* Botões Padrão do Cabeçalho */
.btn-header {
  cursor: pointer;
  padding: 10px 18px;
  border-radius: 50px;
  border: none;
  color: white;
  font-weight: bold;
  font-family: 'Fredoka';
  font-size: .9rem;
  user-select: none;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-header:active { transform: translateY(4px); box-shadow: 0 0 0 transparent !important; }

.btn-verde { background: var(--btn-verde); box-shadow: 0 4px 0 var(--btn-verde-escuro); }
.btn-vermelho { background: var(--btn-vermelho); box-shadow: 0 4px 0 var(--btn-vermelho-escuro); }
.btn-azul { background: var(--btn-azul); box-shadow: 0 4px 0 var(--btn-azul-escuro); }

.btn-verde-grande {
  padding: 15px 40px;
  font-size: 1.5rem;
  background: var(--btn-verde);
  box-shadow: 0 4px 0 var(--btn-verde-escuro);
}

/* HUD (Pontos + Sequência + Tempo) */
#hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  line-height: 1.05;
  white-space: nowrap;
  min-width: 120px;
}
#hud-right .pontos { font-weight: bold; font-size: 1.05rem; color: var(--cinza); }
#hud-right .pontos span { color: var(--laranja); }

#hud-tempo {
  font-weight: bold; font-size: 1.1rem; color: var(--btn-vermelho);
  animation: pulseTimer 1s infinite alternate;
}
@keyframes pulseTimer { from { transform: scale(1); } to { transform: scale(1.05); } }

#seq-wrap {
  font-weight: 700; font-size: .92rem; color: #1f2a33; padding: 4px 10px;
  border-radius: 999px; background: rgba(108,92,231,.12); border: 2px solid rgba(108,92,231,.25);
  transform-origin: 100% 50%;
}
#seq-wrap b { color: var(--azul-tile); }
.combo-pop { animation: comboPop .22s ease-out; }
@keyframes comboPop { 0% { transform: scale(1); } 55% { transform: scale(1.18); } 100% { transform: scale(1); } }
.combo-glow { box-shadow: 0 0 0 0 rgba(46,204,113,.0); animation: comboGlow .55s ease-out; }
@keyframes comboGlow { 0% { box-shadow: 0 0 0 0 rgba(46,204,113,.0); } 35% { box-shadow: 0 0 22px 6px rgba(46,204,113,.35); } 100% { box-shadow: 0 0 0 0 rgba(46,204,113,.0); } }

/* Menus e Modais */
#menu-niveis, #como-jogar, #sobre-o-jogo {
  position: fixed; inset: 0; background: rgba(44,62,80,.95); backdrop-filter: blur(10px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 2000;
}

.menu-caixa {
  background: white; padding: 25px; border-radius: 35px; border: 8px solid var(--laranja);
  width: 90%; max-width: 850px; text-align: center; max-height: 90vh; overflow-y: auto; box-sizing: border-box;
}

.titulo-etapa { color: #576574; font-size: 1.1rem; margin: 15px 0 10px 0; text-transform: uppercase; letter-spacing: 1px; }

/* Botões de Seleção de Modo */
.seletor-modo { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.btn-modo {
  padding: 10px 20px; border-radius: 20px; border: 3px solid #dfe4ea; background: #f1f2f6;
  font-family: 'Fredoka'; font-weight: bold; cursor: pointer; color: #576574; transition: 0.2s;
}
.btn-modo.ativo { background: var(--laranja); color: white; border-color: #e67e22; box-shadow: 0 4px 0 #d35400; }

.grade-niveis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; padding: 15px; }
.secao-nivel { background: #f1f2f6; padding: 12px; border-radius: 20px; border: 3px solid #dfe4ea; }
.secao-nivel h3 { margin: 5px 0 12px 0; color: #576574; }

.btn-nivel {
  width: 100%; padding: 12px; margin: 5px 0; font-size: 1rem; cursor: pointer; border: none;
  border-radius: 12px; background: var(--azul-tile); color: white; font-family: 'Fredoka';
  box-shadow: 0 4px 0 var(--azul-tile-escuro); user-select: none; transition: transform 0.1s, box-shadow 0.1s;
}
.btn-nivel:active { transform: translateY(4px); box-shadow: 0 0 0 var(--azul-tile-escuro); }
.btn-nivel.concluido { background: var(--btn-verde) !important; box-shadow: 0 4px 0 var(--btn-verde-escuro) !important; }

#area-jogo {
  position: relative; width: 98vw; height: calc(100dvh - 92px); height: calc(100vh - 92px);
  margin-top: 10px; z-index: 10; overflow: hidden;
}

/* Cartas */
.carta {
  position: absolute; width: clamp(85px, 13vw, 120px); height: clamp(55px, 9vw, 80px);
  background: white; color: #2d3436; display: flex; justify-content: center; align-items: center;
  border-radius: 18px; cursor: grab; font-size: clamp(1rem, 2vw, 1.4rem); font-weight: bold;
  box-shadow: 0 8px 0 var(--azul-tile), 0 12px 15px rgba(0,0,0,.15); user-select: none;
  border: 3px solid var(--azul-tile); text-align: center; touch-action: none; -webkit-user-select: none;
  padding: 0 6px; box-sizing: border-box; transition: transform 0.1s, box-shadow 0.1s;
}
.carta:active {
  cursor: grabbing; transform: translateY(8px) scale(1.05) !important;
  box-shadow: 0 0px 0 var(--azul-tile), 0 4px 6px rgba(0,0,0,.2) !important; z-index: 500;
}
.carta.res { border-color: var(--laranja); background: #fffcf0; }
.acertou { transform: scale(0) !important; transition: .5s; pointer-events: none; opacity: 0; }

.carta.match { animation: matchPulse .28s ease-out; box-shadow: 0 0 24px rgba(46,204,113,.35), 0 6px 0 rgba(0,0,0,.1); border-color: var(--btn-verde); }
@keyframes matchPulse { 0% { transform: scale(1); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }

.carta.wrong { border-color: var(--btn-vermelho); animation: wrongShake .22s ease-out; }
@keyframes wrongShake { 0% { transform: translateX(0); } 25% { transform: translateX(-6px); } 55% { transform: translateX(6px); } 80% { transform: translateX(-4px); } 100% { transform: translateX(0); } }

.sparkle {
  position: absolute; pointer-events: none; font-size: 18px; opacity: 0;
  transform: translate(0,0) scale(.6); animation: sparkleFly .55s ease-out forwards;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,.18));
}
@keyframes sparkleFly { 0% { opacity: 0; transform: translate(0,0) scale(.6); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.2); } }

.controles-fixos { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 2100; padding-bottom: env(safe-area-inset-bottom); }
.btn-circular {
  width: 60px; height: 60px; border-radius: 50%; border: none; background: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  box-shadow: 0 4px 15px rgba(0,0,0,.2); user-select: none; transition: transform 0.1s;
}
.btn-circular:active { transform: translateY(4px); }
.btn-circular.ativo { background: var(--btn-verde); color: white; }

#vitoria, #game-over { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 3000; align-items: center; justify-content: center; }

/* Tutorial Setup */
.tutorial-caixa { background: white; padding: 40px; border-radius: 40px; border: 8px solid var(--laranja); width: 90%; max-width: 600px; text-align: center; position: relative; box-sizing: border-box; }
.tutorial-ilustracao { display: flex; justify-content: center; align-items: center; gap: 30px; margin: 40px 0; position: relative; }
.tutorial-card { width: 140px; height: 100px; border: 4px solid var(--azul-tile); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 3rem; font-weight: bold; color: var(--azul-tile); user-select: none; }
.mao-zinha { position: absolute; font-size: 4rem; animation: deslizarMao 2s infinite ease-in-out; pointer-events: none; z-index: 5; }
@keyframes deslizarMao { 0% { transform: translate(-80px,0); opacity: 0; } 20% { opacity: 1; } 80% { transform: translate(80px,0); opacity: 1; } 100% { transform: translate(80px,0); opacity: 0; } }

/* Responsividade Básica */
@media (max-width: 768px) {
  #info-nivel { display: none; } /* Oculta o título central em telas menores para não encavalar nos botões */
}

@media (max-width: 520px) {
  header { padding: 10px; flex-direction: column; gap: 10px; }
  .header-grupo-botoes { width: 100%; justify-content: center; flex-wrap: wrap; }
  .btn-header { padding: 8px 12px; font-size: .80rem; }
  .controles-fixos { right: 14px; bottom: 14px; } 
  .btn-circular { width: 56px; height: 56px; font-size: 1.4rem; }
  #hud-right { min-width: 96px; align-items: center; flex-direction: row; gap: 15px; } 
  #hud-right .pontos { font-size: 1rem; } 
  #seq-wrap { font-size: .86rem; padding: 4px 8px; }
}