:root {
  --bg: #0f1720;
  --surface: #182430;
  --surface-2: #1e2c3a;
  --border: #2c3e50;
  --text: #e7eef5;
  --muted: #9fb2c4;
  --accent: #e63946;      /* rouge Côte d'Ivoire / médical */
  --accent-2: #2a9d8f;    /* vert validation */
  --ok: #2a9d8f;
  --ko: #e63946;
  --warn: #f4a261;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }

.site-header {
  background: linear-gradient(120deg, #101d29, #16303a);
  border-bottom: 1px solid var(--border);
  padding: 1.1rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .6rem;
}
.site-header .brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .3px; }
.site-header .brand span { color: var(--accent); }
.site-nav a { color: var(--muted); margin-left: 1.1rem; font-size: .95rem; }
.site-nav a:hover, .site-nav a.active { color: var(--text); }

main { max-width: 940px; margin: 0 auto; padding: 1.6rem 1.4rem 4rem; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; color: var(--muted); text-transform: uppercase;
     letter-spacing: .08em; margin: 2rem 0 .8rem; }
.lead { color: var(--muted); margin-top: 0; }

/* --- Accueil : grille matières --- */
.grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.matiere-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; display: block;
  transition: transform .12s ease, border-color .12s ease;
}
.matiere-card:not(.disabled):hover { transform: translateY(-2px); border-color: var(--accent); }
.matiere-card.disabled { opacity: .5; cursor: not-allowed; }
.mc-nom { margin: 0 0 .5rem; font-size: 1.05rem; }
.mc-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.badge { font-size: .72rem; padding: .12rem .5rem; border-radius: 999px; font-weight: 600; }
.badge-ready { background: rgba(42,157,143,.18); color: #6fd8c8; }
.badge-soon { background: rgba(159,178,196,.15); color: var(--muted); }
.mc-prog { font-size: .78rem; color: var(--muted); }

/* --- Boutons / formulaires --- */
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: .55rem 1.1rem; border-radius: 9px; font-size: .95rem; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:disabled { opacity: .5; cursor: default; }
select, input[type=number] {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; font-size: .95rem;
}
.toolbar { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.4rem; }
.toolbar label { white-space: nowrap; }
/* Empêche un menu déroulant aux longs libellés (ex. chapitres d'immuno) d'élargir
   la barre et de renvoyer « Annale » à la ligne : largeur plafonnée + ellipse. */
.toolbar select { max-width: 12rem; min-width: 0; text-overflow: ellipsis; }

/* --- Filtres (menus déroulants chapitre / annale) --- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 1.1rem; margin-bottom: 1.4rem; }
.filter-group { display: flex; flex-direction: column; gap: .3rem; }
.filter-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); }
.filter-group select {
  width: min(18rem, calc(100vw - 3rem));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .7rem; font-size: .92rem; cursor: pointer;
}
.filter-group select:hover { border-color: var(--accent); }
.filter-group select:focus { outline: none; border-color: var(--accent); }
.filter-group input[type=number] {
  width: 6rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .7rem; font-size: .92rem;
}
.filter-group input[type=number]:hover { border-color: var(--accent); }
.filter-group input[type=number]:focus { outline: none; border-color: var(--accent); }

/* --- Menu déroulant à cases à cocher (annales, multi-sélection) --- */
.multiselect { position: relative; }
.ms-toggle {
  font: inherit; min-width: 16rem; max-width: min(30rem, calc(100vw - 3rem)); text-align: left;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .7rem; font-size: .92rem; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.ms-toggle::after { content: '▾'; color: var(--muted); font-size: .75rem; }
.ms-toggle:hover, .ms-toggle[aria-expanded="true"] { border-color: var(--accent); }
.ms-panel {
  position: absolute; top: calc(100% + .3rem); left: 0; z-index: 20;
  width: max(100%, 42rem); max-width: min(46rem, calc(100vw - 3rem)); max-height: 16rem;
  overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: .4rem;
}
.ms-panel.hidden { display: none; }
.ms-reset {
  display: block; width: 100%; text-align: left; font: inherit; font-size: .82rem;
  background: none; border: none; border-bottom: 1px solid var(--border); color: var(--accent-2);
  cursor: pointer; padding: .4rem .5rem .55rem; margin-bottom: .3rem;
}
.ms-reset:hover { color: var(--text); }
.ms-option {
  display: flex; align-items: center; gap: .55rem; padding: .35rem .5rem;
  border-radius: 6px; cursor: pointer; font-size: .88rem;
}
.ms-option:hover { background: var(--surface-2); }
.ms-option input[type=checkbox] { accent-color: var(--accent); width: 1rem; height: 1rem; cursor: pointer; }

/* --- Quiz --- */
.quiz { display: flex; flex-direction: column; gap: 1rem; }
.q-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.q-card.q-cas { border-left: 3px solid var(--warn); }
.q-tag { font-size: .72rem; font-weight: 700; letter-spacing: .1em; color: var(--warn); margin-bottom: .4rem; }
.q-enonce { font-style: italic; color: var(--muted); margin-bottom: .8rem;
  border-left: 2px solid var(--border); padding-left: .7rem; white-space: pre-wrap;
  overflow-wrap: anywhere; }
.q-single.nested { padding: .7rem 0 0; border-top: 1px dashed var(--border); margin-top: .7rem; }
.q-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.q-num {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; min-width: 1.6rem; text-align: center; font-size: .8rem;
  padding: .05rem .35rem; font-weight: 600;
}
.q-text { flex: 1; min-width: 60%; overflow-wrap: anywhere; }
.q-type { font-size: .68rem; color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px; padding: .05rem .4rem; }
.q-annale { font-size: .68rem; font-weight: 600; color: #f4c26b;
  background: rgba(244,162,97,.14); border: 1px solid var(--warn);
  border-radius: 5px; padding: .05rem .45rem; white-space: nowrap; }
.q-opts { display: flex; flex-direction: column; gap: .35rem; margin: .7rem 0 0; }
.q-opts.qcd { flex-direction: row; gap: 1.4rem; }
.opt {
  display: flex; align-items: flex-start; gap: .5rem; padding: .4rem .55rem;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
}
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: .25rem; }
.opt-lettre { color: var(--muted); font-weight: 600; }
.opt-correct { background: rgba(42,157,143,.15); border-color: var(--ok); }
.opt-wrong { background: rgba(230,57,70,.14); border-color: var(--ko); }
.q-ouvert { width: 100%; margin-top: .6rem; background: var(--surface-2);
  color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; }

.q-images { display: flex; flex-wrap: wrap; gap: .9rem; margin: .7rem 0; }
.q-image { display: flex; flex-direction: column; align-items: center; gap: .35rem;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .6rem; }
.q-image img { max-width: 260px; width: 100%; height: auto; }
.q-image span { font-size: .78rem; color: #333; font-weight: 600; }

.q-single.ok .q-num { background: var(--ok); color: #fff; border-color: var(--ok); }
.q-single.ko .q-num { background: var(--ko); color: #fff; border-color: var(--ko); }

.q-feedback { margin-top: .7rem; font-size: .9rem; background: var(--surface-2);
  border-radius: 8px; padding: .6rem .75rem; border: 1px solid var(--border); }
.fb-verdict { font-weight: 700; margin-bottom: .3rem; }
.fb-modele { color: #6fd8c8; margin-bottom: .3rem; white-space: pre-wrap; }
.fb-expl { color: var(--text); }
.fb-src { color: var(--muted); font-size: .78rem; margin-top: .4rem; }

.quiz-actions { margin-top: .4rem; }
.score-box { background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-top: .6rem; }
.score-num { font-size: 1.25rem; font-weight: 700; }
.score-bar { height: 10px; background: var(--surface-2); border-radius: 999px;
  overflow: hidden; margin: .6rem 0; }
.score-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.score-note { font-size: .8rem; color: var(--muted); }

/* --- Examen --- */
.exam-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; max-width: 520px; }
.chk { display: flex; align-items: center; gap: .5rem; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .3rem 0; }
.field input { width: 90px; }
.exam-head { display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--bg); padding: .7rem 0; z-index: 5;
  border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
#exam-chrono { font-size: 1.4rem; font-variant-numeric: tabular-nums; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .2rem .7rem; }
#exam-chrono.urgent { color: #fff; background: var(--accent); border-color: var(--accent); }
.exam-expired { background: rgba(244,162,97,.15); border: 1px solid var(--warn);
  color: var(--warn); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1rem; }

.hidden { display: none !important; }
.vide, .erreur { color: var(--muted); font-style: italic; }
.erreur { color: var(--ko); }

@media (max-width: 560px) {
  .q-opts.qcd { flex-direction: column; gap: .3rem; }
  .site-nav a { margin-left: .7rem; }
}

.exam-retry { background: var(--card, rgba(127,127,127,.08)); border: 1px solid var(--accent);
  border-radius: 8px; padding: .8rem 1rem; margin: .8rem 0; }
.exam-retry-txt { margin: 0 0 .5rem; }
.exam-retry .quiz-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; }

/* --- Reprise des erreurs : bandeau + navigation flottante discrète --- */
.quiz-banner { background: rgba(244,162,97,.12); border: 1px solid var(--warn);
  color: var(--warn); border-radius: 8px; padding: .55rem .8rem; font-size: .9rem; }
.score-box .exam-retry { margin: .8rem 0 0; }
.q-single { scroll-margin-top: 90px; }
.q-single.miss .q-num { background: var(--warn); color: #1a1a1a; border-color: var(--warn); }

.err-nav { position: fixed; right: 14px; bottom: 18px; z-index: 30;
  display: flex; align-items: center; gap: .15rem; padding: .2rem .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow); opacity: .5; transition: opacity .15s ease, border-color .15s ease; }
.err-nav:hover, .err-nav:focus-within { opacity: 1; border-color: var(--accent); }
.err-nav-btn { background: none; border: none; color: var(--text); cursor: pointer;
  font-size: .8rem; line-height: 1; width: 1.9rem; height: 1.9rem; border-radius: 50%; }
.err-nav-btn:hover { background: var(--accent); color: #fff; }
.err-nav-count { font-size: .72rem; color: var(--muted); min-width: 2.4rem; text-align: center;
  font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .err-nav { opacity: .7; right: 10px; bottom: 12px; } }

/* --- Export / import de la progression (accueil) --- */
.sauvegarde .quiz-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.sauvegarde .score-note { margin: .6rem 0 0; min-height: 1.2em; }
.sauvegarde .score-note.erreur { color: var(--ko); font-style: normal; }
