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

body {
  background-color: #0C0D14;
  color: #E0E0E0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

.game-container {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

@media (max-height: 600px), (max-width: 500px) {
  body {
    padding: 8px;
  }

  .game-container {
    gap: 12px;
  }

  .game-header {
    gap: 8px;
  }
}

/* Header */
.game-header {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 0.02em;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.difficulty-selector {
  display: flex;
  gap: 4px;
  background: #1A1B26;
  border-radius: 10px;
  padding: 4px;
}

.diff-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #888;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  color: #BBB;
}

.diff-btn.active {
  background: #7C4DFF;
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(124, 77, 255, 0.4);
}

.new-game-btn {
  padding: 8px 22px;
  border: 2px solid #7C4DFF;
  border-radius: 10px;
  background: transparent;
  color: #7C4DFF;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.new-game-btn:hover {
  background: #7C4DFF;
  color: #FFFFFF;
  box-shadow: 0 2px 12px rgba(124, 77, 255, 0.4);
}

/* Stats */
.stats {
  display: flex;
  gap: 32px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #FFFFFF;
  font-variant-numeric: tabular-nums;
}

/* Card Grid */
.card-grid {
  display: grid;
  gap: 12px;
  width: 100%;
  justify-content: center;
  padding: 10px 0;
}

.card-grid[data-cols="4"] {
  grid-template-columns: repeat(4, 1fr);
  max-width: 440px;
}

.card-grid[data-cols="6"] {
  grid-template-columns: repeat(6, 1fr);
  max-width: 660px;
}

/* Card */
.card {
  aspect-ratio: 1;
  perspective: 600px;
  cursor: pointer;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
  border-radius: 12px;
}

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

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Card Back */
.card-back {
  background: linear-gradient(135deg, #7C4DFF 0%, #5C35CC 100%);
  box-shadow: 0 4px 12px rgba(124, 77, 255, 0.25);
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
}

.card-back::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

/* Card Front */
.card-front {
  background: #1A1B26;
  transform: rotateY(180deg);
  font-size: 2.2rem;
  border: 2px solid #2A2B36;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card:hover .card-inner {
  transform: scale(1.03);
}

.card.flipped:hover .card-inner {
  transform: rotateY(180deg) scale(1.03);
}

/* Matched card */
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card.matched .card-front {
  border-color: #7C4DFF;
  box-shadow:
    0 0 12px rgba(124, 77, 255, 0.5),
    0 0 30px rgba(124, 77, 255, 0.2),
    inset 0 0 12px rgba(124, 77, 255, 0.1);
}

.card.matched {
  cursor: default;
}

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

/* Match pop animation */
@keyframes matchPop {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card.match-anim .card-inner {
  animation: matchPop 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Win Overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 13, 20, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 100;
}

.win-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.win-modal {
  background: #1A1B26;
  border: 2px solid #7C4DFF;
  border-radius: 20px;
  padding: 40px 56px;
  text-align: center;
  box-shadow: 0 0 40px rgba(124, 77, 255, 0.3);
  transform: scale(0.9);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.win-overlay.visible .win-modal {
  transform: scale(1);
}

.win-modal h2 {
  font-size: 2rem;
  color: #7C4DFF;
  margin-bottom: 20px;
}

.win-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin-bottom: 28px;
}

.win-stats p {
  font-size: 1.1rem;
  color: #AAA;
}

.win-stats span {
  color: #FFFFFF;
  font-weight: 700;
}

/* Card entrance animation */
@keyframes cardEnter {
  from {
    opacity: 0;
    transform: scale(0.7) rotateY(40deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotateY(0deg);
  }
}

.card {
  animation: cardEnter 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Responsive */
@media (max-width: 500px) {
  .game-header h1 {
    font-size: 1.5rem;
  }

  .card-grid {
    gap: 8px;
  }

  .card-front {
    font-size: 1.6rem;
  }

  .stats {
    gap: 24px;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .win-modal {
    padding: 28px 32px;
  }
}

@media (max-width: 380px) {
  .card-grid {
    gap: 6px;
  }

  .card-front {
    font-size: 1.3rem;
  }

  .diff-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
}
