/**
 * GCSE Revision Hub - Unified Quiz Container System
 * 
 * Feature: F-030 Quiz System Standardization
 * Created: 2026-01-22
 * 
 * This file provides a standardized container system for ALL quiz question types
 * to prevent frame jumping and create consistent user experience.
 * 
 * USAGE:
 * 1. Include this CSS BEFORE individual question type stylesheets
 * 2. Wrap question content in .quiz-container with BEM structure
 * 3. Use design tokens only (NO hardcoded values)
 * 
 * CONTAINER HIERARCHY:
 * .question-display (parent frame - NEVER changes)
 *   └── .quiz-container (universal inner wrapper)
 *       ├── .quiz-container__header (stem + metadata)
 *       ├── .quiz-container__main (question content)
 *       └── .quiz-container__footer (submit + feedback)
 */

/* ============================================================================
   CORE CONTAINER STRUCTURE
   ============================================================================ */

.quiz-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  
  /* Consistent content minimums prevent layout jumps */
  min-height: 640px; /* Default: mobile */
  
  /* No CSS animation — first-load fade-in is JS-based (inline style on
     #question-container) because dynamic class additions from QuizHeightManager
     disrupt CSS animations. Carousel transitions are also JS-based. */
}

/* ============================================================================
   BEM STRUCTURE COMPONENTS
   ============================================================================ */

/* Header: Question stem, marks, metadata */
.quiz-container__header {
  flex-shrink: 0; /* Never compress */
  margin-bottom: var(--space-6, 1.5rem);
  padding-bottom: var(--space-4, 1rem);
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.1));
}

/* Main: Interactive question content area */
.quiz-container__main {
  flex: 1; /* Grows to fill available space */
  display: flex;
  flex-direction: column;
  min-height: 300px; /* Ensures minimum content area */
  
  /* Consistent spacing for all question types */
  gap: var(--space-4, 1rem);
}

/* Footer: Submit button, feedback, results */
.quiz-container__footer {
  flex-shrink: 0; /* Never compress */
  margin-top: var(--space-6, 1.5rem);
  padding-top: var(--space-4, 1rem);
  
  /* Optional separator for visual clarity */
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.05));
}

/* ============================================================================
   RESPONSIVE DIMENSIONS (Fixed height system - LEGACY)
   ============================================================================ */

/* Mobile: Default (<768px) */
.quiz-container {
  min-height: 600px; /* Optimized for compact MCQ layout */
}

/* Tablet: 768px - 1023px */
@media (min-width: 768px) and (max-width: 1023px) {
  .quiz-container {
    min-height: 720px; /* More space for side-by-side layouts */
  }
  
  .quiz-container__main {
    min-height: 400px; /* Increased for consistency */
  }
}

/* Desktop: 1024px+ */
@media (min-width: 1024px) {
  .quiz-container {
    min-height: 600px; /* Optimized for compact MCQ layout */
  }
  
  .quiz-container__main {
    min-height: 350px; /* Adjusted for compact options */
  }
}

/* ============================================================================
   DYNAMIC HEIGHT SYSTEM (New UX-optimized approach)
   ============================================================================ */

/* Base dynamic container - Gen Z optimized timing */
.quiz-container--dynamic {
  min-height: auto;
  height: auto;
  
  /* Gen Z smooth transitions - faster than social media (120ms vs 150ms) */
  transition: min-height 120ms cubic-bezier(0.23, 1, 0.32, 1),
              opacity 60ms ease-out;
  overflow: hidden;
  
  /* GPU acceleration for 60fps */
  will-change: min-height, opacity;
  transform: translateZ(0);
}

/* Question-type specific minimum content heights */
.quiz-container--dynamic.quiz-container--mcq {
  min-height: 400px; /* Compact for multiple choice options */
}

.quiz-container--dynamic.quiz-container--keyword {
  min-height: 500px; /* Input area + sidebar feedback */
}

.quiz-container--dynamic.quiz-container--multipart {
  min-height: 600px; /* Tabs + content areas */
}

.quiz-container--dynamic.quiz-container--exact {
  min-height: 450px; /* Similar to MCQ but with input */
}

.quiz-container--dynamic.quiz-container--self {
  min-height: 450px; /* Rating interface + textarea */
}

.quiz-container--dynamic.quiz-container--fillblank {
  min-height: 480px; /* Text with input fields */
}

.quiz-container--dynamic.quiz-container--ordering {
  min-height: 520px; /* Draggable list items */
}

.quiz-container--dynamic.quiz-container--matching {
  min-height: 550px; /* Two-column matching interface */
}

.quiz-container--dynamic.quiz-container--diagram {
  min-height: 600px; /* Image + label placement */
}

/* Mobile-first optimizations */
@media (max-width: 767px) {
  .quiz-container--dynamic {
    padding: var(--space-4, 1rem);
  }
  
  .quiz-container--dynamic .quiz-container__header {
    margin-bottom: var(--space-4, 1rem);
  }
  
  .quiz-container--dynamic .quiz-container__footer {
    margin-top: var(--space-4, 1rem);
  }
  
  /* Tighter mobile minimums */
  .quiz-container--dynamic.quiz-container--mcq {
    min-height: 360px;
  }
  
  .quiz-container--dynamic.quiz-container--keyword {
    min-height: 450px;
  }
  
  .quiz-container--dynamic.quiz-container--multipart {
    min-height: 500px; /* Accordion layout is more compact */
  }
  
  .quiz-container--dynamic.quiz-container--exact {
    min-height: 380px;
  }
  
  .quiz-container--dynamic.quiz-container--self {
    min-height: 400px;
  }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1023px) {
  .quiz-container--dynamic.quiz-container--multipart {
    min-height: 580px; /* Tabs need more space than accordion */
  }
  
  .quiz-container--dynamic.quiz-container--diagram {
    min-height: 650px; /* Larger images on tablet */
  }
}

/* Gen Z Transition states - Social media quality */
.quiz-container--transitioning {
  pointer-events: none; /* Prevent interaction during transition */
}

/* Swipe-based transitions for smoother Gen Z experience */
.quiz-container__main--swipe-out-left {
  animation: swipeOutLeft 200ms cubic-bezier(0.55, 0, 0.1, 1) forwards;
}

.quiz-container__main--swipe-in-right {
  animation: swipeInRight 200ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

.quiz-container__main--swipe-out-right {
  animation: swipeOutRight 200ms cubic-bezier(0.55, 0, 0.1, 1) forwards;
}

.quiz-container__main--swipe-in-left {
  animation: swipeInLeft 200ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes swipeOutLeft {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-40%); }
}

@keyframes swipeInRight {
  0%   { transform: translateX(40%); }
  100% { transform: translateX(0); }
}

@keyframes swipeOutRight {
  0%   { transform: translateX(0); }
  100% { transform: translateX(40%); }
}

@keyframes swipeInLeft {
  0%   { transform: translateX(-40%); }
  100% { transform: translateX(0); }
}

/* Carousel wrapper — overflow visible so arrows sit outside card border */
.quiz-carousel-wrapper {
  position: relative;
  overflow: visible;
}

/* ============================================================================
   CAROUSEL PEEK CARDS — adjacent card edges visible at sides
   ============================================================================ */

.quiz-carousel-wrapper::before,
.quiz-carousel-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 16px;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.18);
  opacity: 0.7;
  z-index: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Light mode: darker peek edges */
body.light-mode .quiz-carousel-wrapper::before,
body.light-mode .quiz-carousel-wrapper::after,
[data-theme="light"] .quiz-carousel-wrapper::before,
[data-theme="light"] .quiz-carousel-wrapper::after {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.12);
}

/* Left peek — right edge of "previous" card */
.quiz-carousel-wrapper::before {
  right: 100%;
  margin-right: 4px;
  border-radius: 0 11px 11px 0; /* rounded top-right + bottom-right (card-facing side) */
  border-left: none; /* cut-off edge */
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.08);
}

/* Right peek — left edge of "next" card */
.quiz-carousel-wrapper::after {
  left: 100%;
  margin-left: 4px;
  border-radius: 11px 0 0 11px; /* rounded top-left + bottom-left (card-facing side) */
  border-right: none; /* cut-off edge */
  box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.08);
}

/* Hide peeks at carousel boundaries */
.quiz-carousel-wrapper[data-pos="first"]::before,
.quiz-carousel-wrapper[data-pos="only"]::before,
.quiz-carousel-wrapper[data-pos="only"]::after {
  display: none;
}
.quiz-carousel-wrapper[data-pos="last"]::after {
  display: none;
}

/* Fade peeks during carousel slide transition */
.quiz-carousel-wrapper.carousel-transitioning::before,
.quiz-carousel-wrapper.carousel-transitioning::after {
  opacity: 0;
}

/* Mobile: peek edges — same height as card, narrower width */
@media (max-width: 768px) {
  .quiz-carousel-wrapper::before,
  .quiz-carousel-wrapper::after {
    width: 10px;
    /* Keep card-height and card-top from JS — matches the question frame */
    margin-left: 3px;
    margin-right: 3px;
    opacity: 0.7;
    box-shadow: none;
  }
  .quiz-carousel-wrapper::before {
    border-left: none;
    border-radius: 0 11px 11px 0;
  }
  .quiz-carousel-wrapper::after {
    border-right: none;
    border-radius: 11px 0 0 11px;
  }
  /* Light mode mobile */
  body.light-mode .quiz-carousel-wrapper::before,
  body.light-mode .quiz-carousel-wrapper::after,
  [data-theme="light"] .quiz-carousel-wrapper::before,
  [data-theme="light"] .quiz-carousel-wrapper::after {
    border-color: rgba(0, 0, 0, 0.15);
    background: rgba(0, 0, 0, 0.04);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  }
}

/* Desktop wide: slightly larger peek */
@media (min-width: 1024px) {
  .quiz-carousel-wrapper::before,
  .quiz-carousel-wrapper::after {
    width: 24px;
    opacity: 0.65;
  }
}

/* Carousel arrow buttons — fixed at card edges on all screen sizes */
.quiz-carousel-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
  background: var(--bg-card, rgba(255,255,255,0.95));
  color: var(--text-secondary, #4b5563);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: opacity 150ms, transform 150ms, background 150ms;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.quiz-carousel-arrow:hover:not(:disabled) {
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
  background: var(--bg-hover, rgba(245,245,250,1));
}

.quiz-carousel-arrow:active:not(:disabled) {
  transform: translateY(-50%) scale(0.95);
}

.quiz-carousel-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.quiz-carousel-arrow svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.5;
}

/* Desktop: position just outside the 800px content area */
.quiz-carousel-arrow--prev { left: calc((100vw - 800px) / 2 - 8px); }
.quiz-carousel-arrow--next { right: calc((100vw - 800px) / 2 - 8px); }

/* Mobile: position at card edges */
@media (max-width: 768px) {
  .quiz-carousel-arrow {
    width: 32px;
    height: 32px;
    opacity: 0.75;
  }
  .quiz-carousel-arrow svg {
    width: 16px;
    height: 16px;
  }
  .quiz-carousel-arrow--prev { left: 4px; }
  .quiz-carousel-arrow--next { right: 4px; }
}

/* Legacy fade transitions - kept for fallback */
.quiz-container__main--entering {
  opacity: 0;
  transform: translateY(6px);
  animation: quiz-content-enter-gen-z 120ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
  animation-delay: 20ms;
}

.quiz-container__main--exiting {
  opacity: 1;
  transform: translateY(0);
  animation: quiz-content-exit-gen-z 60ms cubic-bezier(0.55, 0, 0.1, 1) forwards;
}

/* Gen Z optimized keyframes - faster, smoother */
@keyframes quiz-content-enter-gen-z {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  60% {
    opacity: 0.8;
    transform: translateY(1px) scale(1.005); /* Micro-bounce */
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes quiz-content-exit-gen-z {
  to {
    opacity: 0;
    transform: translateY(-4px) scale(0.99); /* Subtle scale for depth */
  }
}

/* Emergency rollback - add this class to revert to fixed heights */
.quiz-container--force-fixed {
  min-height: 600px !important;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .quiz-container--force-fixed {
    min-height: 720px !important;
  }
}

/* ============================================================================
   QUESTION STEM STANDARDIZATION
   ============================================================================ */

/* Question stem with badges below text */
.quiz-question-stem {
  display: flex;
  flex-direction: column;
  gap: var(--space-3, 0.75rem);
  margin-bottom: var(--space-3, 0.75rem);
}

.quiz-question-stem .quiz-question-text {
  margin: 0;
}

.quiz-question-number {
  font-weight: 700;
  color: var(--text-secondary, #64748b);
}

/* ============================================================================
   MARKS BADGE COMPONENT
   ============================================================================ */

.quiz-marks-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  white-space: nowrap;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: 6px;
  padding: 3px 8px;
}

.quiz-marks-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent, #2563EB);
}

.quiz-marks-label {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted, #64748b);
  text-transform: lowercase;
}

/* Shield + marks badge wrapper — right-aligned on its own line */
.quiz-stem-badges {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding-top: var(--space-2, 0.5rem);
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.1));
}

/* Mastery shield next to marks badge */
.quiz-marks-shield {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  line-height: 0;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: 6px;
  padding: 2px;
}

.quiz-marks-shield svg {
  width: 22px;
  height: 22px;
}

/* Dark mode: marks text remains readable via CSS variables */

/* Mobile: badges layout unchanged (already stacked column) */

/* ============================================================================
   ORIGINAL STEM STANDARDIZATION
   ============================================================================ */

.quiz-container__header .quiz-question-stem {
  margin: 0; /* Remove default margins */
}

.quiz-container__header .quiz-question-text {
  font-size: var(--text-lg, 1.125rem);
  font-weight: var(--font-semibold, 600);
  color: var(--text-primary, #f9fafb);
  line-height: var(--leading-relaxed, 1.625);
  margin: 0 0 var(--space-3, 0.75rem) 0;
}

.quiz-container__header .quiz-question-marks {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1, 0.25rem) var(--space-3, 0.75rem);
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-primary, #2563EB);
  border-radius: var(--radius-full, 9999px);
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--font-semibold, 600);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* ============================================================================
   SUBMIT BUTTON STANDARDIZATION
   ============================================================================ */

.quiz-container__footer .quiz-btn-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-6, 1.5rem);
  
  /* Consistent button styling across all question types */
  background: var(--color-primary, #2563EB);
  color: white;
  border: none;
  border-radius: var(--radius-md, 0.5rem);
  font-size: var(--text-base, 1rem);
  font-weight: var(--font-semibold, 600);
  
  cursor: pointer;
  transition: var(--transition-all, all 150ms ease-in-out);
  
  /* Accessibility: Touch target minimum 44px */
  min-height: 44px;
  min-width: 120px;
}

.quiz-container__footer .quiz-btn-submit:hover {
  background: #2563eb; /* Slightly darker blue */
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

.quiz-container__footer .quiz-btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Mobile: Full-width submit button */
@media (max-width: 767px) {
  .quiz-container__footer .quiz-btn-submit {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================================================
   FEEDBACK SYSTEM STANDARDIZATION
   ============================================================================ */

.quiz-container__footer .quiz-feedback {
  margin-top: var(--space-4, 1rem);
  padding: var(--space-4, 1rem);
  border-radius: var(--radius-md, 0.5rem);
  font-size: var(--text-sm, 0.875rem);
  line-height: var(--leading-normal, 1.5);
  
  /* Hidden by default */
  opacity: 0;
  transform: translateY(-8px);
  transition: var(--transition-all, all 150ms ease-in-out);
  pointer-events: none;
}

.quiz-container__footer .quiz-feedback.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.quiz-container__footer .quiz-feedback.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-success, #22c55e);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.quiz-container__footer .quiz-feedback.warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-warning, #f59e0b);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.quiz-container__footer .quiz-feedback.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-error, #ef4444);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ============================================================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================================================ */

/* Focus management for keyboard navigation */
.quiz-container:focus-within {
  outline: 2px solid var(--color-primary, #2563EB);
  outline-offset: 4px;
  border-radius: var(--radius-md, 0.5rem);
}

/* Screen reader announcements */
.quiz-container__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* High contrast support */
@media (prefers-contrast: high) {
  .quiz-container__header {
    border-bottom-width: 2px;
  }
  
  .quiz-container__footer {
    border-top-width: 2px;
  }
  
  .quiz-container__footer .quiz-btn-submit {
    border: 2px solid currentColor;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .quiz-container,
  .quiz-container__footer .quiz-feedback,
  .quiz-container__footer .quiz-btn-submit {
    transition: none;
    animation: none;
  }
  
  .quiz-container__footer .quiz-btn-submit:hover {
    transform: none;
  }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .quiz-container {
    min-height: auto;
    page-break-inside: avoid;
  }
  
  .quiz-container__footer .quiz-btn-submit {
    display: none; /* Hide interactive elements */
  }
  
  .quiz-container__header,
  .quiz-container__footer {
    border: none; /* Remove decorative borders */
  }
}