body {
  margin: 0;
  font-family: 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #333;
  min-height: 100vh;
}

header {
  padding: 20px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 2rem;
  color: #333;
}

.back-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 15px;
  background: #667eea;
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.3s ease;
}

.back-btn:hover {
  background: #5a6fd8;
}

main {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 20px;
  border-radius: 15px;
  margin-bottom: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.stats {
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
}

.stat-item {
  text-align: center;
}

.stat-item .label {
  display: block;
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 5px;
}

.stat-item span:last-child {
  font-size: 1.2rem;
  font-weight: bold;
  color: #333;
}

.controls {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #f8f9fa;
  color: #333;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn.primary {
  background: #667eea;
  color: white;
}

.btn.primary:hover {
  background: #5a6fd8;
}

.game-container {
  position: relative;
}

.game-board {
  display: grid;
  gap: 10px;
  justify-content: center;
  perspective: 1000px;
  background: rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 15px;
  backdrop-filter: blur(10px);
}

/* Dynamic grid sizes based on level */
.grid-4x3 { grid-template-columns: repeat(4, 1fr); }
.grid-4x4 { grid-template-columns: repeat(4, 1fr); }
.grid-6x4 { grid-template-columns: repeat(6, 1fr); }
.grid-6x5 { grid-template-columns: repeat(6, 1fr); }

.card {
  width: 80px;
  height: 80px;
  position: relative;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
  user-select: none;
}

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

.card.matched {
  transform: rotateY(180deg) scale(1.1);
  animation: matchSuccess 0.8s ease;
}

.card.shake {
  animation: cardShake 0.5s ease;
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  border: 3px solid rgba(255, 255, 255, 0.3);
}

.card-back {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  font-size: 1.5rem;
}

.card-front {
  background: linear-gradient(135deg, #ffffff, #f8f9fa);
  color: #333;
  transform: rotateY(180deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.card:hover:not(.flipped):not(.matched) {
  transform: translateY(-5px) rotateX(10deg);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

/* Particle effect for matches */
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #ffd700;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFloat 1s ease-out forwards;
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 20px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease-out;
}

.modal-content h2 {
  margin: 0 0 20px 0;
  color: #333;
}

.modal-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
}

#gameOverStats {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 10px;
  margin: 15px 0;
  line-height: 1.6;
}

/* Timer warning states */
.timer-warning {
  color: #ff9500 !important;
  animation: pulse 1s ease-in-out infinite;
}

.timer-critical {
  color: #ff3b30 !important;
  animation: criticalPulse 0.5s ease-in-out infinite;
}

/* Animations */
@keyframes matchSuccess {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.3); }
  100% { transform: rotateY(180deg) scale(1.1); }
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes particleFloat {
  0% {
    transform: translateY(0) scale(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-100px) scale(1);
    opacity: 0;
  }
}

@keyframes modalSlideIn {
  0% {
    transform: translateY(-50px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes criticalPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Responsive design */
@media (max-width: 768px) {
  .game-info {
    flex-direction: column;
    gap: 15px;
  }
  
  .stats {
    justify-content: center;
  }
  
  .card {
    width: 60px;
    height: 60px;
  }
  
  .card-face {
    font-size: 1.8rem;
  }
  
  .game-board {
    gap: 8px;
    padding: 15px;
  }
}

/* Timer Container for Memory Game */
.timer-container-memory {
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 15px;
  margin: 20px 0;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}

.timer-mode-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  justify-content: center;
}

.timer-mode-btn {
  padding: 8px 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  color: #666;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.timer-mode-btn:hover {
  border-color: #e74c3c;
  color: #e74c3c;
}

.timer-mode-btn.active {
  background: linear-gradient(135deg, #e74c3c, #f39c12);
  color: white;
  border-color: #e74c3c;
}

.timer-progress-memory {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 15px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.timer-controls-memory {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.control-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.control-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#addTimeBtn {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}

#addTimeBtn:hover {
  box-shadow: 0 6px 20px rgba(243, 156, 18, 0.4);
}

@media (max-width: 768px) {
  .game-info {
    flex-direction: column;
    gap: 15px;
  }
  
  .stats {
    justify-content: center;
  }
  
  .card {
    width: 60px;
    height: 60px;
  }
  
  .card-face {
    font-size: 1.8rem;
  }
  
  .game-board {
    gap: 8px;
    padding: 15px;
  }
  
  .timer-container-memory {
    margin: 10px 0;
    padding: 15px;
  }
  
  .timer-mode-selector {
    flex-direction: column;
    align-items: center;
  }
  
  .timer-controls-memory {
    flex-direction: column;
    align-items: center;
  }
  
  .control-btn {
    width: 100%;
    max-width: 200px;
  }
}

@media (max-width: 480px) {
  .card {
    width: 50px;
    height: 50px;
  }
  
  .card-face {
    font-size: 1.5rem;
  }
  
  .stats {
    gap: 15px;
  }
}