/* =================== QUIZ MODAL FIXES =================== */

/* 1. FIX: Ensure modal doesn't get cut off - add max-height and scrolling */
.quiz-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8); /* Increased opacity for better contrast */
  backdrop-filter: blur(8px); /* Increased blur */
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px; /* Reduced padding for mobile */
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto; /* ADD: Allow scrolling if content is tall */
}

.quiz-modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.quiz-modal {
  background: white;
  border-radius: 28px;
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 40px); /* FIX: Prevent modal from being taller than viewport */
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden; /* Keep for rounded corners */
  transform: scale(0.94) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative; /* FIX: Ensure close button positions correctly */
  display: flex;
  flex-direction: column; /* FIX: Better layout control */
  margin: auto; /* FIX: Center in overlay when overlay scrolls */
}

.quiz-modal-overlay.open .quiz-modal {
  transform: scale(1) translateY(0);
}

/* 2. FIX: Improved close button - more visible and always accessible */
.quiz-close-btn {
  position: absolute;
  top: 16px; /* Moved closer to top edge */
  right: 16px; /* Moved closer to right edge */
  width: 40px; /* Larger for easier clicking */
  height: 40px;
  border-radius: 12px;
  border: 2px solid rgba(0, 0, 0, 0.1); /* ADD: Border for visibility */
  background: white; /* Changed to white for better visibility */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 18px; /* Larger icon */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100; /* FIX: Ensure it's always on top */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* ADD: Shadow for depth */
}

.quiz-close-btn:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #dc2626;
  transform: scale(1.1); /* ADD: Slight scale on hover */
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
}

.quiz-close-btn:active {
  transform: scale(0.95);
}

/* 3. FIX: Progress bar - ensure it's visible */
.quiz-progress-strip {
  height: 6px; /* Slightly taller */
  background: #e2e8f0; /* Better contrast */
  flex-shrink: 0; /* FIX: Don't shrink when space is tight */
}

.quiz-progress-strip-fill {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #a855f7);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.5); /* ADD: Glow effect */
}

/* 4. FIX: Modal body - scrollable content area */
.quiz-modal-body {
  padding: 48px 32px 32px; /* More top padding for close button clearance */
  overflow-y: auto; /* FIX: Allow scrolling within modal body */
  flex: 1; /* FIX: Take available space */
  min-height: 0; /* FIX: Allow flex child to shrink */
}

/* Custom scrollbar for modal body */
.quiz-modal-body::-webkit-scrollbar {
  width: 8px;
}

.quiz-modal-body::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 10px;
}

.quiz-modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.quiz-modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* 5. FIX: Question step label - more visible */
.quiz-step-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: #8b5cf6;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ADD: Progress indicator in step label */
.quiz-step-label::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #8b5cf6;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

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

/* 6. RESPONSIVE: Better mobile experience */
@media (max-width: 640px) {
  .quiz-modal-overlay {
    padding: 12px;
  }
  
  .quiz-modal {
    border-radius: 20px;
    max-height: calc(100vh - 24px);
  }
  
  .quiz-modal-body {
    padding: 40px 20px 24px;
  }
  
  .quiz-close-btn {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }
  
  .quiz-question {
    font-size: 1.25rem;
  }
  
  .quiz-option {
    padding: 14px;
  }
  
  .quiz-result-icon {
    width: 80px;
    height: 80px;
    font-size: 2.5rem;
  }
}

/* 7. ACCESSIBILITY: Focus states */
.quiz-close-btn:focus-visible {
  outline: 3px solid #7c3aed;
  outline-offset: 2px;
}

.quiz-option:focus-visible {
  outline: 3px solid #7c3aed;
  outline-offset: 2px;
}

/* 8. FIX: Ensure modal content doesn't overflow on short screens */
@media (max-height: 700px) {
  .quiz-modal-body {
    padding: 36px 24px 24px;
  }
  
  .quiz-question {
    margin-bottom: 16px;
    font-size: 1.25rem;
  }
  
  .quiz-result-icon {
    width: 72px;
    height: 72px;
    font-size: 2.25rem;
    margin-bottom: 16px;
  }
  
  .quiz-result-type {
    font-size: 1.5rem;
  }
}

/* 9. ENHANCEMENT: Add visual feedback when modal opens */
@keyframes modalFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(8px);
  }
}

.quiz-modal-overlay.open {
  animation: modalFadeIn 0.3s ease-out;
}

/* 10. FIX: Ensure result screen also scrolls properly */
.quiz-result {
  text-align: center;
  padding-bottom: 20px; /* Extra padding at bottom */
}

/* 11. ENHANCEMENT: Better option interaction */
.quiz-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.quiz-option::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(180deg, #7c3aed, #a855f7);
  transform: scaleY(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.quiz-option:hover::before,
.quiz-option.selected::before {
  transform: scaleY(1);
}

.quiz-option:hover {
  border-color: #c4b5fd;
  background: #f5f3ff;
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.1);
}

.quiz-option.selected {
  border-color: #7c3aed;
  background: #ede9fe;
  transform: translateX(4px);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

/* 12. FIX: Improved quiz trigger button */
.quiz-start-btn {
  width: 100%;
  padding: 16px 24px;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: white;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}

.quiz-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.45);
}

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

/* 13. FIX: Ensure keyboard navigation works */
.quiz-option {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.quiz-option:focus {
  outline: none;
}

/* 14. ACCESSIBILITY: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .quiz-modal-overlay,
  .quiz-modal,
  .quiz-option,
  .quiz-close-btn,
  .quiz-progress-strip-fill {
    transition: none;
    animation: none;
  }
}
