*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, sans-serif;
  background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
  color: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.game-container {
  text-align: center;
  max-width: 420px;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.instructions {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  opacity: 0.85;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.stats strong {
  color: #7dd3fc;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  aspect-ratio: 1;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.card-wrapper {
  position: relative;
  aspect-ratio: 1;
  cursor: pointer;
  perspective: 600px;
}

.card-wrapper.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-wrapper.matched .card-inner {
  transform: rotateY(180deg);
}

.card-wrapper.matching .card-face.card-front {
  box-shadow: 0 0 0 3px #22c55e, 0 0 20px rgba(34, 197, 94, 0.6);
  animation: pulse 1s ease-in-out;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 3px #22c55e, 0 0 20px rgba(34, 197, 94, 0.6);
  }
  50% {
    box-shadow: 0 0 0 3px #22c55e, 0 0 30px rgba(34, 197, 94, 0.8);
  }
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s ease;
  transform-style: preserve-3d;
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.card-back {
  background: linear-gradient(145deg, #3b82f6, #2563eb);
  transform: rotateY(0deg);
}

.card-back::after {
  content: "?";
  font-size: 1.5rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.6);
}

.card-front {
  transform: rotateY(180deg);
  font-size: 2.5rem;
}

.card-wrapper:hover:not(.flipped):not(.matched) .card-back {
  background: linear-gradient(145deg, #60a5fa, #3b82f6);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.card-wrapper.matched {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.card-wrapper.matched .card-inner {
  transform: rotateY(180deg);
}

.btn-restart {
  padding: 0.6rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a2e;
  background: linear-gradient(145deg, #7dd3fc, #38bdf8);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-restart:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.5);
}

.btn-restart:active {
  transform: translateY(0);
}

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 1rem;
}

.win-overlay.hidden {
  display: none;
}

.win-message {
  background: #1e293b;
  padding: 2rem;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.win-message h2 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  color: #7dd3fc;
}

.win-message p {
  margin: 0 0 1.5rem;
  font-size: 1.1rem;
}

.win-message .btn-restart {
  background: linear-gradient(145deg, #34d399, #10b981);
}

.win-message .btn-restart:hover {
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.5);
}
