:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #16202e;
  --muted: #5b6878;
  --border: #d9dfe8;
  --primary: #1f5fbf;
  --primary-ink: #ffffff;
  --ok: #138a47;
  --ok-bg: #e3f5ea;
  --bad: #c8102e;
  --bad-bg: #fde8eb;
  --warn: #b26a00;
  --warn-bg: #fff3dc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1f2834; --text: #e8edf4; --muted: #9aa7b8;
    --border: #2b3645; --primary: #5b95ec; --primary-ink: #0b1220; --ok: #43c47c; --ok-bg: #12301f;
    --bad: #ff6b7f; --bad-bg: #3a161d; --warn: #f0b04a; --warn-bg: #3a2a10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e28; --surface-2: #1f2834; --text: #e8edf4; --muted: #9aa7b8;
  --border: #2b3645; --primary: #5b95ec; --primary-ink: #0b1220; --ok: #43c47c; --ok-bg: #12301f;
  --bad: #ff6b7f; --bad-bg: #3a161d; --warn: #f0b04a; --warn-bg: #3a2a10;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--primary); }
button { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; font-weight: 700; font-size: 18px; padding: 0; }
.brand small { font-weight: 500; color: var(--muted); font-size: 14px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); font-weight: 800; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; font-size: 18px; }

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 16px 32px; outline: none; }
.foot { text-align: center; font-size: 13px; color: var(--muted); padding: 16px; border-top: 1px solid var(--border); }

h1 { font-size: 24px; line-height: 1.25; margin: 4px 0 6px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
.lead { color: var(--muted); margin: 0 0 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.tile { text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: transform .08s ease, border-color .15s; }
.tile:hover { border-color: var(--primary); }
.tile:active { transform: scale(.99); }
.tile strong { font-size: 17px; }
.tile span { color: var(--muted); font-size: 14px; }
.tile.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.tile.primary span { color: inherit; opacity: .85; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12px; }

.theme-list { display: flex; flex-direction: column; gap: 8px; }
.theme-row { display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; padding: 12px 14px; }
.theme-row .t { flex: 1; min-width: 0; }
.theme-row .t b { display: block; }
.theme-row .t small { color: var(--muted); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.pct { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3ch; text-align: right; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.btn-row .btn { flex: 1 1 160px; }

/* Quiz */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; color: var(--muted); font-size: 14px; }
.quiz-head .tag { background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 2px 10px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; background: var(--primary); transition: width .2s; }
.q-sign { width: 132px; height: 132px; margin: 4px auto 12px; }
.q-sign svg { width: 100%; height: 100%; display: block; }
.q-text { font-size: 18px; font-weight: 600; margin: 0 0 14px; }
.grave-flag { display: inline-block; font-size: 12px; font-weight: 700; color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 1px 8px; margin-bottom: 8px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 14px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer; }
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice .k { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); font-weight: 700; }
.choice.selected { border-color: var(--primary); }
.choice.selected .k { background: var(--primary); color: var(--primary-ink); }
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.correct .k { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .k { background: var(--bad); color: #fff; }
.choice:disabled { cursor: default; }
.feedback { margin-top: 14px; border-radius: 12px; padding: 14px; border-left: 5px solid; }
.feedback.ok { background: var(--ok-bg); border-color: var(--ok); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.feedback p { margin: 4px 0 0; }
.ref { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Résultats */
.score { text-align: center; padding: 22px 16px; }
.score .big { font-size: 52px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score .verdict { font-size: 20px; font-weight: 700; margin-top: 8px; }
.score.pass .verdict { color: var(--ok); }
.score.fail .verdict { color: var(--bad); }
.review-item { margin-top: 10px; }
.review-item .mini-sign { width: 56px; height: 56px; float: right; margin-left: 10px; }
.review-item .ans { font-size: 14px; margin: 6px 0 0; }
.review-item .ans.bad { color: var(--bad); }
.review-item .ans.ok { color: var(--ok); }

/* Panneaux */
.sign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.sign-card { text-align: center; padding: 12px; cursor: pointer; }
.sign-card svg { width: 84px; height: 84px; }
.sign-card .code { font-weight: 700; font-size: 13px; color: var(--muted); }
.sign-card .lbl { font-size: 14px; min-height: 2.6em; }
.sign-card.hidden-label .lbl { filter: blur(6px); }

/* Mémo */
.memo h3 { margin: 0 0 8px; font-size: 17px; }
.memo ul { margin: 0; padding-left: 20px; }
.memo li { margin: 4px 0; }
.memo .card { margin-bottom: 12px; }

.notice { background: var(--warn-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }

@media (max-width: 480px) {
  h1 { font-size: 21px; }
  .q-sign { width: 112px; height: 112px; }
  .stats { gap: 8px; }
  .stat b { font-size: 19px; }
}

/* ===================== Gamification ===================== */
:root { --fire: #ff7a00; --gold: #f5b400; --purple: #7c4dff; --teal: #0ea5a4; }

.hdr-right { display: flex; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums; }
.chip small { font-weight: 500; color: var(--muted); }
.flame { filter: grayscale(1); opacity: .55; transition: filter .3s, opacity .3s; display: inline-block; }
.flame.lit, .lit .flame { filter: none; opacity: 1; animation: flicker 1.6s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { transform: scale(1) rotate(-2deg); } 50% { transform: scale(1.08) rotate(2deg); } }

/* Accueil */
.hero { padding: 18px; background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%); }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.streak-big { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.streak-big .flame { font-size: 34px; }
.streak-big b { font-size: 40px; font-variant-numeric: tabular-nums; color: var(--fire); }
.streak-big:not(.lit) b { color: var(--muted); }
.streak-big small { color: var(--muted); font-size: 13px; }
.goal { position: relative; width: 96px; height: 96px; flex: none; }
.ring { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring .track { stroke: var(--border); }
.ring .val { stroke: var(--gold); transition: stroke-dashoffset .6s ease; }
.goal-txt { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.goal-txt b { font-size: 16px; font-variant-numeric: tabular-nums; }
.goal-txt small { font-size: 11px; color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 14px 0 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.day i { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--border); font-style: normal; font-size: 15px; }
.day.partial i { border-color: var(--gold); }
.day.done i { background: #fff1e0; border-color: var(--fire); }
.day.frozen i { background: #e0f2fe; border-color: #38bdf8; }
.day.today span { color: var(--text); font-weight: 700; }
.hero-msg { margin: 8px 0 12px; font-size: 15px; }
.freeze-chip { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; background: #e0f2fe; color: #075985; font-size: 13px; font-weight: 700; }
.level { display: flex; align-items: center; gap: 10px; }
.level .bar { flex: 1; margin: 0; height: 10px; }
.level .bar > i { background: linear-gradient(90deg, var(--purple), var(--primary)); }
.level small { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lvl-badge { background: var(--purple); color: #fff; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }

.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.mode { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; cursor: pointer;
  border-width: 2px; border-bottom-width: 5px; transition: transform .08s; min-height: 128px; }
.mode:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 3px; }
.mode:disabled { opacity: .5; cursor: default; }
.mode .mi { font-size: 30px; margin-bottom: 6px; }
.mode strong { font-size: 16px; }
.mode span:last-child { font-size: 13px; color: var(--muted); }
.m-exam { border-color: var(--primary); } .m-swipe { border-color: var(--fire); } .m-chrono { border-color: var(--purple); }
.m-train { border-color: var(--ok); } .m-err { border-color: var(--bad); } .m-signs { border-color: var(--gold); }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 18px 0; }
.grid2 .tile { padding: 12px 14px; }
.grid2 .tile strong { font-size: 15px; }
.grid2 .tile span { font-size: 13px; }

/* En-tête de partie */
.quiz-head { gap: 12px; }
.quiz-head .progress { flex: 1; margin: 0; height: 12px; }
.quiz-head .progress > i { background: linear-gradient(90deg, var(--ok), #4ade80); }
.icon-btn.small { width: 34px; height: 34px; font-size: 15px; flex: none; }
.quiz-sub { display: flex; align-items: center; justify-content: space-between; min-height: 28px; margin-bottom: 10px; color: var(--muted); font-size: 14px; }
.combo { color: var(--fire); font-weight: 800; animation: pop .3s ease; }
.combo.hot { color: var(--bad); }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
.tag.chrono { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; min-width: 4ch; text-align: center; }
.tag.chrono.low { color: #fff; background: var(--bad); border-color: var(--bad); animation: pop .4s ease infinite alternate; }
.chrono-score { flex: 1; font-weight: 800; font-size: 20px; color: var(--ok); text-align: center; }

.float-xp { position: absolute; transform: translateX(-50%); font-weight: 800; color: var(--gold); text-shadow: 0 1px 0 rgba(0,0,0,.2);
  pointer-events: none; animation: floatup .9s ease-out forwards; z-index: 20; }
@keyframes floatup { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -60px; } }
.xp-earned { display: inline-block; margin-top: 12px; padding: 4px 14px; border-radius: 99px; background: var(--gold); color: #2b2100; font-weight: 800; }
.record { margin-top: 8px; font-weight: 800; color: var(--gold); font-size: 18px; }
.score .big small { font-size: 22px; }
.score .lead { margin: 8px 0 0; }

/* Toasts & confettis */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  font-size: 15px; animation: toastin .3s ease; transition: opacity .3s, transform .3s; }
.toast.t-level { background: var(--purple); color: #fff; }
.toast.t-goal { background: var(--fire); color: #fff; }
.toast .ti { font-size: 20px; margin-right: 4px; }
.toast.out { opacity: 0; transform: translateY(10px); }
@keyframes toastin { from { opacity: 0; transform: translateY(20px) scale(.95); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

/* Vrai ou Faux */
.swipe-zone { position: relative; min-height: 330px; }
.swipe-card { position: relative; background: var(--surface); border: 2px solid var(--border); border-radius: 20px; box-shadow: 0 6px 20px rgba(16,24,40,.12);
  padding: 22px 18px; touch-action: pan-y; user-select: none; cursor: grab; transition: transform .25s ease, opacity .25s ease; }
.swipe-card.dragging { transition: none; cursor: grabbing; }
.swipe-card.fly { transition: transform .28s ease-in, opacity .28s ease-in; opacity: 0; }
.swipe-card.fly.right { transform: translateX(130%) rotate(18deg) !important; }
.swipe-card.fly.left { transform: translateX(-130%) rotate(-18deg) !important; }
.swipe-card.good { border-color: var(--ok); } .swipe-card.badc { border-color: var(--bad); }
.swipe-card .q-text { font-size: 17px; }
.proposal { margin-top: 14px; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 2px dashed var(--border); font-size: 18px; font-weight: 700; }
.proposal small { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.stamp { position: absolute; top: 18px; padding: 4px 12px; border: 4px solid; border-radius: 10px; font-weight: 900; font-size: 22px; letter-spacing: .05em;
  opacity: 0; pointer-events: none; z-index: 2; background: var(--surface); }
.stamp.yes { left: 16px; color: var(--ok); transform: rotate(-12deg); }
.stamp.no { right: 16px; color: var(--bad); transform: rotate(12deg); }
.swipe-actions { display: flex; justify-content: center; gap: 40px; margin-top: 18px; }
.round-btn { width: 76px; height: 76px; border-radius: 50%; border: 3px solid; background: var(--surface); font-size: 30px; font-weight: 800; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; box-shadow: var(--shadow); transition: transform .08s; }
.round-btn small { font-size: 11px; font-weight: 700; margin-top: 3px; }
.round-btn:active { transform: scale(.92); }
.round-btn.no { color: var(--bad); border-color: var(--bad); }
.round-btn.yes { color: var(--ok); border-color: var(--ok); }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }

/* Badges, stats, réglages */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 10px; }
.badge .bi { font-size: 36px; filter: grayscale(1); opacity: .35; }
.badge.got .bi { filter: none; opacity: 1; }
.badge small { color: var(--muted); font-size: 12px; }
.badge em { font-size: 11px; color: var(--ok); font-style: normal; font-weight: 700; }
.badge:not(.got) b { color: var(--muted); }
.stats { grid-template-columns: repeat(3, 1fr); }
.cal { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; }
.cal i { aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.cal i.c1 { background: #ffe4c4; } .cal i.c2 { background: #ffb366; } .cal i.c3 { background: var(--fire); border-color: var(--fire); }
.srow { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr auto; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.srow .bar { margin: 0; }
.exams .srow { grid-template-columns: 1fr auto; }
.okc { color: var(--ok); } .badc { color: var(--bad); }
.goals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.goal-opt { display: flex; flex-direction: column; align-items: flex-start; padding: 12px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; }
.goal-opt small { color: var(--muted); }
.goal-opt.on { border-color: var(--gold); background: var(--warn-bg); }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 20px; height: 20px; }

@media (max-width: 480px) {
  .hdr-right .chip { padding: 0 10px; }
  .brand small { display: none; }
  .streak-big b { font-size: 34px; }
  .modes { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .mode { min-height: 118px; padding: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Photos de situation */
.q-photo { margin: -2px -2px 14px; }
.q-photo img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 12px; background: var(--surface-2); cursor: zoom-in; }
.q-photo figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.q-photo figcaption a { color: inherit; }
.q-photo.small { margin: 0 0 10px; }
.swipe-card .q-photo img { pointer-events: none; -webkit-user-drag: none; }
.review-item .q-photo.small img { aspect-ratio: 16 / 9; }
.focus { font-weight: 600; }
.m-photo { border-color: var(--teal); }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .9); display: grid; place-items: center; padding: 12px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Cours */
.m-cours { border-color: #0f766e; background: linear-gradient(135deg, var(--surface), var(--ok-bg)); }
.lesson { font-size: 16.5px; }
.lesson-intro { font-size: 17px; color: var(--muted); margin-top: 0; }
.lesson-h { margin: 4px 0 10px; font-size: 20px; }
.lesson-body p { margin: 0 0 10px; }
.lesson-body ul, .lesson-body ol { margin: 0 0 10px; padding-left: 22px; }
.lesson-body li { margin: 4px 0; }
.lesson-signs { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 6px 0 14px; }
.lesson-signs figure { margin: 0; width: 92px; text-align: center; }
.lesson-signs svg { width: 72px; height: 72px; }
.lesson-signs figcaption { font-size: 12px; color: var(--muted); line-height: 1.25; }
.tip { background: var(--warn-bg); border-radius: 12px; padding: 12px 14px; margin: 12px 0 6px; font-size: 15px; }
.keypoints { padding-left: 0; list-style: none; margin: 0; }
.keypoints li { padding: 10px 12px 10px 38px; margin: 8px 0; background: var(--ok-bg); border-radius: 12px; position: relative; font-weight: 600; }
.keypoints li::before { content: '✓'; position: absolute; left: 14px; color: var(--ok); font-weight: 900; }
.row-actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
