/* Omnyscio — feuille de style de base (mobile-first, responsive). */

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --ko: #ef4444;
  --radius: 12px;
  --gap: 16px;
  --maxw: 720px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit gagner sur les display des classes de layout
   (.stack/.row en flex le neutralisaient silencieusement). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 32px;
  min-height: 100dvh;
}

h1, h2, h3 { line-height: 1.2; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  min-height: 44px; /* cible tactile confortable sur mobile */
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #04243a; font-weight: 600; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--gap);
}

.muted { color: var(--muted); }

.app-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px;
  text-align: center;
  font-size: 0.8rem;
  border-top: 1px solid var(--surface-2);
}
.app-footer a { color: var(--accent); text-decoration: none; }
.grow { flex: 1; }
.center { text-align: center; align-items: center; }

/* Layout utilitaires */
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap, .wrap { flex-wrap: wrap; }

.card + .card, #app > div > .card { margin-top: var(--gap); }

/* Réglages : rôles et champs */
.colrow { padding: 6px 0; border-bottom: 1px solid var(--surface-2); }
.roles { display: flex; gap: 12px; flex-wrap: wrap; }
.role { font-size: 0.9rem; color: var(--muted); white-space: nowrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.field select, .preset-bar select, .field input, .answer-input, input[type="text"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--surface-2); border-radius: 8px; padding: 10px; min-height: 40px;
}
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2);
  padding: 6px 10px; border-radius: 999px; font-size: 0.85rem; }

/* Tableau des rôles de colonnes */
.table-wrap { overflow-x: auto; }
.roles-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.roles-table th, .roles-table td { padding: 7px 8px; border-bottom: 1px solid var(--surface-2); }
.roles-table thead th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-align: center; }
.roles-table thead th:first-child { text-align: left; }
.roles-table .rc { text-align: center; width: 1%; white-space: nowrap; }
.roles-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.roles-table .colname { text-align: left; }
.roles-table .ctype { display: block; font-size: 0.72rem; }
.roles-table tr.master td { border-top: 2px solid var(--surface-2); border-bottom: none; }
.mini { min-height: 28px; padding: 2px 10px; font-size: 0.95rem; line-height: 1; background: var(--surface); }

/* Configuration avancée (panneau repliable des réglages de session) */
details.advanced > summary {
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  list-style-position: inside;
}
details.advanced[open] > summary { margin-bottom: var(--gap); }
/* Sections par intention (h3) et réglages (h4) — SPECS §6.2. */
details.advanced h3 {
  margin: 8px 0 0; font-size: 1rem; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--accent);
  border-bottom: 1px solid var(--surface-2); padding-bottom: 4px;
}
details.advanced h4 { margin: 0; font-size: 0.95rem; }

/* Badge des types de question concernés par un réglage (QCU/QCM/QRC/FlashCard). */
.qtype-badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px;
  border-radius: 999px; font-size: 0.68rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  vertical-align: middle; text-transform: none; letter-spacing: normal;
}

/* Bloc de réglage dont aucun type concerné n'est coché : REPLIÉ ET GRISÉ —
   le titre (1er enfant) reste visible (découvrabilité si on ajoute un type
   plus tard), le contenu disparaît. Les valeurs ne sont jamais effacées. */
.qtype-off > :first-child { opacity: 0.45; }
.qtype-off > :first-child::after {
  content: ' — type de question non coché';
  font-size: 0.72rem; font-weight: normal; font-style: italic;
  color: var(--muted); text-transform: none; letter-spacing: normal;
}
.qtype-off > :not(:first-child) { display: none !important; }

/* Pastille d'état sur le résumé d'un panneau replié (réglages/filtres actifs). */
.active-badge { background: var(--accent); color: #04243a; }
.typo-tolerance select { max-width: 320px; }

/* Bloc « Types de question » (sessions mixtes) : case + poids par type. */
.qtype-row { justify-content: space-between; }
.qtype-row .chip { flex: 1; }
.qtype-row input[type="number"] { width: 80px; }
.qtypes input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.weight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.weight-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.9rem; }
.weight-row input { width: 80px; }
.choice-count { max-width: 220px; }

/* Préréglages nommés */
.preset-bar select { flex: 1; min-width: 140px; }
.preset-status { margin: 8px 0; font-size: 0.9rem; }
.preset-status strong { color: var(--accent); }
.preset-dirty { color: var(--ko); }
.preset-description { margin: 0 0 8px; font-size: 0.85rem; font-style: italic; }
.preset-manage { margin-top: 6px; }

/* Bouton à appui long (remise à plat) */
.hold-btn { position: relative; overflow: hidden; }
.hold-btn::before {
  content: ''; position: absolute; inset: 0; width: 0;
  background: rgba(239, 68, 68, 0.55); /* = var(--ko), repli si color-mix absent */
  background: color-mix(in srgb, var(--ko) 55%, transparent);
  pointer-events: none;
}
.hold-btn.holding::before { width: 100%; transition: width var(--hold-ms, 1500ms) linear; }

/* Bannière « nouvelle version disponible » */
.update-banner {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  max-width: calc(100% - 32px);
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 10px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  z-index: 100;
}

/* Session / questions */
.stage { min-height: 50dvh; }
.prompt { margin: 0; }

/* Rappel des raccourcis clavier (desktop uniquement) */
.kbd-hint { font-size: 0.8rem; margin: 2px 0 0; }
@media (max-width: 700px), (pointer: coarse) { .kbd-hint { display: none; } }

/* Relecture des questions précédentes (barre au-dessus de la scène) */
.review-nav { margin: 6px 0; }
.review-nav .review-pos { flex: 1; text-align: center; font-size: 0.9rem; }
.review { opacity: 0.92; }

/* Accompagnement (contexte / indices) */
.extras { display: flex; flex-direction: column; gap: 8px; }
.extras:empty { display: none; }
.extra { margin: 0; }
/* Cellule à tags : une puce par tag (cf. extras-view.js). */
.extra-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.extra-label { margin: 0; font-size: 0.85rem; }
.hints .row { margin: 0; }
.hint-btn { align-self: flex-start; }
.choices { display: grid; gap: 10px; }
.choice { text-align: left; }
.choice.selected { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.choice.correct { background: var(--ok); color: #042; border-color: var(--ok); }
.choice.incorrect { background: var(--ko); color: #400; border-color: var(--ko); }
.answer-input { flex: 1; }
.feedback { font-weight: 600; min-height: 1.4em; margin: 4px 0 0; }
.feedback.ok { color: var(--ok); }
.feedback.ko { color: var(--ko); }

/* Guide intégré (#/guide) et aide contextuelle ⓘ */
.help-btn { min-height: 22px; padding: 0 7px; font-size: 0.85rem; border-radius: 999px; vertical-align: middle; }
dialog.help-dialog {
  border: none; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  max-width: min(440px, 92vw); padding: 16px;
}
dialog.help-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.help-dialog h3 { margin: 0 0 8px; }
dialog.help-dialog p { margin: 0 0 12px; }
.guide .tab-active { border-color: var(--accent); font-weight: 600; }
.md h1, .md h2, .md h3 { scroll-margin-top: 12px; }
.md h2 { margin-top: 22px; }
.md table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.md th, .md td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--surface-2); }
.md th { color: var(--muted); font-weight: 500; }
.md blockquote { margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.md pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.md li { margin: 3px 0; }

/* Tableau de bord de progression (📊) */
.stats-tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.stats-tile {
  flex: 1 1 110px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 8px;
  background: var(--surface-2);
  border-radius: var(--radius);
  text-align: center;
}
.stats-tile strong { font-size: 1.3rem; }
.stats-tile span { font-size: 0.8rem; }
.stats-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.stats-table th, .stats-table td { text-align: left; padding: 4px 8px; }
.stats-table th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.stats-table tbody tr:nth-child(odd) { background: var(--surface-2); }
.stats-history p { margin: 4px 0; }

/* Fin de session */
.summary { max-width: 420px; margin: 0 auto; }
.summary .row { width: 100%; }
.summary h3 { margin: 4px 0 0; }
.summary-stats p { margin: 0; }
.summary-errors {
  margin: 0; padding-left: 1.2em; text-align: left;
  max-height: 40dvh; overflow-y: auto; width: 100%;
  font-size: 0.9rem;
}
.summary-errors li { margin-bottom: 6px; }
.summary select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--surface-2); border-radius: 8px; padding: 10px; min-height: 44px;
}

/* FlashCard */
.flashcard .answer { text-align: center; }
/* Compléments au verso : alignés à gauche sous la réponse, séparés d'un filet. */
.flashcard .answer .reveals {
  text-align: left;
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--surface-2);
}

/* Carte groupée : auto-évaluation par élément au verso */
.groupcard .answer.verso { text-align: left; display: flex; flex-direction: column; gap: 10px; }
.verso-element { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.verso-element .extra { flex: 1; }
.grade-toggle { min-width: 96px; flex-shrink: 0; }
.grade-toggle.ok { background: var(--ok); color: #042; border-color: var(--ok); }
.grade-toggle.ko { background: var(--ko); color: #400; border-color: var(--ko); }

/* Éditeur de cartes groupées (config avancée) : puce cyclant Recto → Verso → exclue */
.group-editor { padding: 12px; }
.group-editor input[type="text"] { flex: 1; min-width: 0; }
.side-chip { border-radius: 999px; font-size: 0.85rem; min-height: 32px; padding: 4px 12px; }
.side-chip.recto { background: var(--accent); color: #04243a; border-color: var(--accent); font-weight: 600; }
.side-chip.verso { background: var(--ok); color: #042; border-color: var(--ok); font-weight: 600; }
.answer-value { font-size: 1.6rem; font-weight: 700; }
.answer-list { margin: 0; padding-left: 1.2em; text-align: left; }
.answer-list li { font-size: 1.1rem; font-weight: 600; }
.ok-btn { background: var(--ok); color: #042; }
.ko-btn { background: var(--ko); color: #400; }

/* Média */
.media { max-width: 100%; border-radius: 8px; }
/* Lisibilité : une image d'énoncé/d'accompagnement ne mange pas l'écran. */
img.media { max-height: 38dvh; width: auto; object-fit: contain; display: block; }
img.media.zoomable { cursor: zoom-in; }
.media-attribution { font-size: 0.75rem; margin: 4px 0 0; }
.media-attribution a { color: inherit; }
.media-source { font-size: 0.75rem; margin: 2px 0 0; }

/* Propositions MÉDIA (réponse média, SPECS §5.2) : grille de cartes. */
.choices.media-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: start; }
/* La carte est un div (les commandes audio doivent rester cliquables) :
   on lui donne l'apparence des boutons de choix. */
.choice.media-choice {
  cursor: pointer;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.choice.media-choice:hover:not(.locked) { border-color: var(--accent); }
.choice.media-choice img.media { max-height: 160px; margin: 0 auto; }
.choice.media-choice audio.media { width: 100%; }
.choice.media-choice .media-attribution,
.choice.media-choice .media-source { font-size: 0.68rem; }
.choice.media-choice.locked { cursor: default; }

/* Lightbox : agrandissement plein écran d'une image (clic pour fermer). */
dialog.lightbox { border: none; background: transparent; padding: 0; max-width: 96vw; max-height: 96dvh; }
dialog.lightbox::backdrop { background: rgba(0, 0, 0, 0.75); }
dialog.lightbox img { max-width: 96vw; max-height: 96dvh; object-fit: contain; cursor: zoom-out; border-radius: 8px; }

/* Hors-ligne par thème */
button.danger { background: var(--ko); color: #400; font-weight: 600; }
button.offline-on { background: var(--ok); color: #042; border-color: var(--ok); }
.offline-panel { margin-top: 8px; }

/* Réglages : éditeur de source média d'une colonne (⚙ dans la table des rôles) */
.msrc-panel { margin: 4px 0; padding: 6px 8px; background: var(--surface); border-radius: 8px; }
.msrc-panel .chip { white-space: nowrap; }
.msrc-note { margin: 4px 0 0; font-size: 0.85rem; }

/* Accueil : entrée du catalogue non installée (bases intégrées) */
.catalog-entry { padding: 6px 0; }
.catalog-entry .catalog-desc { margin: 2px 0 0; font-size: 0.9rem; }

/* Cartes dues (répétition espacée) : pastille sur le bouton du thème */
.due-chip {
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.85rem;
  font-weight: 600;
}
.offline-cols { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.offline-col { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.offline-col input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.offline-storage { margin-top: 8px; }
.offline-badge { color: var(--ok); font-weight: 600; }
.progress {
  height: 10px; background: var(--surface-2); border-radius: 999px;
  overflow: hidden; margin: 8px 0;
}
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

@media (min-width: 600px) {
  .choices { grid-template-columns: 1fr 1fr; }
}
