:root {
  --bg-color: #1e1b4b;
  --surface-color: #312e81;
  --primary-color: #4f46e5;
  --accent-color: #fbbf24; /* Gold */
  --text-color: #ffffff;
  --card-back-color: #4338ca;
  --card-front-color: #ffffff;
  --font-family: 'Inter', system-ui, sans-serif;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
}

header {
  width: 100%;
  padding: 1rem 2rem;
  background: rgba(30, 27, 75, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-color);
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

.stats {
  display: flex;
  gap: 2rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  opacity: 0.7;
  letter-spacing: 1px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#combo-display {
  color: var(--accent-color);
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.3s;
}

#combo-display.active {
  opacity: 1;
}

.controls {
  margin: 1.5rem 0;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

select, button {
  background: var(--surface-color);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}

button:hover, select:hover {
  background: var(--primary-color);
  border-color: var(--accent-color);
}

button:active {
  transform: translateY(1px);
}

#reset-btn {
  background: var(--primary-color);
  font-weight: 600;
}

.game-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  width: 100%;
  padding: 1rem;
}

.game-board {
  display: grid;
  gap: 1rem;
  perspective: 1000px;
  max-width: 1000px;
  margin: 0 auto;
}

/* Grid Layouts based on columns */
.game-board.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.game-board.cols-6 {
  grid-template-columns: repeat(6, 1fr);
}

@keyframes shuffle-in {
  0% { transform: translateY(20px) scale(0.8); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  cursor: pointer;
  border-radius: 12px;
  animation: shuffle-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  /* Remove preserve-3d from card, apply to card-inner */
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
  transform-style: preserve-3d;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

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

.card.matched .card-inner {
  box-shadow: 0 0 15px var(--accent-color);
  animation: pulse 1s infinite;
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5rem;
  user-select: none;
}

.card-back {
  background-color: var(--card-back-color);
  background-image: linear-gradient(135deg, rgba(255,255,255,0.1) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.1) 75%, transparent 75%, transparent);
  background-size: 20px 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  color: var(--accent-color);
}

.card-back::after {
  content: '?';
  font-size: 2rem;
  font-weight: bold;
  opacity: 0.5;
}

.card-front {
  background-color: var(--card-front-color);
  color: #1f2937;
  transform: rotateY(180deg);
  border: 2px solid var(--accent-color);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

.modal {
  background: var(--surface-color);
  padding: 2rem;
  border-radius: 1rem;
  text-align: center;
  max-width: 500px;
  width: 90%;
  border: 1px solid var(--accent-color);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal h2 {
  color: var(--accent-color);
  margin-top: 0;
  font-size: 2rem;
}

.score-summary {
  margin: 2rem 0;
  display: flex;
  justify-content: space-around;
}

.score-box {
  background: rgba(0, 0, 0, 0.2);
  padding: 1rem;
  border-radius: 0.5rem;
  min-width: 100px;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  text-align: left;
  max-height: 200px;
  overflow-y: auto;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-list li:nth-child(1) { color: gold; font-weight: bold; }
.leaderboard-list li:nth-child(2) { color: silver; }
.leaderboard-list li:nth-child(3) { color: #cd7f32; } /* Bronze */

@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7); }
  70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(251, 191, 36, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); }
}

/* Responsiveness */
@media (max-width: 600px) {
  .game-board {
    gap: 0.5rem;
  }
  .card-front, .card-back::after {
    font-size: 1.5rem;
  }
  header {
    flex-direction: column;
    gap: 1rem;
  }
}
