/* ============================================================
   Kefli — feuille de style unique. RTL, grosses cibles tactiles,
   pensée pour un téléphone tenu à deux mains par un enfant de 8 ans.
   ============================================================ */

:root {
  --bg: #f4f1ff;
  --bg2: #ffffff;
  --card: #ffffff;
  --ink: #241c48;
  --ink-soft: #6b6390;
  --line: #e4dffa;
  --brand: #6c4cf1;
  --brand-2: #b061f5;
  --ok: #17b978;
  --ok-soft: #dcfaeb;
  --bad: #f2545b;
  --bad-soft: #ffe4e5;
  --gold: #ffb020;
  --viz-fill: #b9a6fb;
  --viz-empty: #f1edff;
  --viz-line: #4a3d80;
  --r: 20px;
  --shadow: 0 4px 0 rgba(56, 40, 120, .14);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191333; --bg2: #221a45; --card: #251d4c; --ink: #f3f0ff;
    --ink-soft: #a79ed4; --line: #362b6b; --viz-empty: #302563;
    --viz-fill: #8f77f0; --viz-line: #e6e0ff; --ok-soft: #17402f; --bad-soft: #45222a;
    --shadow: 0 4px 0 rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Rubik", "Segoe UI", system-ui, -apple-system, "Arial Hebrew", Arial, sans-serif;
  font-size: 17px;
  overscroll-behavior: none;
}
body { user-select: none; }

#app {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--sat)) 14px calc(18px + var(--sab));
  display: flex; flex-direction: column;
}

/* ---------- éléments de base ---------- */
.btn {
  border: 0; border-radius: var(--r);
  background: var(--brand); color: #fff;
  font: inherit; font-weight: 700; font-size: 19px;
  padding: 16px 22px; width: 100%;
  box-shadow: 0 4px 0 #4b2fc4;
  cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4b2fc4; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn.small { font-size: 16px; padding: 12px 16px; width: auto; }
.btn.ok { background: var(--ok); box-shadow: 0 4px 0 #0e8a58; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.card {
  background: var(--card); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow);
}
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.center { text-align: center; }
h1 { font-size: 27px; margin: 0 0 4px; }
h2 { font-size: 21px; margin: 0 0 10px; }
.muted { color: var(--ink-soft); font-size: 15px; }
.hidden { display: none !important; }

input.txt, select.txt {
  width: 100%; font: inherit; font-size: 19px; padding: 14px;
  border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg2); color: var(--ink); text-align: center;
}
input.txt:focus, select.txt:focus { outline: 0; border-color: var(--brand); }

/* ---------- en-tête ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.pill {
  background: var(--card); border-radius: 999px; padding: 7px 14px;
  font-weight: 700; font-size: 15px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 5px;
}
.avatar-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 26px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; border: 0;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 20px; cursor: pointer;
}

/* ---------- accueil ---------- */
.hero {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; border-radius: 26px; padding: 20px; margin-bottom: 14px;
  box-shadow: 0 6px 0 #4b2fc4;
}
.hero h1 { color: #fff; }
.goal-bar { height: 14px; background: rgba(255,255,255,.28); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.goal-bar > i { display: block; height: 100%; background: #ffd75e; border-radius: 999px; transition: width .5s; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  border: 0; background: var(--card); box-shadow: var(--shadow);
  border-radius: var(--r); padding: 16px 12px; cursor: pointer;
  font: inherit; color: var(--ink); text-align: center;
}
.tile .em { font-size: 30px; display: block; margin-bottom: 6px; }
.tile b { display: block; font-size: 16px; }
.tile small { color: var(--ink-soft); }

.skill-list { display: flex; flex-direction: column; gap: 8px; }
.skill-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.skill-row .em { font-size: 22px; }
.mastery { height: 9px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.mastery > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 999px; }
.lvl-badge { font-size: 13px; font-weight: 700; background: var(--line); color: var(--ink-soft); border-radius: 999px; padding: 3px 9px; }

/* ---------- session ---------- */
.progress { display: flex; gap: 4px; margin-bottom: 14px; }
.progress > i { flex: 1; height: 8px; border-radius: 999px; background: var(--line); }
.progress > i.done { background: var(--ok); }
.progress > i.miss { background: var(--bad); }
.progress > i.now { background: var(--brand); }

.q-card { background: var(--card); border-radius: 26px; padding: 20px 16px; box-shadow: var(--shadow); text-align: center; }
.q-text { font-size: 23px; font-weight: 700; line-height: 1.45; }
.q-text.math { font-size: 38px; letter-spacing: 1px; direction: ltr; }
.big-letter { font-size: 1.25em; color: var(--brand); direction: ltr; display: inline-block; }
.en-word { direction: ltr; display: inline-block; letter-spacing: 3px; color: var(--brand); }
.big-emoji { font-size: 76px; line-height: 1.2; }
.emoji-row { font-size: 26px; letter-spacing: 3px; margin: 8px 0; }
.viz { width: 100%; max-width: 190px; height: auto; margin: 10px auto 0; display: block; }
.viz-pair { display: flex; gap: 10px; justify-content: center; }
.viz-pair .viz { max-width: 46%; margin: 6px 0 0; }
.coin-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.coin {
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(160deg, #ffd86b, #e8a41a);
  color: #543c00; font-weight: 800; font-size: 18px;
  display: grid; place-items: center; box-shadow: 0 3px 0 #b8830f;
}
.coin small { font-size: 11px; }
.speak-btn {
  border: 0; background: var(--brand); color: #fff; font: inherit; font-weight: 700;
  border-radius: 999px; padding: 12px 20px; margin-top: 12px; cursor: pointer;
}

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.answers.stack { grid-template-columns: 1fr; }
.ans {
  border: 2px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 18px; padding: 18px 10px; font: inherit; font-size: 21px; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow); min-height: 64px;
  transition: transform .1s;
}
.ans.ltr { direction: ltr; }
.ans:active { transform: scale(.97); }
.ans.right { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.ans.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.ans.dim { opacity: .4; }

/* pavé numérique maison : pas de clavier système qui masque l'écran */
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.numpad button {
  border: 0; background: var(--card); color: var(--ink); box-shadow: var(--shadow);
  border-radius: 16px; font: inherit; font-size: 26px; font-weight: 700;
  padding: 14px 0; cursor: pointer;
}
.numpad button:active { transform: translateY(2px); }
.numpad .wide { grid-column: span 1; }
.numpad .go { background: var(--ok); color: #fff; box-shadow: 0 4px 0 #0e8a58; }
.answer-box {
  margin-top: 14px; background: var(--bg2); border: 3px dashed var(--line);
  border-radius: 18px; min-height: 64px; display: grid; place-items: center;
  font-size: 34px; font-weight: 800; direction: ltr; color: var(--brand);
}
.answer-box.right { border-color: var(--ok); border-style: solid; background: var(--ok-soft); color: var(--ok); }
.answer-box.wrong { border-color: var(--bad); border-style: solid; background: var(--bad-soft); color: var(--bad); }

.feedback { margin-top: 12px; border-radius: 18px; padding: 14px; font-weight: 700; }
.feedback.good { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback .why { font-weight: 500; color: var(--ink); margin-top: 6px; font-size: 16px; direction: rtl; }
/* la bonne réponse peut être « 42 », « cat » ou « 1/2 » : on l'isole du RTL */
.feedback b { direction: ltr; display: inline-block; unicode-bidi: isolate; }

/* ---------- résultat ---------- */
.stars { font-size: 46px; letter-spacing: 6px; }
.result-stat { display: flex; gap: 10px; margin: 14px 0; }
.result-stat > div { flex: 1; background: var(--card); border-radius: 18px; padding: 12px; box-shadow: var(--shadow); text-align: center; }
.result-stat b { display: block; font-size: 26px; }

/* ---------- collection ---------- */
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sticker {
  aspect-ratio: 1; border: 0; border-radius: 18px; background: var(--card);
  box-shadow: var(--shadow); font-size: 30px; cursor: pointer; position: relative;
  display: grid; place-items: center;
}
.sticker.locked { filter: grayscale(1); opacity: .45; font-size: 24px; }
.sticker .price {
  position: absolute; bottom: 3px; inset-inline: 0; font-size: 11px; font-weight: 700;
  color: var(--ink-soft);
}
.sticker.owned::after {
  content: "✓"; position: absolute; top: 2px; inset-inline-end: 6px;
  font-size: 13px; color: var(--ok); font-weight: 800;
}

/* ---------- réglages parent ---------- */
.toggle-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(-20px); }
[dir="ltr"] .switch input:checked + i::after { transform: translateX(20px); }

.bars7 { display: flex; gap: 6px; align-items: flex-end; height: 90px; margin-top: 10px; }
.bars7 > div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.bars7 i { display: block; width: 100%; background: linear-gradient(180deg, var(--brand-2), var(--brand)); border-radius: 6px 6px 0 0; min-height: 3px; }
.bars7 small { font-size: 10px; color: var(--ink-soft); }

/* ---------- animations ---------- */
@keyframes pop { 0% { transform: scale(.86); opacity: 0 } 60% { transform: scale(1.03) } 100% { transform: scale(1); opacity: 1 } }
.pop { animation: pop .26s ease-out; }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-7px) } 75% { transform: translateX(7px) } }
.shake { animation: shake .3s; }
@keyframes floatUp { to { transform: translateY(-120px) rotate(var(--rot)); opacity: 0 } }
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 90; }
#confetti span { position: absolute; font-size: 26px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.combo {
  position: fixed; inset-inline: 0; top: 30%; text-align: center; pointer-events: none;
  font-size: 34px; font-weight: 800; color: var(--gold); z-index: 95;
  text-shadow: 0 2px 0 rgba(0,0,0,.15);
  animation: floatUp 1s ease-out forwards; --rot: 0deg;
}

/* ---------- bannière d'installation ---------- */
#install {
  position: fixed; inset-inline: 10px; bottom: calc(10px + var(--sab)); z-index: 80;
  background: var(--card); border-radius: var(--r); padding: 14px;
  box-shadow: 0 8px 24px rgba(40,25,90,.28); max-width: 540px; margin: 0 auto;
}
