/* =========================================================
   Quiz — enveloppe v1 (docs/quiz.md pour la logique, docs/enveloppe-v1.md pour la peau).
   Préfixe .quiz-*, tokens de dicoplus.css : juste = gamme de l'unité, faux = rouge du livre.
========================================================= */

:root {
  --quiz-t-choices: .22s;
  --quiz-t-card:    .42s;
  --quiz-t-pause:   .8s;
  --quiz-t-stagger: .15s;
}

/* ── Hauteur (Pascal, 25/09 : progression, image, réponses et Suivant sur un seul écran) ──
   Chaîne flex de #app (100dvh) jusqu'à la carte stimulus : la carte prend la hauteur qui
   reste, carrée, bornée par la largeur ; réponses, feedback et Suivant gardent leur taille.
   Si ça ne tient vraiment pas (écran minuscule), #view-quiz défile. */
html.is-quiz #app { height: 100dvh; min-height: 310px; }   /* plancher = petit téléphone couché (Pascal, 26/09) : en dessous, la page défile au lieu de s'écraser */
html.is-quiz #main-content { flex: 1 1 auto; min-height: 0; padding-bottom: 0; }
#view-quiz {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; justify-content: center;
  padding: var(--sp-1) var(--gutter) var(--sp-2);
}
.quiz-content {
  position: relative; width: 100%; max-width: var(--card-max);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  container-type: inline-size;   /* les cqi de la scène et de la carte = largeur de la colonne */
}
.quiz-side { display: contents; }   /* réponses + feedback + Suivant : colonne à part seulement en paysage */

/* Page de démarrage : périmètre, nombre de questions, Démarrer ; la scène et les réponses attendent */
.quiz-content.is-waiting > #quiz-stage, .quiz-content.is-waiting > .quiz-side { display: none; }
.quiz-start { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.quiz-start__scope { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-h2); font-weight: 700; }
.quiz-start__count { color: var(--ink-2); font-size: var(--fs-body); }
.quiz-start__btn { margin-top: var(--sp-3); min-width: 200px; min-height: 56px; font-size: var(--fs-h2); transform-origin: center; }
.quiz-start__btn.is-launch { animation: quiz-launch .6s cubic-bezier(.4, 0, .2, 1) forwards; pointer-events: none; }
@keyframes quiz-launch {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}
.quiz-dev-badge {
  position: absolute; top: -8px; right: 0; z-index: 3;
  padding: 2px 6px; border: 1px dashed var(--alert); border-radius: 6px;
  background: var(--paper); color: var(--alert);
  font-family: ui-monospace, monospace; font-size: 11px;
}

/* Scène : carte stimulus 3:2 (format des images, 17/11) + Écouter à cheval sur son bord bas.
   La carte est un item flex qui prend la hauteur restante ; sa largeur découle du ratio 3:2
   et reste bornée par la largeur de la colonne (max-height = 2/3 de la largeur, scène comprise). */
#quiz-stage { flex: 1 1 0; min-height: 120px; max-height: calc(100cqi * 2 / 3 + 24px); width: 100%; display: flex; flex-direction: column; align-items: center; margin-top: 4px; }
.quiz-stimulus {
  position: relative; flex: 1 1 0; min-height: 0; width: auto; max-width: 100%;
  max-height: calc(100cqi * 2 / 3);   /* = largeur de la colonne × 2/3 : Chrome ne transfère pas max-width sur la hauteur, on le fait ici */
  aspect-ratio: 3 / 2; overflow: hidden; border-radius: var(--r-card);
  container-type: size;   /* les unités cq* de la carte (emoji) se réfèrent à la carte, pas à l'écran */
}
.quiz-card {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 4%;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r-card);
  font-size: min(56cqh, 38cqi, 160px); line-height: 1;
  cursor: pointer;
  transition: transform var(--quiz-t-card) cubic-bezier(.4, 0, .2, 1), opacity var(--quiz-t-card) ease-out, border-color var(--t-fast);
}
@media (hover: hover) { .quiz-card:hover { border-color: var(--ink); } }
.quiz-card .flip-card__icon-img { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; pointer-events: none; }
/* Mot sans visuel : l'image par défaut du jeu (_defaut.svg), pas d'icône audio (Pascal, 17/09) */
.quiz-card--novisual .flip-card__icon-img { object-fit: contain; }
.quiz-card.is-entering { transform: translateX(70%); opacity: 0; }
.quiz-card.is-leaving  { transform: translateX(-70%); opacity: 0; }

.quiz-listen {
  position: relative; z-index: 2; margin-top: -24px;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 10px 22px;
  border: 1.5px solid var(--ink); border-radius: var(--r-pill);
  background: var(--paper); color: var(--ink);
  font-size: var(--fs-body); font-weight: 500;
  box-shadow: 0 2px 8px rgba(35, 31, 32, .1);
  transform-origin: center;
  transition: transform var(--t-pop), opacity .22s ease, background var(--t-fast), color var(--t-fast);
}
/* Transition entre deux questions (Pascal, 17/09) : Écouter s'efface juste avant le
   départ de l'image ; l'image suivante arrive seule, puis les réponses, et enfin
   Écouter revient avec un pop (grossit puis redescend). */
.quiz-listen.is-out { opacity: 0; transform: scale(.9); pointer-events: none; }
.quiz-listen.is-in  { animation: quiz-listen-in .5s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes quiz-listen-in {
  from { opacity: 0; transform: scale(.85); }
  55%  { opacity: 1; transform: scale(1.12); }
  to   { opacity: 1; transform: scale(1); }
}
.quiz-listen svg { width: 14px; height: 14px; }
@media (hover: hover) { .quiz-listen:hover { background: var(--ink); color: var(--paper); } }
.quiz-listen.is-emph { font-weight: 700; }
.quiz-listen.is-emph, .quiz-listen.is-playing { transform: scale(1.15); }

/* Quatre propositions */
/* Lignes de hauteur fixe : la place des réponses ne dépend pas des libellés, donc la carte
   ne change pas de taille d'une série à l'autre (Pascal, 25/09) */
/* La grille réserve toujours la hauteur de ses lignes (4, ou 2 en 2×2) : au démarrage les réponses
   n'arrivent qu'après l'image, et sans cette réserve la carte entrait trop grande puis rétrécissait */
#quiz-choices {
  --quiz-gap: 10px; --quiz-rows: 4;
  display: grid; grid-auto-rows: var(--quiz-choice-h, 56px); gap: var(--quiz-gap); width: 100%; margin-top: 6px;
  min-height: calc(var(--quiz-rows) * var(--quiz-choice-h, 56px) + (var(--quiz-rows) - 1) * var(--quiz-gap));
  transition: opacity var(--quiz-t-choices) ease-out;
}
#quiz-choices.is-fading { opacity: 0; }
/* Consigne (retours PY v2) : hauteur réservée, la carte ne bouge pas quand elle change */
.quiz-prompt {
  align-self: stretch; margin: 0 0 -6px; min-height: 1.3em;
  font-size: var(--fs-body); font-weight: 500; line-height: 1.3; color: var(--ink-2); text-align: center;
}
.quiz-choice {
  height: var(--quiz-choice-h, 56px); display: flex; align-items: center; gap: var(--sp-2); padding: 6px 4px 6px var(--sp-2);
  border: 1.5px solid var(--line); border-radius: var(--r-ctl);
  background: var(--paper); color: var(--ink);
  font-size: var(--fs-h2); font-weight: 400; line-height: 1.15; text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), opacity .25s ease;
}
.quiz-choice__label { text-wrap: balance; }
.quiz-choice--l  { font-size: var(--fs-body); letter-spacing: -.01em; }
.quiz-choice--xl { font-size: 15px; letter-spacing: -.02em; }
.quiz-choice.is-hidden { opacity: 0; transform: translateY(6px); }
#quiz-choices.is-revealing .quiz-choice {
  transition: opacity .25s ease, transform .25s ease;
  transition-delay: calc(var(--i, 0) * var(--quiz-t-stagger));
}
@media (hover: hover) { .quiz-choice:hover:not(:disabled) { border-color: var(--ink); background: var(--paper-2); } }
.quiz-choice:disabled { cursor: default; }
.quiz-choice__num {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--ink-3); color: var(--ink-muted);
  font-size: var(--fs-xs); font-variant-numeric: tabular-nums;
}
.quiz-choice.is-correct { font-weight: 700; background: var(--ok-pale); border-color: var(--ok); color: var(--ink); }
.quiz-choice.is-correct .quiz-choice__num { background: var(--ok-text); border-color: var(--ok-text); color: var(--paper); }
.quiz-choice.is-wrong { background: var(--alert-pale); border-color: var(--alert); color: var(--alert); opacity: .6; }
.quiz-choice.is-wrong .quiz-choice__num { border-color: var(--alert); color: var(--alert); }
#quiz-choices.is-answered-right .quiz-choice:disabled:not(.is-correct) { opacity: .5; }
#quiz-choices.is-answered-wrong .quiz-choice:disabled:not(.is-correct):not(.is-wrong) { opacity: .22; }

.quiz-feedback { min-height: 24px; font-size: var(--fs-body); color: var(--ink-2); text-align: center; }
.quiz-feedback.is-correct { color: var(--ok-text); font-weight: 700; }

#quiz-next { width: 100%; max-width: 300px; }
/* Suivant garde sa place avant la réponse : la carte ne change pas de taille en cours de question */
#quiz-next.u-hidden { display: inline-flex !important; visibility: hidden; pointer-events: none; }

/* Écrans bas (iPhone SE 667, iPhone 16 852 avec les barres de Safari) : tout se resserre un peu */
@media (max-height: 720px) {
  .quiz-content { gap: 8px; }
  #quiz-choices { --quiz-gap: 8px; --quiz-choice-h: 46px; margin-top: 0; }
  .quiz-choice { padding: 4px 14px; font-size: var(--fs-body); gap: 12px; }
  .quiz-choice--l { font-size: 15px; }
  .quiz-choice--xl { font-size: 14px; }
  .quiz-feedback { min-height: 20px; font-size: var(--fs-small); }
  #quiz-next { min-height: 42px; }
}

/* Téléphone couché (852×393) ou fenêtre basse : la carte à gauche, les réponses à droite */
@media (orientation: landscape) and (max-height: 560px) {
  .quiz-content { flex-direction: row; align-items: stretch; max-width: none; gap: 20px; }
  #quiz-stage { flex: 1 1 0; min-width: 0; min-height: 0; margin-top: 0; justify-content: center; }
  .quiz-stimulus { flex: 0 1 auto; width: 100%; }   /* la carte garde son 3:2 au lieu de prendre toute la hauteur */
  .quiz-side { display: flex; flex-direction: column; justify-content: safe center; gap: 8px; flex: 1 1 0; min-width: 0; }   /* safe : jamais rogné par le haut */
  #quiz-choices { margin-top: 0; }
  #quiz-next { align-self: center; }
}

/* Grand écran (portable) : la hauteur manque plus que la largeur → réponses sur deux colonnes */
@container app (min-width: 900px) {
  #quiz-choices { --quiz-rows: 2; grid-template-columns: 1fr 1fr; }
}

/* ≥ 8/10 : petit ressort sur le score */
#quiz-complete.is-high #quiz-complete__score { animation: quiz-pop .6s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes quiz-pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #quiz-complete.is-high #quiz-complete__score { animation: none; }
  .quiz-choice, .quiz-card, .quiz-listen, #quiz-choices { transition: none; }
  .quiz-listen.is-in { animation: none; }
  .quiz-start__btn.is-launch { animation: none; }
}
