body {
  font-family: "Poppins", sans-serif;
  touch-action: manipulation;
}

/* Logo Text Styling */
.logo-text {
  font-family: "Jua", sans-serif;
  font-weight: 400;
  letter-spacing: 0.05em;
}
.grid-container {
  display: grid;
  gap: 2px;
  padding: 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 2px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  max-width: 100%;
  width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  box-sizing: border-box;
}
.cell {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  transition: all 0.2s ease-in-out;
  user-select: none;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  font-size: clamp(0.6rem, 2.5vw, 1.5rem);
  position: relative;
  min-height: 30px;
  min-width: 30px;
}
.cell-clue {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  color: #475569;
  cursor: not-allowed;
  border-color: #cbd5e1;
  font-weight: 700;
}
.cell-start {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  color: #166534;
  border-color: #86efac;
  font-weight: 700;
}
.cell-end {
  background: linear-gradient(135deg, #fef2f2 0%, #fecaca 100%);
  color: #991b1b;
  border-color: #fca5a5;
  font-weight: 700;
}
.cell-user {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  color: #1e40af;
  border-color: #93c5fd;
  font-weight: 700;
}
.cell-empty:hover {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-color: #cbd5e1;
  transform: scale(1.02);
}
.cell.highlight {
  border: 3px solid #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
  z-index: 10;
  transform: scale(1.05);
}
.cell.error {
  animation: shake 0.5s;
  background: linear-gradient(135deg, #fef2f2 0%, #fecaca 100%);
  border-color: #f87171;
  color: #dc2626;
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}
.hint-highlight {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
  color: #92400e !important;
  border: 3px solid #f59e0b !important;
  animation: pulse 1s infinite;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3) !important;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Popup Styles */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #f3f4f6;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* Game Over Popup with opacity overlay */
.popup-overlay.game-over-overlay {
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

/* Level Completion Popup with opacity overlay */
.popup-overlay.level-completion-overlay {
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

/* Hint Popup with opacity overlay */
.popup-overlay.hint-overlay {
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.popup-content {
  background: white;
  border-radius: 20px;
  padding: 1rem;
  max-width: min(400px, 90vw);
  width: 85%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: popupSlideIn 0.3s ease-out;
  margin: 1rem;
}

@keyframes popupSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.popup-header {
  text-align: center;
  margin-bottom: 0.75rem;
}

.popup-header h1 {
  line-height: 1.2;
  word-break: break-word;
  hyphens: auto;
}

.popup-body {
  margin-bottom: 0.75rem;
}

/* Beautiful How to Play Title */
.how-to-play-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #374151;
  text-align: center;
  position: relative;
  padding: 0.25rem 0;
}

.title-icon {
  font-size: 1.75rem;
  animation: icon-bounce 2s ease-in-out infinite;
}

.title-text {
  position: relative;
  letter-spacing: 0.025em;
}

@keyframes icon-bounce {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-3px) rotate(-2deg);
  }
  75% {
    transform: translateY(-1px) rotate(2deg);
  }
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  padding: 0.75rem;
  background-color: #f8fafc;
  border-radius: 12px;
  border-left: 4px solid #6366f1;
}

.rule-number {
  background-color: #6366f1;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.875rem;
  margin-right: 1rem;
  flex-shrink: 0;
}

.rule-item p {
  margin: 0;
  line-height: 1.5;
  color: #374151;
}

.celebration-section {
  text-align: center;
}

.celebration-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

.popup-footer {
  text-align: center;
}

.start-button,
.next-button {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
  min-width: 150px;
}

.start-button:hover,
.next-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.start-button:active,
.next-button:active {
  transform: translateY(0);
}

.next-button {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.next-button:hover {
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.hidden {
  display: none !important;
}

/* Loading Spinner */
.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #6366f1;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Loading text animation */
.loading-text {
  animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Mobile Responsive Adjustments */

.error-highlight {
  background-color: #fecaca !important;
  border: 3px solid #dc2626 !important;
  animation: errorPulse 0.5s ease-in-out;
}

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

/* Top Left Controls Container */
.top-left-controls {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.top-left-controls:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
}

/* Level Display Styles */
#levelDisplay {
  background: transparent;
  box-shadow: none;
  border: none;
  padding: 0;
  margin: 0;
  position: static;
}

#levelDisplay p {
  margin: 0;
  white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  font-size: 1.125rem;
  font-weight: 700;
  color: #1e40af;
  letter-spacing: 0.025em;
}

/* Back Button Icon */
.back-button-icon {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.back-button-icon::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.back-button-icon:hover::before {
  left: 100%;
}

.back-button-icon:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.back-button-icon:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.back-button-icon svg {
  transition: transform 0.2s ease;
}

.back-button-icon:hover svg {
  transform: translateX(-2px);
}

/* Mobile responsive for level selection */
@media (max-width: 640px) {
  .levels-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }

  .level-button {
    font-size: 1rem;
    min-height: 50px;
  }

  #levelDisplay {
    top: 0.5rem;
    padding: 0.5rem 1rem;
  }

  #levelDisplay p {
    font-size: 0.875rem;
  }
}

/* Beautiful Button Styles */
.beautiful-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  text-decoration: none;
  min-width: 100px;
  z-index: 1;
}

.beautiful-button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
  z-index: -1;
}

.beautiful-button:hover::before {
  left: 100%;
}

.beautiful-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  animation: buttonPulse 0.6s ease-in-out;
}

@keyframes buttonPulse {
  0% {
    transform: translateY(-2px) scale(1);
  }
  50% {
    transform: translateY(-2px) scale(1.05);
  }
  100% {
    transform: translateY(-2px) scale(1);
  }
}

.beautiful-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.beautiful-button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.beautiful-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.beautiful-button:disabled:hover {
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Back Button */
.back-button {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  font-size: 1.25rem;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-width: auto;
  font-weight: bold;
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.back-button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.back-button:hover::before {
  left: 100%;
}

.back-button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.back-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Hint Button */
.hint-button {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.hint-button:hover {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

.hint-button:disabled {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  box-shadow: 0 2px 8px rgba(156, 163, 175, 0.2);
}

/* Solution Button */
.solution-button {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.solution-button:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.solution-button:disabled {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  box-shadow: 0 2px 8px rgba(156, 163, 175, 0.2);
}

/* Reset Button */
.reset-button {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.reset-button:hover {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.4);
}

.reset-button:disabled {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  box-shadow: 0 2px 8px rgba(156, 163, 175, 0.2);
}

/* Undo Button */
.undo-button {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(107, 114, 128, 0.3);
}

.undo-button:hover {
  background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
  box-shadow: 0 8px 25px rgba(107, 114, 128, 0.4);
}

.undo-button:disabled {
  background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
  box-shadow: 0 2px 8px rgba(209, 213, 219, 0.2);
}

/* Audio Button */
.audio-button {
  background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.3);
  padding: 0.75rem 1.5rem;
  min-width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-button svg {
  transition: transform 0.2s ease;
}

.audio-button:hover svg {
  transform: scale(1.1);
}

.audio-button:hover {
  background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%);
  box-shadow: 0 8px 25px rgba(6, 182, 212, 0.4);
}

.audio-button:disabled {
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
  box-shadow: 0 2px 8px rgba(156, 163, 175, 0.2);
}

/* Popup Button Styles */
.popup-footer .start-button {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  min-width: 150px;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.3);
}

.popup-footer .start-button:hover {
  background: linear-gradient(135deg, #5b21b6 0%, #7c3aed 100%);
  box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
}

.back-button {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  font-size: 1rem;
  padding: 0.875rem 1.75rem;
  min-width: 150px;
  box-shadow: 0 4px 15px rgba(107, 114, 128, 0.3);
}

.back-button:hover {
  background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
  box-shadow: 0 6px 20px rgba(107, 114, 128, 0.4);
}

.play-again-button {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  font-size: 1.125rem;
  padding: 1rem 2rem;
  min-width: 200px;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.3);
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
  margin-top: 1rem;
}

.play-again-button:hover {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.4);
  transform: translateY(-2px);
}

.play-again-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.hint-ok-button {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
  font-size: 1rem;
  padding: 0.875rem 1.75rem;
  min-width: 120px;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.hint-ok-button:hover {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.next-level-button {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  font-size: 1rem;
  padding: 0.875rem 1.75rem;
  min-width: 150px;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.next-level-button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.back-to-home-button {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  font-size: 1rem;
  padding: 0.875rem 1.75rem;
  min-width: 150px;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.back-to-home-button:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* Enhanced Game Over Popup Styles */
.game-over-popup {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 2px solid #10b981;
  box-shadow: 0 25px 50px -12px rgba(16, 185, 129, 0.25),
    0 0 0 1px rgba(16, 185, 129, 0.1);
}

.celebration-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  font-size: 1.5rem;
  animation: confetti-fall 3s ease-in-out infinite;
  opacity: 0.8;
}

.confetti-1 {
  top: -20px;
  left: 10%;
  animation-delay: 0s;
}

.confetti-2 {
  top: -20px;
  left: 30%;
  animation-delay: 0.5s;
}

.confetti-3 {
  top: -20px;
  left: 50%;
  animation-delay: 1s;
}

.confetti-4 {
  top: -20px;
  left: 70%;
  animation-delay: 1.5s;
}

.confetti-5 {
  top: -20px;
  left: 90%;
  animation-delay: 2s;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

.success-icon-container {
  position: relative;
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.success-icon {
  font-size: 4rem;
  animation: success-bounce 1s ease-in-out;
  z-index: 2;
  position: relative;
}

.success-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border: 3px solid #10b981;
  border-radius: 50%;
  animation: success-pulse 2s ease-in-out infinite;
}

@keyframes success-bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes success-pulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 0.7;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

.achievement-section {
  text-align: center;
  padding: 1rem 0;
}

.achievement-badge {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 20px;
  margin-bottom: 1.5rem;
  box-shadow: 0 8px 25px rgba(251, 191, 36, 0.3);
  animation: badge-glow 2s ease-in-out infinite alternate;
}

.badge-icon {
  font-size: 2rem;
  margin-right: 0.75rem;
  animation: trophy-spin 1s ease-in-out;
}

.badge-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.badge-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.badge-subtitle {
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0.9;
  line-height: 1;
}

@keyframes badge-glow {
  0% {
    box-shadow: 0 8px 25px rgba(251, 191, 36, 0.3);
  }
  100% {
    box-shadow: 0 12px 35px rgba(251, 191, 36, 0.5);
  }
}

@keyframes trophy-spin {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(10deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

.celebration-message {
  font-size: 1.125rem;
  line-height: 1.6;
  color: #374151;
  max-width: 400px;
  margin: 0 auto;
  font-weight: 500;
}

.celebration-button {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
  font-size: 1.125rem;
  padding: 1rem 2rem;
  min-width: 200px;
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.celebration-button:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  box-shadow: 0 8px 30px rgba(59, 130, 246, 0.4);
  transform: translateY(-2px) scale(1.02);
}

.button-icon {
  font-size: 1.25rem;
  animation: rocket-bounce 1s ease-in-out infinite;
}

.button-text {
  font-weight: 600;
}

@keyframes rocket-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

/* ===== COMPREHENSIVE RESPONSIVE DESIGN ===== */

/* Override min-height: 100vh for landscape mode only */
@media (orientation: landscape) {
  body {
    min-height: auto !important;
  }
}

/* Keep min-height: 100vh for web screens (desktop) */
@media (min-width: 1024px) {
  body {
    min-height: 100vh !important;
  }
}

/* Extra small screens - ensure popup never exceeds viewport */
@media (max-width: 320px) {
  .popup-content {
    width: 95%;
    max-width: min(320px, calc(100vw - 0.5rem));
    padding: 0.75rem;
    margin: 0.25rem;
  }

  .popup-header h1 {
    line-height: 1.1;
  }

  .popup-header p {
    font-size: 0.875rem;
  }
}

/* Landscape Mobile (orientation: landscape) */
@media (orientation: landscape) and (max-height: 600px) {
  body {
    padding: 0.5rem;
  }

  .popup-content {
    max-height: 90vh;
    padding: 1rem;
    margin: 0.5rem;
    max-width: min(400px, 90vw);
  }

  .popup-header h1 {
    margin-bottom: 0.5rem;
  }

  .popup-header p {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
  }

  .rules-section {
    margin-bottom: 0.5rem;
  }

  .rule-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .rule-number {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
    margin-right: 0.75rem;
  }

  .celebration-section {
    margin-bottom: 0.5rem;
  }

  .celebration-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }

  .start-button,
  .next-button {
    padding: 0.75rem;
    font-size: 1rem;
    min-width: 160px;
  }

  .game-over-popup {
    max-height: 85vh;
    padding: 1rem;
  }

  .success-icon {
    font-size: 2.5rem;
  }

  .achievement-badge {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
  }

  .badge-icon {
    font-size: 1.25rem;
    margin-right: 0.5rem;
  }

  .badge-title {
    font-size: 0.875rem;
  }

  .badge-subtitle {
    font-size: 0.625rem;
  }

  .celebration-message {
    font-size: 0.875rem;
    padding: 0 0.5rem;
  }

  .celebration-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    min-width: 140px;
  }

  .confetti {
    font-size: 1rem;
  }

  .how-to-play-title {
    font-size: 1.125rem;
    gap: 0.25rem;
    margin-bottom: 0.375rem;
  }

  .title-icon {
    font-size: 1.25rem;
  }

  .levels-grid {
    max-height: 20rem;
    padding: 0.5rem;
  }

  .level-button {
    font-size: 0.875rem;
    min-height: 40px;
  }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  body {
    padding: 0.5rem;
    overflow-x: hidden;
  }

  .grid-container {
    gap: 1px;
    padding: 8px;
    max-width: calc(100vw - 3rem);
    width: calc(100vw - 3rem);
  }

  .cell {
    font-size: clamp(0.5rem, 3vw, 0.8rem);
    border-radius: 6px;
    min-height: 25px;
    min-width: 25px;
  }

  .top-left-controls {
    top: 0.25rem;
    left: 0.25rem;
    padding: 0.375rem 0.5rem;
    gap: 0.5rem;
  }

  #levelDisplay p {
    font-size: 0.75rem;
    font-weight: 600;
  }

  .back-button-icon {
    width: 32px;
    height: 32px;
  }

  .back-button-icon svg {
    width: 16px;
    height: 16px;
  }

  .beautiful-button {
    font-size: 0.625rem;
    padding: 0.5rem 1rem;
    min-width: 70px;
    border-radius: 8px;
  }

  .popup-content {
    width: 90%;
    padding: 1rem;
    margin: 0.5rem;
    border-radius: 12px;
    max-width: min(350px, 90vw);
  }

  .popup-header h1 {
    margin-bottom: 0.5rem;
    line-height: 1.1;
  }

  .popup-header p {
    font-size: 0.875rem;
  }

  .how-to-play-title {
    font-size: 1rem;
    gap: 0.25rem;
    margin-bottom: 0.375rem;
  }

  .title-icon {
    font-size: 1.125rem;
  }

  .rule-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .rule-number {
    width: 20px;
    height: 20px;
    font-size: 0.625rem;
    margin-right: 0.5rem;
  }

  .rule-item p {
    font-size: 0.75rem;
    line-height: 1.4;
  }

  .start-button,
  .next-button {
    padding: 0.75rem;
    font-size: 0.875rem;
    min-width: 140px;
  }

  .levels-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .level-button {
    font-size: 0.75rem;
    min-height: 40px;
    border-radius: 8px;
  }

  .celebration-section {
    margin-bottom: 0.75rem;
  }

  .celebration-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
  }

  .game-over-popup {
    margin: 0.5rem;
    max-width: min(350px, calc(100vw - 1rem));
    padding: 0.75rem;
  }

  .success-icon {
    font-size: 2.5rem;
  }

  .success-ring {
    width: 50px;
    height: 50px;
  }

  .achievement-badge {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: 12px;
  }

  .badge-icon {
    font-size: 1.25rem;
    margin-right: 0.375rem;
  }

  .badge-title {
    font-size: 0.875rem;
  }

  .badge-subtitle {
    font-size: 0.625rem;
  }

  .celebration-message {
    font-size: 0.875rem;
    padding: 0 0.5rem;
  }

  .celebration-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    min-width: 140px;
  }

  .confetti {
    font-size: 1rem;
  }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
  body {
    padding: 0.75rem;
    overflow-x: hidden;
  }

  .grid-container {
    gap: 1.5px;
    padding: 10px;
    max-width: calc(100vw - 4rem);
    width: calc(100vw - 4rem);
  }

  .cell {
    font-size: clamp(0.6rem, 2.5vw, 1rem);
    border-radius: 8px;
    min-height: 28px;
    min-width: 28px;
  }

  .beautiful-button {
    font-size: 0.75rem;
    padding: 0.625rem 1.25rem;
    min-width: 80px;
  }

  .top-left-controls {
    top: 0.5rem;
    left: 0.5rem;
    padding: 0.5rem 0.75rem;
  }

  #levelDisplay p {
    font-size: 0.875rem;
    font-weight: 600;
  }

  .back-button-icon {
    width: 36px;
    height: 36px;
  }

  .back-button-icon svg {
    width: 18px;
    height: 18px;
  }

  .start-button {
    font-size: 1rem;
    padding: 0.875rem 1.75rem;
    min-width: 180px;
  }

  .popup-footer .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 120px;
  }

  .levels-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
  }

  .level-button {
    font-size: 1rem;
    min-height: 50px;
  }

  /* Mobile adjustments for game over popup */
  .game-over-popup {
    margin: 0.5rem;
    max-width: min(400px, calc(100vw - 1rem));
  }

  .success-icon {
    font-size: 3rem;
  }

  .success-ring {
    width: 60px;
    height: 60px;
  }

  .achievement-badge {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
  }

  .badge-icon {
    font-size: 1.5rem;
    margin-right: 0.5rem;
  }

  .badge-title {
    font-size: 1rem;
  }

  .badge-subtitle {
    font-size: 0.75rem;
  }

  .celebration-message {
    font-size: 1rem;
    padding: 0 1rem;
  }

  .celebration-button {
    font-size: 1rem;
    padding: 0.875rem 1.5rem;
    min-width: 180px;
  }

  .confetti {
    font-size: 1.25rem;
  }

  /* Mobile adjustments for How to Play title */
  .how-to-play-title {
    font-size: 1.25rem;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
    padding: 0.125rem 0;
  }

  .title-icon {
    font-size: 1.5rem;
  }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
  body {
    padding: 1rem;
  }

  .grid-container {
    gap: 2px;
    padding: 12px;
  }

  .cell {
    font-size: 1.1rem;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 90px;
  }

  .top-left-controls {
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.625rem 0.875rem;
  }

  #levelDisplay p {
    font-size: 1rem;
  }

  .back-button-icon {
    width: 38px;
    height: 38px;
  }

  .back-button-icon svg {
    width: 19px;
    height: 19px;
  }

  .popup-content {
    max-width: 480px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.125rem;
    min-height: 55px;
  }

  .how-to-play-title {
    font-size: 1.375rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 190px;
  }

  .celebration-icon {
    font-size: 3.5rem;
  }

  .success-icon {
    font-size: 3.5rem;
  }

  .achievement-badge {
    padding: 1rem 1.25rem;
  }

  .badge-icon {
    font-size: 1.75rem;
  }

  .badge-title {
    font-size: 1.125rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 1.75rem;
    min-width: 190px;
  }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  body {
    padding: 1.5rem;
  }

  .grid-container {
    gap: 2px;
    padding: 14px;
  }

  .cell {
    font-size: 1.2rem;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 100px;
  }

  .top-left-controls {
    top: 1rem;
    left: 1rem;
    padding: 0.75rem 1rem;
  }

  #levelDisplay p {
    font-size: 1.125rem;
  }

  .back-button-icon {
    width: 40px;
    height: 40px;
  }

  .popup-content {
    max-width: 550px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.25rem;
    min-height: 60px;
  }

  .how-to-play-title {
    font-size: 1.5rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 200px;
  }

  .celebration-icon {
    font-size: 4rem;
  }

  .success-icon {
    font-size: 4rem;
  }

  .achievement-badge {
    padding: 1rem 1.5rem;
  }

  .badge-icon {
    font-size: 2rem;
  }

  .badge-title {
    font-size: 1.25rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 2rem;
    min-width: 200px;
  }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
  body {
    padding: 2rem;
  }

  .grid-container {
    gap: 2px;
    padding: 12px;
  }

  .cell {
    font-size: 1.1rem;
  }

  .beautiful-button {
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    min-width: 100px;
  }

  .top-left-controls {
    top: 1rem;
    left: 1rem;
    padding: 0.75rem 1rem;
  }

  #levelDisplay p {
    font-size: 1.125rem;
  }

  .popup-content {
    max-width: 400px;
    padding: 1.5rem;
  }

  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
  }

  .level-button {
    font-size: 1.25rem;
    min-height: 60px;
  }

  .how-to-play-title {
    font-size: 1.5rem;
  }

  .rule-item {
    padding: 0.75rem;
  }

  .rule-number {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
  }

  .start-button,
  .next-button {
    padding: 1rem;
    font-size: 1.125rem;
    min-width: 200px;
  }

  .celebration-icon {
    font-size: 4rem;
  }

  .success-icon {
    font-size: 4rem;
  }

  .achievement-badge {
    padding: 1rem 1.5rem;
  }

  .badge-icon {
    font-size: 2rem;
  }

  .badge-title {
    font-size: 1.25rem;
  }

  .celebration-message {
    font-size: 1.125rem;
  }

  .celebration-button {
    font-size: 1.125rem;
    padding: 1rem 2rem;
    min-width: 200px;
  }
}

/* Large Desktop (≥1440px) */
@media (min-width: 1440px) {
  body {
    padding: 3rem;
  }

  .popup-content {
    max-width: 480px;
    padding: 1.5rem;
  }

  .levels-grid {
    max-width: 800px;
    margin: 0 auto;
  }

  .level-button {
    font-size: 1.375rem;
    min-height: 70px;
  }

  .how-to-play-title {
    font-size: 1.75rem;
  }

  .rule-item {
    padding: 1rem;
  }

  .rule-number {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .start-button,
  .next-button {
    padding: 1.25rem;
    font-size: 1.25rem;
    min-width: 220px;
  }

  .celebration-icon {
    font-size: 5rem;
  }

  .success-icon {
    font-size: 5rem;
  }

  .achievement-badge {
    padding: 1.25rem 2rem;
  }

  .badge-icon {
    font-size: 2.5rem;
  }

  .badge-title {
    font-size: 1.5rem;
  }

  .celebration-message {
    font-size: 1.25rem;
  }

  .celebration-button {
    font-size: 1.25rem;
    padding: 1.25rem 2.5rem;
    min-width: 220px;
  }
}
