body {
  background: linear-gradient(120deg, #89f7fe, #66a6ff 100%);
  min-height: 100vh;
  margin: 0;
  font-family: 'Segoe UI', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-container {
  background: rgba(255,255,255,0.95);
  box-shadow: 0 8px 32px rgba(100,150,200,0.15);
  padding: 2rem;
  border-radius: 1.5rem;
  max-width: 420px;
  width: 95vw;
  text-align: center;
  position: relative;
  z-index: 1;
}

h1 {
  letter-spacing: 2px;
  color: #3a5998;
}

#moves {
  margin: 0.5rem 0 1rem 0;
  font-weight: 500;
  color: #395667;
}

#restart {
  margin-bottom: 1rem;
  background: #3989c9;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
#restart:hover { background: #276ca5; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(60px, 1fr));
  gap: 1rem;
  justify-content: center;
  margin: 0 auto;
  max-width: 100%;
}

.card {
  background: linear-gradient(135deg,#e3eeff,#7fafdb);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(80,150,180,0.10);
  width: 100%;
  max-width: 80px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5rem;
  color: #333;
  cursor: pointer;
  position: relative;
  perspective: 1000px;
  user-select: none;
  transition: transform 0.2s;
}

.card.flipped,
.card.matched {
  background: #f7ffc3;
  color: #3989c9;
  cursor: default;
  transform: scale(1.07);
}

.card .hide {
  visibility: hidden;
  opacity: 0;
}

@media (max-width: 700px) {
  .game-container {
    padding: 1rem;
    max-width: 98vw;
  }
  .card {
    max-width: 60px;
    height: 65px;
    font-size: 2rem;
  }
}

@media (max-width: 400px) {
  .card {
    height: 60px;
    font-size: 1.8rem;
  }
}

/* Congratulation Overlay For Pair Match */

.congrats-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(50, 200, 100, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: white;
  font-size: 3rem;
  font-weight: bold;
  text-shadow: 0 0 15px #2aff00;
  animation: fadeinout 2s forwards;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

@keyframes fadeinout {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

/* Game Over Overlay (Game Completed with Stars) */

.gameover-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #4b1177 60%, #231943 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10001;
  animation: fadein-bg 0.7s ease;
}
@keyframes fadein-bg {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.gameover-board {
  background: #76aef7;
  border-radius: 32px;
  box-shadow: 0 10px 40px #23294333;
  width: 320px;
  padding: 2.5rem 1.2rem 2.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.stars {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
  margin-top: -40px;
  min-height: 60px;
}
.star {
  font-size: 2.8rem;
  color: #ffc94d;
  filter: drop-shadow(0 0 11px #fff3);
  opacity: 0;
  transform: scale(0.2);
  transition: opacity 0.22s, transform 0.28s;
}
.star.animate {
  opacity: 1;
  transform: scale(1.11) rotate(-8deg);
  animation: popstar .36s cubic-bezier(.4,1.8,.7,.9);
}
@keyframes popstar {
  0%   { opacity: 0; transform: scale(0.2) rotate(0deg);}
  60%  { opacity: 1; transform: scale(1.25) rotate(10deg);}
  100% { transform: scale(1.07) rotate(-8deg);}
}
.gameover-text {
  color: #fffbe5;
  font-family: 'Segoe UI', sans-serif;
  font-size: 1.5rem;
  letter-spacing: 0.09em;
  font-weight: bold;
  margin-bottom: 1.1rem;
  margin-top: 0.5rem;
  text-shadow: 0 0 18px #fff;
  text-align: center;
}
.next-btn {
  background: #57b0f0;
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 0.65rem 2.5rem;
  font-size: 1.14rem;
  letter-spacing: 0.08em;
  margin-top: 0.8rem;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 2px 6px #1590e240;
  transition: background 0.16s;
}
.next-btn:hover {
  background: #2a98cf;
}

/* Responsive */
@media (max-width: 450px) {
  .gameover-board {
    width: 94vw;
    font-size: 1rem;
    padding: 1.5rem 4vw 1.5rem 4vw;
  }
  .star { font-size: 2rem; }
}
