/* ═══════════════════════════════════════════════
   QCM Examen — Style « feuille d'épreuve BIA »
   Reproduit le look officiel : papier blanc, police
   serif, numérotation N.N, grille réponse A/B/C/D
   ═══════════════════════════════════════════════ */

/* ── Reset & page ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --exam-bg: #fff;
  --exam-text: #1a1a1a;
  --exam-muted: #555;
  --exam-border: #999;
  --exam-accent: #0d47a1;
  --exam-correct: #2e7d32;
  --exam-wrong: #c62828;
  --exam-selected: #e3f2fd;
  --exam-paper-shadow: 0 2px 12px rgba(0,0,0,0.12);
  --exam-radius: 2px;
  /* A4 exact : 210mm × 297mm → 794px × 1123px à 96dpi */
  --a4-w: 794px;
  --a4-h: calc(var(--a4-w) * 297 / 210); /* = 1123px */
  --page-gap: 1.5rem;
  --grille-w: 260px;
}

html { font-size: 16px; }

body {
  font-family: "Times New Roman", "Liberation Serif", Georgia, serif;
  color: var(--exam-text);
  background: #e8e8e8;
  line-height: 1.5;
  -webkit-font-smoothing: auto;
}

/* ── Layout wrapper (body flex: paper col + grille col) ── */
.exam-layout {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  justify-content: center;
  padding: var(--page-gap) 1rem;
}

/* ── Paper column: stack of A4 pages ── */
.exam-paper-col {
  flex-shrink: 0;
  width: var(--a4-w);
}

/* ── Individual A4 page ── */
.exam-paper-page {
  background: var(--exam-bg);
  box-shadow: var(--exam-paper-shadow);
  padding: 2.5rem 3rem;
  margin-bottom: var(--page-gap);
  /* Hauteur exacte A4 — contenu paginé par JS */
  width: var(--a4-w);
  min-height: var(--a4-h);
  overflow: visible;
}

/* Cover page : hauteur A4 + flex pour pousser le footer en bas */
.exam-paper-page--cover {
  display: flex;
  flex-direction: column;
  min-height: var(--a4-h);
}

/* Résultats : page A4 centrée au-dessus des questions */
.exam-paper-page--results {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: auto;
  padding: 2rem 3rem;
}

@media (max-width: 900px) {
  .exam-layout { flex-direction: column; align-items: stretch; padding: 0; gap: 0; }
  .exam-paper-col { width: 100%; }
  .exam-paper-page { padding: 1.2rem 1rem; box-shadow: none; width: auto; min-height: auto; overflow: visible; margin-bottom: 0; }
  .exam-grille-col { position: static !important; max-height: none !important; width: 100% !important; }
}

/* ── Cover content (inside .exam-paper-page--cover) ── */
.exam-cover {
  flex: 1;
  text-align: center;
  padding: 1rem 0 1.5rem;
}

.exam-title-box {
  border: 2px solid var(--exam-text);
  padding: 0.8rem 1.5rem;
  display: inline-block;
  margin-bottom: 2rem;
}

.exam-title-box h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.exam-session {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1.5rem 0;
}

.exam-subtitle {
  font-size: 1.15rem;
  margin: 1rem 0;
}

.exam-meta {
  font-style: italic;
  color: var(--exam-muted);
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

/* ── Mode selector (leçon picker) ── */
.exam-mode-selector {
  margin: 2rem 0;
  padding: 1.2rem;
  border: 1px solid #ccc;
  background: #fafafa;
}

.exam-mode-selector h2 {
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.mode-btn-global {
  font-size: 1.1rem !important;
  padding: 0.7rem 2rem !important;
  border-width: 2px !important;
  letter-spacing: 0.02em;
}

.mode-separator {
  display: flex;
  align-items: center;
  width: 80%;
  margin: 0.8rem 0;
  gap: 0.8rem;
  color: var(--exam-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.mode-separator::before,
.mode-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #ccc;
}

.mode-lecons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.mode-btn {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--exam-border);
  background: var(--exam-bg);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.mode-btn:hover { border-color: var(--exam-accent); background: var(--exam-selected); }
.mode-btn.active { border-color: var(--exam-accent); background: var(--exam-accent); color: #fff; font-weight: 700; }

/* ── Name input ── */
.exam-name-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.exam-name-row label { font-weight: 700; font-size: 1rem; }

.exam-name-input {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--exam-border);
  width: 220px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.exam-name-input:focus { outline: 2px solid var(--exam-accent); border-color: var(--exam-accent); }

.exam-start-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.5rem 1.5rem;
  border: 2px solid var(--exam-accent);
  background: var(--exam-accent);
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: opacity 0.2s;
}

.exam-start-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.exam-start-btn:not(:disabled):hover { opacity: 0.85; }

/* ── Instructions box ── */
.exam-instructions {
  border: 1px solid #999;
  padding: 0.8rem 1.5rem 0.9rem;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  background: #fcfcfc;
  text-align: left;
}

.exam-instr-title {
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #ccc;
}

.exam-instr-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.exam-instr-list li {
  padding: 0.18rem 0 0.18rem 1.4rem;
  line-height: 1.5;
  position: relative;
}

.exam-instr-list li::before {
  content: '▸';
  position: absolute;
  left: 0.2rem;
  color: var(--exam-accent);
  font-size: 0.75rem;
  top: 0.28rem;
}

/* ── Part header (Partie n° 5 : HISTOIRE…) ── */
.exam-part-header {
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.6rem 0;
  margin: 1.5rem 0 1rem;
  border-top: 1px solid var(--exam-text);
  border-bottom: 1px solid var(--exam-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Leçon sub-header ── */
.exam-lecon-header {
  font-weight: 700;
  font-size: 1rem;
  color: var(--exam-accent);
  margin: 1.5rem 0 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid #ddd;
}

/* ── Question block ── */
.exam-question {
  margin-bottom: 1.3rem;
  page-break-inside: avoid;
}

.exam-q-number {
  font-weight: 700;
  margin-right: 0.4rem;
}

.exam-q-text {
  font-weight: 700;
  margin-bottom: 0.4rem;
  line-height: 1.45;
}

/* ── Options (A. B. C. D.) ── */
.exam-options {
  list-style: none;
  padding-left: 1.5rem;
}

.exam-option {
  position: relative;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.15rem;
  cursor: pointer;
  border-radius: var(--exam-radius);
  border: 1.5px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.4;
}

/* ── Correction badge superposé sur l'option ── */
.correction-badge {
  position: absolute;
  top: 0.25rem;
  right: 0.45rem;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.correction-badge.badge-correct { background: var(--exam-correct); color: #fff; }
.correction-badge.badge-wrong   { background: var(--exam-wrong);   color: #fff; }

.exam-option:hover:not(.locked) {
  background: #f0f0f0;
  border-color: #ccc;
}

.exam-option.selected {
  background: var(--exam-selected);
  border-color: var(--exam-accent);
  font-weight: 600;
}

.exam-option .option-letter {
  font-weight: 700;
  margin-right: 0.3rem;
  display: inline-block;
  min-width: 1.3em;
}

/* ── Post-correction states ── */
.exam-option.correct-answer {
  background: #e8f5e9;
  border-color: var(--exam-correct);
}

.exam-option.correct-answer .option-letter { color: var(--exam-correct); }

.exam-option.wrong-selected {
  background: #ffebee;
  border-color: var(--exam-wrong);
  text-decoration: line-through;
  text-decoration-color: var(--exam-wrong);
}

.exam-option.wrong-selected .option-letter { color: var(--exam-wrong); }

.exam-option.locked { cursor: default; }

/* ── Grille réponse (response grid) ── */
.exam-grille-section {
  border: 1px solid #ccc;
  padding: 1rem;
  background: #fafafa;
  page-break-inside: avoid;
}

/* ── Grille col: sticky flex sibling of paper column ── */
.exam-grille-col {
  flex-shrink: 0;
  width: var(--grille-w);
  position: sticky;
  top: var(--page-gap);
  max-height: calc(100vh - calc(var(--page-gap) * 2));
  overflow-y: auto;
}

.exam-grille-section h3 {
  font-size: 1rem;
  margin-bottom: 0.8rem;
  text-align: center;
}

.exam-grille-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
  text-align: center;
}

.exam-grille-table th,
.exam-grille-table td {
  border: 1px solid #999;
  padding: 0.25rem 0.4rem;
  min-width: 2.2rem;
}

.exam-grille-table th {
  background: #f0f0f0;
  font-weight: 700;
  font-size: 0.8rem;
  position: sticky;
  top: 0;
  z-index: 1;
}

.exam-grille-table .row-label {
  font-weight: 700;
  background: #f5f5f5;
  white-space: nowrap;
  font-size: 0.78rem;
}

.grille-lecon-row td {
  background: var(--exam-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 0.2rem 0.3rem;
  text-align: left;
  letter-spacing: 0.02em;
}

.exam-grille-cell {
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
  font-size: 1rem;
  line-height: 1;
}

.exam-grille-cell:hover:not(.locked) { background: #e0e0e0; }
.exam-grille-cell.marked { background: var(--exam-selected); font-weight: 700; }
.exam-grille-cell.marked::after { content: "✕"; }

.exam-grille-cell.correct-mark { background: #e8f5e9; }
.exam-grille-cell.correct-mark::after { content: "✕"; color: var(--exam-correct); font-weight: 700; }

.exam-grille-cell.wrong-mark { background: #ffebee; }
.exam-grille-cell.wrong-mark::after { content: "✕"; color: var(--exam-wrong); }

.exam-grille-cell.expected-mark { background: #e8f5e9; }
.exam-grille-cell.expected-mark::after { content: "○"; color: var(--exam-correct); font-weight: 700; }

/* ── Footer bar (hors page A4 désormais) ── */
.exam-footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.5rem;
  border-top: 1px solid #ccc;
  font-size: 0.85rem;
  color: var(--exam-muted);
  margin-top: 0;
  background: #f5f5f5;
  max-width: var(--a4-w);
}

.exam-page-code { font-family: monospace; }

/* ── Barre résultats compacte (pleine largeur, au-dessus des 2 colonnes) ── */
.exam-results-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: #fff;
  border: 2px solid var(--exam-accent);
  box-shadow: var(--exam-paper-shadow);
  padding: 0.7rem 1.5rem;
  width: calc(var(--a4-w) + var(--page-gap) + var(--grille-w));
  margin: var(--page-gap) auto 0;
  box-sizing: border-box;
  flex-wrap: wrap;
}

.results-bar-score {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  min-width: 0;
}

.results-bar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Éléments inline dans la barre */
.rb-name {
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.rb-score {
  font-size: 1.5rem;
  font-weight: 700;
  white-space: nowrap;
}

.rb-score .rb-score-num { color: var(--exam-accent); }
.rb-score .rb-score-sep { color: var(--exam-muted); margin: 0 0.05rem; }

.rb-pct {
  font-size: 1.1rem;
  color: var(--exam-muted);
  white-space: nowrap;
}

.rb-verdict {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.2rem 0.7rem;
  white-space: nowrap;
}

.rb-unanswered {
  font-size: 0.85rem;
  color: var(--exam-wrong);
  white-space: nowrap;
}

.rb-elapsed {
  font-size: 0.85rem;
  color: var(--exam-muted);
  white-space: nowrap;
}

/* ── Action buttons ── */
.exam-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.exam-btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.6rem 1.8rem;
  border: 2px solid;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, background 0.15s;
}

.exam-btn:hover { opacity: 0.85; }

.exam-btn-primary { border-color: var(--exam-accent); background: var(--exam-accent); color: #fff; }
.exam-btn-secondary { border-color: var(--exam-border); background: var(--exam-bg); color: var(--exam-text); }
.exam-btn-success { border-color: var(--exam-correct); background: var(--exam-correct); color: #fff; }

/* ── Results panel ── */
.exam-results {
  border: 2px solid var(--exam-accent);
  padding: 1.5rem;
  margin: 2rem 0;
  text-align: center;
}

.exam-results h2 { font-size: 1.2rem; margin-bottom: 1rem; }

.exam-score-display {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0.5rem 0;
}

.exam-score-display .score-num { color: var(--exam-accent); }
.exam-score-display .score-sep { color: var(--exam-muted); margin: 0 0.1rem; }

.exam-score-pct {
  font-size: 1.1rem;
  color: var(--exam-muted);
  margin-bottom: 0.5rem;
}

.exam-score-verdict {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  display: inline-block;
  margin: 0.5rem 0;
}

.verdict-pass { background: #e8f5e9; color: var(--exam-correct); border: 1px solid var(--exam-correct); }
.verdict-fail { background: #ffebee; color: var(--exam-wrong); border: 1px solid var(--exam-wrong); }

.exam-elapsed {
  font-size: 0.9rem;
  color: var(--exam-muted);
  margin-top: 0.5rem;
}

.exam-unanswered {
  font-size: 0.9rem;
  color: var(--exam-wrong);
  margin-top: 0.4rem;
}

/* ── Timer bar ── */
/* Timer: dans la colonne grille (sticky), pas besoin de position:sticky propre */
.exam-timer {
  background: var(--exam-accent);
  color: #fff;
  border-radius: var(--exam-radius) var(--exam-radius) 0 0;
  padding: 0.5rem 0;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  font-family: "Courier New", monospace;
  letter-spacing: 0.05em;
}

/* ── Back link ── */
.exam-back {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.95rem;
}

.exam-back a { color: var(--exam-accent); }

/* ── Print styles (page principale — Ctrl+P direct) ── */
@media print {
  body { background: #fff; }
  .exam-layout { display: block; }
  .exam-paper-col { width: 100%; }
  .exam-results-bar,
  .exam-mode-selector,
  .exam-actions,
  .exam-timer,
  .exam-back,
  .exam-grille-col { display: none; }

  .exam-paper-page {
    box-shadow: none;
    padding: 1cm;
    width: auto;
    min-height: auto;
    overflow: visible;
    margin-bottom: 0;
    page-break-after: always;
    break-after: page;
  }

  .exam-question { page-break-inside: avoid; break-inside: avoid; }
}

/* ── Responsive grid overflow ── */
.exam-grille-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .exam-grille-table { font-size: 0.75rem; }
  .exam-grille-table th, .exam-grille-table td { padding: 0.2rem 0.3rem; min-width: 1.8rem; }
}

/* ── Grille current-row highlight ── */
tr.grille-row-current > td {
  background: #fff8e1 !important;
}
tr.grille-row-current > .row-label {
  background: #ffe082 !important;
  font-weight: 700;
}

/* ── Explanation box (shown after correction) ── */
.exam-explanation {
  margin-top: 0.6rem;
  padding: 0.55rem 0.8rem;
  background: #f0f4ff;
  border-left: 3px solid var(--exam-accent);
  font-size: 0.9rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
  color: #1a2a4a;
  border-radius: 0 3px 3px 0;
}

.expl-icon {
  font-weight: 700;
  margin-right: 0.35rem;
}

.expl-icon.expl-correct { color: var(--exam-correct); }
.expl-icon.expl-wrong   { color: var(--exam-wrong); }
.expl-icon.expl-unanswered { color: var(--exam-muted); }

/* ── Hidden utility ── */
.hidden { display: none !important; }
