/* ============================================
   Modal Styles and Animations
   ============================================ */

.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0);
  transition: background 0.3s ease;
}

.modal-overlay.active {
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 20px;
  padding: 2rem;
  max-width: 90%;
  max-height: 90%;
  overflow: auto;
  transform: scale(0.7) translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content.active {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-body {
  text-align: center;
  padding: 1rem;
}

.modal-title {
  font-size: 2rem;
  font-weight: bold;
  margin: 1rem 0;
  color: #2c3e50;
}

.modal-message {
  font-size: 1.1rem;
  color: #7f8c8d;
  margin: 1rem 0;
}

.modal-btn {
  margin-top: 1.5rem;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #16A34A 0%, #DC2626 100%);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(22, 163, 74, 0.4);
}

.modal-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(22, 163, 74, 0.5);
}

/* ============================================
   Success Checkmark Animation
   ============================================ */

.success-checkmark {
  width: 80px;
  height: 80px;
  margin: 0 auto 1rem;
}

.check-icon {
  width: 80px;
  height: 80px;
  position: relative;
  border-radius: 50%;
  box-sizing: content-box;
  border: 4px solid #4CAF50;
  animation: checkmarkScale 0.6s ease;
}

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

.icon-line {
  height: 5px;
  background-color: #4CAF50;
  display: block;
  border-radius: 2px;
  position: absolute;
  z-index: 10;
}

.line-tip {
  top: 46px;
  left: 14px;
  width: 25px;
  transform: rotate(45deg);
  animation: checkmarkTip 0.5s 0.4s ease forwards;
  opacity: 0;
}

.line-long {
  top: 38px;
  right: 8px;
  width: 47px;
  transform: rotate(-45deg);
  animation: checkmarkLong 0.5s 0.4s ease forwards;
  opacity: 0;
}

@keyframes checkmarkTip {
  to {
    opacity: 1;
  }
}

@keyframes checkmarkLong {
  to {
    opacity: 1;
  }
}

.icon-circle {
  top: -4px;
  left: -4px;
  z-index: 10;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  position: absolute;
  box-sizing: content-box;
  border: 4px solid rgba(76, 175, 80, .2);
}

.icon-fix {
  top: 8px;
  width: 5px;
  left: 26px;
  z-index: 1;
  height: 85px;
  position: absolute;
  transform: rotate(-45deg);
  background-color: white;
}

/* ============================================
   Error Cross Animation
   ============================================ */

.error-cross {
  width: 80px;
  height: 80px;
  margin: 0 auto 1rem;
}

.cross-icon {
  width: 80px;
  height: 80px;
  position: relative;
  border-radius: 50%;
  box-sizing: content-box;
  border: 4px solid #F44336;
  animation: crossScale 0.6s ease;
}

@keyframes crossScale {
  0% {
    transform: scale(0) rotate(0deg);
  }
  50% {
    transform: scale(1.2) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
  }
}

.cross-line {
  height: 5px;
  background-color: #F44336;
  display: block;
  border-radius: 2px;
  position: absolute;
  z-index: 10;
  width: 48px;
  top: 37px;
  left: 16px;
}

.line-left {
  transform: rotate(45deg);
  animation: crossLineLeft 0.5s 0.4s ease forwards;
  opacity: 0;
}

.line-right {
  transform: rotate(-45deg);
  animation: crossLineRight 0.5s 0.4s ease forwards;
  opacity: 0;
}

@keyframes crossLineLeft {
  to {
    opacity: 1;
  }
}

@keyframes crossLineRight {
  to {
    opacity: 1;
  }
}

.cross-circle {
  top: -4px;
  left: -4px;
  z-index: 10;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  position: absolute;
  box-sizing: content-box;
  border: 4px solid rgba(244, 67, 54, .2);
}

/* ============================================
   Hint Bulb Animation
   ============================================ */

.hint-bulb {
  width: 100px;
  height: 100px;
  margin: 0 auto 1rem;
  position: relative;
}

.bulb {
  font-size: 4rem;
  animation: bulbSwing 2s ease-in-out infinite;
  display: inline-block;
  position: relative;
}

@keyframes bulbSwing {
  0%, 100% {
    transform: rotate(-5deg);
  }
  50% {
    transform: rotate(5deg);
  }
}

.bulb-glow {
  position: absolute;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, rgba(255, 235, 59, 0.5) 0%, transparent 70%);
  border-radius: 50%;
  top: -20px;
  left: -20px;
  animation: glow 1.5s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% {
    opacity: 0.5;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

.modal-hint {
  background: #fff3cd;
  border: 2px solid #ffc107;
  color: #856404;
  padding: 1rem;
  border-radius: 10px;
  margin: 1rem 0;
  font-weight: 500;
}

.modal-warning {
  color: #dc3545;
  font-size: 0.9rem;
  font-style: italic;
  margin-top: 0.5rem;
}

/* ============================================
   Typing Animation
   ============================================ */

.typing-effect {
  overflow: hidden;
  white-space: nowrap;
  margin: 0 auto;
  animation: typing 3.5s steps(40, end), blink-caret .75s step-end infinite;
}

@keyframes typing {
  from { width: 0 }
  to { width: 100% }
}

@keyframes blink-caret {
  from, to { border-color: transparent }
  50% { border-color: #007bff; }
}

/* ============================================
   Floating Bubbles Animation
   ============================================ */

.floating-bubbles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.bubble {
  position: absolute;
  bottom: -100px;
  /* Background color set dynamically in JavaScript */
  border-radius: 50%;
  opacity: 0.5;
  animation: float 15s infinite ease-in-out;
}

@keyframes float {
  0% {
    transform: translateY(0px) translateX(0px);
    opacity: 0;
  }
  10% {
    opacity: 0.5;
  }
  90% {
    opacity: 0.5;
  }
  100% {
    transform: translateY(-1000px) translateX(100px);
    opacity: 0;
  }
}

/* ============================================
   Ripple Effect
   ============================================ */

.ripple {
  position: relative;
  overflow: hidden;
}

.ripple:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  animation: ripple-animation 0.6s ease-out;
}

@keyframes ripple-animation {
  to {
    width: 200%;
    height: 200%;
    opacity: 0;
  }
}

/* ============================================
   Flip Card Animation
   ============================================ */

.flip-card {
  perspective: 1000px;
  animation: flipIn 0.6s ease;
}

@keyframes flipIn {
  0% {
    transform: rotateY(90deg);
    opacity: 0;
  }
  100% {
    transform: rotateY(0);
    opacity: 1;
  }
}

/* ============================================
   Pulse Animation
   ============================================ */

.pulse {
  animation: pulse 1.5s infinite;
}

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

/* ============================================
   Shake Animation
   ============================================ */

.shake {
  animation: shake 0.5s;
}

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

/* ============================================
   Bounce Animation
   ============================================ */

.bounce {
  animation: bounce 0.6s;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-30px);
  }
  60% {
    transform: translateY(-15px);
  }
}

/* ============================================
   Slide Animations
   ============================================ */

.slide-in-left {
  animation: slideInLeft 0.5s ease;
}

@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.slide-in-right {
  animation: slideInRight 0.5s ease;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================
   Fade Animations
   ============================================ */

.fade-in {
  animation: fadeIn 0.5s ease;
}

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

.fade-in-up {
  animation: fadeInUp 0.5s ease;
}

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

/* ============================================
   Loading Spinner
   ============================================ */

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #16A34A;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

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

/* ============================================
   Glow Effect
   ============================================ */

.glow {
  animation: glowEffect 2s ease-in-out infinite;
}

@keyframes glowEffect {
  0%, 100% {
    box-shadow: 0 0 5px rgba(22, 163, 74, 0.5),
                0 0 10px rgba(22, 163, 74, 0.5),
                0 0 15px rgba(22, 163, 74, 0.5);
  }
  50% {
    box-shadow: 0 0 10px rgba(220, 38, 38, 0.8),
                0 0 20px rgba(220, 38, 38, 0.8),
                0 0 30px rgba(220, 38, 38, 0.8);
  }
}

/* ============================================
   Number Counter Animation
   ============================================ */

.counter {
  display: inline-block;
  animation: counterUp 0.5s ease;
}

@keyframes counterUp {
  0% {
    transform: translateY(20px) rotateX(-90deg);
    opacity: 0;
  }
  100% {
    transform: translateY(0) rotateX(0);
    opacity: 1;
  }
}

/* ============================================
   Progress Bar Liquid Fill
   ============================================ */

.liquid-progress {
  position: relative;
  overflow: hidden;
  border-radius: 100px;
}

.liquid-progress::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%);
  animation: liquidWave 3s linear infinite;
}

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

/* ============================================
   Three.js Canvas Styles
   ============================================ */

#three-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  opacity: 0.3;
}

/* ============================================
   Particle Effects
   ============================================ */

.particle {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  animation: particleFloat 4s ease-out forwards;
}

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

/* ============================================
   Hover Effects for Buttons
   ============================================ */

button {
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

button:hover {
  transform: translateY(-2px) rotateX(10deg);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

button:active {
  transform: translateY(0) rotateX(0);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

/* ============================================
   Option Button Enhanced Animations
   ============================================ */

.option-btn {
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.option-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.option-btn:hover::before {
  width: 300px;
  height: 300px;
}

.option-btn.correct {
  animation: correctPulse 0.6s ease;
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%) !important;
}

.option-btn.incorrect {
  animation: incorrectShake 0.6s ease;
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%) !important;
}

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

@keyframes incorrectShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* ============================================
   Timer Pulse Animation
   ============================================ */

#timerDisplay {
  transition: all 0.3s ease;
}

#timerDisplay.warning {
  animation: timerPulse 1s infinite;
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
  color: white;
}

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

/* ============================================
   Code Display Animation
   ============================================ */

#codeDisplay {
  animation: codeGlow 2s ease-in-out infinite alternate;
}

@keyframes codeGlow {
  from {
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
  }
  to {
    text-shadow: 0 0 20px rgba(16, 185, 129, 0.8),
                 0 0 30px rgba(16, 185, 129, 0.6);
  }
}

/* ============================================
   Logo Animation
   ============================================ */

img[alt="UAE Codes Logo"] {
  animation: logoFloat 3s ease-in-out infinite;
}

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

/* ============================================
   Mobile Responsive Animations
   ============================================ */

@media (max-width: 768px) {
  .modal-content {
    max-width: 95%;
    margin: 1rem;
    padding: 1.5rem;
  }

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

  .modal-message {
    font-size: 1rem;
  }

  .success-checkmark,
  .error-cross,
  .hint-bulb {
    transform: scale(0.8);
  }

  /* Ensure logo doesn't stretch on mobile */
  img[alt="UAE Codes Logo"] {
    max-width: 200px;
    height: auto;
    object-fit: contain;
  }

  /* Reduce animation intensity on mobile for performance */
  #three-canvas {
    opacity: 0.1;
  }

  .floating-bubbles {
    display: none;
  }
}