/* ============================================================
   QUIZ UI - Question & Answer Styling
   Professional, engaging, accessible
   ============================================================ */

/* ============================================================
   CUSTOM INPUTS - Radio & Checkbox
   ============================================================ */

.custom-radio,
.custom-checkbox {
  appearance: none;
  width: 24px;
  height: 24px;
  min-width: 24px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 200ms var(--ease-out);
  border: 2px solid #cbd5e1;
  outline: none;
}

.custom-radio {
  border-radius: 50%;
}

.custom-checkbox {
  border-radius: 6px;
}

.custom-radio:hover,
.custom-checkbox:hover {
  border-color: var(--color-primary-500);
  box-shadow: var(--focus-ring);
}

.custom-radio:checked {
  border-color: var(--color-primary-500);
  background: radial-gradient(circle, var(--color-primary-500) 0%, var(--color-primary-500) 30%, white 30%, white 100%);
}

.custom-checkbox:checked {
  background-color: var(--color-primary-500);
  border-color: var(--color-primary-500);
  background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100%;
}

.custom-radio:focus-visible,
.custom-checkbox:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* ============================================================
   ANSWER OPTIONS - Labels
   ============================================================ */

.answer-option {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  border-radius: 10px;
  border: 2px solid #e5e7eb;
  background-color: #fafbfc;
  cursor: pointer;
  transition: all 200ms var(--ease-out);
  user-select: none;
  min-height: 4rem;
}

.answer-option:hover {
  border-color: var(--color-primary-500);
  background-color: #f0f7ff;
  box-shadow: 0 2px 8px color-mix(in oklch, var(--color-primary-500) 8%, transparent);
  transform: translateX(4px);
}

.answer-option:active {
  transform: scale(0.98);
}

.answer-option.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Correct answer state */
.answer-option.correct {
  border-color: #16a34a;
  background-color: #f0fdf4;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1);
}

.answer-option.correct .answer-text {
  color: #166534;
  font-weight: 700;
}

/* Incorrect answer state */
.answer-option.incorrect {
  border-color: #dc2626;
  background-color: #fef2f2;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.answer-option.incorrect .answer-text {
  color: #991b1b;
  text-decoration: line-through;
  font-weight: 600;
}

/* Muted/unselected in learning mode */
.answer-option.muted {
  opacity: 0.5;
  pointer-events: none;
}

.answer-text {
  flex: 1;
  font-size: 1.05rem;
  line-height: 1.6;
  color: #1f2937;
  transition: color 200ms var(--ease-out);
}

.answer-option:hover .answer-text {
  color: var(--color-primary-500);
  font-weight: 600;
}

/* ============================================================
   FEEDBACK & EXPLANATION
   ============================================================ */

/* Side-stripe retiré : bordure pleine + tint de fond (Impeccable compliant).
   Le variant sémantique (correct / incorrect) passe par border-color + bg tint. */
.feedback-container {
  margin-top: 2rem;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  background-color: color-mix(in oklch, var(--color-primary-50) 92%, white);
  border: 1px solid color-mix(in oklch, var(--color-primary-200) 55%, var(--color-border));
}

.feedback-container.correct {
  background-color: color-mix(in oklch, var(--color-success-50) 92%, white);
  border-color: color-mix(in oklch, var(--color-success-300) 55%, var(--color-border));
}

.feedback-container.incorrect {
  background-color: color-mix(in oklch, var(--color-error-50) 92%, white);
  border-color: color-mix(in oklch, var(--color-error-300) 55%, var(--color-border));
}

.feedback-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-primary-700);
}

.feedback-title.correct {
  color: var(--color-success-700);
}

.feedback-title.incorrect {
  color: var(--color-error-700);
}

.feedback-text {
  color: var(--color-text-primary);
  line-height: 1.7;
  font-size: 0.95rem;
}

.feedback-text strong {
  color: var(--color-primary-700);
  font-weight: 700;
}

/* Learning category hints */
.learning-hints {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
}

.hints-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  display: block;
}

.hint-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.hint-tag {
  display: inline-block;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  background-color: var(--color-neutral-100);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-light);
}

/* ============================================================
   BUTTONS - Quiz Navigation
   ============================================================ */

.quiz-btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 200ms var(--ease-out);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.quiz-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.quiz-btn-primary {
  background-color: var(--color-primary-500);
  color: white;
}

.quiz-btn-primary:hover:not(:disabled) {
  background-color: #005189;
  box-shadow: 0 4px 12px color-mix(in oklch, var(--color-primary-500) 30%, transparent);
}

.quiz-btn-primary:active:not(:disabled) {
  transform: scale(0.97);
}

.quiz-btn-secondary {
  background-color: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

.quiz-btn-secondary:hover:not(:disabled) {
  background-color: #e5e7eb;
  border-color: #9ca3af;
}

.quiz-btn-success {
  background-color: #16a34a;
  color: white;
}

.quiz-btn-success:hover:not(:disabled) {
  background-color: #15803d;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

/* ============================================================
   SKELETON LOADING
   ============================================================ */

.skeleton {
  border-radius: 10px;
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 37%, #f3f4f6 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.2s ease infinite;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .answer-option {
    padding: 0.875rem;
    gap: 0.75rem;
  }

  .answer-text {
    font-size: 0.95rem;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .custom-radio,
  .custom-checkbox,
  .answer-option,
  .quiz-btn {
    transition: none;
  }
}

/* ============================================================
   TEXTE JUSTIFIÉ — question & feedback uniquement (blocs long-form).
   Les options de réponse (5-15 mots) restent left-align pour éviter
   les espaces inter-mots monstrueux sur 2-3 lignes.
   ============================================================ */
#questionText,
#feedbackContainer {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hanging-punctuation: first last;
  /* Empêche un mot non hyphénable (URL, terme technique) de forcer
     l'élargissement du conteneur au-delà du viewport mobile. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Override du max-width: 70ch global sur <p> pour la question :
   la question doit occuper toute la largeur du wrapper (comme les choix). */
#questionText {
  max-width: none;
}

/* Garantit que le main du quiz peut rétrécir en flex child : sans
   min-width:0, un enfant descendant (mot long, code, tableau) force
   le main à dépasser la largeur du viewport en mobile. */
#viewQuiz main,
#viewQuiz #questionContainer {
  min-width: 0;
}

/* Feedback : les titres internes (bold) restent alignés à gauche
   pour rester des "ancres" visuelles rapides à scanner. */
#feedbackContainer .font-bold,
#feedbackContainer strong,
#feedbackContainer h1,
#feedbackContainer h2,
#feedbackContainer h3,
#feedbackContainer h4 {
  text-align: left;
  hyphens: manual;
}

/* Sur très petits écrans, garder justify peut créer des espaces
   inter-mots trop larges si peu de mots par ligne : bascule en left. */
@media (max-width: 380px) {
  #questionText,
  #feedbackContainer {
    text-align: left;
    hyphens: auto;
  }
}

/* ============================================================
   TABLEAUX dans les questions & feedbacks
   Certaines questions injectent du HTML <table> inline. Sans styles
   dédiés, l'affichage retombe sur les défauts navigateur (border
   inset laide, padding 1px, pas de contraste th/td).
   ============================================================ */
#questionContainer table,
#feedbackContainer table {
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  margin: 1rem 0;
  font-size: 0.9rem;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  /* Scroll horizontal si contenu trop large (nombres, longues cellules) */
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#questionContainer table th,
#questionContainer table td,
#feedbackContainer table th,
#feedbackContainer table td {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--color-border, #e2e8f0);
  text-align: left;
  vertical-align: top;
  /* Neutralise l'héritage justify + hyphens du parent question */
  hyphens: manual;
  overflow-wrap: normal;
  word-break: normal;
}

#questionContainer table th,
#feedbackContainer table th {
  background: var(--color-primary-50, oklch(94.5% 0.065 236));
  color: var(--color-primary-800, oklch(36% 0.26 236));
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
}

#questionContainer table tr:nth-child(even) td,
#feedbackContainer table tr:nth-child(even) td {
  background: color-mix(in oklch, var(--color-neutral-50, #f8fafc) 60%, white);
}

/* Cellules numériques (chiffres, prix) : tabular-nums pour alignement */
#questionContainer table td,
#feedbackContainer table td {
  font-variant-numeric: tabular-nums;
}

/* Mobile : réduire padding, mais garder lisible */
@media (max-width: 640px) {
  #questionContainer table,
  #feedbackContainer table {
    font-size: 0.85rem;
  }
  #questionContainer table th,
  #questionContainer table td,
  #feedbackContainer table th,
  #feedbackContainer table td {
    padding: 0.45rem 0.55rem;
  }
}
