/* ==========================================================================
   RÉVISIONS 2026 — styles (responsive PC + téléphone, clair / sombre)
   ========================================================================== */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #172033;
  --muted: #5d6882;
  --border: #dde3ee;
  --primary: #1e40af;
  --primary-2: #2f5bd8;
  --on-primary: #ffffff;
  --good: #15803d;
  --good-bg: #e8f7ee;
  --mid: #c2410c;
  --mid-bg: #fff3e6;
  --bad: #c81e1e;
  --bad-bg: #fdecec;
  --info-bg: #eaf1ff;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .06);
  --radius: 14px;
  --side: 250px;
  --top: 56px;
  --bottom: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1422;
    --surface: #172033;
    --surface-2: #1f2a40;
    --text: #e8edf7;
    --muted: #9aa6c0;
    --border: #2b3753;
    --primary: #5b8cff;
    --primary-2: #7ea4ff;
    --on-primary: #0b1020;
    --good: #4ade80;
    --good-bg: #123322;
    --mid: #fb923c;
    --mid-bg: #3a2414;
    --bad: #f87171;
    --bad-bg: #3a1717;
    --info-bg: #1b2b4d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1422; --surface: #172033; --surface-2: #1f2a40; --text: #e8edf7; --muted: #9aa6c0; --border: #2b3753;
  --primary: #5b8cff; --primary-2: #7ea4ff; --on-primary: #0b1020; --good: #4ade80; --good-bg: #123322;
  --mid: #fb923c; --mid-bg: #3a2414; --bad: #f87171; --bad-bg: #3a1717; --info-bg: #1b2b4d; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
button { font: inherit; }
h1, h2, h3 { line-height: 1.25; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 8px; }

/* ---------- Structure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: linear-gradient(90deg, #1e3a8a, #2f5bd8); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.brand { color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .5px; font-size: 1.1rem; }
.brand-sub { opacity: .8; font-size: .85rem; margin-left: auto; }
.layout { display: flex; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; max-width: 900px; margin: 0 auto; padding: 16px 16px calc(var(--bottom) + 24px); outline: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  height: var(--bottom); text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.bottom-nav a span { font-size: 1.35rem; line-height: 1.1; }
.bottom-nav a.active { color: var(--primary); }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .sidebar {
    display: block; position: sticky; top: var(--top); align-self: flex-start;
    width: var(--side); height: calc(100vh - var(--top)); overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px 24px;
  }
  .main { padding: 24px 32px 48px; }
}
.sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: .95rem;
}
.sidebar a span { width: 1.4em; text-align: center; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--info-bg); color: var(--primary); font-weight: 700; }
.side-nav a { font-weight: 600; }
.side-title { margin: 16px 10px 6px; font-size: .75rem; font-weight: 800; color: var(--muted); letter-spacing: 1px; }
.side-subjects a { font-size: .9rem; padding: 6px 10px; }
.side-extra { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; }

/* ---------- Éléments communs ---------- */
.h1 { font-size: 1.5rem; margin: 6px 0 10px; }
.h2 { font-size: 1.15rem; margin: 26px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.big { font-size: 1.6rem; }
.center { text-align: center; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text);
}
.pad { padding: 16px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; margin-top: 10px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.row-actions.center { justify-content: center; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 99px; font-weight: 700; font-size: .9rem; background: var(--surface-2); }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.mid { background: var(--mid-bg); color: var(--mid); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.good { color: var(--good); } .mid { color: var(--mid); } .bad { color: var(--bad); }
.bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; border-radius: 99px; background: var(--muted); transition: width .4s; }
.bar.good span { background: var(--good); } .bar.mid span { background: var(--mid); } .bar.bad span { background: var(--bad); }
.plain { list-style: none; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { padding: 6px 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .9rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 16px); transform: translate(-50%, 30px);
  background: #172033; color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Accueil ---------- */
.hero-box {
  border: 3px double rgba(255, 255, 255, .7); border-radius: 18px; padding: 22px 16px;
  background: linear-gradient(135deg, #1e3a8a, #2f5bd8 60%, #3b82f6); color: #fff; text-align: center;
  box-shadow: 0 10px 30px rgba(30, 58, 138, .25);
}
.hero-title { font-size: 1.7rem; font-weight: 900; letter-spacing: 1.5px; }
.hero-sub { margin: 8px 0 18px; opacity: .95; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .3); border-radius: 14px;
  color: #fff; text-decoration: none; transition: .15s;
}
.tile:hover { background: rgba(255, 255, 255, .24); transform: translateY(-2px); }
.tile-ic { font-size: 1.9rem; }
.tile-l { font-weight: 800; letter-spacing: .5px; }
.tile-s { font-size: .78rem; opacity: .85; }
.resume { display: block; margin: 12px 0; padding: 12px 14px; border-radius: 12px; background: var(--info-bg); text-decoration: none; color: var(--text); }
.review-cta { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin: 12px 0; text-decoration: none; border-left: 5px solid var(--mid); }
.review-cta .chev { margin-left: auto; font-size: 1.6rem; color: var(--muted); }
.home-foot { display: grid; gap: 10px; margin: 18px 0; }
.card.mini { padding: 12px 14px; text-decoration: none; font-weight: 600; text-align: left; cursor: pointer; width: 100%; font-size: 1rem; }
@media (min-width: 600px) { .home-foot { grid-template-columns: 1fr 1fr; } }

.subject-grid { display: grid; gap: 10px; }
@media (min-width: 640px) { .subject-grid { grid-template-columns: 1fr 1fr; } }
.subj {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none;
  border-left: 5px solid var(--c); transition: transform .12s;
}
.subj:hover { transform: translateY(-2px); }
.subj-ic { font-size: 1.8rem; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); flex: none; }
.subj-ic.xl { font-size: 2.3rem; width: 64px; height: 64px; }
.subj-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.subj-score { font-weight: 800; min-width: 52px; text-align: right; }
.subj-score.none { color: var(--muted); }
.subj-head { display: flex; align-items: center; gap: 14px; padding: 6px 0 4px; border-bottom: 3px solid var(--c); margin-bottom: 8px; }
.subj-head .h1 { margin: 0; }
.subj-head p { margin: 2px 0 6px; }

/* ---------- Liste des leçons ---------- */
.lesson-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.lesson-list a {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text);
}
.lesson-list a:hover { border-color: var(--primary); }
.num { font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.lt { flex: 1; display: flex; flex-direction: column; font-weight: 600; }
.lscore { font-weight: 700; white-space: nowrap; }
.lscore.none { color: var(--muted); }

/* ---------- Leçon ---------- */
.lesson-body h3 { margin: 22px 0 8px; font-size: 1.08rem; color: var(--c); }
.lesson-body p, .lesson-body li { max-width: 72ch; }
.lesson-body ul { padding-left: 1.2em; }
.lesson-body li { margin: 4px 0; }
.tw { overflow-x: auto; margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.lesson-body table, .tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.lesson-body th, .lesson-body td, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.lesson-body th { background: var(--surface-2); font-size: .85rem; }
.lesson-body tr:last-child td, .tbl tr:last-child td { border-bottom: 0; }
.tbl .num-c { text-align: right; font-weight: 700; white-space: nowrap; }
.tbl .bar-c { width: 30%; }
.tbl a { text-decoration: none; color: var(--text); font-weight: 600; }
.box { border-radius: 12px; padding: 12px 14px; margin: 14px 0; border-left: 5px solid; }
.box ul { margin: 6px 0 0; padding-left: 1.2em; }
.box p { margin: 6px 0 0; }
.box.retenir { background: var(--good-bg); border-color: var(--good); }
.box.piege { background: var(--bad-bg); border-color: var(--bad); }
.box.explic { background: var(--info-bg); border-color: var(--primary); }
.box.methode { background: var(--surface-2); border-color: var(--muted); }
.box.trancher { background: var(--mid-bg); border-color: var(--mid); }
figure { margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
figure img { display: block; margin: 0 auto; border-radius: 8px; background: #fff; }
figcaption { font-size: .85rem; margin-top: 6px; }
.formula { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.pager .btn { max-width: 48%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; line-height: 28px; }
.sticky-actions { position: sticky; bottom: calc(var(--bottom) + 8px); background: var(--bg); padding: 8px 0; margin-bottom: 0; }
@media (min-width: 900px) { .sticky-actions { bottom: 0; } }

/* ---------- Aide-mémoire ---------- */
.memo {
  background: var(--surface); border: 2px solid var(--c); border-radius: 16px; padding: 14px 16px; margin: 10px 0;
  box-shadow: var(--shadow); break-inside: avoid;
}
.memo-h { font-weight: 900; letter-spacing: .5px; color: var(--c); }
.memo-key { font-size: 1.15rem; font-weight: 800; margin: 8px 0; }
.flow { display: flex; flex-direction: column; align-items: center; margin: 10px 0; text-align: center; }
.flow span { background: var(--surface-2); border-radius: 10px; padding: 6px 12px; font-weight: 600; max-width: 100%; }
.flow i { font-style: normal; color: var(--c); font-weight: 900; line-height: 1.4; }
.memo-pts { padding-left: 1.2em; margin: 8px 0; }
.memo-pts li { margin: 3px 0; }
.memo-tip { background: var(--mid-bg); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-size: .95rem; }
.memo-link { display: inline-block; margin-top: 10px; font-weight: 700; text-decoration: none; }
.memo-grid { display: grid; gap: 4px; }
@media (min-width: 1100px) { .memo-grid { grid-template-columns: 1fr 1fr; gap: 0 14px; } }
.flash .memo { animation: flash 1.6s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 6px var(--c); } 100% { box-shadow: var(--shadow); } }

/* ---------- QCM ---------- */
.setup fieldset { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin: 12px 0; padding: 10px 14px 14px; }
.setup legend { font-weight: 700; padding: 0 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label input { position: absolute; opacity: 0; }
.seg label span { display: inline-block; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; font-weight: 600; min-height: 44px; line-height: 26px; }
.seg label input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.seg label input:focus-visible + span { outline: 3px solid var(--primary-2); outline-offset: 2px; }
.chk { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.chk input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.lesson-checks { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 4px; }

.q-head { border-bottom: 3px solid var(--c); padding-bottom: 8px; margin-bottom: 12px; }
.q-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; font-size: .88rem; font-weight: 600; }
.q-count { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 6px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--c); transition: width .3s; }
.timer { position: relative; height: 24px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.timer span { position: absolute; inset: 0 auto 0 0; width: 100%; background: var(--primary); opacity: .35; transition: width .2s linear; }
.timer span.low { background: var(--bad); opacity: .5; }
.timer b { position: relative; display: block; text-align: center; font-size: .85rem; line-height: 24px; }
.q-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.q-text { font-size: 1.2rem; margin: 0 0 14px; font-weight: 700; }
.q-img { margin: 0 0 14px; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; min-height: 54px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); transition: .12s;
}
.choice:hover:not([disabled]) { border-color: var(--primary); background: var(--info-bg); }
.choice .letter {
  flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px;
  background: var(--surface-2); font-weight: 800;
}
.choice .ct { padding-top: 3px; }
.choice[disabled] { cursor: default; }
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.correct .letter { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .letter { background: var(--bad); color: #fff; }
.choice.dim { opacity: .55; }
.feedback { margin-top: 14px; border-radius: var(--radius); padding: 14px 16px; background: var(--surface); border: 2px solid; outline: none; scroll-margin-top: calc(var(--top) + 8px); }
.feedback.ok { border-color: var(--good); }
.feedback.ko { border-color: var(--bad); }
.fb-title { font-size: 1.25rem; font-weight: 800; }
.feedback.ok .fb-title { color: var(--good); }
.feedback.ko .fb-title { color: var(--bad); }
.fb-good { font-size: 1.05rem; }
.fb-sec { margin: 12px 0; padding: 10px 12px; border-radius: 10px; background: var(--info-bg); }
.fb-sec p { margin: 4px 0 0; }
.fb-sec.retenir { background: var(--good-bg); }
.fb-sec.attention { background: var(--mid-bg); }
.fb-lesson { display: inline-block; margin: 4px 0; font-weight: 700; text-decoration: none; }
.q-foot { margin-top: 18px; text-align: center; }

/* ---------- Résultats ---------- */
.res-head { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 12px; box-shadow: var(--shadow); }
.res-title { font-weight: 900; letter-spacing: 2px; border-top: 3px solid var(--primary); border-bottom: 3px solid var(--primary); padding: 6px; display: inline-block; min-width: 60%; }
.res-subj { margin-top: 14px; font-weight: 800; letter-spacing: 1px; }
.res-score { font-size: 1.4rem; font-weight: 700; margin-top: 6px; }
.res-pct { font-size: 3rem; font-weight: 900; line-height: 1.1; }
.res-ascii { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: -1px; overflow: hidden; white-space: nowrap; }
.prio { background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--muted); border-radius: 12px; padding: 12px 14px; margin: 10px 0; box-shadow: var(--shadow); }
.prio.bad { border-left-color: var(--bad); } .prio.mid { border-left-color: var(--mid); } .prio.good { border-left-color: var(--good); }
.prio-h { font-weight: 800; }
.prio-t { font-size: 1.15rem; font-weight: 700; margin: 2px 0; }
.prio-list { padding: 6px 12px 6px 34px; }
.prio-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.prio-list li:last-child { border-bottom: 0; }
.prio-list li a { text-decoration: none; color: var(--text); }
.prio-list li { display: list-item; }
.prio-list .num-c { float: right; font-weight: 700; }
.memo-links { list-style: none; padding: 8px 14px; }
.memo-links li { padding: 4px 0; }
.err { padding: 10px 14px; margin: 8px 0; }
.err summary { cursor: pointer; font-weight: 600; }
.trancher h3 { margin: 0 0 8px; }
.tr-grid { display: grid; gap: 8px; }
@media (min-width: 640px) { .tr-grid { grid-template-columns: 1fr 1fr; } }
.tr-grid p { margin: 2px 0; }
.tr-keep { background: var(--good-bg); border-radius: 8px; padding: 8px 10px; margin: 10px 0 0; font-weight: 600; }

/* ---------- Impression ---------- */
@media print {
  .topbar, .sidebar, .bottom-nav, .row-actions, .pager, .crumbs, .chips, .toast, .q-foot, .memo-link { display: none !important; }
  body { background: #fff; color: #000; }
  .main { padding: 0; max-width: none; }
  .card, .memo, figure { box-shadow: none; }
}

/* ---------- Symboles de portes logiques ---------- */
svg.gate { width: 130px; height: 54px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; vertical-align: middle; overflow: visible; }
svg.gate text { fill: currentColor; stroke: none; font: 600 12px system-ui, sans-serif; }
svg.gate .g-sign { font-size: 18px; font-weight: 800; }
.q-text svg.gate { display: block; width: 190px; height: 80px; margin: 14px auto 0; }
.choice svg.gate { width: 120px; height: 50px; }
table.gates td { vertical-align: middle; }
