/* ══════════════════════════════════════════════════════════════
   JOGO DA MEMÓRIA — XISPA A COBRINHA  |  style.css
   ══════════════════════════════════════════════════════════════ */

/* ── TOKENS ────────────────────────────────────────────────── */
:root {
  --azul:        #1565C0;
  --azul-esc:    #0D47A1;
  --amarelo:     #FFD600;
  --amarelo-esc: #F9A825;
  --verde:       #2dba6e;
  --branco:      #ffffff;
  --card-back-1: #1E3A8A;
  --card-back-2: #2563EB;
  --radius:      18px;
  --shadow:      0 8px 32px rgba(0,0,0,0.25);
}

/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Baloo 2', 'Fredoka One', Arial Rounded MT Bold, sans-serif;
  background: linear-gradient(160deg, #0D2137 0%, #0D47A1 50%, #1565C0 100%);
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--branco);
}

/* ── ESTRELAS DE FUNDO ─────────────────────────────────────── */
.stars-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.star-float {
  position: absolute;
  bottom: -60px;
  animation: floatUp linear forwards;
  opacity: 0;
  user-select: none;
  pointer-events: none;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg);   opacity: 0; }
  10%  { opacity: 0.8; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-110vh) rotate(360deg); opacity: 0; }
}

/* ── SCREENS ────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; position: relative; z-index: 1; }
.screen.active { display: flex; flex-direction: column; }

/* ── HEADER ─────────────────────────────────────────────────── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(12px);
  border-bottom: 3px solid var(--amarelo);
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-voltar {
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  padding: 8px 18px;
  border-radius: 100px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
  white-space: nowrap;
}
.btn-voltar:hover {
  background: rgba(255,255,255,0.28);
  transform: translateX(-3px);
}
.btn-sound {
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  padding-bottom: 2px;
}
.btn-sound:hover {
  background: rgba(255,255,255,0.28);
  transform: scale(1.1);
  border-color: var(--amarelo);
}
.btn-sound:active {
  transform: scale(0.9);
}
.header-space { width: 100px; }

/* LOGO */
.game-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-snake {
  font-size: 2.5rem;
  animation: wiggle 2.5s ease-in-out infinite;
  display: inline-block;
}
@keyframes wiggle {
  0%,100% { transform: rotate(-8deg); }
  50%      { transform: rotate(8deg) scale(1.1); }
}
.logo-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--amarelo);
  text-shadow: 2px 3px 0 rgba(0,0,0,0.2);
}
.logo-sub {
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.5px;
}

/* STATS */
.game-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 100px;
  padding: 6px 14px;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: #fff;
  min-width: 72px;
  justify-content: center;
}
.stat-icon { font-size: 1.1rem; }
.game-info-center { flex: 1; text-align: center; }
.info-phase {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: var(--amarelo);
  text-shadow: 2px 3px 0 rgba(0,0,0,0.2);
}

/* ══ TELA DE SELEÇÃO ══════════════════════════════════════════ */
.select-main {
  flex: 1;
  padding: 40px 24px 60px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.select-hero {
  text-align: center;
  margin-bottom: 44px;
}
.hero-badge {
  display: inline-block;
  background: var(--amarelo);
  color: var(--azul-esc);
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  padding: 6px 20px;
  border-radius: 100px;
  margin-bottom: 18px;
  box-shadow: 0 5px 0 var(--amarelo-esc);
  animation: badgePop 0.6s ease;
}
@keyframes badgePop {
  0%  { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.12); }
  100%{ transform: scale(1); opacity: 1; }
}
.select-hero h1 {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2rem, 5vw, 3.4rem);
  color: #fff;
  text-shadow: 3px 5px 0 rgba(0,0,0,0.2);
  margin-bottom: 12px;
}
.select-hero p {
  font-size: 1.05rem;
  font-weight: 700;
  color: rgba(255,255,255,0.82);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.7;
}

/* GRID DAS FASES */
.phases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 20px;
}

.phase-card {
  background: rgba(255,255,255,0.1);
  border: 3px solid rgba(255,255,255,0.18);
  border-radius: 22px;
  padding: 28px 16px 22px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1),
              background 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(6px);
}
.phase-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--phase-color, rgba(255,255,255,0.08));
  opacity: 0;
  transition: opacity 0.2s;
  border-radius: inherit;
}
.phase-card:hover::before { opacity: 1; }
.phase-card:hover {
  transform: translateY(-8px) scale(1.04);
  border-color: var(--phase-border, var(--amarelo));
  box-shadow: 0 16px 40px rgba(0,0,0,0.35), 0 0 0 4px var(--phase-border, var(--amarelo));
}
.phase-card:active { transform: scale(0.97); }

.phase-number {
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.5);
}
.phase-emoji {
  font-size: 3.2rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
  transition: transform 0.3s;
}
.phase-card:hover .phase-emoji { transform: scale(1.2) rotate(-5deg); }
.phase-name {
  font-family: 'Fredoka One', cursive;
  font-size: 1.15rem;
  color: #fff;
  display: block;
  margin-bottom: 6px;
  text-shadow: 1px 2px 0 rgba(0,0,0,0.15);
}
.phase-tag {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255,255,255,0.65);
  background: rgba(0,0,0,0.2);
  border-radius: 100px;
  padding: 3px 11px;
  display: inline-block;
}
.phase-completed .phase-number::after {
  content: ' ✓';
  color: var(--amarelo);
  font-size: 1rem;
}
.phase-lock {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  backdrop-filter: blur(2px);
  transition: opacity 0.3s;
}

/* ══ TABULEIRO ════════════════════════════════════════════════ */
.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 700px;
}

/* ── CARTA ─────────────────────────────────────────────────── */
.card {
  aspect-ratio: 3/4;
  perspective: 900px;
  cursor: pointer;
}
.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  border-radius: var(--radius);
}
.card.flipped   .card-inner { transform: rotateY(180deg); }
.card.matched   .card-inner { transform: rotateY(180deg); }

/* FRENTE E VERSO */
.card-front, .card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* VERSO (lado oculto, com logo Xispa) */
.card-back {
  background: linear-gradient(135deg, var(--card-back-1) 0%, var(--card-back-2) 100%);
  border: 4px solid rgba(255,255,255,0.2);
  box-shadow: var(--shadow);
}
.card-back-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.card-back-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4)) brightness(1.05);
  transition: transform 0.3s;
}
.card:hover:not(.flipped):not(.matched) .card-back-logo {
  transform: scale(1.08);
}

/* FRENTE (lado visível) */
.card-front {
  background: #fff;
  transform: rotateY(180deg);
  border: 4px solid rgba(255,255,255,0.3);
  box-shadow: var(--shadow);
  padding: 0;
}
.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius) - 4px);
  display: block;
}

/* ESTADOS DA CARTA */
.card:hover:not(.flipped):not(.matched) .card-back {
  border-color: var(--amarelo);
  box-shadow: 0 0 0 4px var(--amarelo), var(--shadow);
}

.card.matched .card-front {
  border-color: #4CAF50;
  box-shadow: 0 0 0 4px #4CAF50, 0 0 30px rgba(76,175,80,0.5);
}
.card.matched::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 8px;
  color: #4CAF50;
  font-size: 1.4rem;
  font-weight: 900;
  z-index: 10;
  text-shadow: 0 2px 6px rgba(0,0,0,0.3);
  animation: checkPop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes checkPop {
  0%  { transform: scale(0) rotate(-30deg); }
  100%{ transform: scale(1) rotate(0deg); }
}

/* ── ANIMAÇÃO DE ACERTO ────────────────────────────────────── */
@keyframes matchBounce {
  0%   { transform: rotateY(180deg) scale(1); }
  30%  { transform: rotateY(180deg) scale(1.12); }
  60%  { transform: rotateY(180deg) scale(0.96); }
  100% { transform: rotateY(180deg) scale(1); }
}
.card.matched .card-inner {
  animation: matchBounce 0.5s ease 0.1s both;
}

/* ── ANIMAÇÃO DE ERRO ──────────────────────────────────────── */
@keyframes wrongShake {
  0%,100%{ transform: rotateY(180deg) translateX(0); }
  20%     { transform: rotateY(180deg) translateX(-6px); }
  40%     { transform: rotateY(180deg) translateX(6px); }
  60%     { transform: rotateY(180deg) translateX(-4px); }
  80%     { transform: rotateY(180deg) translateX(4px); }
}
.card.wrong .card-inner {
  animation: wrongShake 0.45s ease;
  border-color: #F44336;
}
.card.wrong .card-front {
  border-color: #F44336;
  box-shadow: 0 0 0 4px #F44336, 0 0 20px rgba(244,67,54,0.4);
}

/* ══ COUNTDOWN DA PRÉVIA ═════════════════════════════════════ */
.preview-countdown {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 20, 60, 0.88);
  backdrop-filter: blur(14px);
  border: 3px solid var(--amarelo);
  border-radius: 100px;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 6px rgba(255,214,0,0.12);
  animation: cdSlideIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 50;
}
@keyframes cdSlideIn {
  0%  { transform: translateX(-50%) translateY(30px); opacity: 0; }
  100%{ transform: translateX(-50%) translateY(0); opacity: 1; }
}
.preview-countdown.preview-hide {
  animation: cdSlideOut 0.5s ease forwards;
}
@keyframes cdSlideOut {
  0%  { transform: translateX(-50%) translateY(0); opacity: 1; }
  100%{ transform: translateX(-50%) translateY(20px); opacity: 0; }
}
.preview-icon {
  font-size: 1.6rem;
  animation: eyeBounce 0.8s ease-in-out infinite alternate;
}
@keyframes eyeBounce {
  from { transform: scaleY(1); }
  to   { transform: scaleY(0.6); }
}
.preview-text {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  color: #fff;
  text-shadow: 1px 2px 0 rgba(0,0,0,0.2);
}
.preview-num {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: var(--amarelo);
  text-shadow: 2px 3px 0 rgba(0,0,0,0.25);
  min-width: 36px;
  text-align: center;
  animation: numPulse 1s ease-in-out infinite;
}
@keyframes numPulse {
  0%,100%{ transform: scale(1); }
  50%    { transform: scale(1.15); }
}
.preview-num-urgent {
  color: #FF5252 !important;
  animation: numUrgent 0.3s ease-in-out infinite alternate !important;
}
@keyframes numUrgent {
  from { transform: scale(1); }
  to   { transform: scale(1.3); }
}

/* ══ MODAL DE VITÓRIA ════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,20,0.75);
  backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.win-modal {
  background: linear-gradient(160deg, #0D2137, #1565C0);
  border: 4px solid var(--amarelo);
  border-radius: 28px;
  padding: 44px 36px 36px;
  text-align: center;
  max-width: 460px;
  width: 100%;
  position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 0 8px rgba(255,214,0,0.15);
  animation: modalPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
  overflow: hidden;
}
@keyframes modalPop {
  0%  { transform: scale(0.5) translateY(60px); opacity: 0; }
  100%{ transform: scale(1) translateY(0); opacity: 1; }
}

.win-trophy {
  font-size: 5rem;
  display: block;
  animation: trophySpin 1.2s cubic-bezier(0.34,1.56,0.64,1);
  filter: drop-shadow(0 8px 24px rgba(255,214,0,0.5));
}
@keyframes trophySpin {
  0%  { transform: rotate(-30deg) scale(0); }
  60% { transform: rotate(10deg) scale(1.15); }
  100%{ transform: rotate(0deg) scale(1); }
}
.win-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.8rem;
  color: var(--amarelo);
  text-shadow: 3px 5px 0 rgba(0,0,0,0.2);
  margin: 12px 0 4px;
}
.win-sub {
  font-size: 1.1rem;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  margin-bottom: 28px;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 30px;
}
.win-stat {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 16px;
  padding: 14px 20px;
  min-width: 90px;
}
.win-stat-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  color: var(--amarelo);
}
.win-stat-lbl {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255,255,255,0.65);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.win-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}
.btn-win {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  padding: 12px 22px;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn-win:hover  { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.btn-win:active { transform: scale(0.96); }
.btn-replay { background: rgba(255,255,255,0.15); color: #fff; border: 2px solid rgba(255,255,255,0.3); }
.btn-next   { background: var(--amarelo); color: var(--azul-esc); box-shadow: 0 5px 0 var(--amarelo-esc); }
.btn-select { background: var(--verde);  color: #fff; box-shadow: 0 5px 0 #1a8a4a; }

/* Confetti */
.win-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}
.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: confettiFall linear forwards;
  top: -20px;
}
@keyframes confettiFall {
  0%  { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100%{ transform: translateY(500px) rotate(720deg) scale(0.5); opacity: 0; }
}

/* ── RESPONSIVO ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .game-header { padding: 10px 14px; gap: 8px; }
  .header-space { display: none; }
  .logo-title { font-size: 1.1rem; }
  .logo-sub   { display: none; }
  .stat-pill  { font-size: 0.88rem; padding: 5px 10px; min-width: 60px; }
  .board { grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 100%; }
  .phases-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .select-main { padding: 24px 14px 40px; }
  .win-modal { padding: 32px 20px 24px; }
  .win-stats { gap: 10px; }
  .win-stat  { padding: 10px 12px; min-width: 70px; }
}

@media (max-width: 400px) {
  .board { grid-template-columns: repeat(3, 1fr); }
  .game-stats { gap: 5px; }
}

/* ── UTILITÁRIOS ────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── SCROLLBAR ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: var(--amarelo); border-radius: 4px; }
