/*
 * Interface des tests Codeclic
 * Commune à l'espace membre (espace/examen/index.php et pedagogique.php) et aux tests gratuits.
 * Le mode pédagogique ajoute la correction après chaque réponse (.cc-pedago).
 *
 * Tout est rangé sous .cc-exam pour ne rien changer au reste de la page
 * (contenu, titres, tableaux) : seul le test lui-même prend ces styles.
 */

.cc-exam {
  --primary: #446e9b;
  --success: #3cb521;
  --success-dark: #30911a;
  --info: #3399f3;
  --danger: #cd0200;
  --warning: #d47500;
  --light: #f8f9fa;
  --dark: #212529;
  --gray: #6a8494;
  --radius: 12px;
  --transition: 0.2s ease;
}

.cc-exam *,
.cc-exam *::before,
.cc-exam *::after {
  box-sizing: border-box;
}

body.exam-mode {
  background: #fff;
  overflow-x: hidden;
}

.cc-exam .exam-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem;
}

/* Mode sombre (espace membre) */
body.dark-mode {
  background: #1a1a1a;
  color: #e0e0e0;
}

body.dark-mode .cc-exam .exam-area {
  background: #1a1a1a;
  color: #e0e0e0;
}

body.dark-mode .cc-exam .media-wrapper img,
body.dark-mode .cc-exam .media-wrapper video {
  border-color: #404040;
  opacity: 1;
  filter: none;
}

body.dark-mode .cc-exam .question-text {
  color: #e0e0e0;
}

body.dark-mode .cc-exam .choice-label {
  background: #2d2d2d;
  color: #e0e0e0;
  border-color: #404040;
}

body.dark-mode .cc-exam .choice-input:checked + .choice-label {
  background: #5ed03d;
  color: white;
}

body.dark-mode .cc-exam .validate-btn button {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

body.dark-mode .cc-exam .validate-btn {
  background: #2d2d2d;
  border-top-color: #404040;
}

body.dark-mode .cc-exam .question-info {
  background: #3a3a3a;
}

body.dark-mode .cc-exam #questionType {
  color: #e0e0e0;
  background: #404040;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-weight: 600;
}

/* Masquer le type de question quand hideCorrect est actif */
body.hide-correct .cc-exam #questionType {
  display: none;
}

body.dark-mode .cc-exam #zoomModal {
  background: rgba(0,0,0,0.95);
}

/* Zone d'examen */
.cc-exam .exam-area {
  display: none;
}

.cc-exam .exam-area.active {
  display: block;
}

/* Media (image/vidéo) */
.cc-exam .media-wrapper {
  position: relative;
  width: 100%;
  margin-bottom: 0.5rem;
}

.cc-exam .media-wrapper img,
.cc-exam .media-wrapper video {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  /* Cadre des photos et des vidéos (960x470) réservé avant leur chargement : rien ne saute */
  aspect-ratio: auto 960 / 470;
}

/* Spinner vidéo (connexion lente) */
.cc-exam .media-wrapper .video-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: cc-spin 0.8s linear infinite;
  z-index: 10;
  pointer-events: none;
}

/* Optimisation tablette pour éviter le scroll */
@media (min-width: 768px) and (max-width: 1024px) {
  .cc-exam .exam-container {
    max-height: 100vh;
    overflow-y: auto;
    padding: 0.5rem;
  }

  .cc-exam .exam-area {
    display: flex;
    flex-direction: column;
    max-height: 100vh;
  }

  .cc-exam .media-wrapper {
    max-height: 35vh;
    margin-bottom: 0.5rem;
  }

  .cc-exam .media-wrapper img,
  .cc-exam .media-wrapper video {
    max-height: 35vh;
    width: auto;
    max-width: 100%;
    margin: 0 auto;
    display: block;
  }

  .cc-exam .question-text p {
    font-size: 0.95rem;
    margin: 0 0 0.4rem 0;
  }

  .cc-exam .choices-container {
    gap: 0.3rem;
    margin-bottom: 0.5rem;
  }

  .cc-exam .choice-label {
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
  }

  .cc-exam .validate-btn {
    margin-top: 0.75rem;
  }

  .cc-exam .validate-btn button {
    padding: 0.7rem 1rem;
  }
}

/* Timer */
.cc-exam .timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.75rem;
  text-align: center;
  font-weight: 700;
  border-radius: 0 0 var(--radius) var(--radius);
  display: none !important;  /* Masqué car le décompte est dans le bouton */
}

.cc-exam .timer-bar.active {
  display: block;
}

.cc-exam .timer-bar.urgent {
  background: rgba(220, 53, 69, 0.85);
  animation: cc-pulse 1s infinite;
}

@keyframes cc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

/* Info question */
.cc-exam .question-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--light);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.cc-exam .question-number {
  color: var(--primary);
}

.cc-exam .question-difficulty {
  color: var(--danger);
}

/* Réglages pendant le test : son et mode sombre, au bout de la barre de la question.
   Le type de question se range juste à leur gauche. */
.cc-exam .question-info {
  gap: 0.5rem;
}

.cc-exam #questionType {
  margin: -0.2rem 0 -0.2rem auto;
}

/* Même boîte pour le type de question en clair et en sombre : changer de mode ne décale rien.
   En sombre, seul le fond de l'étiquette apparaît (règle plus haut, dont le retrait est remplacé ici). */
.cc-exam #questionType,
body.dark-mode .cc-exam #questionType {
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
}

.cc-exam .cc-reglages {
  display: flex;
  flex: none;
  gap: 0.3rem;
  margin: -0.3rem -0.3rem -0.3rem 0;   /* les boutons ne grandissent pas la barre */
}

body.hide-correct .cc-exam .cc-reglages {
  margin-left: auto;
}

/* Les textes de la barre restent sur une ligne. Si la place manque (petit téléphone,
   question difficile), le script garde « ⚠️ » sans le mot « Difficile » (cc-serre),
   et en tout dernier recours laisse les textes passer à la ligne (cc-serre-plus). */
.cc-exam .question-info > span {
  white-space: nowrap;
}

.cc-exam .question-info.cc-serre .cc-mot {
  display: none;
}

.cc-exam .question-info.cc-serre-plus > span {
  white-space: normal;
}

.cc-exam .cc-reglage {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgba(68, 110, 155, 0.12);   /* fond visible : on voit tout de suite que ce sont des boutons */
  color: var(--primary);
  cursor: pointer;
}

.cc-exam .cc-reglage svg {
  width: 18px;
  height: 18px;
}

.cc-exam .cc-reglage .cc-ic-b,
.cc-exam .cc-reglage.cc-actif .cc-ic-a {
  display: none;
}

.cc-exam .cc-reglage.cc-actif .cc-ic-b {
  display: block;
}

@media (hover: hover) {
  .cc-exam .cc-reglage:hover {
    background: rgba(68, 110, 155, 0.22);
  }
}

.cc-exam .cc-reglage:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

body.dark-mode .cc-exam .cc-reglage {
  color: #e0e0e0;
  background: rgba(255, 255, 255, 0.12);
}

@media (hover: hover) {
  body.dark-mode .cc-exam .cc-reglage:hover {
    background: rgba(255, 255, 255, 0.22);
  }
}

/* Téléphone : barre un peu plus serrée (après les règles des boutons, pour passer devant) */
@media (max-width: 420px) {
  .cc-exam .question-info {
    gap: 0.3rem;
  }

  .cc-exam .cc-reglage {
    width: 30px;
  }

  .cc-exam #questionType,
  body.dark-mode .cc-exam #questionType {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }
}

/* Très petits téléphones (320 px) */
@media (max-width: 340px) {
  .cc-exam .question-info {
    gap: 0.2rem;
  }

  .cc-exam #questionType,
  body.dark-mode .cc-exam #questionType {
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }
}

/* Mode sombre : la barre du haut de la page suit (pages des tests seulement) */
body.dark-mode .navbar.bg-light {
  background-color: #2d2d2d !important;
  background-image: none !important;   /* le thème du site y met un dégradé clair */
  border-color: #404040 !important;
}

body.dark-mode .navbar-light .navbar-nav .nav-link {
  color: rgba(255, 255, 255, 0.75);
}

body.dark-mode .navbar-light .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.25);
}

body.dark-mode .navbar-light .navbar-toggler-icon {
  filter: invert(1);
}

/* Question */
.cc-exam .question-text {
  margin-bottom: 0.75rem;
}

.cc-exam .question-text p {
  font-size: 1rem;
  line-height: 1.4;
  margin: 0 0 0.5rem 0;
  font-weight: 700;
}

.cc-exam .question-text-part2 {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.4;
  margin: 0.75rem 0;
}

.cc-exam .question-text-part2 p {
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 700;
  margin: 0;
}

/* Choix de réponses */
.cc-exam .choices-container {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.cc-exam .choice-item {
  position: relative;
}

.cc-exam .choice-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.cc-exam .choice-label {
  display: block;
  padding: 0.75rem 1rem;
  background: var(--gray);
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
}

@media (max-width: 991px) {
  .cc-exam .choice-label {
    padding: 0.6rem 1rem;
  }
}

.cc-exam .choice-input:checked + .choice-label {
  background: #5ed03d;
}

/* Bouton de validation */
.cc-exam .validate-btn {
  margin-top: 1.5rem;
}

@media (max-width: 991px) {
  .cc-exam .validate-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #dee2e6;
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    z-index: 100;
    margin-top: 0;
  }

  .cc-exam .exam-area {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

.cc-exam .validate-btn button {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 900;
  border-radius: var(--radius);
  border: none;
  background: var(--success);
  color: white;
  cursor: pointer;
  transition: background 0.3s ease;
}

.cc-exam .validate-btn button.timer-urgent {
  background: #ff6b6b;
  animation: cc-pulse 1s infinite;
}

@media (max-width: 991px) {
  .cc-exam .validate-btn button {
    padding: 0.7rem 1rem;
  }
}

.cc-exam .validate-btn button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.cc-exam .validate-btn button:not(:disabled):hover {
  background: #48c02b;
}

/* Zoom (mobile) */
.cc-exam .zoom-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  z-index: 50;
}

@media (max-width: 991px) {
  .cc-exam .zoom-btn {
    display: flex;
  }
}

.cc-exam .zoom-btn svg {
  width: 20px;
  height: 20px;
}

/* Modal zoom carrée avec pan et zoom */
.cc-exam .zoom-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.cc-exam .zoom-modal.active {
  display: flex;
}

.cc-exam .zoom-container {
  position: relative;
  width: min(90vw, 90vh);
  height: min(90vw, 90vh);
  overflow: hidden;
  border-radius: var(--radius);
  touch-action: none;
}

.cc-exam .zoom-modal img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 100%;
  min-height: 100%;
  max-width: none;
  cursor: grab;
  user-select: none;
}

.cc-exam .zoom-modal img.zoomed {
  cursor: move;
}

.cc-exam .zoom-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}

/* La croix vient de la feuille de style : pas de texte dans la page avant le départ */
.cc-exam .zoom-close::before {
  content: "\2715";
}

/* Responsive */
/* « Question » devant le numéro, sur ordinateur et tablette seulement (texte venu de la feuille de style) */
.cc-exam .question-label-desktop::before {
  content: "Question\00a0";
}

@media (max-width: 767px) {
  .cc-exam .question-label-desktop {
    display: none;
  }
}

@media (min-width: 768px) {
  .cc-exam .exam-container {
    padding: 1rem;
  }
}

/* Téléphone, pages gratuites : la colonne de la page (container) a déjà sa marge de 12 px.
   Le test n'en ajoute pas une deuxième : photo, question et réponses s'alignent sur Valider. */
@media (max-width: 767.98px) {
  .container > .cc-exam .exam-container {
    padding-left: 0;
    padding-right: 0;
  }
}

/* Audio caché */
.cc-exam audio {
  display: none !important;
}

/* Chargement */
.cc-exam .loading {
  text-align: center;
  padding: 3rem 1rem;
}

.cc-exam .loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: cc-spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes cc-spin {
  to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------------
 * Mode pédagogique : la correction après chaque réponse
 * ------------------------------------------------------------------ */

/* Réponses corrigées */
.cc-exam .choice-label.correct {
  background: var(--success) !important;
}

.cc-exam .choice-label.incorrect {
  background: var(--danger) !important;
}

.cc-exam .choice-label.incorrect::before {
  content: '✗ ';
  font-weight: bold;
  margin-right: 0.25rem;
}

.cc-exam .choice-label.disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* Correction et explication, sous les réponses */
.cc-exam .correction-area {
  display: none;
  margin-bottom: 0.75rem;
  padding: 1rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: var(--radius);
}

.cc-exam .correction-area.active {
  display: block;
}

.cc-exam .correction-result {
  display: flex;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1.05rem;
}

.cc-exam .correction-result.correct {
  background: #d1e7dd;
  color: #0f5132;
}

.cc-exam .correction-result.incorrect {
  background: #f8d7da;
  color: #842029;
}

.cc-exam .correction-text {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--dark);
}

.cc-exam .correction-text p:last-child {
  margin-bottom: 0;
}

/* « Question suivante », à la place de Valider dans la même barre */
.cc-exam .validate-btn button.btn-suivante {
  background: var(--primary);
}

/* Sur téléphone, le doigt reste « posé » sur le bouton qui apparaît : pas de couleur de survol */
.cc-exam .validate-btn button.btn-suivante:not(:disabled):hover {
  background: var(--primary);
}

@media (hover: hover) {
  .cc-exam .validate-btn button.btn-suivante:not(:disabled):hover {
    background: #365a80;
  }
}

/* « Modifier la question » (administrateur) */
.cc-exam .admin-edit-container {
  display: none;
  margin-bottom: 0.75rem;
}

.cc-exam .btn-admin-edit {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  color: white;
  background: var(--warning);
  border-radius: var(--radius);
}

.cc-exam .btn-admin-edit:hover {
  color: white;
  background: #b86500;
}

body.dark-mode .cc-exam .choice-label.correct,
body.dark-mode .cc-exam .choice-label.incorrect {
  color: white;
}

body.dark-mode .cc-exam .correction-area {
  background: #2d2d2d;
}

body.dark-mode .cc-exam .correction-result {
  background: #1a1a1a;
}

body.dark-mode .cc-exam .correction-result.correct {
  color: #75b798;
}

body.dark-mode .cc-exam .correction-result.incorrect {
  color: #ea868f;
}

body.dark-mode .cc-exam .correction-text {
  color: #e0e0e0;
}
