/* ===== Thèmes (fond crème par défaut : moins de contraste agressif, plus confortable pour les lecteurs dyslexiques) ===== */
:root {
  --bg: #fbf6e9;
  --surface: #fffdf6;
  --surface-2: #f3ecd9;
  --text: #2b2a33;
  --muted: #6b6878;
  --line: #e4dcc6;
  --primary: #3d6cf0;
  --primary-ink: #ffffff;
  --good: #1f9d63;
  --good-bg: #dff5e9;
  --bad: #d4553b;
  --bad-bg: #fbe4dc;
  --warn: #c88a0b;
  --warn-bg: #fdf1d3;
  --xp: #f2a900;
  --syl-a: #2f5fd0;
  --syl-b: #c0392b;
  --b: #2f5fd0; --d: #c0392b; --p: #1f9d63; --q: #8e44ad;
  --shadow: 0 2px 0 rgba(0,0,0,.08), 0 6px 18px rgba(60,50,20,.08);
  --radius: 18px;
  --font: "Lexend", system-ui, sans-serif;
  --scale: 1;
  --ls: 0.01em;
  --lh: 1.5;
  --ws: 0em;
  color-scheme: light;
}
:root[data-skin="light"] { --bg: #f6f7fb; --surface: #ffffff; --surface-2: #eef0f6; --line: #dfe2ec; }
:root[data-skin="blue"]  { --bg: #e8f0fa; --surface: #f6f9fe; --surface-2: #dce7f6; --line: #c9d8ee; }
:root[data-skin="dark"] {
  --bg: #1b1c24; --surface: #252733; --surface-2: #2f3240; --text: #ecebf2; --muted: #a6a4b5; --line: #3a3d4d;
  --primary: #7b9cff; --primary-ink: #111; --good: #4fd394; --good-bg: #1e3b2f; --bad: #ff8a70; --bad-bg: #44261f;
  --warn: #ffc94d; --warn-bg: #43391f; --syl-a: #8fb0ff; --syl-b: #ff9a8a;
  --b: #8fb0ff; --d: #ff9a8a; --p: #6fe0a8; --q: #d39cf0;
  --shadow: 0 2px 0 rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.3);
  color-scheme: dark;
}
:root[data-font="atkinson"] { --font: "Atkinson Hyperlegible", system-ui, sans-serif; }
:root[data-font="system"]   { --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
:root[data-spacing="on"]    { --ls: 0.08em; --lh: 1.8; --ws: 0.12em; }

/* ===== Base ===== */
* { box-sizing: border-box; }
html { font-size: calc(17px * var(--scale)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: var(--ls);
  word-spacing: var(--ws);
  line-height: var(--lh);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; letter-spacing: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
.muted { color: var(--muted); }
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 80px; outline: none; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

/* ===== Barre du haut ===== */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; cursor: pointer; padding: 4px; font-weight: 700; font-size: 1.1rem; }
.brand-logo { font-size: 1.4rem; }
.top-stats { display: flex; align-items: center; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .95rem; }
.icon-btn { background: var(--surface-2); border: 0; border-radius: 12px; width: 40px; height: 40px; font-size: 1.15rem; cursor: pointer; }
.icon-btn:hover { filter: brightness(.95); }
@media (max-width: 480px) { .brand-name { display: none; } }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 22px; min-height: 52px; border-radius: 14px; border: 2px solid transparent;
  background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 1rem;
  box-shadow: 0 3px 0 rgba(0,0,0,.12); transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.12); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: .9rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }

/* ===== Cartes ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.levels { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.modes { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stack > * + * { margin-top: 16px; }

/* ===== Accueil ===== */
.hero { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; background: var(--warn-bg); flex: none; }
.hero-info { flex: 1; min-width: 200px; }
.bar { height: 14px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--xp), #ffcf4a); border-radius: inherit; transition: width .6s ease; }
.bar.goal > i { background: linear-gradient(90deg, var(--good), #6fdca3); }
.bar-label { display: flex; flex-wrap: wrap; gap: 0 12px; justify-content: space-between; font-size: .9rem; color: var(--muted); margin-top: 4px; }
.level-card { text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; font: inherit; color: inherit; }
.level-card:hover { border-color: var(--primary); }
.level-head { display: flex; align-items: center; gap: 10px; }
.level-emoji { font-size: 1.8rem; }
.level-tag { font-weight: 700; font-size: 1.25rem; }
.level-card .muted { font-size: .92rem; }
.tip { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-bg); border-radius: 14px; padding: 12px 14px; }

/* ===== Modes ===== */
.mode-card { cursor: pointer; text-align: left; font: inherit; color: inherit; display: flex; gap: 12px; align-items: center; }
.mode-card:hover { border-color: var(--primary); }
.mode-icon { font-size: 1.9rem; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 14px; background: var(--surface-2); flex: none; }
.mode-card b { display: block; }
.mode-card span.muted { font-size: .88rem; }

/* ===== Jeu ===== */
.game-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.game-top .bar { flex: 1; }
.combo { font-weight: 700; color: var(--xp); min-width: 52px; text-align: right; }
.prompt { text-align: center; padding: 26px 18px; }
.prompt .label { color: var(--muted); font-size: .95rem; margin-bottom: 6px; }
.prompt .big { font-size: 2.1rem; font-weight: 700; word-break: break-word; }
.prompt .fr { font-size: 1.35rem; font-weight: 600; }
.prompt .example { margin-top: 10px; color: var(--muted); font-style: normal; }
.speak { border: 0; background: var(--primary); color: var(--primary-ink); width: 64px; height: 64px; border-radius: 50%; font-size: 1.7rem; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.speak.slow { width: 48px; height: 48px; font-size: 1.2rem; background: var(--surface-2); color: var(--text); }
.speak-row { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 10px 0; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
@media (max-width: 520px) { .options { grid-template-columns: 1fr; } }
.opt {
  text-align: left; padding: 16px; min-height: 64px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 1.12rem; font-weight: 600; box-shadow: 0 3px 0 var(--line);
  display: flex; gap: 10px; align-items: center;
}
.opt .key { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: .8rem; background: var(--surface-2); color: var(--muted); }
.opt:hover:not([disabled]) { border-color: var(--primary); }
.opt.correct { border-color: var(--good); background: var(--good-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt[disabled] { cursor: default; }

.slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 64px; margin: 16px 0; padding: 10px; border-radius: 14px; border: 2px dashed var(--line); }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.tile {
  min-width: 52px; height: 56px; padding: 0 14px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface); font-size: 1.4rem; font-weight: 700; cursor: pointer; box-shadow: 0 3px 0 var(--line);
}
.tile.word { font-size: 1.1rem; height: 50px; }
.tile.used { visibility: hidden; }
.tile.placed { background: var(--surface-2); }
.slots.correct { border-color: var(--good); background: var(--good-bg); }
.slots.wrong { border-color: var(--bad); background: var(--bad-bg); }
.slot-empty { width: 40px; height: 56px; border-bottom: 3px solid var(--line); }

.write-input {
  width: 100%; font-size: 1.6rem; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); text-align: center; font-weight: 600; margin-top: 14px;
}
.write-input:focus { border-color: var(--primary); outline: none; }
.diff { font-size: 1.6rem; font-weight: 700; letter-spacing: .1em; }
.diff .ok { color: var(--good); }
.diff .ko { color: var(--bad); text-decoration: underline; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

.feedback {
  position: sticky; bottom: 0; margin: 20px -16px -80px; padding: 16px 16px 24px;
  border-top: 3px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 10px; animation: up .25s ease;
}
.feedback.good { background: var(--good-bg); border-color: var(--good); }
.feedback.almost { background: var(--warn-bg); border-color: var(--warn); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.feedback .fb-title { font-weight: 700; font-size: 1.2rem; }
.feedback .fb-xp { color: var(--xp); font-weight: 700; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Flashcards */
.flash { perspective: 1000px; cursor: pointer; min-height: 230px; }
.flash-inner { position: relative; min-height: 230px; transition: transform .5s; transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
.flash-back { transform: rotateY(180deg); }

/* Mots colorés : syllabes et b/d/p/q */
.syl:nth-child(odd) { color: var(--syl-a); }
.syl:nth-child(even) { color: var(--syl-b); }
.l-b { color: var(--b); } .l-d { color: var(--d); } .l-p { color: var(--p); } .l-q { color: var(--q); }
.l-b, .l-d, .l-p, .l-q { font-weight: 800; }

/* Résultats */
.result { text-align: center; }
.result .big-emoji { font-size: 4rem; }
.stats-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 12px 16px; min-width: 110px; }
.stat b { display: block; font-size: 1.5rem; }
.review-list { text-align: left; margin: 0 auto; max-width: 480px; padding: 0; list-style: none; }
.review-list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }

/* Badges */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.badge { text-align: center; padding: 14px 10px; }
.badge .b-icon { font-size: 2.2rem; }
.badge.locked { opacity: .4; filter: grayscale(1); }
.badge small { display: block; color: var(--muted); font-size: .8rem; }

/* Lexique */
.lex { list-style: none; padding: 0; margin: 0; }
.lex li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lex .w { font-weight: 700; font-size: 1.1rem; }
.lex .grow { flex: 1; }
.mini-speak { border: 0; background: var(--surface-2); border-radius: 10px; width: 40px; height: 40px; cursor: pointer; font-size: 1.1rem; flex: none; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--good); }

/* Réglages */
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 520px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20,20,30,.45); }
.settings-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; max-height: 85vh; overflow: auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.field select, .field input[type=range] { font-weight: 400; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.toggle { display: flex; gap: 10px; align-items: center; cursor: pointer; padding: 6px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.row-end { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* Toasts & confettis */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--surface); border: 2px solid var(--xp); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); font-weight: 600; animation: up .3s ease; display: flex; gap: 10px; align-items: center; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }

.back { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 0; font-size: .95rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 26px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
