/* Harf · direction « ludique » : le dégradé bleu → violet → rose du menu donne le ton.
   Fond violet nuit (ou lavande en clair) éclairé de halos colorés, cartes violettes,
   vert menthe pour « réussi », or pour le défi final. L'étoile khatam reste le motif. */

:root {
  --bg: #f3f0ff;          /* lavande */
  --surface: #ffffff;
  --surface-2: #ebe5ff;
  --ink: #241a52;         /* violet encre */
  --muted: #6a6391;
  --line: #e1daf6;
  --band: #241a52;        /* bandeaux sombres (toast…) */
  --on-band: #ffffff;
  --accent: #6246d8;      /* violet de la marque : titres, liens */
  --hello: #d63f86;       /* rose des salutations */
  --primary: #0f9b6c;     /* menthe : réussi, bonne réponse */
  --primary-dark: #0b7a55;
  --primary-soft: #d7f5e8;
  --gold: #e0a630;
  --gold-dark: #a8740f;
  --gold-soft: #fff1d1;
  --danger: #e0445a;
  --danger-dark: #b8324a;
  --danger-soft: #ffe0e6;
  --locked: #bdb4dc;
  --btn-bg: #6246d8;
  --btn-fg: #ffffff;
  --trace-guide: #e1daf6;
  --glow-a: rgba(79, 195, 247, .16);  /* halo bleu */
  --glow-b: rgba(255, 126, 182, .16); /* halo rose */
  --radius: 22px;
  /* Barre latérale / tiroir du menu : version foncée du dégradé de l'accueil (texte blanc lisible). */
  --side-gradient: linear-gradient(170deg, #2f7fd0 0%, #6246d8 55%, #c94b8c 100%);
  --fun-line: linear-gradient(90deg, #4fc3f7, #7c6cff 60%, #ff7eb6);
  --shadow: 0 10px 24px rgba(60, 40, 140, .12);
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ar: "Noto Naskh Arabic", "Amiri", "Traditional Arabic", serif;  /* lettres à apprendre */
  --font-deco: "Reem Kufi", var(--font-ar);                               /* logo uniquement */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #130e30;          /* violet nuit */
    --surface: #1e1748;
    --surface-2: #2a2160;
    --ink: #f4f1ff;
    --muted: #aaa3d4;
    --line: #352b72;
    --band: #0d0924;
    --accent: #b3a6ff;
    --hello: #ff8ec4;
    --primary: #3ddc97;
    --primary-dark: #2bb57b;
    --primary-soft: #173d3a;
    --gold: #ffcb52;
    --gold-dark: #ffcb52;
    --gold-soft: #3b2f1c;
    --danger: #ff6b81;
    --danger-dark: #ff6b81;
    --danger-soft: #45203a;
    --locked: #4b4380;
    --btn-bg: #7c6cff;
    --btn-fg: #ffffff;
    --trace-guide: #352b72;
    --glow-a: rgba(79, 195, 247, .13);
    --glow-b: rgba(255, 126, 182, .12);
    --shadow: 0 10px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  /* Halos bleu et rose, rappel discret du dégradé du menu. */
  background:
    radial-gradient(900px 520px at 100% -8%, var(--glow-b), transparent 65%),
    radial-gradient(760px 520px at -12% 35%, var(--glow-a), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px;
}

h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; font-weight: 800; }
p { margin: 0; }

.ar { font-family: var(--font-ar); font-weight: 400; line-height: 1.6; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

svg.i { width: 18px; height: 18px; flex-shrink: 0; vertical-align: middle; }

.eyebrow {
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Boutons ---------- */

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  font-weight: 800;
  font-size: 1rem;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--btn-bg); color: var(--btn-fg); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.15); }
.btn.ghost { background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--ink); }
.btn.danger { background: var(--danger); color: #fffaf1; }
.btn.danger:hover:not(:disabled) { background: var(--danger-dark); }
.link-btn.danger-link { justify-self: center; color: var(--danger); margin-top: 4px; }
.account-links { display: grid; gap: 8px; margin-top: 4px; }
.account-sub { text-align: left; }
.account-sub .modal-actions .btn { padding: 12px 10px; font-size: .9rem; }
.btn:disabled { opacity: .5; }

.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn svg.i { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Étoile khatam : sa couleur vient du contexte (fill / stroke). */
svg.khatam { width: 100%; height: 100%; overflow: visible; }

/* ---------- Barre de progression ---------- */

.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  flex: 1;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--fun-line);
  transition: width .35s ease;
}

/* ---------- Accueil ---------- */

.home { padding-bottom: 48px; }

.band {
  position: relative;
  overflow: hidden;
  margin: 0 -16px;
  padding: 18px 16px 62px;
  background: var(--band);
  color: var(--on-band);
  border-radius: 0 0 28px 28px;
}
.band-pattern { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .22; }
/* Bandeau de l'accueil (mobile) et barre latérale (grand écran) : dégradé coloré du menu. */
.home > .band { --on-band: #fff; background: var(--side-gradient); }
.home > .band .band-pattern { display: none; }

.topbar { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-ar { font-family: var(--font-deco); font-weight: 600; font-size: 2rem; line-height: 1; }
.brand-name { font-weight: 800; font-size: .85rem; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }

.stats { display: flex; align-items: center; gap: 6px; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  border: none;
  border-radius: 99px;
  background: rgba(241, 231, 214, .14);
  color: var(--on-band);
  font-size: .8rem;
  font-weight: 800;
  white-space: nowrap;
}
.stat svg.i { width: 16px; height: 16px; color: var(--gold); }
.lang-btn:hover { background: rgba(241, 231, 214, .25); }

.hero {
  position: relative;
  margin-top: -44px;
  padding: 18px 20px;
  display: grid;
  gap: 6px;
  /* Contour en dégradé (comme le menu) autour d'une carte unie. */
  border: 2px solid transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--side-gradient) border-box;
}
.segments { display: grid; grid-template-columns: repeat(var(--n, 8), 1fr); gap: 4px; margin-top: 8px; }
.segments i { height: 7px; border-radius: 4px; background: var(--surface-2); }
.segments i.on { background: var(--fun-line); }
.segments i.boss { background: var(--gold-soft); }
.segments i.boss.on { background: var(--gold); }

.review {
  margin-top: 14px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: none;
  text-align: left;
  background: var(--gold-soft);
  box-shadow: none;
}
.review > span:nth-child(2) { display: grid; flex: 1; }
.review-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #182343;
}
.review-icon svg.i { width: 22px; height: 22px; }
.review-cta { font-weight: 800; color: var(--gold-dark); }

/* Chemin des leçons : des étoiles en zigzag */
.path { display: flex; flex-direction: column; gap: 4px; padding: 26px 0 20px; }
.node-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-left: var(--x);
}
.node {
  position: relative;
  width: 70px;
  height: 70px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  background: none;
  display: grid;
  place-items: center;
  color: var(--ink);
}
.node svg.khatam {
  position: absolute;
  inset: 0;
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
  transition: transform .2s ease;
}
.node .ar { position: relative; font-size: 1.9rem; line-height: 1; }
.node.wide .ar { font-size: 1.15rem; }
.node:hover:not(:disabled) svg.khatam { transform: scale(1.07) rotate(8deg); }
.node:active:not(:disabled) svg.khatam { transform: scale(.94); }
/* Leçon réussie : étoile remplie du dégradé du menu (défini dans le sprite de index.html). */
.node.done svg.khatam { fill: url(#g-fun); stroke: none; }
.node.done .ar { color: #fff; }
.node.current svg.khatam {
  stroke: var(--gold);
  stroke-width: 6;
  filter: drop-shadow(0 0 10px rgba(255, 203, 82, .45));
  animation: turn 24s linear infinite;
}
.node:disabled svg.khatam { fill: none; stroke: var(--locked); }
.node:disabled .ar { color: var(--locked); }

.node.boss { width: 86px; height: 86px; }
.node.boss svg.khatam { fill: var(--gold-soft); stroke: var(--gold); stroke-width: 4; }
.node.boss .boss-icon { position: relative; width: 30px; height: 30px; color: var(--gold-dark); }
.node.boss.done svg.khatam { fill: var(--gold); stroke: none; }
.node.boss.done .boss-icon { color: #182343; }
.node.boss:disabled svg.khatam { fill: none; stroke: var(--locked); }
.node.boss:disabled .boss-icon { color: var(--locked); }

.node-label { display: grid; font-size: .9rem; line-height: 1.35; }
.node-letters { font-size: 1.25rem; color: var(--muted); line-height: 1.5; justify-self: start; }
.node-wrap:has(.node:disabled) .node-label { opacity: .55; }

.stars { color: var(--locked); letter-spacing: 2px; font-size: .9rem; }
.star.on { color: var(--gold); }
.stars.big { font-size: 2.4rem; }

/* Navigation des paliers, dans le bandeau bleu nuit.
   Mobile : cartes compactes qui défilent horizontalement.
   Grand écran : barre latérale fixe (voir la media query plus bas). */
.palier-nav { position: relative; }
.palier-nav-title {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.palier-list {
  position: relative;
  display: flex;
  gap: 8px;
  margin: 16px -16px 0;
  padding: 2px 16px 4px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding: 0 16px;
  scrollbar-width: none;
}
.palier-list::-webkit-scrollbar { display: none; }
.palier-card {
  flex: 0 0 auto;
  width: 152px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 16px;
  background: rgba(241, 231, 214, .07);
  box-shadow: inset 0 0 0 1.5px rgba(241, 231, 214, .14);
  color: var(--on-band);
  text-align: left;
  scroll-snap-align: start;
  transition: background .15s ease, box-shadow .15s ease;
}
.palier-card:hover:not(:disabled) { background: rgba(241, 231, 214, .14); }
.palier-card:disabled { opacity: .45; }
.palier-text { display: grid; min-width: 0; line-height: 1.25; }
.palier-text strong { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palier-eyebrow { display: none; font-size: .68rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; opacity: .6; }
.palier-meta { font-size: .74rem; opacity: .7; }
.palier-num {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: rgba(241, 231, 214, .14);
}
.palier-num svg.i { width: 17px; height: 17px; }
.palier-card.done .palier-num { background: var(--primary); color: #fffaf1; }
.palier-card.open .palier-num { background: var(--gold); color: #182343; }
.palier-mini {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: rgba(241, 231, 214, .14);
  overflow: hidden;
}
.palier-mini i { display: block; height: 100%; border-radius: 2px; background: var(--gold); }
.palier-card.done .palier-mini i { background: var(--primary); }
/* Palier affiché : carte claire sur le fond sombre. */
.palier-card.viewing { background: #f1e7d6; color: #182343; box-shadow: inset 0 0 0 2px var(--gold); }
.palier-card.viewing .palier-mini { background: rgba(24, 35, 67, .12); }
.palier-card.viewing .palier-num:not(:is(.done *, .open *)) { background: rgba(24, 35, 67, .1); }

/* ---------- Menu principal ----------
   Mobile : tiroir qui glisse depuis la gauche (bouton ☰). Grand écran : dans la barre latérale. */
.menu-btn { color: var(--on-band); margin-left: -8px; }
.menu-btn:hover { background: rgba(241, 231, 214, .14); color: var(--on-band); }
.topbar .brand { margin-right: auto; }
.main-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 25;
  width: min(84vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  overflow-y: auto;
  --on-band: #fff;
  background: var(--side-gradient);
  color: var(--on-band);
  box-shadow: 8px 0 30px rgba(0, 0, 0, .3);
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform .25s ease, visibility .25s;
}
.home.menu-open .main-menu { transform: none; visibility: visible; }
.menu-backdrop { position: fixed; inset: 0; z-index: 24; background: rgba(10, 16, 36, .55); animation: fade-in .2s ease; }
.menu-backdrop[hidden] { display: none; }
.menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.menu-close { color: var(--on-band); }
.menu-close:hover { background: rgba(241, 231, 214, .14); color: var(--on-band); }
.menu-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 16px;
  background: rgba(241, 231, 214, .08);
}
.menu-user > span:last-child { display: grid; line-height: 1.25; }
.menu-user .small { opacity: .7; }
.menu-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--avatar, #7c6cff);
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
}
.main-menu ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: none;
  border-radius: 14px;
  background: none;
  color: var(--on-band);
  font-weight: 700;
  text-align: left;
}
.menu-item svg.i { width: 20px; height: 20px; opacity: .85; }
.menu-item:hover { background: rgba(241, 231, 214, .1); }
.menu-item[aria-current="page"] { background: #f1e7d6; color: #182343; }
.menu-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--gold);
  color: #182343;
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.menu-lang { display: flex; align-items: center; gap: 12px; padding: 8px 12px; font-weight: 700; }
.menu-lang svg.i { width: 20px; height: 20px; opacity: .85; }
.seg { margin-left: auto; display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: rgba(241, 231, 214, .12); }
.seg button { border: none; border-radius: 8px; padding: 4px 10px; background: none; color: var(--on-band); font-size: .8rem; font-weight: 800; }
.seg button[aria-pressed="true"] { background: var(--gold); color: #182343; }
.menu-bottom { margin-top: auto !important; padding-top: 8px !important; border-top: 1px solid rgba(255, 255, 255, .25); }
/* Bas de la barre latérale (grand écran) et bulles de lettres : seulement sur grand écran. */
.side-bottom, .side-bubbles { display: none; }

/* ---------- Tableau de l'alphabet ---------- */
.alphabet { display: grid; gap: 12px; }
.alpha-icon { font-size: 1.1rem; line-height: 1; }
.alpha-legend { display: flex; align-items: center; gap: 8px; }
.alpha-solo-mark { flex-shrink: 0; width: 22px; height: 16px; border-radius: 6px; border: 2px dashed var(--accent); }
.alpha-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.alpha-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 12px 6px 10px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform .1s ease, border-color .15s ease;
}
.alpha-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.alpha-card.solo { border-style: dashed; border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.alpha-card.learned { background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); }
.alpha-num { position: absolute; top: 6px; right: 9px; font-size: .68rem; font-weight: 800; color: var(--muted); }
.alpha-check { position: absolute; top: 6px; left: 7px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; }
.alpha-check svg.i { width: 12px; height: 12px; }
.alpha-char { font-size: 2.5rem; line-height: 1.5; }
.alpha-name { font-weight: 800; font-size: .88rem; direction: ltr; }
.alpha-tr { font-size: .75rem; color: var(--muted); direction: ltr; }
.alpha-back { justify-self: start; }

/* Étape « L'alphabet » sur le chemin du palier 0 */
.node.alpha svg.khatam { fill: var(--gold-soft); stroke: var(--gold); stroke-width: 4; stroke-dasharray: 10 6; }
.node.alpha .ar { color: var(--ink); }

/* Fiche d'une lettre */
.letter-modal-box { width: min(100%, 440px); }
.letter-sheet { display: grid; justify-items: center; gap: 10px; }
.letter-frame.small-frame { width: 130px; height: 130px; }
.letter-frame.small-frame .ar { font-size: 3.4rem; padding-bottom: 8px; }
.letter-arname { font-size: 1.3rem; color: var(--accent); margin-inline-start: 6px; }
.letter-audio { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.letter-audio .btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; }
.letter-forms { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.letter-form { display: grid; justify-items: center; padding: 6px 4px; border-radius: 14px; background: var(--surface-2); }
.letter-form .ar { font-size: 2rem; line-height: 1.6; }
.letter-form .small { direction: ltr; color: var(--muted); }
.letter-nav { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-top: 4px; }
.letter-nav .btn { padding: 10px 12px; }
.letter-nav .ar { font-size: 1.3rem; line-height: 1; }

/* ---------- Mes amis ---------- */
.friends-root { display: grid; gap: 12px; }
.friends-root > :first-child { position: relative; }
.fr-top { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.fr-code { justify-items: start; }
.fr-head { display: flex; align-items: center; gap: 8px; }
.fr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fr-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--bg);
}
.fr-row.me { box-shadow: inset 0 0 0 2px var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.fr-pos {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 800;
}
/* Podium : or, argent, bronze */
.fr-pos.pos-1 { background: #ffcb52; color: #3b2a00; }
.fr-pos.pos-2 { background: #cfd6e6; color: #2a3145; }
.fr-pos.pos-3 { background: #e7a46b; color: #3d1f05; }
.fr-name { display: grid; flex: 1; min-width: 0; line-height: 1.3; }
.fr-name .ar { font-size: .95rem; }
.fr-xp { font-weight: 800; white-space: nowrap; }
.link-btn.fr-remove { padding: 4px 6px; text-decoration: none; font-size: .8rem; }
.fr-requests .member { flex-wrap: wrap; }
.fr-requests .t-actions { margin-left: auto; }

/* ---------- Ma classe ---------- */
.classroom { display: grid; gap: 12px; }
.classroom > :first-child { position: relative; }
.class-switch { display: flex; flex-wrap: wrap; gap: 6px; }
.class-switch .t-chip { border: none; cursor: pointer; }
.class-pane { display: grid; gap: 12px; }
.tab-count { display: inline-grid; margin-left: 4px; min-width: 18px; height: 18px; font-size: .68rem; vertical-align: middle; }
.link-btn.class-leave { justify-self: center; color: var(--danger); }
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 4px; font-weight: 600; }
.member .t-chip { margin-left: 6px; background: #ffe1d4; color: #b4461c; }

/* Conversations (questions au prof) */
.msgs { display: grid; gap: 10px; max-height: 50vh; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 85%; display: grid; gap: 2px; padding: 10px 14px; border-radius: 18px; }
.msg p { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { justify-self: end; background: var(--btn-bg); color: var(--btn-fg); border-bottom-right-radius: 6px; }
.msg.theirs { justify-self: start; background: var(--surface-2); border-bottom-left-radius: 6px; }
.msg-who { opacity: .75; font-weight: 700; }
.msg-form { display: grid; gap: 8px; }
.msg-form textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  resize: vertical;
}
.msg-form textarea:focus { outline: none; border-color: var(--primary); }
.msg-form .btn { justify-self: end; }
.t-excerpt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn.t-back-inline { justify-self: start; text-decoration: none; font-weight: 700; color: var(--accent); }

/* Nombre de devoirs à faire, dans le menu */
.menu-count {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 99px;
  background: #ff5fa2;
  color: #fff;
  font-size: .75rem;
  font-weight: 800;
}

/* Page « Devoirs » */
.homework { display: grid; gap: 12px; }
.homework-head { position: relative; margin-top: -44px; display: flex; align-items: center; gap: 14px; padding: 18px 20px; }
.hw-icon { width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; border-radius: 14px; background: var(--side-gradient); color: #fff; }
.hw-icon svg.i { width: 26px; height: 26px; }
.hw-empty { padding: 20px; text-align: center; color: var(--muted); }
.hw-card {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 4px 0 0 var(--gold), var(--shadow);
}
.hw-card h3 { margin: 0; font-size: 1.05rem; }
.hw-card .btn { justify-self: start; margin-top: 4px; padding: 10px 18px; }
.hw-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hw-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 99px;
  background: var(--gold-soft);
  color: var(--gold-dark);
  font-size: .75rem;
  font-weight: 800;
}
.hw-status svg.i { width: 14px; height: 14px; }
.hw-target { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .9rem; }
.hw-target svg.i { color: var(--primary); }
.hw-card.done { box-shadow: inset 4px 0 0 var(--primary), var(--shadow); }
.hw-card.done .hw-status { background: var(--primary-soft); color: var(--primary); }
.hw-card.late { box-shadow: inset 4px 0 0 var(--danger), var(--shadow); }
.hw-card.late .hw-status { background: var(--danger-soft); color: var(--danger); }
.hw-card.today .hw-status { background: #ffe1ef; color: #c2185b; }

/* Code de classe et classes dans « Mon compte » */
.code-input { text-transform: uppercase; letter-spacing: .12em; font-weight: 700 !important; }
.account-classes { display: grid; gap: 4px; text-align: left; padding: 10px 12px; border-radius: 14px; background: var(--bg); }
.account-class { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .9rem; }
.account-class .link-btn { padding: 0; }

/* ---------- Espace prof (js/teacher.js) ---------- */
.teacher-root { display: grid; gap: 14px; }
.t-loading { padding: 20px; text-align: center; color: var(--muted); }
/* Le 1er bloc chevauche le bandeau coloré (comme la carte du palier sur l'accueil). */
.teacher-root > :first-child { position: relative; margin-top: -44px; }
.t-head { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 18px 20px; }
.t-section { display: grid; gap: 10px; }
.t-section > h2, .t-panel > h2 { font-size: 1.05rem; }
.t-panel { padding: 16px 18px; display: grid; gap: 10px; }
.link-btn.t-back {
  justify-self: start;
  padding: 7px 14px;
  border-radius: 99px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  font-weight: 700;
  color: var(--accent);
}
.t-class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.t-class-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: none;
  text-align: left;
  color: var(--ink);
  transition: transform .1s ease, box-shadow .15s ease;
}
.t-class-card:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 2px var(--accent), var(--shadow); }
.t-class-name { font-weight: 800; font-size: 1.05rem; }
.t-chip {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--surface-2);
  font-size: .78rem;
  font-weight: 600;
}
.t-chip svg.i { width: 13px; height: 13px; }
.t-chip.ok { background: var(--primary-soft); color: var(--primary); }
.t-inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.t-inline .field { flex: 1 1 220px; }
.t-class-head { align-items: flex-start; }
.t-class-title { flex: 1 1 260px; min-width: 0; }
.t-code { display: grid; justify-items: start; gap: 2px; padding: 10px 14px; border-radius: 16px; background: var(--surface-2); }
.t-code-value { font-size: 1.5rem; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.t-code-hint { flex-basis: 100%; margin-top: -6px; }
.btn.t-small { padding: 8px 12px; font-size: .85rem; border-radius: 12px; }
.t-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.t-end { justify-content: flex-end; }
.t-danger { color: var(--danger) !important; }
.btn.t-armed, .link-btn.t-armed { background: var(--danger); color: #fff !important; box-shadow: none; padding: 8px 12px; border-radius: 12px; text-decoration: none; }
.t-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}
.t-tabs button[role="tab"] { flex: 0 1 auto; border: none; border-radius: 10px; padding: 9px 14px; background: none; font-weight: 800; font-size: .9rem; color: var(--muted); }
.t-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 6px rgba(36, 26, 82, .12); }
.link-btn.t-refresh { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; text-decoration: none; padding: 6px 10px; }
.t-refresh svg.i { width: 15px; height: 15px; }
.t-students { display: grid; gap: 8px; }
.t-student {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 12px 16px;
  border: none;
  text-align: left;
  color: var(--ink);
}
.t-student:hover { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow); }
.t-student-main { display: grid; flex: 1 1 160px; min-width: 0; }
.t-stat { display: grid; min-width: 70px; line-height: 1.25; }
.t-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field select, .field textarea {
  width: 100%;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
}
.field textarea { resize: vertical; }
.field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.t-date { max-width: 260px; }
.t-progress { display: flex; align-items: center; gap: 10px; }
.t-progress .bar { flex: 0 1 180px; }
.t-who { display: flex; flex-wrap: wrap; gap: 6px; }
.t-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.t-hw-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.t-hw-line .hw-status svg.i { width: 13px; height: 13px; }
.t-hw-line.done .hw-status { background: var(--primary-soft); color: var(--primary); }
.t-hw-line.late .hw-status { background: var(--danger-soft); color: var(--danger); }
.t-palier { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px 14px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.t-palier:last-child { border-bottom: none; }
.t-palier.locked { opacity: .55; }
.t-palier-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.t-stars { display: flex; gap: 4px; }
.t-stars i { font-style: normal; min-width: 30px; text-align: center; padding: 2px 4px; border-radius: 8px; background: var(--surface-2); color: var(--locked); font-size: .75rem; letter-spacing: -1px; }
.t-stars i.on { background: var(--gold-soft); color: var(--gold-dark); }
.t-ok { color: var(--primary); font-weight: 700; }
.t-letters { display: flex; flex-wrap: wrap; gap: 8px; }
.t-letter { display: grid; justify-items: center; min-width: 64px; padding: 6px 10px; border-radius: 14px; background: var(--danger-soft); color: var(--ink); }
.t-letter .ar { font-size: 1.8rem; line-height: 1.3; }
.t-student-head { align-items: center; }
.t-avatar-big { width: 64px; height: 64px; font-size: 1.6rem; }
.t-kpis { margin-left: auto; display: flex; gap: 10px; }
.t-kpis > span { display: grid; justify-items: center; min-width: 64px; padding: 8px 10px; border-radius: 14px; background: var(--surface-2); }
.t-kpis strong { font-size: 1.2rem; }
@media (max-width: 560px) {
  .t-grid2 { grid-template-columns: 1fr; }
  .t-palier { grid-template-columns: 1fr; }
  .t-kpis { margin-left: 0; }
}

/* Page « Espace prof » (à venir) */
.teacher-space {
  position: relative;
  margin-top: -44px;
  padding: 28px 20px;
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}
.teacher-space .teacher-badge { margin-top: 0; }
.teacher-space .menu-badge { margin-left: 0; }
.teacher-features { list-style: none; margin: 4px 0; padding: 0; width: 100%; display: grid; gap: 8px; text-align: left; }
.teacher-features li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--bg); font-weight: 600; }
.teacher-features svg.i { width: 22px; height: 22px; color: var(--primary); }

/* Grand écran : barre latérale à gauche, chemin des leçons à droite. */
@media (min-width: 900px) {
  .menu-btn, .menu-head, .menu-backdrop { display: none !important; }
  .main-menu {
    position: static;
    width: auto;
    margin-top: 22px;
    padding: 0;
    overflow: visible;
    background: none;
    box-shadow: none;
    transform: none;
    visibility: visible;
    transition: none;
  }
  .teacher-space, .homework-head, .teacher-root > :first-child { margin-top: 0; }
  .home-main.wide { max-width: 980px; }
  .side-bubbles { display: block; position: absolute; inset: 0; overflow: hidden; pointer-events: none; opacity: .4; }
  /* Les bulles dépassent du bord droit : décor sans gêner la lecture. */
  .side-bubbles .bubbles span { left: calc(100% - var(--s) * .55); }
  .home > .band > :not(.side-bubbles, .band-pattern) { position: relative; }
  .main-menu .menu-bottom { display: none; }
  .side-bottom {
    display: block;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, .25);
  }
  #app:has(> .home) { max-width: none; padding: 0; }
  .home { display: grid; grid-template-columns: 300px minmax(0, 1fr); align-items: start; padding-bottom: 0; }
  .band {
    position: sticky;
    top: 0;
    height: 100dvh;
    margin: 0;
    padding: 24px 18px;
    border-radius: 0 28px 28px 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .band-pattern { position: fixed; width: 300px; height: 100dvh; }
  .topbar { flex-direction: column; align-items: stretch; gap: 16px; }
  .stats { flex-wrap: wrap; }
  .palier-nav-title {
    position: static; width: auto; height: auto; clip: auto;
    margin: 28px 4px 10px;
    font-size: .72rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    opacity: .65;
  }
  .palier-list { flex-direction: column; margin: 0; padding: 0 0 8px; overflow: visible; }
  .palier-card { width: 100%; padding: 12px 14px; }
  .palier-num { width: 40px; height: 40px; border-radius: 12px; }
  .palier-eyebrow { display: block; }
  .palier-text strong { font-size: .95rem; white-space: normal; }
  .home-main { width: 100%; max-width: 580px; margin: 0 auto; padding: 32px 24px 56px; }
  .hero { margin-top: 0; }
}

.badge {
  grid-column: 2;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge svg.i { width: 13px; height: 13px; }

/* Mode test (?dev) */
.dev-panel {
  display: grid;
  gap: 6px;
  margin-top: 24px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 2px dashed var(--gold);
}
.dev-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.dev-actions .btn { padding: 10px 14px; font-size: .9rem; }

/* ---------- Session ---------- */

.session {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 150px;
}
.session-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  position: sticky;
  top: 0;
  /* Translucide : laisse passer les halos colorés du fond. */
  background: color-mix(in srgb, var(--bg) 40%, transparent);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.hearts { display: flex; gap: 2px; color: var(--danger); }
.hearts svg.i { width: 22px; height: 22px; }
.hearts .lost { color: var(--locked); opacity: .5; }

.stage { flex: 1; padding-top: 8px; }

.ex { display: grid; gap: 20px; animation: slide-in .25s ease; }
.prompt { font-size: 1.25rem; font-weight: 800; }
.stimulus { display: grid; justify-items: center; gap: 4px; }

.big-letter { font-size: 6.5rem; line-height: 1.35; text-align: center; color: var(--ink); }

/* La lettre posée dans une grande étoile aux couleurs de la marque */
.letter-frame { position: relative; width: 210px; height: 210px; display: grid; place-items: center; }
.letter-frame svg.khatam { position: absolute; inset: 0; fill: url(#g-fun); filter: drop-shadow(0 10px 22px rgba(98, 70, 216, .35)); }
.letter-frame .ar { position: relative; font-size: 5.2rem; line-height: 1; color: #fff; padding-bottom: 14px; }

.sound-btn {
  position: relative;
  width: 150px;
  height: 150px;
  border: none;
  background: none;
  padding: 0;
  display: grid;
  place-items: center;
  color: #fffaf1;
}
.sound-btn svg.khatam { position: absolute; inset: 0; fill: var(--primary); transition: transform .2s ease; }
.sound-btn svg.i { position: relative; width: 52px; height: 52px; }
.sound-btn:hover svg.khatam { transform: rotate(8deg); }
.sound-btn:active svg.khatam { transform: scale(.94); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  position: relative;
  min-height: 66px;
  padding: 12px;
  border: none;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 800;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.option small { display: block; font-weight: 600; color: var(--muted); font-size: .8rem; }
.options-ar .option { min-height: 96px; }
.options-ar .option .ar { font-size: 3rem; line-height: 1.2; }
.option:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--primary); }
.option:active:not(:disabled) { transform: scale(.97); }
.option .key { position: absolute; top: 6px; left: 9px; font-size: .68rem; font-weight: 800; color: var(--muted); opacity: .7; }
.option.correct { background: var(--primary); color: #fffaf1; box-shadow: none; }
.option.correct small, .option.correct .key { color: #d6eee8; }
.option.wrong { background: var(--danger-soft); box-shadow: inset 0 0 0 2px var(--danger); animation: shake .4s; }
.option:disabled:not(.correct):not(.wrong) { opacity: .45; }

/* Fiche de découverte d'une lettre */
.intro { gap: 14px; }
.intro-card {
  position: relative;
  overflow: hidden;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px 16px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.intro-card .big-letter { font-size: 7.5rem; color: var(--primary); }
.translit {
  font-size: .95rem;
  font-weight: 800;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 2px 8px;
  vertical-align: middle;
}
.audio-row { display: flex; gap: 10px; margin-top: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  border-radius: 99px;
  padding: 7px 14px;
  font-weight: 800;
  font-size: .9rem;
}
.chip svg.i { color: var(--primary); }
.chip:hover { box-shadow: inset 0 0 0 2px var(--primary); }

.facts { margin: 0; display: grid; gap: 10px; }
.facts > div { background: var(--surface); border-radius: 16px; padding: 10px 14px; box-shadow: inset 0 0 0 2px var(--line); }
.facts dt { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); }
.facts dd { margin: 0; font-weight: 600; }

.forms-block { display: grid; gap: 8px; }
.forms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.form-cell {
  display: grid;
  justify-items: center;
  padding: 6px 4px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
}
.form-cell .ar { font-size: 2.2rem; line-height: 1.5; }
.form-cell small { color: var(--muted); font-weight: 700; font-size: .72rem; }
.note { color: var(--gold-dark); font-weight: 700; }

/* Palier 1 : fiches, mots, décomposition */
.center { text-align: center; }
.tip-card {
  display: grid;
  gap: 10px;
  padding: 22px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tip-card p { font-weight: 600; line-height: 1.6; }
.tip-example {
  margin-top: 6px;
  padding: 10px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 2rem;
  text-align: center;
  line-height: 1.6;
}
@media (prefers-color-scheme: dark) { .tip-example { color: var(--primary); } }

.word { font-size: 4.6rem; line-height: 1.5; text-align: center; }
.letters-sum { font-size: 2.6rem; line-height: 1.6; text-align: center; padding: 12px 18px; border-radius: 18px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); }
.options-ar .option .ar { white-space: nowrap; }

.slots { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.slot {
  width: 62px;
  height: 70px;
  border: 2px dashed var(--locked);
  border-radius: 14px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}
.slot .ar { font-size: 2.2rem; line-height: 1; }
.slot.filled { background: var(--surface); border: 2px solid var(--primary); }
.slot.right { background: var(--primary); color: #fffaf1; border-color: var(--primary); }
.slot.bad { background: var(--danger-soft); border: 2px solid var(--danger); }
.tiles-row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.tile-letter {
  width: 58px;
  height: 62px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  display: grid;
  place-items: center;
  transition: transform .08s ease, opacity .15s ease;
}
.tile-letter .ar { font-size: 2rem; line-height: 1; }
.tile-letter:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--primary); }
.tile-letter:active:not(:disabled) { transform: scale(.95); }
.tile-letter:disabled { opacity: .25; }

/* Paliers 2 et 3 : texte vocalisé, racines */
.ar.voc { line-height: 1.9; }
.word.voc { font-size: 4rem; }
.options-ar .option .ar.voc { font-size: 2.3rem; line-height: 1.9; }
.translit-option { font-size: 1.2rem; letter-spacing: .02em; }

.root-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.root-frame { width: 170px; height: 170px; }
.root-frame .ar { font-size: 2.6rem; padding-bottom: 6px; word-spacing: .15em; }
.family { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.family li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 8px 8px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
}
.family-text { display: grid; line-height: 1.3; }
.family-ar { font-size: 1.8rem; }
.chip.icon-only { padding: 8px; }

/* Paliers 4 à 6 : phrases, panneaux, dialogues */
.sentence { font-size: 2.2rem; line-height: 1.8; text-align: center; }
.sentence.voc { line-height: 2.1; }
.sentence mark { background: var(--gold-soft); color: inherit; border-radius: 8px; padding: 0 6px; box-shadow: inset 0 -3px 0 var(--gold); }
.sentence .gap { display: inline-block; min-width: 2.2em; border-bottom: 3px dashed var(--gold); color: var(--gold-dark); }
.sentence-option { font-size: 1.5rem; line-height: 1.9; }
.options-ar .option small { margin-top: 2px; }
.to-translate { font-size: 1.15rem; font-weight: 800; text-align: center; padding: 12px 16px; border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); }

.answer-line {
  min-height: 72px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 8px;
  padding: 8px;
  border-radius: 16px;
  border: 2px dashed var(--locked);
}
.answer-line.right { border: 2px solid var(--primary); background: var(--primary-soft); }
.answer-line.bad { border: 2px solid var(--danger); background: var(--danger-soft); }
.tile-word {
  min-height: 52px;
  padding: 2px 14px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
}
.tile-word .ar { font-size: 1.6rem; line-height: 1.9; }
.tile-word:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--primary); }
.tile-word:disabled { opacity: .25; }
.tile-word.placed { box-shadow: inset 0 0 0 2px var(--primary); }

/* Panneau de rue : plaque bleu nuit à liseré doré */
.sign {
  display: inline-block;
  padding: 10px 28px;
  border-radius: 12px;
  background: var(--band);
  color: #f1e7d6;
  box-shadow: inset 0 0 0 3px var(--band), inset 0 0 0 5px var(--gold);
  font-size: 2.6rem;
  line-height: 1.5;
}
.sign.small-sign { font-size: 1.5rem; padding: 4px 16px; }

/* Dialogues et textes */
.bubbles { display: grid; gap: 10px; }
.bubble {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 92%;
  padding: 10px 14px 10px 10px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  transition: box-shadow .2s ease;
}
.bubbles.dialogue .bubble.me { justify-self: end; border-top-right-radius: 4px; }
.bubbles.dialogue .bubble.other { justify-self: start; border-top-left-radius: 4px; background: var(--primary-soft); box-shadow: none; }
.bubble.playing { box-shadow: inset 0 0 0 2px var(--gold); }
.bubble-text { display: grid; gap: 2px; flex: 1; }
.bubble-text .ar { font-size: 1.5rem; margin: 0; text-align: right; }
.translation { font-weight: 700; color: var(--primary-dark); }
@media (prefers-color-scheme: dark) { .translation { color: var(--primary); } }
.story-mini { max-height: 240px; overflow-y: auto; padding: 4px; width: 100%; }
.story-mini .bubble { padding: 6px 12px; }
.story-mini .bubble-text .ar { font-size: 1.2rem; }

/* Paires */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair-col { display: grid; gap: 10px; }
.pair-tile {
  min-height: 64px;
  border: none;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 800;
  font-size: 1.02rem;
  transition: background .15s ease, box-shadow .15s ease, opacity .3s ease;
}
.pair-tile .ar { font-size: 2.2rem; line-height: 1.2; }
.pair-tile.selected { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
.pair-tile.matched { opacity: .3; box-shadow: none; background: var(--surface-2); }
.pair-tile.shake { background: var(--danger-soft); box-shadow: inset 0 0 0 2px var(--danger); animation: shake .4s; }

/* Tracé */
.trace-box {
  justify-self: center;
  width: min(100%, 320px);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background-color: var(--surface);
  background-image: linear-gradient(var(--surface-2) 1px, transparent 1px);
  background-size: 100% 40px;
  box-shadow: inset 0 0 0 2px var(--line);
}
.trace-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.trace-hint { text-align: center; min-height: 1.4em; }
.trace-hint.warn { color: var(--danger); font-weight: 700; }
.trace-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Bandeau de réponse en bas d'écran */
.feedback {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px max(16px, calc((100vw - 520px) / 2 + 16px)) calc(18px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  box-shadow: 0 -1px 0 var(--line);
  animation: rise .2s ease;
  z-index: 10;
}
.feedback[hidden] { display: none; }
.feedback-msg { display: grid; gap: 2px; font-size: 1.1rem; }
.feedback .solution { font-size: .95rem; font-weight: 600; }
.feedback .solution .ar { font-size: 1.5rem; }
.feedback.neutral { justify-content: flex-end; }
.feedback.good { background: var(--primary-soft); color: var(--primary-dark); box-shadow: none; }
.feedback.good .btn.primary { background: var(--primary); color: #fffaf1; }
.feedback.bad { background: var(--danger-soft); color: var(--danger-dark); box-shadow: none; }
.feedback.bad .btn.primary { background: var(--danger); color: #fffaf1; }
@media (prefers-color-scheme: dark) {
  .feedback.good { color: var(--primary); }
}

/* Fenêtres (« Quitter », « Compte ») */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 16, 36, .6);
  z-index: 30;
  animation: fade-in .15s ease;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(100%, 380px);
  display: grid;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop .2s ease;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }

/* Série de jours */
.streak-btn { cursor: pointer; }
.streak-btn:hover { background: rgba(241, 231, 214, .25); }
.streak-badge {
  position: relative;
  justify-self: center;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  color: #182343;
  animation: pop .4s ease;
}
.streak-badge svg.khatam { position: absolute; inset: 0; fill: var(--gold); animation: turn 30s linear infinite; }
.streak-badge svg.i { position: relative; width: 38px; height: 38px; }
.streak-badge.off svg.khatam { fill: var(--surface-2); }
.streak-badge.off { color: var(--muted); }
.streak-today {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--gold-soft);
  color: var(--gold-dark);
  font-weight: 700;
  font-size: .9rem;
}
.streak-today.done { background: var(--primary-soft); color: var(--primary-dark); }
@media (prefers-color-scheme: dark) { .streak-today.done { color: var(--primary); } }
.streak-cheer { font-weight: 800; }
.modal .btn { margin-top: 6px; }

/* XP, rangs et classement */
.stat-btn { cursor: pointer; }
.stat-btn:hover { background: rgba(241, 231, 214, .25); }
.xp-modal .modal, .streak-modal .modal { max-height: calc(100dvh - 32px); overflow-y: auto; }
.rank-badge {
  position: relative;
  justify-self: center;
  width: 110px;
  height: 110px;
  display: grid;
  place-items: center;
  animation: pop .4s ease;
}
.rank-badge svg.khatam { position: absolute; inset: 0; fill: url(#g-fun); stroke: var(--gold); stroke-width: 4; }
.rank-badge .ar { position: relative; color: #fff; font-size: 1.35rem; line-height: 1; padding-bottom: 4px; }
.rank-name { font-size: 1.05rem; }
.modal-section { display: grid; gap: 8px; text-align: left; padding-top: 12px; margin-top: 4px; border-top: 2px solid var(--line); }
.modal-section h3 { margin: 0; font-size: 1.05rem; }
.xp-rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.xp-rules strong { display: inline-block; min-width: 42px; color: var(--primary); }
.lb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lb-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--surface-2);
}
.lb-list li.me { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
.lb-list li:nth-child(1) .lb-pos { color: var(--gold-dark); }
.lb-list .lb-gap { display: block; text-align: center; background: none; padding: 0; color: var(--muted); }
.lb-pos { font-weight: 800; text-align: center; }
.lb-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name small { color: var(--muted); font-weight: 600; }
.lb-rank { font-size: 1.1rem; color: var(--muted); }
.lb-xp { font-weight: 800; font-size: .85rem; }
.link-btn { border: none; background: none; padding: 4px 0; color: var(--muted); font-size: .85rem; text-decoration: underline; justify-self: start; }
.warn-text { color: var(--danger); font-weight: 700; }
.modal-section .btn.ghost { display: inline-flex; align-items: center; gap: 6px; justify-self: start; }

/* Compte / sauvegarde en ligne */
.account-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 99px;
  background: rgba(241, 231, 214, .14);
  color: var(--on-band);
}
.account-btn svg.i { width: 18px; height: 18px; }
.account-btn:hover { background: rgba(241, 231, 214, .25); }
.account-btn.on { color: #5fd3bd; }
.account-btn.on::after,
.account-btn.error::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--band);
  background: #5fd3bd;
}
.account-btn.error::after { background: var(--danger); }

.account-form { display: grid; gap: 10px; margin-top: 4px; }
.account-form input {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.account-form input:focus { outline: none; border-color: var(--primary); }
.account-msg { min-height: 1.4em; color: var(--primary); font-weight: 700; }
.account-msg.warn { color: var(--danger); }
.sync-status { font-weight: 700; }
.sync-status.saved { color: var(--primary); }
.sync-status.error { color: var(--danger); }

/* ---------- Démarrage, connexion, test de niveau ---------- */

/* Écrans d'accueil (lancement, connexion, prénom) : version colorée et ludique.
   Mêmes couleurs en mode clair et sombre : c'est l'identité de l'app. */
.fun-bg {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #4fc3f7 0%, #7c6cff 52%, #ff7eb6 100%);
  color: #fff;
}

/* Lettres arabes qui flottent en arrière-plan. */
.bubbles { position: absolute; inset: 0; pointer-events: none; }
.bubbles span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .28);
  color: var(--c);
  font-family: var(--font-ar);
  font-size: calc(var(--s) * .5);
  line-height: 1;
  animation: float 6s ease-in-out infinite, fade-in .6s ease both;
  animation-delay: var(--d), 0s;
}

/* Logo : étoile soleil qui rebondit, حرف au centre. */
.logo-star {
  position: relative;
  width: 150px;
  height: 150px;
  display: grid;
  place-items: center;
  color: #182343;
}
.logo-star svg.khatam {
  position: absolute;
  inset: 0;
  fill: #ffd23f;
  stroke: #fff;
  stroke-width: 4;
  filter: drop-shadow(0 10px 18px rgba(60, 20, 120, .35));
  animation: turn 30s linear infinite;
}
.logo-star .brand-ar { position: relative; font-size: 3rem; }

.splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  z-index: 30;
}
.splash .logo-star { animation: bounce-in .9s cubic-bezier(.3, 1.6, .5, 1) both; }
.splash-name {
  position: relative;
  font-weight: 800;
  font-size: 2.2rem;
  letter-spacing: .02em;
  animation: slide-in .5s .45s ease both;
}
.splash-hello { position: relative; max-width: 28ch; padding: 0 16px; font-size: 1.1rem; font-weight: 700; animation: slide-in .5s .7s ease both; }
.splash-hello .ar { font-size: 1.4rem; margin-inline-end: 6px; }
.dots { position: relative; display: flex; gap: 8px; margin-top: 18px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: #fff; animation: dot 1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; background: #ffd23f; }
.dots i:nth-child(3) { animation-delay: .3s; background: #3ddc97; }

.auth, .name-step { min-height: 100dvh; padding-bottom: 32px; animation: fade-in .4s ease; }
.auth-band {
  margin: 0 -16px;
  padding: 48px 16px 84px;
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  border-radius: 0 0 36px 36px;
}
.auth-band > :not(.bubbles) { position: relative; }
.auth-band .logo-star { width: 112px; height: 112px; animation: bounce-in .7s cubic-bezier(.3, 1.6, .5, 1) both; }
.auth-band .logo-star .brand-ar { font-size: 2.3rem; }
.auth-band .brand-name { font-size: 1.5rem; letter-spacing: .02em; text-transform: none; opacity: 1; }
.auth-lang { position: absolute !important; top: 16px; right: 16px; background: rgba(255, 255, 255, .25) !important; color: #fff !important; }
.auth-tagline { font-size: 1rem; font-weight: 600; max-width: 26ch; }
.auth-card { position: relative; margin-top: -56px; padding: 20px; border-radius: 28px; }
/* Bouton principal des écrans d'accueil : dégradé joyeux. */
.btn.fun {
  background: linear-gradient(135deg, #ff8a5c, #ff5fa2);
  color: #fff;
  box-shadow: 0 6px 0 #d8457f;
  transform: translateY(0);
}
.btn.fun:hover:not(:disabled) { filter: brightness(1.06); }
.btn.fun:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #d8457f; }

/* Étape « Comment tu t'appelles ? » */
.name-step .auth-band { padding: 64px 16px 120px; }
.name-title { font-size: 1.75rem; }
.name-card { display: grid; justify-items: center; gap: 12px; text-align: center; }
.name-avatar {
  width: 96px;
  height: 96px;
  margin-top: -68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 5px solid var(--surface);
  background: var(--avatar, #7c6cff);
  color: #fff;
  font-size: 2.6rem;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: background .3s ease;
  animation: bounce-in .7s cubic-bezier(.3, 1.6, .5, 1) both;
}
.name-card form { width: 100%; display: grid; gap: 12px; text-align: left; }
.name-card .field input { font-size: 1.2rem; text-align: center; }

.name-step .auth-band, .onboarding .auth-band { padding: 64px 16px 120px; }
.onboarding { min-height: 100dvh; padding-bottom: 32px; animation: fade-in .4s ease; }
.teacher-badge { --avatar: #ff8a5c; width: 110px; height: 110px; margin-top: -76px; }
.teacher-badge .ar { font-size: 1.5rem; line-height: 1; }
.teacher-word { margin-top: -4px; }
.name-card form .btn.ghost { font-size: .95rem; }

/* Choix du niveau : grandes cartes colorées */
.level-step .auth-card { margin-top: -84px; }
.level-list { width: 100%; display: grid; gap: 10px; }
.level-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: none;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
  text-align: left;
  transition: transform .1s ease, box-shadow .15s ease;
}
.level-card:hover:not(:disabled) { box-shadow: inset 0 0 0 3px var(--tint); transform: translateY(-1px); }
.level-card.picked { box-shadow: inset 0 0 0 3px var(--tint); }
.level-sample {
  flex-shrink: 0;
  width: 64px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--tint);
  color: #fff;
  font-size: 1.15rem;
  line-height: 1.2;
}
.level-text { display: grid; line-height: 1.3; }

/* Salutation sur l'accueil */
.hello { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-weight: 800; font-size: 1.15rem; }
.hello .ar { font-size: 1.35rem; color: var(--hello); }
.hello-sub { margin-top: -2px; }
.hero-sep { width: 100%; height: 0; margin: 8px 0 4px; border: none; border-top: 2px dashed var(--line); }
.place-intro .hello { justify-content: center; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: var(--surface-2);
}
.auth-tabs button {
  border: none;
  border-radius: 10px;
  padding: 10px 8px;
  background: none;
  font-weight: 800;
  font-size: .9rem;
  color: var(--muted);
}
.auth-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 6px rgba(24, 35, 67, .12); }
.auth-form { display: grid; gap: 12px; }
.auth-form .btn.primary { margin-top: 4px; }
.auth-form > .link-btn { justify-self: center; }
.auth-form .auth-forgot { justify-self: end; margin-top: -6px; }
.field { display: grid; gap: 6px; font-size: .85rem; font-weight: 800; }
.field input {
  width: 100%;
  font: inherit;
  font-weight: 400;
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.field input:focus { outline: none; border-color: var(--primary); }
.field-hint { margin-top: -6px; }
.pw-rules { display: grid; gap: 4px; margin-top: -4px; }
.pw-rules ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.pw-rules li { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.pw-rules li svg.i {
  width: 18px; height: 18px; padding: 2px; border-radius: 99px;
  color: transparent; box-shadow: inset 0 0 0 2px var(--line);
  transition: background .15s ease, color .15s ease;
}
.pw-rules li.ok { color: var(--ink); }
.pw-rules li.ok svg.i { background: var(--primary); color: #fffaf1; box-shadow: none; }
.pw-rules.show-missing li:not(.ok) { color: var(--danger); font-weight: 700; }
.pw-rules.show-missing li:not(.ok) svg.i { box-shadow: inset 0 0 0 2px var(--danger); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--muted);
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }
.captcha { display: flex; justify-content: center; }
.auth-msg { min-height: 1.4em; color: var(--primary); font-weight: 700; }
.auth-msg:empty { display: none; }
.auth-msg.warn { color: var(--danger); }
.auth-confirm { justify-items: center; text-align: center; }
.auth-confirm-icon { position: relative; width: 84px; height: 84px; display: grid; place-items: center; color: #182343; }
.auth-confirm-icon svg.khatam { position: absolute; inset: 0; fill: var(--gold); }
.auth-confirm-icon svg.i { position: relative; width: 32px; height: 32px; }

.place-intro {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
  padding: 32px 0;
}
.place-intro .result-actions { flex-direction: column; width: min(100%, 320px); }
.place-step { text-align: center; margin: -4px 0 4px; }
.place-palier { display: grid; gap: 2px; padding: 12px 18px; border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); }

@media (min-width: 900px) {
  .auth { max-width: 440px; margin: 0 auto; }
}

/* ---------- Résultat ---------- */

.result {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
  padding: 32px 0;
}
.result-badge {
  position: relative;
  width: 140px;
  height: 140px;
  display: grid;
  place-items: center;
  color: #182343;
  animation: pop .5s ease;
}
.result-badge svg.khatam { position: absolute; inset: 0; fill: var(--gold); animation: turn 30s linear infinite; }
.result-badge svg.i { position: relative; width: 48px; height: 48px; }
.result-badge.lost svg.khatam { fill: var(--surface-2); }
.result-badge.lost { color: var(--muted); }
.result .ar { font-size: 1.6rem; }
.tiles { display: flex; gap: 12px; margin: 8px 0; }
.tile {
  display: grid;
  min-width: 120px;
  padding: 12px 18px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
}
.tile-value { font-size: 1.6rem; font-weight: 800; }
.tile-label { font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.result-actions { display: flex; gap: 12px; margin-top: 8px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  background: var(--band);
  color: var(--on-band);
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 600;
  font-size: .9rem;
  box-shadow: var(--shadow);
  z-index: 40;
}
.toast[hidden] { display: none; }

/* ---------- Animations ---------- */

@keyframes turn { to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes bounce-in { 0% { transform: scale(0) rotate(-90deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes dot { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-8px); } }

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