/* Reset and base setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: 'Segoe UI', sans-serif;
  background: linear-gradient(to right, #8e2de2, #4a00e0);
  color: white;
}

body.light {
  background: linear-gradient(to right, #fefefe, #e0e0e0);
  color: #000;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Game wrapper */
.game-container {
  width: 100%;
  max-width: 800px;
  height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Header with stats */
header {
  text-align: center;
}

.stats {
  display: flex;
  justify-content: space-around;
  margin-top: 10px;
}

/* Buttons */
#restart,
#reset-best,
#toggle-theme,
#play-again,
#mute-toggle {
  margin-top: 10px;
  padding: 8px 20px;
  border: none;
  background: #fff;
  color: #000;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.3s;
}

#restart:hover,
#toggle-theme:hover,
#play-again:hover,
#mute-toggle:hover {
  background: #f2f2f2;
}

body.light #restart,
body.light #toggle-theme,
body.light #play-again,
body.light #mute-toggle {
  background: #222;
  color: white;
}

body.light #restart:hover,
body.light #toggle-theme:hover,
body.light #play-again:hover,
body.light #mute-toggle:hover {
  background: #444;
}

/* Game grid */
.grid {
  flex-grow: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin: 20px 0 40px;
}

/* Card container */
.card {
  perspective: 1000px;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  user-select: none;
}

/* Card flipping logic */
.card-inner {
  width: 100%;
  height: 100%;
  transition: transform 0.6s ease;
  transform-style: preserve-3d;
  position: relative;
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

/* Front and back */
.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
}

.card-front {
  background: #ffffff20;
}

.card-back {
  background: white;
  color: black;
  transform: rotateY(180deg);
}

body.light .card-front {
  background-color: rgba(0, 0, 0, 0.1);
}

body.light .card-back {
  background-color: white;
  color: black;
}

/* Overlay */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
}

/* Win message popup */
#win-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: linear-gradient(145deg, #ffffff, #f2f2f2);
  color: #111;
  padding: 40px 60px;
  border-radius: 20px;
  text-align: center;
  z-index: 999;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
  font-size: 2.2rem;
  font-weight: bold;
  opacity: 0;
  animation: popupIn 0.5s ease-out forwards;
}

/* Win text animation */
#win-message h1 {
  font-size: 3rem;
  color: #6a4c93;
  animation: pulse 2s infinite;
  margin-bottom: 15px;
}

#win-message p {
  font-size: 1.2rem;
  color: #333;
}

/* Glowing pulse */
@keyframes pulse {
  0% { text-shadow: 0 0 10px #6a4c93; transform: scale(1); }
  50% { text-shadow: 0 0 20px #b983ff; transform: scale(1.05); }
  100% { text-shadow: 0 0 10px #6a4c93; transform: scale(1); }
}

/* Popup entrance */
@keyframes popupIn {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* Hide utility */
.hidden {
  display: none !important;
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 997;
}

/* Responsive */
@media screen and (max-width: 768px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .card-front, .card-back {
    font-size: 1.8rem;
  }
}

@media screen and (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .card-front, .card-back {
    font-size: 1.5rem;
  }
}

/* Top button controls (Dark Mode + Mute) */
.top-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
/* How to Play Popup */
#how-to-play-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  background: white;
  color: #333;
  padding: 30px 40px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  z-index: 999;
  width: 90%;
  max-width: 400px;
  text-align: center;
  font-size: 1.1rem;
  animation: popupIn 0.4s ease-out;
}

#how-to-play-popup h2 {
  font-size: 1.8rem;
  margin-bottom: 10px;
  color: #6a4c93;
}

#how-to-play-popup ul {
  text-align: left;
  margin: 15px 0;
  padding-left: 20px;
}

#how-to-play-popup li {
  margin: 6px 0;
  list-style-type: disc;
}

#close-how {
  margin-top: 15px;
  padding: 10px 20px;
  background: #6a4c93;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.3s;
}

#close-how:hover {
  background: #593773;
}
