/* ================================================================
   KADÉMIA — Design System
   PWA mobile-first · zéro dépendance · thème clair/sombre/auto
   Deux "skins" partageant le même moteur : Emma (CE1) et Enora (4e)
   ================================================================ */

:root {
  --cream: #FFF8EC;
  --card: #FFFFFF;
  --ink: #241C14;
  --muted: #7A7062;
  --stroke: rgba(36, 28, 20, 0.10);
  --stroke-2: rgba(36, 28, 20, 0.18);
  --veil: rgba(36, 28, 20, 0.45);

  --text-1: #241C14;
  --text-2: #7A7062;
  --text-3: #A79C8B;

  --green: #58CC02;   --green-dark: #46A302;
  --red: #FF4B4B;      --red-dim: rgba(255, 75, 75, 0.14);
  --blue: #1CB0F6;     --blue-dim: rgba(28, 176, 246, 0.14);
  --yellow: #FFC800;   --yellow-dim: rgba(255, 200, 0, 0.18);
  --purple: #7C5CFC;   --purple-dim: rgba(124, 92, 252, 0.14);
  --orange: #FF9600;   --orange-dim: rgba(255, 150, 0, 0.16);
  --pink: #FF86D0;

  /* Skin par défaut = Emma (surchargée par .skin-enora) */
  --brand: #FF9600;
  --brand-dark: #DB7E00;
  --brand-dim: rgba(255, 150, 0, 0.14);
  --accent: #7C5CFC;
  --radius-s: 12px;
  --radius-m: 18px;
  --radius-l: 26px;
  --font-scale: 1;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --cream: #14100C; --card: #201A14; --ink: #F5EFE6; --muted: #B3A695;
    --stroke: rgba(245, 239, 230, 0.10); --stroke-2: rgba(245, 239, 230, 0.18);
    --veil: rgba(0, 0, 0, 0.6);
    --text-1: #F5EFE6; --text-2: #B3A695; --text-3: #7A7062;
  }
}
:root[data-theme="light"] {
  --cream: #FFF8EC; --card: #FFFFFF; --ink: #241C14; --muted: #7A7062;
  --stroke: rgba(36, 28, 20, 0.10); --stroke-2: rgba(36, 28, 20, 0.18); --veil: rgba(36, 28, 20, 0.45);
  --text-1: #241C14; --text-2: #7A7062; --text-3: #A79C8B;
}
:root[data-theme="dark"] {
  --cream: #14100C; --card: #201A14; --ink: #F5EFE6; --muted: #B3A695;
  --stroke: rgba(245, 239, 230, 0.10); --stroke-2: rgba(245, 239, 230, 0.18); --veil: rgba(0, 0, 0, 0.6);
  --text-1: #F5EFE6; --text-2: #B3A695; --text-3: #7A7062;
}

/* --- Skin Enora (4e) : plus sobre, plus "ado" --- */
body.skin-enora {
  --brand: #7C5CFC;
  --brand-dark: #5F3FE0;
  --brand-dim: rgba(124, 92, 252, 0.14);
  --accent: #1CB0F6;
  --radius-m: 14px;
  --radius-l: 20px;
  --font-scale: 0.96;
}

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

html, body {
  position: fixed; inset: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none;
}
body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
  font-size: calc(16px * var(--font-scale));
}
.app { max-width: 520px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; background: var(--cream); }

.screen {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: calc(14px + var(--safe-top)) 18px calc(90px + var(--safe-bottom));
  animation: screenIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; margin-bottom: 4px; }
h2 { font-size: 1.15rem; margin-bottom: 10px; }
p.sub { color: var(--text-2); font-size: 0.92rem; margin-bottom: 16px; }

button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }

/* --- Cards --- */
.card {
  background: var(--card); border: 2px solid var(--stroke); border-radius: var(--radius-l);
  padding: 16px; box-shadow: 0 3px 0 var(--stroke);
}
.card + .card { margin-top: 12px; }

/* --- Tabbar --- */
.tabbar {
  display: flex; justify-content: space-around; align-items: center;
  padding: 8px 4px calc(8px + var(--safe-bottom));
  background: var(--card); border-top: 1px solid var(--stroke);
}
.tabbar.hidden { display: none; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 14px; border-radius: var(--radius-s); color: var(--text-3); font-size: 0.68rem; font-weight: 700; }
.tab.active { color: var(--brand); }
.tab svg { width: 24px; height: 24px; }

/* --- Boutons primaires (style Duolingo : relief 3D) --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 18px; border-radius: var(--radius-m);
  font-weight: 800; font-size: 1rem; letter-spacing: 0.02em; text-transform: uppercase;
  transition: transform 0.06s ease;
}
.btn:active { transform: translateY(2px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-dark); }
.btn-primary:active { box-shadow: 0 2px 0 var(--brand-dark); }
.btn-primary:disabled { background: var(--stroke-2); color: var(--text-3); box-shadow: none; pointer-events: none; }
.btn-ghost { background: var(--card); color: var(--text-1); border: 2px solid var(--stroke-2); box-shadow: 0 3px 0 var(--stroke-2); }
.btn-danger { background: var(--red); color: #fff; box-shadow: 0 4px 0 #C23434; }
.btn-sm { width: auto; padding: 9px 16px; font-size: 0.8rem; }

/* --- Profils --- */
.profile-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.profile-card {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius-l);
  background: var(--card); border: 2px solid var(--stroke); box-shadow: 0 3px 0 var(--stroke); text-align: left;
}
.avatar {
  width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0; color: #fff; font-weight: 800;
}
.profile-card .meta { flex: 1; }
.profile-card .name { font-weight: 800; font-size: 1.05rem; }
.profile-card .level { color: var(--text-2); font-size: 0.85rem; }

/* --- Barre de statut (accueil) --- */
.statbar { display: flex; gap: 10px; margin-bottom: 18px; }
.stat-pill {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); border: 2px solid var(--stroke); border-radius: var(--radius-m); padding: 10px 6px;
}
.stat-pill .val { font-weight: 800; font-size: 1.1rem; }
.stat-pill .lbl { font-size: 0.62rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }

/* --- Grille de matières --- */
.subject-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.subject-card {
  position: relative; border-radius: var(--radius-l); padding: 16px 14px; text-align: left;
  background: var(--card); border: 2px solid var(--stroke); box-shadow: 0 3px 0 var(--stroke); overflow: hidden;
}
.subject-card .icon { font-size: 1.8rem; }
.subject-card .title { font-weight: 800; margin-top: 8px; font-size: 0.95rem; }
.subject-card .prog { margin-top: 8px; height: 6px; border-radius: 3px; background: var(--stroke-2); overflow: hidden; }
.subject-card .prog > i { display: block; height: 100%; background: var(--subj-color, var(--brand)); }
.subject-card .due-badge {
  position: absolute; top: 10px; right: 10px; background: var(--red); color: #fff;
  font-size: 0.6rem; font-weight: 800; padding: 2px 6px; border-radius: 20px;
}

/* --- Parcours de compétences (chemin façon Duolingo) --- */
.path { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0 30px; }
.path-unit-title { align-self: stretch; text-align: center; font-weight: 800; font-size: 0.95rem; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 0 10px; }
.node-row { display: flex; justify-content: center; width: 100%; }
.node {
  width: 68px; height: 68px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; position: relative; flex-shrink: 0;
}
.node.locked { background: var(--stroke-2); color: var(--text-3); box-shadow: 0 5px 0 var(--stroke); }
.node.available { background: var(--brand); color: #fff; box-shadow: 0 5px 0 var(--brand-dark); }
.node.done { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-dark); }
.node.due { background: var(--yellow); color: #4A3A00; box-shadow: 0 5px 0 #C99A00; }
.node .crown { position: absolute; top: -10px; font-size: 1rem; }
.node-label { font-size: 0.72rem; font-weight: 700; color: var(--text-2); text-align: center; max-width: 90px; margin-top: 2px; }
.node-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 4px 0; }

/* --- Lesson player --- */
.lesson-header { display: flex; align-items: center; gap: 12px; padding-bottom: 14px; }
.progress-bar { flex: 1; height: 14px; border-radius: 8px; background: var(--stroke-2); overflow: hidden; }
.progress-bar > i { display: block; height: 100%; background: var(--green); transition: width 0.3s ease; }
.hearts { display: flex; gap: 3px; font-size: 1rem; }
.close-x { font-size: 1.3rem; color: var(--text-3); padding: 4px; }

.exercise-prompt { font-size: 1.15rem; font-weight: 700; line-height: 1.4; margin: 14px 0 20px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 14px 16px;
  border-radius: var(--radius-m); border: 2px solid var(--stroke-2); background: var(--card);
  font-weight: 700; font-size: 0.98rem; box-shadow: 0 3px 0 var(--stroke-2);
}
.choice-btn.selected { border-color: var(--blue); background: var(--blue-dim); box-shadow: 0 3px 0 var(--blue); }
.choice-btn.correct { border-color: var(--green); background: rgba(88,204,2,0.14); box-shadow: 0 3px 0 var(--green); }
.choice-btn.wrong { border-color: var(--red); background: var(--red-dim); box-shadow: 0 3px 0 var(--red); }
.choice-btn:disabled { pointer-events: none; }

.image-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.image-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 10px;
  border-radius: var(--radius-m); border: 2px solid var(--stroke-2); background: var(--card); box-shadow: 0 3px 0 var(--stroke-2);
}
.image-tile .emoji { font-size: 2.4rem; }
.image-tile.correct { border-color: var(--green); box-shadow: 0 3px 0 var(--green); }
.image-tile.wrong { border-color: var(--red); box-shadow: 0 3px 0 var(--red); }

.blank-text { font-size: 1.15rem; line-height: 1.7; font-weight: 600; }
.blank-input {
  display: inline-block; min-width: 70px; border: none; border-bottom: 3px solid var(--brand);
  background: transparent; font-weight: 800; font-size: 1.05rem; text-align: center; color: var(--text-1);
  padding: 2px 4px; font-family: inherit;
}
.blank-slot { display: inline-block; min-width: 90px; border-bottom: 3px dashed var(--stroke-2); font-weight: 800; text-align: center; padding: 0 4px; color: var(--brand); }
.word-bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.chip {
  padding: 9px 14px; border-radius: 20px; border: 2px solid var(--stroke-2); background: var(--card);
  font-weight: 700; font-size: 0.92rem; box-shadow: 0 2px 0 var(--stroke-2);
}
.chip.used { opacity: 0.35; pointer-events: none; }
.chip.placed { background: var(--blue-dim); border-color: var(--blue); }

.text-answer-input {
  width: 100%; padding: 14px; border-radius: var(--radius-m); border: 2px solid var(--stroke-2);
  background: var(--card); font-size: 1.05rem; font-weight: 700; font-family: inherit; color: var(--text-1);
}

.order-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.order-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-m);
  border: 2px solid var(--stroke-2); background: var(--card); font-weight: 700; box-shadow: 0 2px 0 var(--stroke-2);
}
.order-item .handle { color: var(--text-3); }
.order-item.placed-ok { border-color: var(--green); }
.order-item.placed-bad { border-color: var(--red); }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.assoc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-top: 10px; }
.assoc-item {
  padding: 12px; border-radius: var(--radius-m); border: 2px solid var(--stroke-2); background: var(--card);
  font-weight: 700; font-size: 0.92rem; text-align: center; box-shadow: 0 2px 0 var(--stroke-2);
}
.assoc-item.selected, .assoc-item.picked, .assoc-item.matched-pending { border-color: var(--blue); background: var(--blue-dim); }
.assoc-item.matched { border-color: var(--green); background: rgba(88,204,2,0.14); opacity: 0.7; }
.assoc-item.wrong { border-color: var(--red); background: var(--red-dim); opacity: 0.7; }

.calc-display { text-align: center; font-size: 2rem; font-weight: 800; margin: 10px 0 22px; }
.calc-timer { text-align: center; font-weight: 800; color: var(--orange); margin-bottom: 10px; }

.listen-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 20px; border-radius: var(--radius-l); background: var(--purple-dim); border: 2px dashed var(--purple);
  font-weight: 800; color: var(--purple); font-size: 1rem; margin-bottom: 18px;
}

/* --- Mode compact : pages de leçon/module, pensées pour tenir sans scroll --- */
.lesson-compact .lesson-header { padding-bottom: 8px; }
.lesson-compact .exercise-prompt { font-size: 1.02rem; margin: 8px 0 12px; line-height: 1.3; }
.lesson-compact .choices { gap: 7px; }
.lesson-compact .choice-btn { padding: 10px 13px; font-size: 0.92rem; }
.lesson-compact .image-grid { gap: 8px; }
.lesson-compact .image-tile { padding: 10px 8px; gap: 4px; }
.lesson-compact .image-tile .emoji { font-size: 1.9rem; }
.lesson-compact .word-bank { margin-top: 12px; gap: 6px; }
.lesson-compact .chip { padding: 6px 11px; font-size: 0.85rem; }
.lesson-compact .order-pool { margin-top: 10px; gap: 6px; }
.lesson-compact .order-list { display: flex; flex-direction: row; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.lesson-compact .order-item { padding: 6px 10px; font-size: 0.85rem; gap: 5px; width: auto; }
.lesson-compact .assoc-grid { gap: 7px 10px; margin-top: 6px; }
.lesson-compact .assoc-item { padding: 9px; font-size: 0.85rem; }
.lesson-compact .calc-display { margin: 6px 0 12px; font-size: 1.6rem; }
.lesson-compact .calc-timer { margin-bottom: 6px; }
.lesson-compact .listen-btn { padding: 13px; margin-bottom: 12px; }
.lesson-compact .blank-text { font-size: 1.02rem; line-height: 1.45; }
.lesson-compact .exercise-spacer { height: 64px; }

/* --- Barre d'action (bas d'écran, façon Duolingo) : Vérifier, puis retour ok/bad --- */
.feedback-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; padding: 12px 18px calc(12px + var(--safe-bottom));
  background: var(--card); border-top: 2px solid var(--stroke);
  transform: translateY(0); transition: transform 0.25s cubic-bezier(0.22,1,0.36,1);
}
.feedback-bar.ok { background: rgba(88,204,2,0.18); border-top-color: var(--green); }
.feedback-bar.bad { background: var(--red-dim); border-top-color: var(--red); }
.feedback-inner { max-width: 484px; margin: 0 auto; }
.feedback-title { font-weight: 800; font-size: 1.05rem; margin-bottom: 2px; }
.feedback-bar.ok .feedback-title { color: var(--green-dark); }
.feedback-bar.bad .feedback-title { color: var(--red); }
.feedback-sub { font-size: 0.85rem; color: var(--text-2); margin-bottom: 12px; }

/* --- Écran de résultat --- */
.result-hero { text-align: center; padding: 30px 0 10px; }
.result-hero .big-emoji { font-size: 4rem; }
.result-cards { display: flex; gap: 10px; margin: 20px 0; }
.result-cards .card { flex: 1; text-align: center; }
.result-cards .val { font-size: 1.4rem; font-weight: 800; }
.result-cards .lbl { font-size: 0.7rem; color: var(--text-2); text-transform: uppercase; }

/* --- Badges --- */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.badge-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: var(--radius-m);
  background: var(--card); border: 2px solid var(--stroke); text-align: center; }
.badge-tile.locked { opacity: 0.35; }
.badge-tile .emoji { font-size: 1.8rem; }
.badge-tile .name { font-size: 0.68rem; font-weight: 700; }

/* --- Parent gate / dashboard --- */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 30px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--stroke-2); }
.pin-dot.filled { background: var(--brand); border-color: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 280px; margin: 0 auto; }
.keypad button { padding: 18px; font-size: 1.3rem; font-weight: 700; background: var(--card); border-radius: var(--radius-m); border: 2px solid var(--stroke); }

.weak-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--stroke); }
.weak-item:last-child { border-bottom: none; }
.weak-item .tag { font-weight: 700; font-size: 0.9rem; }
.weak-item .subj { font-size: 0.72rem; color: var(--text-2); }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .lbl { width: 92px; font-size: 0.78rem; font-weight: 700; flex-shrink: 0; }
.bar-track { flex: 1; height: 10px; border-radius: 6px; background: var(--stroke-2); overflow: hidden; }
.bar-track > i { display: block; height: 100%; }
.bar-row .pct { width: 34px; text-align: right; font-size: 0.78rem; font-weight: 700; color: var(--text-2); }

/* --- Overlay --- */
.overlay[hidden] { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50; display: flex; align-items: flex-end; }
.overlay.center { align-items: center; padding: 24px; }
.sheet { background: var(--card); border-radius: 24px 24px 0 0; padding: 24px 20px calc(24px + var(--safe-bottom)); width: 100%; max-width: 520px; margin: 0 auto; }
.overlay.center .sheet { border-radius: var(--radius-l); }

.top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.icon-btn { font-size: 1.3rem; padding: 6px; color: var(--text-2); }

.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.form-field input { width: 100%; padding: 13px; border-radius: var(--radius-m); border: 2px solid var(--stroke-2); background: var(--cream); font-size: 1rem; font-family: inherit; color: var(--text-1); }

.empty-hint { text-align: center; color: var(--text-2); padding: 30px 10px; font-size: 0.9rem; }
