@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap');

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

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #F8F3FD;
  color: #1F2937;
  min-height: 100vh;
  line-height: 1.5;
}

.game-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  border-radius: 16px;
  margin-bottom: 24px;
  color: #fff;
  gap: 12px;
}

.game-header .back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.game-header .back-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.game-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}

.game-header .stars {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.game-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 4px 24px rgba(124, 58, 237, 0.08);
  transition: transform 0.2s, box-shadow 0.2s;
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.12);
}

.animal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: #fff;
  border-radius: 16px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.animal-card:hover {
  transform: scale(1.05);
  border-color: #7C3AED;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.15);
}

.animal-card:active {
  transform: scale(0.97);
}

.animal-card.selected {
  border-color: #7C3AED;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.05), rgba(236, 72, 153, 0.05));
}

.animal-card .emoji {
  font-size: 48px;
  line-height: 1;
}

.animal-card .name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1F2937;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.4);
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  background: #fff;
  color: #7C3AED;
  border: 3px solid #7C3AED;
  border-radius: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, color 0.2s;
}

.btn-secondary:hover {
  background: #7C3AED;
  color: #fff;
  transform: translateY(-2px);
}

.btn-success {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  background: linear-gradient(135deg, #10B981, #34D399);
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(16, 185, 129, 0.4);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.3);
}

.btn-icon:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.4);
}

.feedback-correct {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  background: linear-gradient(135deg, #D1FAE5, #A7F3D0);
  color: #065F46;
  border-radius: 16px;
  font-weight: 700;
  font-size: 1.1rem;
  animation: bounce 0.5s ease;
  border: 3px solid #10B981;
}

.feedback-wrong {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  background: linear-gradient(135deg, #FEE2E2, #FECACA);
  color: #991B1B;
  border-radius: 16px;
  font-weight: 700;
  font-size: 1.1rem;
  animation: shake 0.5s ease;
  border: 3px solid #EF4444;
}

.stars {
  display: flex;
  align-items: center;
  gap: 6px;
}

.star {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 28px;
  transition: transform 0.2s;
}

.star.filled {
  animation: starBounce 0.4s ease;
  filter: drop-shadow(0 2px 4px rgba(245, 158, 11, 0.4));
}

.star.empty {
  opacity: 0.3;
  filter: grayscale(1);
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: #E9D5FF;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #7C3AED, #EC4899);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(236, 72, 153, 0.1));
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  color: #7C3AED;
}

.score-display .star-icon {
  font-size: 20px;
}

.game-grid {
  display: grid;
  gap: 16px;
}

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

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

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

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 3px dashed #C4B5FD;
  border-radius: 16px;
  background: rgba(124, 58, 237, 0.03);
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  padding: 16px;
}

.drop-zone:hover {
  border-color: #7C3AED;
  background: rgba(124, 58, 237, 0.08);
}

.drop-zone.active {
  border-color: #EC4899;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(236, 72, 153, 0.08));
  transform: scale(1.02);
}

.drop-zone .label {
  font-weight: 600;
  color: #A78BFA;
  font-size: 0.95rem;
}

.draggable {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  background: #fff;
  border: 2px solid #E9D5FF;
  border-radius: 12px;
  cursor: grab;
  transition: transform 0.2s, box-shadow 0.2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.draggable:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.15);
}

.draggable:active,
.draggable.dragging {
  cursor: grabbing;
  transform: scale(1.1);
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.25);
  z-index: 100;
}

.puzzle-piece {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid #E9D5FF;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  touch-action: none;
}

.puzzle-piece:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.15);
}

.puzzle-piece.placed {
  border-color: #10B981;
  background: #ECFDF5;
}

.memory-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  perspective: 600px;
  cursor: pointer;
}

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

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

.memory-card .front,
.memory-card .back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.memory-card .front {
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  color: #fff;
  font-size: 32px;
}

.memory-card .back {
  background: #fff;
  border: 3px solid #E9D5FF;
  transform: rotateY(180deg);
  font-size: 40px;
}

.memory-card.matched .front,
.memory-card.matched .back {
  border-color: #10B981;
  background: #ECFDF5;
}

.celebration {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(248, 243, 253, 0.92);
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.celebration .title {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
  animation: slideUp 0.5s ease 0.2s both;
}

.celebration .stars-display {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  animation: slideUp 0.5s ease 0.4s both;
}

.celebration .stars-display .star {
  font-size: 48px;
}

.celebration .score-text {
  font-size: 1.3rem;
  font-weight: 600;
  color: #7C3AED;
  margin-bottom: 32px;
  animation: slideUp 0.5s ease 0.5s both;
}

.celebration .actions {
  display: flex;
  gap: 16px;
  animation: slideUp 0.5s ease 0.6s both;
}

.celebration .confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.celebration .confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  top: -20px;
  animation: confetti 3s ease forwards;
}

.difficulty-selector {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: #E9D5FF;
  border-radius: 14px;
  margin-bottom: 24px;
}

.difficulty-selector .tab {
  flex: 1;
  padding: 10px 20px;
  border: none;
  border-radius: 12px;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  color: #7C3AED;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.difficulty-selector .tab:hover {
  background: rgba(255, 255, 255, 0.5);
}

.difficulty-selector .tab.active {
  background: #fff;
  color: #7C3AED;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.15);
  transform: scale(1.02);
}

.sound-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C3AED, #EC4899);
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: pulse 2s ease-in-out infinite;
}

.sound-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.4);
}

.sound-btn.muted {
  background: #D1D5DB;
  animation: none;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-12px); }
  50% { transform: translateY(-6px); }
  70% { transform: translateY(-3px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10% { transform: translateX(-8px); }
  20% { transform: translateX(8px); }
  30% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  50% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 16px rgba(124, 58, 237, 0.3); }
  50% { transform: scale(1.05); box-shadow: 0 6px 24px rgba(124, 58, 237, 0.5); }
}

@keyframes confetti {
  0% { top: -20px; opacity: 1; transform: rotate(0deg) translateX(0); }
  100% { top: 110vh; opacity: 0; transform: rotate(720deg) translateX(100px); }
}

@keyframes starBounce {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (max-width: 768px) {
  .game-container {
    padding: 12px;
  }

  .game-header {
    padding: 12px 16px;
    border-radius: 12px;
  }

  .game-header h1 {
    font-size: 1.1rem;
  }

  .game-card {
    padding: 20px;
    border-radius: 12px;
  }

  .animal-card {
    padding: 14px;
    border-radius: 12px;
  }

  .animal-card .emoji {
    font-size: 36px;
  }

  .animal-card .name {
    font-size: 0.85rem;
  }

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

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

  .btn-primary,
  .btn-secondary,
  .btn-success {
    padding: 12px 24px;
    font-size: 1rem;
  }

  .btn-icon {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }

  .celebration .title {
    font-size: 1.8rem;
  }

  .celebration .stars-display .star {
    font-size: 36px;
  }

  .celebration .actions {
    flex-direction: column;
    width: 100%;
    padding: 0 20px;
  }

  .celebration .actions .btn-primary,
  .celebration .actions .btn-secondary {
    width: 100%;
  }

  .difficulty-selector {
    border-radius: 10px;
  }

  .difficulty-selector .tab {
    padding: 8px 12px;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  .game-grid.cols-2 {
    grid-template-columns: 1fr;
  }

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

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

  .animal-card .emoji {
    font-size: 30px;
  }

  .drop-zone {
    min-height: 90px;
  }

  .memory-card .back {
    font-size: 28px;
  }

  .memory-card .front {
    font-size: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .memory-card .inner {
    transition-duration: 0.01ms;
  }
}

:focus-visible {
  outline: 3px solid #7C3AED;
  outline-offset: 2px;
  border-radius: 8px;
}

.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-success:focus-visible {
  outline: 3px solid #7C3AED;
  outline-offset: 3px;
}

.game-area {
  touch-action: none;
}

.animal-card,
.draggable,
.puzzle-piece {
  touch-action: none;
  -webkit-touch-callout: none;
}

@media (hover: none) and (pointer: coarse) {
  .animal-card:hover {
    transform: none;
    border-color: transparent;
    box-shadow: none;
  }

  .draggable:hover {
    transform: none;
    box-shadow: none;
  }

  .puzzle-piece:hover {
    transform: none;
    box-shadow: none;
  }
}
