/* Doit rester APRÈS toutes les feuilles qu'il surcharge (ordre des <link> dans index.html). */
/* ----------------------------------------------------------- responsive */
@media (max-width: 1000px) {
  .table-grid, .bg { grid-template-columns: 1fr; gap: 30px; }
  .seance { grid-template-columns: 1fr; }
  .seance-side { position: static; flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: 24px; order: -1; }
  .chrono { font-size: 54px; }
  .hint { display: none; }
  .bilan { grid-template-columns: 1fr; }
}
/* Mobile : l'appli tient dans une main. Barre d'onglets en bas (pouce), en-tête réduit, une colonne, l'action
   principale de l'écran reste collée au-dessus de la barre, cibles tactiles ≥ 44 px, champs à 16 px (pas de zoom iOS). */
@media (max-width: 720px) {
  html { -webkit-text-size-adjust: 100%; }
  button, .btn, .chip, .opt, .vst, .stamp-btn, .mode, .prow, .exrow, .jrow, .crow, .srow, .fold, .rec { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  /* ⚠️ Sans l'inset du haut, l'en-tête passe SOUS la barre d'état (l'heure et le wifi écrasés par la marque) :
     c'est ce que montrait la capture de Fabio le 12/09. Les insets latéraux servent au mode paysage sur un
     téléphone à encoche. `viewport-fit=cover` est déjà posé dans le <meta viewport>, sans quoi ces variables
     valent toutes zéro. */
  .top { padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
         gap: 10px; flex-wrap: nowrap; align-items: center; }
  .brand { font-size: 17px; letter-spacing: .12em; }
  .brand small { display: none; }
  .trk { margin-left: auto; padding: 8px 10px; font-size: 11px; }
  nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; background: var(--baize-deep); border-top: 1px solid var(--baize-line); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
  /* Sept libellés côte à côte ne tiennent pas dans 390 px : ils se coupaient aux deux bords. L'icône porte
     la reconnaissance, le libellé reste dessous en très petit — une icône seule se devine, elle ne se lit pas. */
  nav.tabs button { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; min-height: 54px; padding: 7px 1px 6px; border-bottom: 0; border-top: 2px solid transparent; }
  nav.tabs .ic { display: block; width: 22px; height: 22px; opacity: .82; }
  nav.tabs button.on .ic { opacity: 1; }
  nav.tabs .lb { font-family: var(--disp); font-size: 9.5px; letter-spacing: .04em; text-transform: uppercase;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  nav.tabs button.on { border-top-color: var(--cream); }
  /* le compteur des dus se pose sur le coin de l'icône, comme une pastille d'application */
  nav.tabs button b { display: inline-block; position: absolute; top: 4px; right: calc(50% - 20px); margin: 0; padding: 0 4px;
    font-size: 10px; line-height: 15px; min-width: 15px; text-align: center; border-radius: 8px; vertical-align: 0; }
  main { padding: 14px calc(16px + env(safe-area-inset-right)) calc(86px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
  .toast { bottom: calc(66px + env(safe-area-inset-bottom)); width: calc(100% - 32px); text-align: center; }
  h1 { font-size: 26px; }
  .btn { min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .actions { gap: 8px; }
  .actions .btn { flex: 1 1 auto; }
  .chip { min-height: 36px; padding: 7px 11px; }
  input.inp, .wbox textarea, textarea, select { font-size: 16px; }
  /* l'action principale de l'écran reste sous le pouce, au-dessus de la barre d'onglets */
  .actions:has(> #next), .actions:has(> #run), .actions:has(> #pjrun), .actions:has(> #srev) { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 5; padding: 10px 0 6px; margin-top: 6px; background: linear-gradient(to top, var(--baize) 70%, transparent); }
  .sheet .actions:has(> #next), .edwrap .actions:has(> #pjrun), .wbox .actions:has(> #srev) { background: linear-gradient(to top, var(--card) 70%, transparent); }
  .actions:has(> #reveal), .actions:has(> #srev) { flex-wrap: wrap; }
  .actions:has(> #reveal) .dict, .actions:has(> #srev) .dict { flex: 1 1 100%; }
  .actions:has(> #reveal) .stamp-btn, .actions:has(> #run) .stamp-btn, .actions:has(> #pjrun) .stamp-btn, .actions:has(> #srev) .stamp-btn { width: 100%; }
  .actions:has(> #next) #next { width: 100%; }
  /* table */
  .count { font-size: 64px; }
  .count-l { max-width: none; }
  .modes { grid-template-columns: 1fr; gap: 8px; }
  .mode { min-height: 56px; }
  .fan { height: 170px; }
  .stamp-btn { font-size: 18px; padding: 14px 22px; }
  .jrow { grid-template-columns: minmax(0, 1fr) 70px 34px; min-height: 48px; }
  /* séance : le côté (chrono, progression, arrêt) devient un bandeau collé en haut */
  .seance { gap: 12px; }
  .seance-side { position: sticky; top: 0; z-index: 6; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "chrono prog quit" "toggle toggle toggle" "hint hint hint"; align-items: center; gap: 4px 12px; padding: 8px 0 8px; margin: -14px -16px 0; padding-left: 16px; padding-right: 16px; background: var(--baize); border-bottom: 1px solid var(--baize-line); order: -1; }
  .seance-side > div:nth-child(1) { grid-area: chrono; display: flex; align-items: baseline; gap: 8px; }
  .seance-side > div:nth-child(2) { grid-area: prog; }
  .seance-side .mode-toggle { grid-area: toggle; display: flex; margin-top: 4px; }
  .seance-side .mode-toggle button { flex: 1; min-height: 36px; }
  .seance-side .hint { grid-area: hint; display: none; }
  .seance-side .endbtns { grid-area: quit; }
  .seance-side #quit, .seance-side #later { grid-area: quit; min-height: 36px; padding: 6px 10px; font-size: 0; white-space: nowrap; }
  .seance-side #quit::after { content: 'Arrêter'; font-size: 11px; }
  .seance-side #later::after { content: 'Pause'; font-size: 11px; }
  .seance-side[data-phase="grade"] .mode-toggle { display: none; }
  .chrono { font-size: 30px; line-height: 1; }
  .chrono-l { display: none; }
  .prog { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* `start` faisait dimensionner le bloc sur son contenu : le libellé en nowrap débordait de sa colonne et
     passait SOUS les boutons de sortie (deux boutons en test de niveau depuis le 12/09). Contraint, il ellipse. */
  .seance-side > div:nth-child(2) { justify-self: stretch; min-width: 0; }
  .dots { margin-top: 4px; }
  .stage { gap: 14px; min-width: 0; }
  .ticket { padding: 14px 14px 14px calc(var(--stub) + 12px); --stub: 30px; overflow: hidden; }
  .ticket .tq { font-size: 16px; margin-top: 8px; }
  .ticket .thead { font-size: 11px; gap: 4px 10px; }
  .ticket .code, .sheet .code, .lesson .code, .aiout .code { font-size: 12.5px; }
  .opt { min-height: 46px; font-size: 14px; }
  .sheet { padding: 16px 14px; }
  .wbox { padding: 14px; }
  .wbox textarea { min-height: 130px; }
  .verdict { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .vst { min-height: 60px; }
  .dialog { padding: 12px 14px; }
  .dialog .turn { grid-template-columns: 1fr; gap: 2px; }
  .dict { width: 100%; }
  .dict .rec { flex: 1; justify-content: center; min-height: 44px; }
  /* parcours */
  .phead { gap: 12px; }
  .phead .lead.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .more { font-family: var(--disp); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-dim); margin-top: 6px; }
  .aibox { min-width: 0; max-width: none; width: 100%; }
  .aibox.aifold { display: block; text-transform: none; }
  .aibox.aifold .aicfg { display: none; }
  .aibox.aifold::after { content: 'Réglages ▾'; display: block; font-family: var(--disp); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-top: 6px; }
  .aibox.aifold.open .aicfg { display: block; }
  .aibox.aifold.open::after { content: 'Replier ▴'; }
  .prow { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; min-height: 56px; align-items: start; }
  .prow > span:first-child { grid-row: 1; grid-column: 1; }
  .prow > .stamp { grid-row: 1; grid-column: 2; align-self: start; }
  .prow .pn { grid-row: 2; grid-column: 1 / -1; font-size: 14px; color: var(--fg-dim); }
  /* fiche sujet */
  .scope .sh { gap: 8px; }
  .scope .sh h3 { width: 100%; font-size: 17px; }
  .scope .meta { width: 100%; }
  .lesson .body { max-width: none; }
  .airow .btn { flex: 1 1 46%; min-width: 0; }
  .exrow { grid-template-columns: 30px minmax(0, 1fr); min-height: 48px; }
  .exrow .st { grid-column: 2; text-align: left; }
  /* exercice */
  .edwrap { padding: 12px; }
  .CodeMirror { min-height: 42vh; font-size: 13px; }
  .editor { min-height: 280px; font-size: 13px; }
  /* sujets / bilan */
  .filters { gap: 8px; }
  .filters .inp { flex: 1 1 100%; width: 100%; }
  .brow { grid-template-columns: 22px minmax(0, 1fr) 72px; }
  .brow .t { display: none; }
  .srow { grid-template-columns: 90px minmax(0, 1fr) 50px; }
  .srow .t { display: none; }
  .cal { grid-template-columns: repeat(7, 1fr); }
  .qrow { grid-template-columns: 22px minmax(0, 1fr); row-gap: 2px; }
  .qrow .st { grid-column: 2; text-align: left; }
  .nextbox { flex-direction: column; align-items: stretch; }
  .nextbox .mode-toggle { display: flex; width: 100%; margin-left: 0 !important; }
  .nextbox .mode-toggle button { flex: 1; min-height: 40px; white-space: nowrap; }
  .nextbox .btn { margin-left: 0 !important; }
  /* projets : l'arbre garde son fil, la fiche passe en une colonne */
  .pjline { margin-left: 5px; padding-left: 18px; }
  .pjrow { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .pjrow::before { left: -25px; top: 22px; }
  .pjside { flex-direction: row; align-items: center; justify-content: flex-start; text-align: left; flex-wrap: wrap; gap: 10px 14px; }
  .pjside .btn { flex: 1 1 100%; }
  .pjlink { grid-template-columns: minmax(0, 1fr) auto; }
  .pjlink .btn { grid-column: 1 / -1; }
  .jal { grid-template-columns: 24px minmax(0, 1fr); padding: 11px 6px; }
  .jal .k { grid-column: 2; padding-top: 0; }
  .jalb { grid-column: 1 / -1; }
  .soutrow { grid-template-columns: 22px minmax(0, 1fr) 70px; }
  /* glossaire : la bulle devient une feuille en bas, au-dessus des onglets */
  .gltip { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: calc(52px + env(safe-area-inset-bottom)) !important; width: auto !important; max-height: 58vh; overflow: auto; border-radius: 10px 10px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0, 0, 0, .35); }
  .gltip .gll { min-height: 44px; }
  .tgroup > .th { grid-template-columns: minmax(0, 1fr) 64px 50px; }
}
