:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #1c2033;
  --muted: #5d6480;
  --border: #dde1ee;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #e7e6fd;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --gold: #eab308;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 4px 16px rgba(20, 24, 50, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220;
    --surface: #181c2e;
    --surface-2: #22273d;
    --text: #e8eaf4;
    --muted: #a0a6c0;
    --border: #2e3450;
    --accent: #8b85ff;
    --accent-2: #b48cff;
    --accent-soft: #2a2856;
    --good: #4ade80;
    --good-soft: #143224;
    --bad: #f87171;
    --bad-soft: #3a1a1f;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1220;
  --surface: #181c2e;
  --surface-2: #22273d;
  --text: #e8eaf4;
  --muted: #a0a6c0;
  --border: #2e3450;
  --accent: #8b85ff;
  --accent-2: #b48cff;
  --accent-soft: #2a2856;
  --good: #4ade80;
  --good-soft: #143224;
  --bad: #f87171;
  --bad-soft: #3a1a1f;
  --warn: #fbbf24;
  --warn-soft: #3a2e12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
button { font: inherit; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.logo { font-size: 1.4rem; }
.hud { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-size: .88rem; font-weight: 600; white-space: nowrap;
}
.chip.lvl { background: var(--accent-soft); color: var(--accent); }
.xpbar { width: 90px; height: 7px; border-radius: 4px; background: var(--border); overflow: hidden; }
.xpbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* Mise en page */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 56px); }
.sidenav {
  position: sticky; top: 56px; align-self: start;
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 10px; height: calc(100vh - 56px);
  border-right: 1px solid var(--border); background: var(--surface);
}
.sidenav a {
  display: flex; gap: 10px; align-items: center;
  padding: 9px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .95rem;
}
.sidenav a:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); }
main { padding: 26px clamp(16px, 4vw, 44px) 60px; max-width: 1100px; width: 100%; outline: none; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 30;
    flex-direction: row; justify-content: space-around; height: auto;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
  }
  .sidenav a { flex-direction: column; gap: 0; font-size: .66rem; padding: 4px 4px; text-align: center; }
  .sidenav a span { font-size: 1.25rem; }
  .sidenav a[data-nav="reglages"], .sidenav a[data-nav="badges"], .sidenav a[data-nav="compte"] { display: none; }
  .hud .hide-sm { display: none; }
  main { padding: 18px 16px 96px; }
  .topbar { padding: 8px 16px; }
  .xpbar, .chip.hide-sm { display: none; }
  .brand span:last-child { display: none; }
  h1 { font-size: 1.4rem; }
}

/* Cartes et grilles */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card.link { cursor: pointer; text-decoration: none; color: inherit; display: block; transition: transform .12s, border-color .12s; }
.card.link:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { margin-bottom: .3em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.mt { margin-top: 22px; }
.badge-icon { font-size: 2rem; }
.mod-head { display: flex; gap: 14px; align-items: center; }
.mod-ico { font-size: 2rem; width: 54px; height: 54px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-2); flex: none; }

.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; }
.progress.good > i { background: var(--good); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 650; cursor: pointer;
  text-decoration: none; min-height: 42px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, a:focus-visible, .opt:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Héros du tableau de bord */
.hero {
  display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: 18px; padding: 22px 26px; box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 4px; }
.hero .muted { color: rgba(255, 255, 255, .85); }
.ring { --p: 0; width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255, 255, 255, .25) 0); }
.ring > div { width: 82px; height: 82px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; text-align: center; font-weight: 800; line-height: 1.1; }
.ring small { display: block; font-weight: 600; font-size: .7rem; opacity: .9; }
@media (max-width: 560px) { .hero { grid-template-columns: 1fr; text-align: center; justify-items: center; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

/* Onglets */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 14px 0 20px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); text-decoration: none; font-weight: 650; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* Fiche */
.fiche h2 { margin-top: 1.4em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.fiche ul { padding-left: 1.2em; margin: .4em 0 1em; }
.fiche li { margin: .3em 0; }
.callout { border-radius: 12px; padding: 14px 18px; margin: 16px 0; border: 1px solid var(--border); background: var(--surface); }
.callout.key { background: var(--accent-soft); border-color: transparent; }
.callout.trap { background: var(--warn-soft); border-color: transparent; }
.callout h3 { margin-bottom: .3em; }
.defs { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin: 10px 0; }
.def { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; }
.def b { display: block; margin-bottom: 2px; }

/* Flashcards */
.flash-wrap { max-width: 640px; margin: 0 auto; }
.flashcard { perspective: 1200px; cursor: pointer; margin: 14px 0; }
.flashcard .inner { position: relative; min-height: 260px; transition: transform .45s; transform-style: preserve-3d; }
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  padding: 26px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  font-size: 1.12rem; overflow-y: auto;
}
.flashcard .face.back { transform: rotateY(180deg); background: var(--accent-soft); }
.flashcard .tag { position: absolute; top: 12px; left: 16px; font-size: .78rem; color: var(--muted); font-weight: 650; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades .btn { flex-direction: column; gap: 0; padding: 8px; line-height: 1.2; }
.grades .btn small { font-weight: 500; color: var(--muted); font-size: .75rem; }
.grades .again { border-color: var(--bad); }
.grades .hard { border-color: var(--warn); }
.grades .goodb { border-color: var(--good); }
.grades .easy { border-color: var(--accent); }
@media (max-width: 480px) { .grades { grid-template-columns: repeat(2, 1fr); } }

/* Quiz */
.quiz { max-width: 760px; margin: 0 auto; }
.qtext { font-size: 1.15rem; font-weight: 650; margin: 10px 0 16px; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; padding: 13px 16px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: flex; gap: 12px; align-items: flex-start;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.expl { margin-top: 14px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); }
.expl.ok { border-left: 4px solid var(--good); }
.expl.ko { border-left: 4px solid var(--bad); }
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.combo { color: var(--warn); font-weight: 800; }
.lives { letter-spacing: 2px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 750; }
.timer.low { color: var(--bad); }
.result-big { font-size: 3rem; font-weight: 850; line-height: 1; }
.review-item { border-left: 4px solid var(--bad); padding: 8px 14px; background: var(--surface); border-radius: 8px; margin: 8px 0; }

/* Association */
.match { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; }
.match .col { display: grid; gap: 10px; align-content: start; }
.tile {
  padding: 12px 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface);
  cursor: pointer; text-align: left; color: var(--text); font-size: .93rem; transition: opacity .3s, transform .15s;
}
.tile.term { font-weight: 700; }
.tile:hover { border-color: var(--accent); }
.tile.sel { border-color: var(--accent); background: var(--accent-soft); }
.tile.ok { border-color: var(--good); background: var(--good-soft); opacity: .35; cursor: default; }
.tile.ko { animation: shake .35s; border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (max-width: 600px) { .match { grid-template-columns: 1fr; } }

/* Badges */
.badge { text-align: center; }
.badge.locked { opacity: .45; filter: grayscale(1); }

/* Glossaire */
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
select.search { width: auto; }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; }

/* Notifications */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 650; animation: pop .25s; max-width: 320px; }
.toast.badge-t { background: linear-gradient(135deg, var(--gold), var(--warn)); color: #1a1300; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
@media (max-width: 760px) { #toasts { bottom: 84px; left: 16px; right: 16px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Compte */
.chip.account { text-decoration: none; border: 1px solid var(--border); }
.chip.account:hover { border-color: var(--accent); }
.narrow { max-width: 460px; }
.field { display: grid; gap: 6px; font-weight: 600; }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
.err:empty { display: none; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
button.card.choice { font: inherit; text-align: left; background: var(--surface); color: var(--text); width: 100%; }
