:root {
  --bg: #0b0d17; --surface: #151930; --surface2: #1e2342; --line: #2b3157;
  --text: #eef0ff; --muted: #9aa0c3;
  --primary: #7c5cff; --accent: #22d3ee; --ok: #34d399; --ko: #fb7185; --gold: #fbbf24;
  --grad: linear-gradient(135deg, var(--primary), var(--accent));
  --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: none; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 8px 0 10px; }
h2 { font-size: 1.05rem; margin: 26px 0 10px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 6px 0; }
sub { font-size: .7em; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { max-width: 600px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#view { flex: 1; padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); }
.loading, .empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* Bandeau du haut */
#top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); }
.brand { font-weight: 800; letter-spacing: -.02em; }
.brand b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lvl { flex: 1; display: flex; align-items: center; gap: 8px; }
.lvl-n { min-width: 26px; height: 26px; padding: 0 6px; display: grid; place-items: center; border-radius: 9px; background: var(--grad); font-weight: 800; font-size: .85rem; }
.xpbar, .bar { flex: 1; height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.xpbar i, .bar i { display: block; height: 100%; background: var(--grad); border-radius: 99px; transition: width .5s; }
.flame { font-weight: 700; font-variant-numeric: tabular-nums; }
.sync { width: 12px; height: 12px; border-radius: 50%; background: var(--line); padding: 0; }
.sync.ok { background: var(--ok); } .sync.wait { background: var(--gold); } .sync.off { background: var(--ko); }

/* Barre d'onglets */
#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 4px; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
#nav a { flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; font-size: .72rem; color: var(--muted); padding: 4px; border-radius: 12px; }
#nav a span { font-size: 1.3rem; filter: grayscale(.8); }
#nav a.on { color: var(--text); } #nav a.on span { filter: none; }
.in-player #nav, .in-player #top { display: none; }
.in-player #view { padding: 0; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface2); font-weight: 700; cursor: pointer; transition: transform .1s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: 0; color: #fff; }
.btn.ghost { background: none; color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Accueil */
.hero { display: flex; align-items: center; gap: 16px; padding: 8px 0 14px; }
.ring { width: 84px; flex: none; }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--surface2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset .6s; }
.ring text { fill: var(--text); font-weight: 800; font-size: 18px; }
.hello { font-size: 1.3rem; font-weight: 800; margin: 0; }
.goal { color: var(--muted); } .goal b { color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 8px; text-align: center; }
.stats b { display: block; font-size: 1.1rem; } .stats span { font-size: .75rem; color: var(--muted); }
.continue { display: block; padding: 18px; border-radius: 20px; background: var(--grad); box-shadow: 0 10px 30px -12px var(--primary); }
.continue small { display: block; opacity: .85; } .continue b { display: block; font-size: 1.25rem; margin: 2px 0 6px; }
.continue span { display: inline-block; background: #0003; padding: 3px 10px; border-radius: 99px; font-size: .85rem; font-weight: 600; }
.notice { display: block; margin-top: 12px; padding: 12px 14px; border: 1px dashed var(--accent); border-radius: var(--r); color: var(--accent); font-size: .92rem; }
.subjects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.subject { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 6px; text-align: center; font-size: .82rem; }
.subject span { display: block; font-size: 1.8rem; }
.subject.soon { opacity: .45; } .subject small { display: block; color: var(--muted); }

/* Programme et chapitre */
.lead { color: var(--muted); }
.back { color: var(--muted); font-size: .9rem; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin: 12px 0; }
.box summary { cursor: pointer; font-weight: 700; }
.box ul { margin: 10px 0 2px; padding-left: 20px; } .box li { margin: 6px 0; }
.chapters { display: grid; gap: 8px; }
.chapter { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.chapter small { display: block; color: var(--muted); font-size: .8rem; }
.chapter .bar { grid-column: 1 / -1; height: 5px; }
.chapter .pct { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.chapter.soon { opacity: .45; }
.bar.big { height: 10px; margin: 12px 0; flex: none; }
.notion { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.notion header { display: flex; gap: 12px; align-items: flex-start; }
.notion header p { color: var(--muted); font-size: .88rem; margin: 2px 0 0; }
.num { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--surface2); font-weight: 800; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 12px; background: var(--surface2); font-size: .72rem; font-weight: 600; }
.step span { font-size: 1.15rem; line-height: 1.3; }
.step.done { background: color-mix(in srgb, var(--ok) 16%, var(--surface2)); color: var(--ok); }
.legend { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 16px; }

/* Compte */
.auth { display: grid; gap: 12px; }
.auth label { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
input:not([type=range]) { min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 1rem; width: 100%; }
.err { color: var(--ko); }
#acct > .btn { width: 100%; margin-top: 8px; }

/* Lecteurs */
.player { min-height: 100dvh; display: flex; flex-direction: column; padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.player-top { display: flex; align-items: center; gap: 12px; }
.close { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--surface2); color: var(--muted); flex: none; }
.segments { flex: 1; display: flex; gap: 4px; }
.segments i { flex: 1; height: 5px; border-radius: 99px; background: var(--surface2); transition: background .3s; }
.segments i.on { background: var(--accent); }
.player-title { color: var(--muted); font-size: .82rem; margin: 10px 0 6px; }
.player-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cards { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -16px; }
.cards::-webkit-scrollbar { display: none; }
.cardx { flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always; padding: 4px 16px 16px; overflow-y: auto; }
.cardx h2 { font-size: 1.45rem; line-height: 1.2; margin: 6px 0 14px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.cardx p, .cardx li { font-size: 1.05rem; }
.cardx ul, .cardx ol { padding-left: 22px; } .cardx li { margin: 8px 0; }
.cardx b { color: #fff; }
.cardx .tip, .cardx .trap { border-radius: 14px; padding: 12px 14px; margin: 14px 0; background: var(--surface); border-left: 4px solid var(--accent); }
.cardx .trap { border-left-color: var(--ko); }
.cardx table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .95rem; }
.cardx th, .cardx td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.cardx th { color: var(--muted); font-weight: 600; }
.cardx svg.fig { display: block; width: 100%; max-width: 340px; margin: 12px auto; color: var(--muted); }
.player-actions { display: flex; gap: 8px; padding-top: 10px; }
.player-actions .primary { flex: 1; }

.formula { text-align: center; margin: 16px 0; padding: 16px 10px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); font-size: 1.3rem; font-weight: 700; }
.frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; margin: 0 4px; line-height: 1.25; }
.frac span:first-child { border-bottom: 2px solid currentColor; padding: 0 6px 2px; }
.frac span:last-child { padding: 2px 6px 0; }

/* Questions */
.statement { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; font-size: .95rem; }
.statement b { display: block; color: var(--accent); margin-bottom: 4px; }
.stepno { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin: 8px 0 0; }
.q-prompt { font-size: 1.15rem; font-weight: 600; margin: 10px 0 16px; }
.q-body { display: grid; gap: 8px; }
.choice { text-align: left; min-height: 52px; padding: 12px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1rem; }
.choice:not(:disabled):hover { border-color: var(--primary); }
.choice.good { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 18%, var(--surface)); }
.choice.bad { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 18%, var(--surface)); }
.numform { display: flex; align-items: center; gap: 8px; }
.numform input { flex: 1; min-width: 0; font-size: 1.2rem; font-weight: 700; }
.unit { font-weight: 700; color: var(--accent); white-space: nowrap; }
.q-hint { color: var(--gold); font-size: .95rem; }
.q-fb { margin-top: 14px; padding: 14px; border-radius: var(--r); border: 1.5px solid; display: grid; gap: 8px; animation: pop .25s; }
.q-fb.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--bg)); }
.q-fb.ko { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 10%, var(--bg)); }
.q-fb p { margin: 0; }
.q-explain { color: var(--muted); font-size: .95rem; } .q-explain b { color: var(--text); }
.q-explain ol { margin: 4px 0; padding-left: 20px; }

/* Écran de fin */
.done { align-items: stretch; justify-content: center; text-align: center; gap: 10px; }
.done-emoji { font-size: 4rem; animation: pop .4s; }
.done h1 { font-size: 2rem; margin: 0; }
.done-text { color: var(--muted); }
.xp-gain { font-size: 1.6rem; font-weight: 800; color: var(--gold); margin: 6px 0 14px; }
.method { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; color: var(--text); }
.method ol { margin: 6px 0 0; padding-left: 20px; } .method li { margin: 4px 0; }

/* Mini-labos */
.lab { display: flex; gap: 12px; align-items: center; background: var(--surface); border-radius: var(--r); padding: 12px; margin-top: 12px; }
.beaker { width: 96px; flex: none; color: var(--muted); } .beaker .liq { fill: var(--primary); transition: all .2s; }
.lab-ctl { flex: 1; min-width: 0; } .lab-ctl label { display: block; font-size: .9rem; color: var(--muted); }
.lab-ctl b { color: var(--text); }
input[type=range] { width: 100%; accent-color: var(--primary); }
.lab-out { font-size: 1rem !important; margin-top: 8px; min-height: 1.5em; }
.tubes { display: flex; justify-content: center; align-items: flex-end; gap: 8px; margin-top: 14px; }
.tube { text-align: center; font-size: .8rem; color: var(--muted); }
.tube i { display: block; width: 30px; height: 84px; border-radius: 4px 4px 15px 15px; background: var(--primary); box-shadow: 0 0 0 2px var(--line); margin-bottom: 4px; }
.tubes .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 6px; }
.lab-q { font-size: .95rem !important; text-align: center; }
.lab-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; } .lab-btns .btn { padding: 0 4px; min-height: 42px; font-size: .85rem; }

/* Notifications et confettis */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 6px; z-index: 20; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); font-weight: 600; padding: 10px 16px; border-radius: 99px; animation: pop .25s; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti span { position: absolute; top: -40px; animation: fall 2s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .3; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* Tableau de données dans un énoncé */
.statement table { border-collapse: collapse; margin: 8px 0; font-size: .9rem; }
.statement th, .statement td { padding: 4px 10px; border: 1px solid var(--line); text-align: center; }
.statement th { color: var(--muted); font-weight: 600; text-align: left; }

/* Défi du jour */
.defi { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 14px; border-radius: var(--r); background: var(--surface); border: 1.5px solid var(--gold); }
.defi > span { font-size: 1.6rem; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: color-mix(in srgb, var(--gold) 18%, transparent); flex: none; }
.defi small { display: block; color: var(--muted); }
.defi.is-done { border-color: var(--ok); } .defi.is-done > span { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); font-weight: 800; }
.defi.locked { border-color: var(--line); opacity: .6; }
.tag { display: table; margin-bottom: 8px; padding: 2px 10px; border-radius: 99px; background: var(--surface2); color: var(--accent); font-size: .75rem; font-weight: 600; }

/* Badges */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 6px; text-align: center; }
.badge span { display: block; font-size: 1.8rem; }
.badge b { display: block; font-size: .8rem; line-height: 1.2; margin: 4px 0 2px; }
.badge small { display: block; font-size: .68rem; line-height: 1.25; color: var(--muted); }
.badge:not(.locked) { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, var(--surface)); }
.badge.locked span { filter: grayscale(1); opacity: .5; } .badge.locked b { color: var(--muted); }
.new-badge { display: flex; align-items: center; gap: 12px; text-align: left; margin: 0 0 8px; padding: 10px 14px; border-radius: var(--r); border: 1.5px solid var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--bg)); animation: pop .4s; }
.new-badge span { font-size: 1.8rem; } .new-badge small { display: block; color: var(--gold); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }

/* Guide d'installation */
.install { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 14px; border-radius: var(--r); background: var(--surface); border: 1.5px solid var(--primary); }
.install > span { font-size: 1.6rem; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: color-mix(in srgb, var(--primary) 22%, transparent); flex: none; }
.install div { flex: 1; } .install small { display: block; color: var(--muted); } .install i { font-style: normal; color: var(--primary); font-weight: 800; }
.btn.wide { width: 100%; margin-top: 8px; }
.ok-box { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.perks { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.perks li { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; font-size: .95rem; }
.perks span { font-size: 1.4rem; }
.or { text-align: center; color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.tabs { display: flex; gap: 4px; margin: 18px 0 10px; padding: 4px; background: var(--surface); border-radius: 14px; }
.tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: .85rem; cursor: pointer; }
.tabs button.on { background: var(--grad); color: #fff; }
.howto { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 8px; }
.howto li { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.howto-n { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--grad); font-weight: 800; }
.howto div { flex: 1; } .howto p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.howto-ic { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--surface2); color: var(--accent); }
.howto-ic svg { width: 26px; height: 26px; }