/* Dictons ! — feuille de style unique.
   Le cahier d'écolier : papier Seyès (lignes lilas, marge rouge), encre bleue, stylo rouge du correcteur. */

@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Literata"; src: url("../fonts/literata-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Literata"; src: url("../fonts/literata-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Literata"; src: url("../fonts/literata-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --encre: #1e3a9e;          /* encre bleue */
  --encre-fonce: #142a77;
  --encre-pale: #e7ebfa;
  --rouge: #c8102e;          /* stylo rouge */
  --rouge-pale: #fdecef;
  --vert: #12804a;
  --vert-pale: #e6f4ec;
  --lignes: #cdc8ef;         /* Seyès : lignes lilas */
  --lignes-fortes: #a9a1e3;
  --marge: #e25563;          /* marge rouge */
  --papier: #ffffff;
  --fond: #f2f4f9;
  --texte: #1b2233;
  --gris: #5b6477;
  --bord: #d6dbe6;
  --ambre: #a35c00;
  --ambre-pale: #fff3df;
  --ui: "Atkinson", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --cahier: "Literata", "Iowan Old Style", Georgia, serif;
  --interligne: 36px;        /* un grand carreau Seyès */
  --rayon: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.5;
  color: var(--texte);
  background: var(--fond);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--encre); }
:focus-visible { outline: 3px solid var(--encre); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.visuellement-cache { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Structure ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.entete {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--papier);
  border-bottom: 1px solid var(--bord);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-family: var(--cahier); font-weight: 600; font-size: 22px; color: var(--encre); text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.logo .point { color: var(--rouge); }
.entete nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.entete nav a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--gris); white-space: nowrap; }
.entete nav a[aria-current="page"] { color: var(--encre); background: var(--encre-pale); }
.icone-nav { width: 24px; height: 24px; display: none; }
@media (max-width: 720px) {
  .entete { flex-wrap: wrap; row-gap: 4px; }
  .app:not(.role-eleve) .entete nav { margin-left: 0; width: 100%; margin-bottom: -4px; }
  /* Élève sur téléphone : barre d'onglets en bas, au pouce. */
  .app.role-eleve .entete nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; margin: 0;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; overflow: visible;
    padding: 4px 4px calc(env(safe-area-inset-bottom) + 4px);
    background: var(--papier); border-top: 1px solid var(--bord);
    box-shadow: 0 -2px 12px rgba(20, 28, 48, .06);
  }
  .app.role-eleve .entete nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; padding: 4px 2px; font-size: 12.5px; line-height: 1.1; text-align: center; white-space: nowrap;
  }
  .app.role-eleve .icone-nav { display: block; }
  .app.role-eleve .contenu { padding-bottom: calc(env(safe-area-inset-bottom) + 100px); }
  .app.role-eleve ~ .toast, body:has(.role-eleve) .toast { bottom: calc(env(safe-area-inset-bottom) + 84px); }
}
.contenu { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }
.contenu.large { max-width: 1180px; }
.contenu:focus { outline: none; }
.pied { text-align: center; color: var(--gris); font-size: 14px; padding: 16px; }

h1 { font-size: 26px; line-height: 1.2; margin: 8px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 20px; line-height: 1.25; margin: 24px 0 10px; }
h3 { font-size: 17px; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
.discret { color: var(--gris); font-size: 15px; }
.petit { font-size: 14px; }

/* ---------- Boutons, champs ---------- */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid var(--bord); border-radius: var(--rayon);
  background: var(--papier); color: var(--texte);
  font-weight: 700; cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.bouton:hover { border-color: var(--encre); }
.bouton.principal { background: var(--encre); border-color: var(--encre); color: #fff; }
.bouton.principal:hover { background: var(--encre-fonce); }
.bouton.danger { color: var(--rouge); border-color: #efb3bd; }
.bouton.grand { width: 100%; min-height: 56px; font-size: 19px; }
.bouton:disabled { opacity: .45; cursor: not-allowed; }
.lien-bouton { background: none; border: none; padding: 8px 4px; color: var(--encre); text-decoration: underline; cursor: pointer; min-height: 44px; }
.rangee { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rangee.fin { justify-content: flex-end; }

label { display: block; font-weight: 700; margin: 12px 0 4px; }
label.ligne { display: flex; gap: 10px; align-items: center; font-weight: 400; }
input[type="text"], input[type="email"], input[type="number"], input[type="time"], input[type="date"], input[type="month"], input[type="search"], select, textarea.champ {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--bord); border-radius: 8px; background: var(--papier);
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--encre); }
textarea.champ { min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 15px; }
.aide { color: var(--gris); font-size: 14px; margin-top: 4px; }
fieldset { border: 1px solid var(--bord); border-radius: var(--rayon); padding: 12px 14px; margin: 12px 0; }
legend { font-weight: 700; padding: 0 6px; }

/* ---------- Blocs ---------- */
.bloc { background: var(--papier); border: 1px solid var(--bord); border-radius: 14px; padding: 16px; margin: 0 0 14px; }
.bloc.accent { border-left: 5px solid var(--encre); }
.bloc.alerte { border-left: 5px solid var(--ambre); background: var(--ambre-pale); }
.bloc.erreur { border-left: 5px solid var(--rouge); background: var(--rouge-pale); }
.bloc h2:first-child, .bloc h3:first-child { margin-top: 0; }
.liste { list-style: none; margin: 0; padding: 0; }
.liste > li { padding: 12px 0; border-top: 1px solid var(--bord); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.liste > li:first-child { border-top: none; }
.liste .grandit { flex: 1; min-width: 180px; }
.pastille-etat { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--fond); color: var(--gris); }
.pastille-etat.ok { background: var(--vert-pale); color: var(--vert); }
.pastille-etat.ko { background: var(--rouge-pale); color: var(--rouge); }
.pastille-etat.attente { background: var(--ambre-pale); color: var(--ambre); }
.pastille-etat.info { background: var(--encre-pale); color: var(--encre); }

table.tableau { width: 100%; border-collapse: collapse; font-size: 15px; }
table.tableau th, table.tableau td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--bord); vertical-align: top; }
table.tableau th { color: var(--gris); font-weight: 700; }
.defile-x { overflow-x: auto; }

.onglets { display: flex; gap: 4px; border-bottom: 2px solid var(--bord); margin: 8px 0 16px; overflow-x: auto; }
.onglets button { border: none; background: none; padding: 12px 14px; min-height: 44px; font-weight: 700; color: var(--gris); border-bottom: 3px solid transparent; margin-bottom: -2px; cursor: pointer; white-space: nowrap; }
.onglets button[aria-selected="true"] { color: var(--encre); border-bottom-color: var(--encre); }

.grille-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 900px) { .grille-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* ---------- Papier Seyès ---------- */
.cahier {
  position: relative;
  background-color: var(--papier);
  background-image:
    linear-gradient(90deg, transparent 39px, var(--marge) 39px, var(--marge) 41px, transparent 41px),
    linear-gradient(var(--lignes-fortes) 1px, transparent 1px),
    repeating-linear-gradient(transparent 0, transparent calc(var(--interligne) / 4 - 1px), var(--lignes) calc(var(--interligne) / 4 - 1px), var(--lignes) calc(var(--interligne) / 4));
  background-size: 100% 100%, 100% var(--interligne), 100% var(--interligne);
  background-position: 0 0, 0 calc(var(--interligne) - 7px), 0 -7px;
  background-attachment: local;
  border: 1px solid var(--bord);
  border-radius: 6px;
  padding: 2px 14px 10px 54px;
  font-family: var(--cahier);
  font-size: 20px;
  line-height: var(--interligne);
  color: var(--encre);
}
.cahier .para { margin: 0; }
.cahier .para + .para { margin-top: 0; text-indent: 0; }
textarea.copie {
  display: block; width: 100%; resize: none; border: 1px solid var(--bord);
  outline: none; caret-color: var(--rouge);
}
textarea.copie:focus { border-color: var(--encre); box-shadow: 0 0 0 3px var(--encre-pale); }
.mot { white-space: nowrap; }

/* Marques cliquables (pièges et commentaires) */
.marque {
  font: inherit; color: inherit; background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; border-radius: 3px; text-decoration-thickness: 2px; text-underline-offset: 4px;
  -webkit-tap-highlight-color: transparent;
}
.marque.piege { text-decoration-line: underline; text-decoration-style: solid; }
.marque.commentaire { text-decoration-line: underline; text-decoration-style: dotted; }
.marque.neutre { text-decoration-color: var(--encre); }
.marque.reussie { color: var(--vert); text-decoration-color: var(--vert); background: var(--vert-pale); }
.marque.ratee { color: var(--rouge); text-decoration-color: var(--rouge); background: var(--rouge-pale); }
.marque .icone { width: 12px; height: 12px; vertical-align: super; margin-left: 1px; }
.faute-zone { text-decoration: underline wavy var(--rouge); text-decoration-thickness: 1.5px; text-underline-offset: 5px; cursor: pointer; background: none; border: none; padding: 0; font: inherit; color: inherit; }
.copie-faute { color: var(--rouge); text-decoration: underline var(--rouge) 2px; text-underline-offset: 5px; cursor: pointer; background: none; border: none; padding: 0; font: inherit; }
.copie-entrop { color: var(--rouge); text-decoration: line-through var(--rouge) 2px; cursor: pointer; background: none; border: none; padding: 0; font: inherit; }
.repere-manque { display: inline-block; color: var(--rouge); font-family: var(--ui); font-weight: 700; cursor: pointer; background: none; border: none; padding: 0 1px; font-size: 18px; line-height: 1; vertical-align: -2px; }
.renvoi { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--encre); color: var(--encre); background: var(--encre-pale); font-family: var(--ui); font-size: 0.85em; line-height: 1.6; cursor: pointer; vertical-align: 1px; }
.renvoi.inerte { cursor: default; border-color: var(--bord); background: var(--fond); color: var(--gris); }

/* Note du correcteur */
.note-copie {
  display: inline-flex; align-items: baseline; justify-content: center; gap: 1px; min-width: 96px; height: 64px; padding: 14px 14px 0;
  border: 3px solid var(--rouge); border-radius: 50% 46% 52% 44% / 54% 48% 52% 46%;
  color: var(--rouge); font-family: var(--cahier); font-weight: 600; font-size: 28px; transform: rotate(-4deg);
}
.note-copie small { font-size: 16px; }

/* ---------- Panneau du bas (explications) ---------- */
.voile { position: fixed; inset: 0; background: rgba(20, 28, 48, .35); z-index: 40; }
.panneau {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 80dvh; overflow-y: auto;
  background: var(--papier); border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: 0 -8px 30px rgba(20, 28, 48, .18);
}
.panneau .poignee { width: 44px; height: 5px; border-radius: 3px; background: var(--bord); margin: 2px auto 12px; }
@media (min-width: 760px) {
  .panneau { left: 50%; right: auto; bottom: 24px; width: 560px; transform: translateX(-50%); border-radius: 18px; }
}
.formes { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 16px; margin: 6px 0 12px; }
.formes dt { color: var(--gris); }
.formes dd { margin: 0; font-family: var(--cahier); font-size: 19px; }
.formes .attendu { color: var(--vert); }
.formes .saisi { color: var(--rouge); }
.explication { font-size: 17px; line-height: 1.55; }
.etiquette-points { font-weight: 700; color: var(--gris); font-size: 15px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 60; background: var(--texte); color: #fff; padding: 12px 18px; border-radius: 10px; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.erreur { background: var(--rouge); }

/* ---------- Écran de dictée ---------- */
.ecran-dictee { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--fond); height: 100dvh; z-index: 30; }
.ecran-dictee .barre {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--papier); border-bottom: 1px solid var(--bord);
}
.ecran-dictee .progression { flex: 1; min-width: 0; }
.ecran-dictee .progression strong { display: block; font-size: 17px; }
.ecran-dictee .progression .jauge { height: 6px; border-radius: 3px; background: var(--encre-pale); overflow: hidden; margin-top: 4px; }
.ecran-dictee .progression .jauge span { display: block; height: 100%; background: var(--encre); }
.ecran-dictee .zone-copie { flex: 1; min-height: 0; padding: 8px 10px; display: flex; flex-direction: column; }
.ecran-dictee .zone-copie textarea { flex: 1; min-height: 120px; }
.ecran-dictee .actions { display: flex; gap: 8px; padding: 0 10px 8px; }
.ecran-dictee .consigne { padding: 6px 12px; color: var(--gris); font-size: 15px; min-height: 30px; }
.bouton-rond { min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--bord); background: var(--papier); display: inline-grid; place-items: center; cursor: pointer; padding: 0 10px; font-weight: 700; }
.bouton-rond[aria-pressed="true"] { background: var(--encre-pale); border-color: var(--encre); color: var(--encre); }
.bouton-rond svg { width: 22px; height: 22px; }

/* ---------- Clavier intégré ---------- */
.clavier {
  background: #dfe3ec; padding: 4px 3px calc(env(safe-area-inset-bottom) + 4px);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.clavier .rang { display: flex; gap: 0; }
.clavier .touche {
  flex: 1 1 0; min-width: 0; height: 46px; padding: 3px 2px; border: none; background: none;
  -webkit-tap-highlight-color: transparent; cursor: pointer;
}
.clavier .touche span {
  display: grid; place-items: center; height: 100%; border-radius: 7px; background: #fff;
  box-shadow: 0 1px 0 #a5acbc; font-size: 21px; font-family: var(--ui); color: var(--texte);
}
.clavier .touche.accent span { background: var(--encre-pale); color: var(--encre-fonce); font-size: 20px; }
.clavier .touche.fonction span { background: #c3c9d6; font-size: 16px; font-weight: 700; }
.clavier .touche.large { flex-grow: 1.6; }
.clavier .touche.espace { flex-grow: 4; }
.clavier .touche.enfonce span { background: var(--encre); color: #fff; }
.clavier .touche[aria-pressed="true"] span { background: var(--encre); color: #fff; }
.clavier .touche.verrou span { background: var(--encre-fonce); color: #fff; text-decoration: underline; }
@media (min-height: 760px) { .clavier .touche { height: 50px; } }

/* ---------- Calendrier de programmation ---------- */
.calendrier { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendrier .entete-jour { text-align: center; font-size: 13px; color: var(--gris); padding: 4px 0; }
.calendrier .jour { min-height: 84px; border: 1px solid var(--bord); border-radius: 8px; background: var(--papier); padding: 4px 6px; font-size: 13px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.calendrier .jour.vide { visibility: hidden; }
.calendrier .jour.hors { background: var(--fond); color: var(--gris); cursor: default; }
.calendrier .jour.ferie { background: #f6eef0; }
.calendrier .jour.vacances { background: #eef5ee; }
.calendrier .jour.aujourdhui { outline: 2px solid var(--encre); }
.calendrier .jour .num { font-weight: 700; }
.calendrier .jour .couple { color: var(--encre); font-weight: 700; line-height: 1.2; }
.calendrier .jour .manque { color: var(--ambre); }
@media (max-width: 600px) { .calendrier .jour { min-height: 64px; font-size: 11px; } }

/* ---------- Éditeur ---------- */
.editeur { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 1000px) { .editeur { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.editeur .source { position: relative; }
.autocompletion { position: absolute; z-index: 15; background: var(--papier); border: 1px solid var(--bord); border-radius: 10px; box-shadow: 0 8px 24px rgba(20,28,48,.16); min-width: 280px; max-width: 420px; padding: 4px; }
.autocompletion button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.autocompletion button[aria-selected="true"] { background: var(--encre-pale); }
.autocompletion .id { color: var(--gris); font-size: 13px; }
.diagnostics { font-size: 14px; }
.diagnostics li.erreur { color: var(--rouge); }
.diagnostics li.avertissement { color: var(--ambre); }

/* ---------- Audio du professeur ---------- */
.secateur { width: 100%; min-height: 96px; font-size: 22px; border-radius: 18px; }
.onde { width: 100%; height: 140px; display: block; background: var(--papier); border: 1px solid var(--bord); border-radius: 10px; touch-action: none; }
.texte-defilant { max-height: 40dvh; overflow-y: auto; }
.texte-defilant .groupe { padding: 2px 4px; border-radius: 4px; }
.texte-defilant .groupe.actif { background: var(--encre-pale); outline: 2px solid var(--encre); }
.texte-defilant .groupe.fait { color: var(--gris); }

/* ---------- Graphiques ---------- */
.graphique { width: 100%; height: auto; display: block; }
.graphique .axe { stroke: var(--bord); }
.graphique .courbe { fill: none; stroke: var(--encre); stroke-width: 2.5; }
.graphique .courbe.rouge { stroke: var(--rouge); }
.graphique .bande { fill: var(--encre-pale); }
.graphique text { fill: var(--gris); font-size: 11px; font-family: var(--ui); }
.barre-maitrise { height: 10px; background: var(--fond); border-radius: 5px; overflow: hidden; }
.barre-maitrise span { display: block; height: 100%; background: var(--vert); }
.barre-maitrise span.faible { background: var(--rouge); }
.barre-maitrise span.moyen { background: var(--ambre); }

/* ---------- Accueil élève ---------- */
.dictee-du-jour { background: var(--encre); color: #fff; border-radius: 16px; padding: 20px; margin-bottom: 14px; }
.dictee-du-jour h2 { margin: 0 0 6px; font-size: 22px; }
.dictee-du-jour .bouton { background: #fff; color: var(--encre); border-color: #fff; }
.dictee-du-jour p { color: #dfe5ff; }
.serie { font-family: var(--cahier); font-size: 34px; color: var(--encre); line-height: 1; }
.exercice-trou { width: 7ch; min-height: 36px; padding: 2px 6px; border: none; border-bottom: 2px solid var(--encre); border-radius: 0; font-family: var(--cahier); font-size: 19px; color: var(--encre); background: transparent; }
.exercice-trou.juste { border-bottom-color: var(--vert); color: var(--vert); }
.exercice-trou.faux { border-bottom-color: var(--rouge); color: var(--rouge); }
.curseur-difficulte { width: 100%; }
.centre { text-align: center; }
.chargement { padding: 24px; font-family: var(--ui); color: var(--gris); }
.bouton svg, .lien-bouton svg { width: 22px; height: 22px; flex: none; }

/* ---------- Petits écrans : rien ne déborde de la page ---------- */
input[type="file"] { max-width: 100%; }
.calendrier { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendrier .jour { min-width: 0; overflow: hidden; overflow-wrap: anywhere; hyphens: auto; }
@media (max-width: 720px) {
  table.tableau { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .calendrier .jour .couple + * { display: none; }
}

/* Comptes communs avec l'intranet : permuter la vue (admin ⇄ professeur), lien de retour. */
.entete .permuter-vue { margin-left: 8px; white-space: nowrap; }
.entete .lien-intranet { margin-left: 8px; padding: 8px 10px; border-radius: 8px; color: var(--gris); text-decoration: none; white-space: nowrap; font-size: 0.9em; }
.entete .lien-intranet:hover { color: var(--encre); background: var(--encre-pale); }
