:root {
  --bg: #f6f5ff;
  --surface: #ffffff;
  --surface-2: #f0efff;
  --ink: #1b1b33;
  --ink-2: #55557a;
  --line: #e3e1f5;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --brand-soft: #e9e7ff;
  --def: #2563eb;   --def-bg: #e8f0ff;
  --tip: #059669;   --tip-bg: #e3f8ef;
  --warn: #d97706;  --warn-bg: #fff3e0;
  --mnemo: #9333ea; --mnemo-bg: #f3e8ff;
  --ref: #475569;   --ref-bg: #eef1f5;
  --ok: #059669; --ko: #dc2626;
  --shadow: 0 1px 2px rgba(40, 30, 120, .06), 0 8px 24px rgba(40, 30, 120, .07);
  --r: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11111f;
    --surface: #1a1a2e;
    --surface-2: #232340;
    --ink: #ececff;
    --ink-2: #a5a5cc;
    --line: #2f2f52;
    --brand: #8b83ff;
    --brand-ink: #11111f;
    --brand-soft: #26254d;
    --def: #7aa7ff;  --def-bg: #1b2745;
    --tip: #4ade9a;  --tip-bg: #14302a;
    --warn: #fbbf59; --warn-bg: #3a2a12;
    --mnemo: #c99bff; --mnemo-bg: #2c1d44;
    --ref: #b4bfd0;  --ref-bg: #222a38;
    --ok: #4ade9a; --ko: #ff7a7a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 0 var(--safe-r) 0 var(--safe-l);
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
strong { font-weight: 700; }
a { color: var(--brand); }

/* ---------- Layout ---------- */
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px calc(32px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  padding-top: var(--safe-t);
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 880px; margin: 0 auto; padding: 10px 16px 0; }
.bar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.bar h1 { font-size: 1.05rem; line-height: 1.25; margin: 0; flex: 1; font-weight: 750; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; font-size: 1.1rem;
}
.iconbtn:active { transform: scale(.96); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ---------- Home ---------- */
.hero { padding: 28px 0 8px; }
.hero .eyebrow { color: var(--brand); font-weight: 700; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.15; margin: 6px 0 10px; letter-spacing: -.02em; }
.hero p { color: var(--ink-2); margin: 0; max-width: 56ch; }
.cards { display: grid; gap: 12px; margin-top: 22px; }
.chcard {
  display: flex; gap: 14px; align-items: center; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow); cursor: pointer; text-decoration: none; color: inherit;
}
.chcard:active { transform: scale(.99); }
.chnum {
  flex: 0 0 52px; height: 52px; border-radius: 15px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 1.3rem;
}
.chcard .t { font-weight: 700; line-height: 1.3; }
.chcard .s { color: var(--ink-2); font-size: .85rem; margin-top: 2px; }
.chev { margin-left: auto; color: var(--ink-2); font-size: 1.4rem; }
.pbar { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin-top: 8px; }
.pbar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.soon { margin-top: 16px; color: var(--ink-2); font-size: .9rem; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--r); }
.install {
  margin-top: 18px; display: none; background: var(--brand-soft); border-radius: var(--r); padding: 14px 16px; font-size: .92rem;
}
.install.show { display: block; }
.install button { margin-top: 8px; background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; cursor: pointer; }

/* ---------- Sections ---------- */
.intro { padding: 18px 0 4px; }
.intro h2 { margin: 0 0 4px; font-size: 1.5rem; line-height: 1.2; letter-spacing: -.01em; }
.intro .part { color: var(--ink-2); font-size: .9rem; }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin: 14px 0; }
.box h3 { margin: 0 0 8px; font-size: 1rem; }
.essentiel { background: linear-gradient(135deg, var(--brand), #7c3aed); color: #fff; border: 0; }
.essentiel h3 { color: #fff; opacity: .9; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.essentiel ul { margin: 0; padding-left: 1.1rem; }
.essentiel li { margin: 6px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: .88rem; }
.chip.plain { background: var(--surface-2); color: var(--ink); }
.compet li { margin: 4px 0; }

details.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); margin: 14px 0; overflow: clip; }
details.sec > summary {
  list-style: none; cursor: pointer; padding: 16px; font-weight: 750; font-size: 1.05rem; display: flex; gap: 10px; align-items: center;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: "⌄"; margin-left: auto; color: var(--ink-2); transition: transform .2s; font-size: 1.2rem; }
details.sec[open] > summary::after { transform: rotate(180deg); }
details.sec > .body { padding: 0 16px 16px; }
.sec .body > *:first-child { margin-top: 0; }

h4.sub { margin: 22px 0 8px; font-size: 1.02rem; color: var(--brand); padding-bottom: 6px; border-bottom: 2px solid var(--brand-soft); }
p { margin: 10px 0; }

.callout { border-radius: 14px; padding: 12px 14px; margin: 12px 0; border-left: 4px solid; }
.callout .lbl { font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; display: block; margin-bottom: 3px; }
.def { background: var(--def-bg); border-color: var(--def); }
.def .lbl { color: var(--def); }
.tip { background: var(--tip-bg); border-color: var(--tip); }
.tip .lbl { color: var(--tip); }
.mnemo { background: var(--mnemo-bg); border-color: var(--mnemo); }
.mnemo .lbl { color: var(--mnemo); }
.ref { background: var(--ref-bg); border-color: var(--ref); font-size: .92rem; }
.ref .lbl { color: var(--ref); }
.warn { background: var(--warn-bg); border-color: var(--warn); }
.warn .lbl { color: var(--warn); }

.grid2 { display: grid; gap: 10px; grid-template-columns: 1fr; margin: 12px 0; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.gcard { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; }
.gcard b { display: block; margin-bottom: 2px; }

/* Flow */
.flowbox { margin: 14px 0; }
.flowbox .cap { font-size: .85rem; color: var(--ink-2); font-weight: 600; margin-bottom: 8px; }
.flow { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.step { background: var(--brand); color: var(--brand-ink); border-radius: 12px; padding: 10px 14px; font-weight: 700; text-align: center; }
.arrow { text-align: center; color: var(--brand); font-size: 1.2rem; line-height: 1.2; padding: 2px 0; }
.chipsrow { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0; }
.chipsrow span { border: 1.5px solid var(--brand); color: var(--ink); border-radius: 10px; padding: 6px 10px; font-size: .85rem; background: var(--surface); }

/* Tables */
.tblwrap { margin: 14px 0; }
.tblwrap .cap { font-size: .85rem; color: var(--ink-2); font-weight: 700; margin-bottom: 6px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .95rem; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface); }
th { background: var(--brand-soft); color: var(--brand); text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; }
td { padding: 10px 12px; vertical-align: top; border-top: 1px solid var(--line); }
td:first-child { font-weight: 600; width: 32%; background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
@media (max-width: 640px) {
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  table { border: 0; background: transparent; border-radius: 0; }
  tr { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; overflow: hidden; }
  td { border: 0; padding: 8px 12px; }
  td:first-child { width: 100%; background: var(--brand-soft); color: var(--ink); font-weight: 700; }
  td:not(:first-child)::before { content: attr(data-label); display: block; font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); margin-bottom: 1px; }
  td:nth-child(2):last-child::before { display: none; }
}

/* Timeline */
.tl { position: relative; margin: 14px 0 6px; padding-left: 18px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl .it { position: relative; padding: 0 0 14px 14px; }
.tl .it::before { content: ""; position: absolute; left: -18px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--brand); }
.tl .d { font-weight: 800; color: var(--brand); font-size: .9rem; }

/* Quiz */
.quiz .progress { display: flex; justify-content: space-between; color: var(--ink-2); font-size: .9rem; font-weight: 600; }
.quiz .q { font-size: 1.15rem; font-weight: 700; margin: 14px 0; line-height: 1.35; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; width: 100%; background: var(--surface); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px; cursor: pointer; display: flex; gap: 12px; align-items: center; min-height: 52px;
}
.opt .k { flex: 0 0 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.opt:active { transform: scale(.99); }
.opt.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.opt.ok .k { background: var(--ok); color: #fff; }
.opt.ko { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 10%, var(--surface)); }
.opt.ko .k { background: var(--ko); color: #fff; }
.opt[disabled] { cursor: default; }
.explain { margin-top: 14px; }
.btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 14px; padding: 13px 20px; font-weight: 700; cursor: pointer; min-height: 48px; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btnrow { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.score { text-align: center; padding: 26px 10px; }
.score .big { font-size: 3.2rem; font-weight: 850; color: var(--brand); line-height: 1; }

/* Cards (flashcards) */
.fc { perspective: 1200px; margin: 18px 0; }
.fc-in { position: relative; min-height: 260px; transition: transform .45s; transform-style: preserve-3d; cursor: pointer; }
.fc.flip .fc-in { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow);
  display: grid; place-items: center; text-align: center; padding: 24px;
}
.face.back { transform: rotateY(180deg); background: var(--brand); color: var(--brand-ink); border: 0; }
.face .term { font-size: 1.5rem; font-weight: 800; line-height: 1.25; }
.face .hint { position: absolute; bottom: 14px; font-size: .78rem; color: var(--ink-2); }
.face.back .hint { color: inherit; opacity: .75; }
.face .def-t { font-size: 1.1rem; line-height: 1.5; }

/* Cas pratiques */
.cas { margin: 14px 0; }
.cas .meta { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.badge { font-size: .72rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); letter-spacing: .03em; }
.consigne { white-space: pre-line; background: var(--surface-2); border-radius: 14px; padding: 12px 14px; font-size: .95rem; margin: 10px 0; }
.reveal { margin-top: 10px; }
.corrige { margin-top: 12px; border-top: 2px dashed var(--line); padding-top: 4px; }
.corrige[hidden] { display: none; }

/* Synthèse map */
.map { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); margin: 12px 0; }
@media (min-width: 720px) { .map { grid-template-columns: repeat(4, 1fr); } }
.mapcol .h { background: var(--brand); color: var(--brand-ink); font-weight: 800; border-radius: 12px; padding: 8px; text-align: center; font-size: .92rem; }
.mapcol .i { background: var(--surface); border: 1.5px solid var(--brand); border-radius: 10px; padding: 8px; margin-top: 8px; text-align: center; font-size: .86rem; }
.center { text-align: center; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 6px; }
.sources span { border: 1.5px solid var(--brand); border-radius: 10px; padding: 6px 10px; font-size: .85rem; background: var(--surface); }
.sorties { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.sorties span { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: .9rem; }

.foot { color: var(--ink-2); font-size: .8rem; text-align: center; padding: 26px 0 6px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; z-index: 50; }

@media (min-width: 900px) {
  body { font-size: 17px; }
  .wrap, .topbar-in { padding-left: 24px; padding-right: 24px; }
}
@media print {
  .topbar, .btnrow, .install, .iconbtn { display: none !important; }
  details.sec > .body { display: block; }
  body { background: #fff; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Exercices ---------- */
a.back { display: inline-block; color: var(--brand); font-weight: 700; text-decoration: none; margin-bottom: 6px; }
.trous { line-height: 2.1; font-size: 1.02rem; }
select.gap {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--surface-2);
  border: 2px solid var(--line); border-radius: 10px; padding: 6px 28px 6px 10px; margin: 0 2px; max-width: 100%;
  min-height: 40px; vertical-align: middle;
}
select.gap.wide { width: 100%; margin-top: 6px; }
select.gap.ok, .orow.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
select.gap.ko, .orow.ko { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 12%, var(--surface)); }
.vf { padding: 12px 0; border-top: 1px solid var(--line); }
.vf:first-child { border-top: 0; padding-top: 0; }
.vf p { margin: 0 0 8px; font-weight: 600; }
.vfb { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt.compact { justify-content: center; padding: 10px; min-height: 46px; font-weight: 700; }
.vfe { margin-top: 8px; font-size: .92rem; padding: 8px 10px; border-radius: 10px; }
.vfe.okt { background: var(--tip-bg); }
.vfe.kot { background: var(--warn-bg); }
.olist { display: grid; gap: 8px; }
.orow { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px; }
.orow .n { flex: 0 0 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.orow .l { flex: 1; min-width: 0; font-weight: 600; }
.orow .od { display: inline-block; background: var(--brand); color: var(--brand-ink); border-radius: 8px; padding: 1px 8px; margin-right: 8px; font-size: .82rem; font-weight: 800; }
.orow .mv { display: flex; gap: 6px; }
.orow .iconbtn { width: 38px; height: 38px; }
.orow .iconbtn[disabled] { opacity: .35; }
.rrow { padding: 10px 0; border-top: 1px solid var(--line); }
.rrow:first-child { border-top: 0; padding-top: 0; }
.rrow .rl { font-weight: 600; }
.ta { width: 100%; font: inherit; color: var(--ink); background: var(--surface-2); border: 2px solid var(--line); border-radius: 14px; padding: 12px; resize: vertical; }
.ta:focus { outline: none; border-color: var(--brand); }
.crit { display: grid; gap: 8px; }
.critl { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); padding: 10px 12px; border-radius: 12px; }
.critl input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--brand); flex: 0 0 auto; }
