* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* Scroll passa a ser no tabuleiro; header fica fixo */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #ffebee 0, #b71c1c 55%, #4e342e 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}

#snow-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 10% 20%, rgba(255,255,255,0.8) 50%, transparent 50%),
    radial-gradient(2px 2px at 80% 30%, rgba(255,255,255,0.7) 50%, transparent 50%),
    radial-gradient(3px 3px at 50% 80%, rgba(255,255,255,0.5) 50%, transparent 50%);
  opacity: 0.7;
  animation: snow 12s linear infinite;
  z-index: 0;
}

@keyframes snow {
  0% { background-position: 0 0, 0 0, 0 0; }
  100% { background-position: 0 600px, 0 800px, 0 1000px; }
}

.game-container {
  position: relative;
  z-index: 1;
  width: min(1200px, calc(100vw - 20px));
  height: calc(100vh - 20px);
  margin: 10px auto;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.game-header {
  text-align: center;
  padding: 16px 16px 10px 16px;
  background: rgba(0,0,0,0.18);
  border-bottom: 1px solid rgba(255,255,255,0.15);
  position: sticky;
  top: 0;
  z-index: 2;
}

.game-header h1 {
  font-size: 1.8rem;
  margin-bottom: 6px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.subtitle { font-size: 0.9rem; opacity: 0.9; margin-bottom: 10px; }

.game-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 0.95rem;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
}

.stat .label { font-weight: 600; }
#timer { font-size: 1.3rem; font-weight: 700; }

.game-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.game-controls button {
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, #ffca28, #ffb300);
  color: #5d4037;
  box-shadow: 0 3px 0 #f57f17;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
}
.game-controls button:hover { filter: brightness(1.05); }
.game-controls button:active { transform: translateY(2px); box-shadow: 0 1px 0 #f57f17; }

.game-main { flex: 1; overflow: hidden; padding: 10px; }

.game-board {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 8px;
  justify-content: center;
  padding: 4px 4px 18px 4px;
  scroll-behavior: smooth;
}

@media (min-width: 320px) { .game-board { grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); } }
@media (min-width: 768px) { .game-board { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); } }

.memory-card { position: relative; width: 100%; padding-top: 130%; perspective: 800px; cursor: pointer; }
.memory-card.flipped .card-inner { transform: rotateY(180deg); }
.memory-card.matched { cursor: default; }

.card-inner { position: absolute; inset: 0; transition: transform 0.5s; transform-style: preserve-3d; }
.card-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 10px; overflow: hidden; border: 2px solid rgba(255,255,255,0.85); }

.card-back {
  background: linear-gradient(135deg, #d32f2f, #7b1fa2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  text-shadow: 0 2px 3px rgba(0,0,0,0.5);
}

.card-front {
  transform: rotateY(180deg);
  background: #212121;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-front img { width: 100%; height: 100%; object-fit: cover; }

.memory-card.matched .card-front img {
  filter: grayscale(100%) brightness(0.8);
  transform: scale(0.96);
  transition: filter 0.2s ease, transform 0.2s ease;
}
.memory-card.matched .card-face { border-color: rgba(200, 200, 200, 0.9); }
.memory-card.matched .card-inner { animation: match-pop 0.4s ease; }

@keyframes match-pop {
  0% { transform: rotateY(180deg) scale(1); }
  30% { transform: rotateY(180deg) scale(1.08); }
  100% { transform: rotateY(180deg) scale(1); }
}

.game-over {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.game-over.hidden { display: none; }

.game-over-content {
  background: #fafafa;
  color: #4e342e;
  padding: 24px 20px;
  border-radius: 16px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.game-over-content h2 { font-size: 1.4rem; margin-bottom: 10px; }
.game-over-content p { margin-bottom: 10px; font-size: 0.95rem; }
.final-rank { margin-top: 6px; font-weight: 700; font-size: 1rem; color: #c62828; }

.game-over-content button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, #43a047, #2e7d32);
  color: #fff;
  box-shadow: 0 3px 0 #1b5e20;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
}
.game-over-content button:hover { filter: brightness(1.05); }
.game-over-content button:active { transform: translateY(2px); box-shadow: 0 1px 0 #1b5e20; }

@media (max-width: 480px) {
  .game-header h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.8rem; }
  .game-controls button { font-size: 0.8rem; padding: 6px 10px; }
}
