:root {
  --fond: #111318;
  --texte: #f4f5f7;
  --doux: #a9adb8;
  --vert: #2fbf71;
  --orange: #f2a33a;
  --rouge-fiche: #c00000;
  --bleu-fiche: #4d4dff;
  --ligne-a: #e4e4fb;
  --ligne-b: #c4c4fb;
  --papier: #ffffff;
  --encre: #1b1d22;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fond); color: var(--texte); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Caméra ---------- */
#ecran-camera { position: fixed; inset: 0; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }

.cadre {
  position: absolute;
  left: 50%; top: 50%;
  width: calc(100vw - 32px); height: 52vh;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 255, 255, .45);
  border-radius: 10px;
  transition: border-color .1s, background-color .1s;
}
/* Clignote en vert à chaque photo gardée pendant le balayage. */
.cadre.stable { border-color: var(--vert); border-style: solid; background: rgba(47, 191, 113, .12); }

.barre {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: linear-gradient(rgba(0,0,0,.7), rgba(0,0,0,0));
}
.eleve {
  display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1;
  border: 0; background: none; color: inherit; padding: 0; text-align: left;
}
.etiquette { font-size: 11px; color: var(--doux); text-transform: uppercase; letter-spacing: .06em; }
.eleve strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }

.pages { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; }
.pages li {
  min-width: 40px; height: 32px; padding: 0 8px;
  display: grid; place-items: center;
  border-radius: 16px; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,.14); color: var(--doux);
}
.pages li.encours { background: var(--orange); color: #241500; }
.pages li small { font-size: 10px; font-weight: 700; margin-left: 3px; }
.pages li.fait { background: var(--vert); color: #04220f; }
@keyframes pulse { to { opacity: .55; } }


.toast {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%) scale(.9);
  padding: 18px 26px; border-radius: 16px;
  background: var(--vert); color: #04220f;
  font-size: 24px; font-weight: 800; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
.toast.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }
/* Notification « page lue » : grand rond vert avec une coche blanche. */
.valide {
  position: absolute; left: 50%; top: 42%;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transform: translate(-50%, -50%) scale(.4);
  opacity: 0; pointer-events: none;
}
.valide svg { width: min(46vw, 210px); height: auto; filter: drop-shadow(0 6px 18px rgba(0,0,0,.45)); }
.valide span {
  padding: 6px 16px; border-radius: 20px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 20px; font-weight: 800;
}
.valide.visible { animation: valide 1.6s ease-out forwards; }
@keyframes valide {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
.toast.erreur { background: #e5484d; color: #fff; font-size: 17px; }
.toast.info { background: #2b2f3a; color: var(--texte); font-size: 18px; }

.bas {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 18px);
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75));
  text-align: center;
}
.etat { margin: 0 0 14px; font-size: 15px; min-height: 1.4em; }
.version { position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 2px); margin: 0; font-size: 10px; color: var(--doux); }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.secondaire {
  flex: 1; max-width: 130px; height: 44px; border-radius: 22px; border: 0;
  background: rgba(255,255,255,.16); color: var(--texte); font-size: 14px;
}
.secondaire.actif { background: #ffd84a; color: #2a2100; }

/* ---------- Feuilles (tableau, réglages) ---------- */
.feuille {
  position: fixed; inset: 0; overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 20px);
  background: #f1f2f6; color: var(--encre);
  display: flex; flex-direction: column; gap: 16px;
}
.feuille h2 { margin: 0; }

.fiche {
  background: var(--papier); border: 1px solid #222; padding: 14px 10px 10px;
}
.fiche table { width: 100%; border-collapse: separate; border-spacing: 2px; font-size: 14px; }
.fiche caption {
  background: var(--bleu-fiche); color: #fff; font-weight: 700;
  padding: 10px 6px; margin-bottom: 4px; font-size: 15px;
}
.fiche thead th { padding: 10px 4px; font-size: 14px; }
.fiche thead th:first-child { width: 52%; }
.fiche td { padding: 10px 8px; }
.fiche td.c { text-align: center; }
.fiche tr.parcours td { background: var(--rouge-fiche); color: #fff; font-weight: 700; }
.fiche tr.dom:nth-child(odd) td { background: var(--ligne-a); }
.fiche tr.dom:nth-child(even) td { background: var(--ligne-b); }

.coche {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border: 3px solid currentColor;
  font-size: 20px; line-height: 1; font-weight: 900;
}
tr.parcours .coche { width: 28px; height: 28px; background: #fff; color: var(--rouge-fiche); border-color: #fff; }
tr.dom .coche { color: #111; background: #fff; }
.coche.oui::after { content: "✔"; color: #0a7a3c; }
tr.parcours .coche.oui::after { color: var(--rouge-fiche); }
.ne { font-size: 12px; font-style: italic; color: #444; }
.note { font-size: 12px; color: #555; margin: 10px 2px 0; }
.fiche-niveau { margin: 0 0 12px; font-size: 15px; }

/* Choix du niveau au démarrage */
.choix-niveau { justify-content: center; }
.choix-niveau h2 { text-align: center; font-size: 22px; margin-bottom: 8px; }
.marque { margin: 0; text-align: center; font-size: 30px; font-weight: 800; color: var(--bleu-fiche); }
.niveau {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 26px 16px; border: 0; border-radius: 16px;
  background: var(--bleu-fiche); color: #fff; font-size: 30px; font-weight: 800;
}
.niveau:nth-of-type(2) { background: var(--rouge-fiche); }
.niveau small { font-size: 14px; font-weight: 500; opacity: .9; }

.principal {
  height: 52px; border: 0; border-radius: 12px;
  background: var(--bleu-fiche); color: #fff; font-size: 17px; font-weight: 700;
}

