/* ==========================================================
   Codi.js — Feuille de style
   Sommaire :
   1. Couleurs & variables      8. Exemples & éditeur de code
   2. Base                      9. Résultat & console
   3. Fond animé               10. Quiz, défi, fin de leçon
   4. Barre du haut            11. Labo
   5. Barre latérale           12. Confettis & toast
   6. Boutons                  13. Responsive
   7. Accueil & leçons
   ========================================================== */

/* ---------- 1. Couleurs & variables ---------- */
:root {
  --bg: #f6f3ff;
  --bg-2: #fff3f9;
  --surface: #ffffff;
  --surface-2: #f5f1ff;
  --surface-3: #ebe4ff;
  --ink: #271f4d;
  --ink-soft: #5a5385;
  --muted: #8a84ad;
  --line: #e7e1fb;

  --violet: #7c4dff;
  --violet-d: #5b2ee0;
  --pink: #ff5fa2;
  --pink-d: #e23d84;
  --yellow: #ffc83d;
  --yellow-d: #e0a512;
  --green: #1fc28b;
  --green-d: #129a6c;
  --blue: #3b82f6;
  --orange: #ff8a3d;
  --red: #ff5a6a;

  --code-bg: #1d1838;
  --code-bar: #28224d;
  --code-ink: #ece8ff;
  --code-line: #3a3368;

  --shadow-sm: 0 2px 8px -2px rgba(60, 40, 150, .14);
  --shadow: 0 14px 34px -14px rgba(76, 52, 170, .30);
  --shadow-lg: 0 30px 60px -24px rgba(76, 52, 170, .40);

  --r-sm: 12px;
  --r: 20px;
  --r-lg: 28px;

  --accent: var(--violet);
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-title: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --font-code: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --topbar: 70px;
  --sidebar: 290px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120f26;
    --bg-2: #1a1236;
    --surface: #1d1940;
    --surface-2: #252050;
    --surface-3: #30296a;
    --ink: #f2efff;
    --ink-soft: #c9c3ee;
    --muted: #9690c4;
    --line: #342d6a;
    --code-bg: #0f0c22;
    --code-bar: #1a1638;
    --code-line: #2b2556;
    --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, .5);
    --shadow: 0 14px 34px -14px rgba(0, 0, 0, .6);
    --shadow-lg: 0 30px 60px -24px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #120f26;
  --bg-2: #1a1236;
  --surface: #1d1940;
  --surface-2: #252050;
  --surface-3: #30296a;
  --ink: #f2efff;
  --ink-soft: #c9c3ee;
  --muted: #9690c4;
  --line: #342d6a;
  --code-bg: #0f0c22;
  --code-bar: #1a1638;
  --code-line: #2b2556;
  --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, .5);
  --shadow: 0 14px 34px -14px rgba(0, 0, 0, .6);
  --shadow-lg: 0 30px 60px -24px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar) + 20px); }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-family: var(--font-title); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
a { color: var(--violet); }
b, strong { font-weight: 800; }
img { max-width: 100%; }

code {
  font-family: var(--font-code);
  font-size: .86em;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
  padding: .12em .45em;
  border-radius: 7px;
  white-space: nowrap;
}

kbd {
  font-family: var(--font-code);
  font-size: .8em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: .05em .4em;
}

::selection { background: color-mix(in srgb, var(--violet) 30%, transparent); }

:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; border-radius: 6px; }

/* ---------- 3. Fond animé ---------- */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-blobs span {
  position: absolute;
  width: 520px; height: 520px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .35;
  animation: drift 22s ease-in-out infinite alternate;
}
.bg-blobs span:nth-child(1) { background: var(--violet); top: -160px; left: -140px; }
.bg-blobs span:nth-child(2) { background: var(--pink); top: 30%; right: -200px; animation-delay: -7s; opacity: .25; }
.bg-blobs span:nth-child(3) { background: var(--yellow); bottom: -220px; left: 30%; animation-delay: -14s; opacity: .22; }

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(60px, 40px) scale(1.1); }
  100% { transform: translate(-40px, 80px) scale(.95); }
}

/* ---------- 4. Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}

.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; }
.logo-bot {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  font-size: 26px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--violet), var(--pink));
  box-shadow: 0 4px 0 var(--violet-d), 0 10px 20px -8px var(--violet);
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.logo:hover .logo-bot { transform: rotate(-10deg) scale(1.08); }
.logo-text { font-family: var(--font-title); font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.logo-text b { color: var(--violet); }

.topnav { display: flex; gap: 6px; }
.topnav a {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  text-decoration: none;
  color: var(--ink-soft);
  transition: background .2s, color .2s;
}
.topnav a:hover { background: var(--surface-2); color: var(--ink); }
.topnav a.on { background: var(--ink); color: var(--surface); }

.top-progress .ring {
  --p: 0;
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--surface-3) 0);
  transition: --p .6s;
}
.top-progress .ring span {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface);
  font-size: 11px; font-weight: 900;
}

.theme-toggle, .burger {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .2s;
}
.theme-toggle:hover { transform: rotate(20deg); }

.burger { display: none; gap: 4px; padding: 12px 11px; }
.burger span { display: block; width: 20px; height: 3px; border-radius: 3px; background: var(--ink); transition: .3s; }
body.drawer-open .burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.drawer-open .burger span:nth-child(2) { opacity: 0; }
body.drawer-open .burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- 5. Barre latérale ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar));
}

.sidebar {
  position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow-y: auto;
  padding: 22px 16px 30px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  scrollbar-width: thin;
}

.side-card {
  background: linear-gradient(135deg, var(--violet), var(--pink));
  color: #fff;
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.side-card-top { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.side-card-top b { display: block; font-family: var(--font-title); font-size: 19px; line-height: 1.1; }
.side-card-top small { opacity: .9; font-weight: 700; }
.side-mascot { font-size: 30px; }
.bar { height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .3); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--yellow); transition: width .6s cubic-bezier(.34, 1.56, .64, 1); }

.lesson-nav { display: flex; flex-direction: column; gap: 4px; }
.ln {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  transition: background .2s, transform .2s;
}
.ln:hover { background: var(--surface-2); transform: translateX(3px); color: var(--ink); }
.ln-num {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 900;
  background: var(--surface-2);
  color: var(--muted);
  border: 2px solid var(--line);
}
.ln-emoji { font-size: 18px; }
.ln.done .ln-num { background: var(--green); border-color: var(--green); color: #fff; }
.ln.on { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--ink); }
.ln.on .ln-num { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 12px -3px var(--accent); }

.side-lab {
  display: flex; gap: 12px; align-items: center;
  margin-top: 18px;
  padding: 14px;
  border-radius: var(--r);
  border: 2px dashed color-mix(in srgb, var(--green) 50%, var(--line));
  background: color-mix(in srgb, var(--green) 8%, var(--surface));
  color: var(--ink);
  text-decoration: none;
  transition: transform .2s;
}
.side-lab:hover { transform: translateY(-2px); }
.side-lab > span { font-size: 28px; }
.side-lab b { display: block; line-height: 1.2; }
.side-lab small { color: var(--muted); font-weight: 700; }

.scrim { display: none; }

.main { min-width: 0; padding: 34px clamp(16px, 4vw, 56px) 80px; outline: none; }

/* ---------- 6. Boutons ---------- */
.btn {
  --b: var(--surface-2);
  --b-d: var(--line);
  --c: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 14px;
  background: var(--b);
  color: var(--c);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--b-d);
  transition: transform .12s, box-shadow .12s, filter .2s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 5px 0 var(--b-d); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--b-d); }

.btn-primary { --b: var(--violet); --b-d: var(--violet-d); --c: #fff; }
.btn-run     { --b: var(--green);  --b-d: var(--green-d);  --c: #fff; }
.btn-pink    { --b: var(--pink);   --b-d: var(--pink-d);   --c: #fff; }
.btn-yellow  { --b: var(--yellow); --b-d: var(--yellow-d); --c: #3a2a00; }
.btn-white   { --b: var(--surface); --b-d: var(--line); }
.btn-soft    { --b: var(--surface-2); --b-d: var(--surface-3); }
.btn-big { padding: 15px 26px; font-size: 18px; border-radius: 18px; box-shadow: 0 6px 0 var(--b-d); }
.btn-big:active { transform: translateY(5px); }

/* ---------- 7. Accueil ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 30px;
  align-items: center;
  max-width: 1180px;
  margin: 0 auto 56px;
}

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 800; font-size: 14px;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.hero h1 { font-size: clamp(38px, 5.4vw, 66px); font-weight: 800; margin-bottom: 18px; }
.grad {
  background: linear-gradient(90deg, var(--violet), var(--pink) 55%, var(--orange));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.lead { font-size: clamp(17px, 1.6vw, 20px); color: var(--ink-soft); max-width: 560px; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 14px; margin: 26px 0 30px; }

.hero-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-stats div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 18px;
  box-shadow: var(--shadow-sm);
}
.hero-stats b { display: block; font-family: var(--font-title); font-size: 28px; line-height: 1; color: var(--violet); }
.hero-stats span { font-size: 14px; font-weight: 700; color: var(--muted); }

/* Le robot Codi */
.hero-art { position: relative; height: 420px; display: grid; place-items: center; }
.hero-art::before {
  content: "";
  position: absolute;
  width: 340px; height: 340px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--yellow) 60%, transparent), transparent 70%);
}
.bot { position: relative; animation: float 4s ease-in-out infinite; }
.bot-antenna {
  width: 6px; height: 34px;
  margin: 0 auto;
  background: var(--ink-soft);
  border-radius: 3px;
  position: relative;
}
.bot-antenna::before {
  content: "";
  position: absolute; top: -14px; left: 50%;
  width: 22px; height: 22px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--yellow) 30%, transparent), 0 0 30px var(--yellow);
  animation: glow 1.6s ease-in-out infinite;
}
.bot-head {
  width: 190px; height: 140px;
  border-radius: 48px;
  background: linear-gradient(160deg, #9b7bff, var(--violet) 60%, var(--violet-d));
  display: flex; justify-content: center; align-items: center; gap: 30px;
  position: relative;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .12), var(--shadow-lg);
}
.bot-head::before {
  content: "";
  position: absolute; inset: 18px 20px 30px;
  border-radius: 30px;
  background: #241c52;
}
.bot-eye {
  position: relative;
  width: 34px; height: 40px;
  border-radius: 50%;
  background: #7ff0ff;
  box-shadow: 0 0 18px #7ff0ff;
  margin-top: -10px;
  animation: blink 5s infinite;
}
.bot-eye::after {
  content: "";
  position: absolute; top: 8px; left: 9px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
}
.bot-mouth {
  position: absolute; bottom: 38px; left: 50%;
  width: 46px; height: 22px;
  transform: translateX(-50%);
  border: 5px solid #7ff0ff;
  border-top: 0;
  border-radius: 0 0 30px 30px;
}
.bot-cheek { position: absolute; bottom: 44px; width: 18px; height: 10px; border-radius: 50%; background: var(--pink); opacity: .7; }
.bot-cheek.l { left: 30px; } .bot-cheek.r { right: 30px; }
.bot-body {
  width: 140px; height: 110px;
  margin: -6px auto 0;
  border-radius: 30px 30px 40px 40px;
  background: linear-gradient(160deg, #ff8cc0, var(--pink) 60%, var(--pink-d));
  display: grid; place-items: center;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .12);
}
.bot-body span {
  font-family: var(--font-title);
  font-weight: 800; font-size: 30px;
  background: var(--yellow);
  color: #3a2a00;
  padding: 0 12px;
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--yellow-d);
}
.bot-arm {
  position: absolute; top: 190px;
  width: 26px; height: 80px;
  border-radius: 14px;
  background: var(--pink);
  transform-origin: top center;
}
.bot-arm.l { left: 0; transform: rotate(20deg); }
.bot-arm.r { right: 0; transform: rotate(-150deg); animation: wave 1.4s ease-in-out infinite; }

.float-chip {
  position: absolute;
  font-family: var(--font-code);
  font-size: 14px; font-weight: 600;
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--code-bg);
  color: var(--code-ink);
  box-shadow: var(--shadow);
  animation: float 5s ease-in-out infinite;
  white-space: nowrap;
}
.float-chip i { font-style: normal; color: #ff7edb; }
.float-chip em { font-style: normal; color: #ffd479; }
.float-chip.c1 { top: 30px; left: 0; animation-delay: -1s; transform: rotate(-6deg); }
.float-chip.c2 { top: 70px; right: -10px; animation-delay: -2.5s; }
.float-chip.c3 { bottom: 50px; left: -10px; animation-delay: -3.5s; }
.float-chip.c4 { bottom: 20px; right: 10px; font-size: 30px; padding: 6px 12px; background: var(--surface); animation-delay: -.5s; }

@keyframes float { 50% { translate: 0 -14px; } }
@keyframes glow { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--yellow) 20%, transparent), 0 0 40px var(--yellow); } }
@keyframes blink { 0%, 46%, 50%, 100% { transform: scaleY(1); } 48% { transform: scaleY(.1); } }
@keyframes wave { 50% { transform: rotate(-120deg); } }

/* Sections de l'accueil */
.section { max-width: 1180px; margin: 0 auto 60px; }
.section-head { text-align: center; margin-bottom: 28px; }
.section-head h2 { font-size: clamp(28px, 3.4vw, 40px); margin-bottom: 6px; }
.section-head p { color: var(--ink-soft); margin: 0; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.step {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px;
  box-shadow: var(--shadow-sm);
  transition: transform .25s, box-shadow .25s;
}
.step:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.step-ico {
  width: 60px; height: 60px;
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: 30px;
  margin-bottom: 14px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
}
.step h3 { font-size: 22px; margin-bottom: 4px; }
.step p { color: var(--ink-soft); margin: 0; font-size: 16px; }
.step-n { position: absolute; top: 18px; right: 22px; font-family: var(--font-title); font-weight: 800; font-size: 40px; color: var(--surface-3); }

.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.lcard {
  --accent: var(--violet);
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  text-decoration: none;
  color: var(--ink);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s, border-color .25s;
}
.lcard::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 6px;
  background: var(--accent);
}
.lcard:hover { transform: translateY(-6px) rotate(-.6deg); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.lcard-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.lcard-emoji {
  width: 56px; height: 56px;
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: 30px;
  background: color-mix(in srgb, var(--accent) 15%, var(--surface));
}
.lcard-num { font-weight: 900; font-size: 13px; color: var(--muted); }
.lcard h3 { font-size: 20px; margin-bottom: 6px; }
.lcard p { font-size: 15px; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.5; }
.lcard-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 800; color: var(--muted); }
.lcard-status { padding: 3px 10px; border-radius: 99px; background: var(--surface-2); }
.lcard.done .lcard-status { background: color-mix(in srgb, var(--green) 18%, var(--surface)); color: var(--green-d); }

.cta-band {
  max-width: 1180px; margin: 0 auto;
  border-radius: var(--r-lg);
  padding: clamp(26px, 4vw, 44px);
  background: linear-gradient(120deg, var(--violet), var(--pink));
  color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
}
.cta-band::after {
  content: "{ }";
  position: absolute; right: 30px; bottom: -40px;
  font-family: var(--font-code); font-size: 160px; font-weight: 600;
  opacity: .12;
}
.cta-band h2 { font-size: clamp(26px, 3vw, 36px); margin: 0 0 4px; }
.cta-band p { margin: 0; opacity: .92; }

.site-foot { text-align: center; color: var(--muted); font-weight: 700; font-size: 14px; margin-top: 50px; }

/* ---------- 7b. Page de leçon ---------- */
.lesson { max-width: 860px; margin: 0 auto; }

.lesson-hero {
  position: relative;
  display: flex; gap: 24px; align-items: center;
  padding: clamp(22px, 4vw, 36px);
  border-radius: var(--r-lg);
  background:
    radial-gradient(circle at 90% 10%, rgba(255, 255, 255, .25), transparent 40%),
    linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--pink)));
  color: #fff;
  box-shadow: 0 24px 50px -24px var(--accent);
  margin-bottom: 34px;
  overflow: hidden;
}
.lesson-hero::after {
  content: "";
  position: absolute; right: -60px; bottom: -80px;
  width: 220px; height: 220px;
  border-radius: 50%;
  border: 30px solid rgba(255, 255, 255, .12);
}
.lh-emoji {
  flex: none;
  width: 96px; height: 96px;
  border-radius: 30px;
  display: grid; place-items: center;
  font-size: 54px;
  background: rgba(255, 255, 255, .22);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
  animation: float 4s ease-in-out infinite;
}
.lh-step {
  display: inline-block;
  font-weight: 900; font-size: 13px; letter-spacing: .06em; text-transform: uppercase;
  background: rgba(0, 0, 0, .18);
  padding: 3px 12px; border-radius: 99px;
  margin-bottom: 8px;
}
.lesson-hero h1 { font-size: clamp(30px, 4vw, 44px); margin-bottom: 6px; }
.lesson-hero p { margin: 0 0 12px; font-size: 18px; opacity: .95; }
.lh-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.lh-meta span { background: rgba(255, 255, 255, .2); padding: 4px 12px; border-radius: 99px; font-weight: 800; font-size: 14px; }

.lesson-body > p { font-size: 18px; }
.lesson-body > * + * { margin-top: 0; }

.sec-title {
  display: flex; align-items: center; gap: 12px;
  font-size: clamp(24px, 3vw, 30px);
  margin: 42px 0 16px;
}
.sec-title::before {
  content: "";
  width: 14px; height: 32px;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: 6px 0 0 color-mix(in srgb, var(--accent) 40%, transparent);
}

.nice-list { list-style: none; padding: 0; margin: 0 0 24px; display: grid; gap: 10px; }
.nice-list li {
  position: relative;
  padding: 12px 16px 12px 52px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  counter-increment: step;
}
.nice-list { counter-reset: step; }
.nice-list li::before {
  content: counter(step);
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 900; font-size: 14px;
}

/* Encadrés */
.box {
  --c: var(--violet);
  display: flex; gap: 16px;
  margin: 24px 0;
  padding: 18px 20px;
  border-radius: var(--r);
  background: color-mix(in srgb, var(--c) 10%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--c) 28%, transparent);
}
.box-ico {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 24px;
  background: var(--surface);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 30%, transparent);
}
.box h4 { font-size: 19px; margin: 2px 0 4px; color: color-mix(in srgb, var(--c) 70%, var(--ink)); }
.box p { margin: 0; }
.box-idea    { --c: #f5b400; }
.box-warn    { --c: #ff6b3d; }
.box-analogy { --c: #ff5fa2; }
.box-word    { --c: #3b82f6; }
.box-tip     { --c: #1fc28b; }
.box-next    { --c: var(--accent); }

/* Objectifs et « À retenir » */
.goals, .recap {
  margin: 26px 0;
  padding: 18px 22px;
  border-radius: var(--r);
  background: var(--surface);
  border: 2px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 22%, var(--line));
}
.goals h4, .recap h4 { font-size: 20px; margin: 0 0 10px; color: color-mix(in srgb, var(--accent) 75%, var(--ink)); }
.goals ul, .recap ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.goals li, .recap li { position: relative; padding-left: 32px; }
.goals li::before, .recap li::before {
  position: absolute; left: 0; top: 1px;
  width: 22px; height: 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 900;
  color: #fff;
  background: var(--accent);
}
.goals li::before { content: "→"; }
.recap li::before { content: "✓"; background: var(--green); }
.recap { background: color-mix(in srgb, var(--green) 7%, var(--surface)); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); box-shadow: 0 6px 0 color-mix(in srgb, var(--green) 25%, var(--line)); }
.recap h4 { color: color-mix(in srgb, var(--green) 60%, var(--ink)); }

/* L'arbre du DOM (leçon 12) */
.dom-tree {
  margin: 20px 0 26px;
  padding: 16px 20px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  font-family: var(--font-code);
  font-size: 15px;
  box-shadow: var(--shadow-sm);
}
.dom-tree div div {
  margin: 6px 0 0 14px;
  padding-left: 14px;
  border-left: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

/* Erreurs fréquentes */
.err-card {
  margin: 18px 0;
  padding: 16px 18px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.err-card h4 { font-size: 18px; margin: 0 0 10px; }
.err-card p { margin: 10px 0 0; color: var(--ink-soft); font-size: 16px; }
.err-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err-grid > div { border-radius: 14px; overflow: hidden; background: var(--code-bg); }
.err-grid > div > span { display: block; padding: 5px 12px; font-size: 13px; font-weight: 900; color: #fff; }
.err-bad > span { background: var(--red); }
.err-good > span { background: var(--green); }
.err-grid pre, .ex-lines pre { margin: 0; padding: 10px 12px; font: 14px/1.6 var(--font-code); color: var(--code-ink); white-space: pre; overflow-x: auto; }
.err-grid code, .ex-lines pre code { all: unset; font: inherit; white-space: pre; }

/* Ligne par ligne, sous les exemples */
.ex-lines {
  margin-top: 14px;
  border-radius: 16px;
  border: 2px dashed color-mix(in srgb, var(--accent) 35%, var(--line));
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.ex-lines summary {
  padding: 10px 16px;
  font-weight: 900;
  cursor: pointer;
  color: color-mix(in srgb, var(--accent) 75%, var(--ink));
}
.ex-lines ol { list-style: none; margin: 0; padding: 0 14px 14px; display: grid; gap: 10px; counter-reset: ligne; }
.ex-lines li { counter-increment: ligne; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 4px 10px; align-items: start; }
.ex-lines li::before {
  content: counter(ligne);
  grid-row: span 2;
  width: 28px; height: 28px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 900; font-size: 13px;
}
.ex-lines li pre { border-radius: 10px; background: var(--code-bg); }
.ex-lines li p { margin: 0; font-size: 15px; color: var(--ink-soft); }

/* HTML / CSS / JS */
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 24px 0; }
.trio-card {
  --c: var(--orange);
  text-align: center;
  padding: 22px 16px;
  border-radius: var(--r);
  background: var(--surface);
  border: 2px solid color-mix(in srgb, var(--c) 35%, var(--line));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--c) 35%, var(--line));
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
}
.trio-card:hover { transform: translateY(-5px) scale(1.02); }
.trio-card.t-css { --c: var(--blue); }
.trio-card.t-js  { --c: var(--yellow); }
.trio-ico { font-size: 40px; }
.trio-card h4 { font-size: 22px; margin: 4px 0; color: color-mix(in srgb, var(--c) 75%, var(--ink)); }
.trio-card p { font-size: 15px; color: var(--ink-soft); margin-bottom: 10px; }

/* Mini-cartes (symboles) */
.cards-mini { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0 26px; }
.mc {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 16px 12px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.mc b {
  font-family: var(--font-code);
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 4px;
  line-height: 1.3;
}
.mc span { font-weight: 800; }
.mc small { color: var(--muted); font-size: 13px; font-weight: 600; line-height: 1.4; }

/* Les boîtes-variables */
.boxes { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; margin: 24px 0 30px; }
.vbox { width: 150px; text-align: center; }
.vbox-lid {
  background: var(--orange); color: #fff;
  font-family: var(--font-code); font-weight: 600; font-size: 14px;
  padding: 6px; border-radius: 10px 10px 4px 4px;
  margin: 0 -6px;
  box-shadow: 0 4px 0 #d9682a;
  position: relative; z-index: 1;
}
.vbox-in {
  background: color-mix(in srgb, var(--orange) 16%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--orange) 40%, transparent);
  border-top: 0;
  padding: 22px 8px 16px;
  border-radius: 0 0 14px 14px;
  font-family: var(--font-code); font-weight: 600; font-size: 18px;
}

/* Le train */
.train { display: flex; align-items: flex-end; gap: 6px; margin: 24px 0 30px; overflow-x: auto; padding: 6px 4px 10px; }
.loco { font-size: 54px; line-height: 1; transform: scaleX(-1); }
.wagon {
  flex: none;
  width: 82px;
  text-align: center;
  background: var(--blue);
  border-radius: 14px 14px 8px 8px;
  padding: 10px 0 4px;
  position: relative;
  box-shadow: 0 5px 0 #2563eb;
}
.wagon span { display: grid; place-items: center; width: 54px; height: 44px; margin: 0 auto; background: var(--surface); border-radius: 10px; font-size: 26px; }
.wagon small { display: block; color: #fff; font-family: var(--font-code); font-weight: 600; font-size: 14px; margin-top: 2px; }
.wagon::before, .wagon::after { content: ""; position: absolute; bottom: -12px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 3px solid var(--surface-3); }
.wagon::before { left: 12px; } .wagon::after { right: 12px; }

/* Fiche d'identité */
.id-card {
  display: flex; gap: 18px; align-items: center;
  max-width: 420px;
  margin: 24px auto 30px;
  padding: 18px;
  border-radius: var(--r);
  background: var(--surface);
  border: 2px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  box-shadow: 0 8px 0 color-mix(in srgb, var(--accent) 25%, var(--line));
  transform: rotate(-1.5deg);
}
.id-photo { width: 90px; height: 90px; flex: none; border-radius: 20px; display: grid; place-items: center; font-size: 52px; background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.id-rows { flex: 1; display: grid; gap: 6px; }
.id-rows div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 2px dashed var(--line); padding-bottom: 4px; font-family: var(--font-code); font-size: 14px; }
.id-rows span { color: var(--muted); }

/* ---------- 8. Exemples & éditeur de code ---------- */
.example {
  margin: 30px 0;
  padding: 20px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.ex-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.ex-num {
  flex: none;
  display: grid; place-items: center;
  min-width: 44px; height: 44px;
  padding: 0 8px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-title); font-weight: 800; font-size: 14px; line-height: 1;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000);
}
.ex-head h3 { font-size: 21px; margin: 0 0 2px; }
.ex-head p { margin: 0; color: var(--ink-soft); font-size: 16px; }

.code-window {
  border-radius: 18px;
  overflow: hidden;
  background: var(--code-bg);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .04), 0 12px 30px -14px rgba(20, 10, 60, .6);
  display: flex; flex-direction: column;
}
.cw-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px;
  height: 44px;
  background: var(--code-bar);
  flex: none;
}
.dots { display: flex; gap: 6px; flex: none; }
.dots i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.dots i:nth-child(2) { background: #febc2e; }
.dots i:nth-child(3) { background: #28c840; }
.cw-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.cw-tab {
  --t: #ffd479;
  border: 0;
  background: transparent;
  color: #a9a3d6;
  font-family: var(--font);
  font-weight: 800; font-size: 13px;
  padding: 6px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.cw-tab[data-l="html"] { --t: #ff9f6b; }
.cw-tab[data-l="css"]  { --t: #7cc7ff; }
.cw-tab:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.cw-tab.on { color: #1d1838; background: var(--t); }
.cw-spacer { flex: 1; }
.cw-hint { color: #8d87bd; font-size: 12px; font-weight: 700; white-space: nowrap; }
.cw-body { position: relative; flex: 1; min-height: 0; }

.editor {
  position: relative;
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.7;
  tab-size: 2;
}
.editor pre,
.editor textarea {
  margin: 0;
  padding: 16px 18px;
  border: 0;
  font: inherit;
  letter-spacing: 0;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  tab-size: 2;
}
.editor pre {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none;
  color: var(--code-ink);
}
.editor pre code { all: unset; font: inherit; white-space: pre; }
.editor textarea {
  position: relative;
  display: block;
  width: 100%;
  min-height: 56px;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #ffd479;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #4a4380 transparent;
}
.editor.grow textarea { overflow-y: hidden; }
.editor textarea::selection { background: rgba(124, 77, 255, .5); -webkit-text-fill-color: transparent; }
.editor.fill { position: absolute; inset: 0; }
.editor.fill textarea { height: 100%; }

/* Couleurs du code */
.tk-k { color: #ff7edb; font-weight: 600; }
.tk-s { color: #a5f3a1; }
.tk-n { color: #ffb86c; }
.tk-c { color: #8079b3; font-style: italic; }
.tk-f { color: #7cc7ff; }
.tk-p { color: #c7b8ff; }
.tk-b { color: #ffb86c; font-weight: 600; }
.tk-tag { color: #ff7edb; }
.tk-attr { color: #ffd479; }
.tk-sel { color: #7cc7ff; font-weight: 600; }
.tk-prop { color: #a5f3a1; }
.tk-punct { color: #8d87bd; }

.ex-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.kbd-hint { color: var(--muted); font-size: 13px; font-weight: 700; margin-left: auto; }
.ex-note {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 15px;
}

/* ---------- 9. Résultat & console ---------- */
.ex-result { display: grid; gap: 12px; margin-top: 14px; animation: pop .35s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }

.pane { border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.pane-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px;
  font-size: 13px; font-weight: 900;
  letter-spacing: .02em;
  background: var(--surface-2);
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
.page-pane iframe { display: block; width: 100%; height: 80px; border: 0; background: #fff; transition: height .2s; }
.ghost-frame { display: none; }

.console { background: var(--code-bg); border-color: transparent; }
.console .pane-label { background: var(--code-bar); color: #b9b3e6; border-color: transparent; }
.console-lines {
  max-height: 260px;
  overflow: auto;
  padding: 8px 0;
  font-family: var(--font-code);
  font-size: 14px;
  color: var(--code-ink);
  scrollbar-width: thin;
}
.console-lines:empty::before {
  content: "La console est vide : Codi n'a rien à signaler 🙂";
  display: block;
  padding: 4px 16px;
  color: #7d77ad;
  font-family: var(--font);
  font-style: italic;
}
.log { display: flex; gap: 10px; padding: 5px 16px; border-bottom: 1px solid rgba(255, 255, 255, .04); animation: slidein .25s ease-out; white-space: pre-wrap; word-break: break-word; }
@keyframes slidein { from { opacity: 0; transform: translateX(-8px); } }
.log-ico { flex: none; color: #7d77ad; width: 16px; }
.v-number, .v-boolean { color: #ffb86c; }
.v-string { color: var(--code-ink); }
.v-undefined, .v-null { color: #8079b3; }
.v-object { color: #7cc7ff; }
.v-element { color: #ff7edb; }
.v-function { color: #c7b8ff; }
.log-warn { background: rgba(255, 200, 61, .08); color: #ffd479; }
.log-error { background: rgba(255, 90, 106, .12); }
.log-error b { display: block; color: #ffb3bb; font-family: var(--font); font-size: 15px; }
.log-error small { display: block; color: #ff8a96; opacity: .8; font-size: 12px; }
.log-error .log-ico { color: inherit; }

/* ---------- 10. Quiz, défi, fin ---------- */
.quiz, .challenge, .finish {
  margin: 40px 0 0;
  border-radius: var(--r-lg);
  padding: clamp(20px, 3vw, 30px);
}

.quiz {
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}
.quiz-tag {
  display: inline-flex; gap: 6px; align-items: center;
  font-weight: 900; font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--violet);
  background: color-mix(in srgb, var(--violet) 12%, var(--surface));
  padding: 4px 12px; border-radius: 99px;
  margin-bottom: 12px;
}
.quiz-q { font-family: var(--font-title); font-size: 22px; font-weight: 700; line-height: 1.5; }
.quiz-q code { white-space: normal; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 14px;
  text-align: left;
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
  transition: transform .15s, border-color .2s, background .2s;
}
.choice:hover:not(:disabled) { border-color: var(--violet); transform: translateY(-2px); }
.choice:disabled { cursor: default; }
.choice .letter {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--surface-2);
  font-weight: 900;
}
.choice.ok { border-color: var(--green); background: color-mix(in srgb, var(--green) 12%, var(--surface)); box-shadow: 0 4px 0 var(--green); }
.choice.ok .letter { background: var(--green); color: #fff; }
.choice.ko { border-color: var(--red); background: color-mix(in srgb, var(--red) 10%, var(--surface)); animation: shake .4s; }
.choice.ko .letter { background: var(--red); color: #fff; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.quiz-why { margin-top: 14px; padding: 12px 16px; border-radius: 14px; font-weight: 700; animation: pop .3s; }
.quiz-why.good { background: color-mix(in srgb, var(--green) 14%, var(--surface)); color: color-mix(in srgb, var(--green) 50%, var(--ink)); }
.quiz-why.bad { background: color-mix(in srgb, var(--red) 12%, var(--surface)); color: color-mix(in srgb, var(--red) 55%, var(--ink)); }

.challenge {
  display: flex; gap: 20px; align-items: flex-start;
  background:
    repeating-linear-gradient(-45deg, transparent 0 14px, rgba(255, 200, 61, .08) 14px 28px),
    color-mix(in srgb, var(--yellow) 14%, var(--surface));
  border: 2px dashed color-mix(in srgb, var(--yellow) 70%, var(--line));
}
.ch-ico {
  flex: none;
  width: 64px; height: 64px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 34px;
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--yellow-d);
  animation: float 3s ease-in-out infinite;
}
.challenge h3 { font-size: 24px; margin-bottom: 4px; }

.finish {
  text-align: center;
  background: linear-gradient(135deg, color-mix(in srgb, var(--green) 14%, var(--surface)), var(--surface));
  border: 2px solid color-mix(in srgb, var(--green) 30%, var(--line));
}
.finish h3 { font-size: 24px; margin-bottom: 4px; }
.finish p { color: var(--ink-soft); }
.finish.is-done .btn-run { --b: var(--surface-2); --b-d: var(--surface-3); --c: var(--ink-soft); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 26px; }
.pager a {
  display: flex; flex-direction: column;
  padding: 16px 20px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform .2s, border-color .2s;
}
.pager a:hover { transform: translateY(-3px); border-color: var(--violet); }
.pager small { color: var(--muted); font-weight: 800; font-size: 13px; }
.pager b { font-family: var(--font-title); font-size: 18px; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- 11. Labo ---------- */
.lab { max-width: 1500px; margin: 0 auto; }
.lab-hero {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 18px;
  margin-bottom: 20px;
}
.lab-hero h1 { font-size: clamp(30px, 4vw, 42px); margin-bottom: 2px; }
.lab-hero p { margin: 0; color: var(--ink-soft); }
.lab-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.select {
  display: flex; align-items: center; gap: 8px;
  padding: 0 6px 0 14px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 0 var(--line);
}
.select select {
  border: 0;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  max-width: 190px;
}

.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 46px; height: 26px;
  border-radius: 99px;
  background: var(--surface-3);
  position: relative;
  transition: background .2s;
}
.switch .track::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--violet); outline-offset: 2px; }

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  height: max(560px, calc(100vh - var(--topbar) - 190px));
}
.lab-col { min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.lab-editors .code-window { flex: 1; min-height: 0; }

.browser {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  border-radius: 18px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.browser-bar {
  display: flex; align-items: center; gap: 12px;
  height: 44px;
  padding: 0 10px 0 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.url {
  flex: 1; min-width: 0;
  background: var(--surface);
  border-radius: 99px;
  padding: 4px 14px;
  font-size: 13px; font-weight: 700;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }
.browser iframe { flex: 1; width: 100%; border: 0; background: #fff; }

.lab-console { flex: none; display: flex; flex-direction: column; }
.lab-console .console-lines { height: 170px; max-height: none; }
.mini {
  border: 0;
  background: rgba(255, 255, 255, .08);
  color: inherit;
  font: inherit; font-size: 12px;
  padding: 2px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.mini:hover { background: rgba(255, 255, 255, .16); }

.run-flash { animation: flash .5s; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--green); } 100% { box-shadow: 0 0 0 14px transparent; } }

/* ---------- 12. Confettis & toast ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
#confetti span {
  position: absolute; top: -40px;
  font-size: 24px;
  animation: fall var(--d, 2s) cubic-bezier(.25, .6, .5, 1) forwards;
}
@keyframes fall { to { transform: translate(var(--x, 0), 110vh) rotate(var(--r, 360deg)); } }

#toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 150;
  transform: translate(-50%, calc(100% + 60px));
  visibility: hidden;
  padding: 12px 22px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--surface);
  font-weight: 800;
  box-shadow: var(--shadow-lg);
  transition: transform .4s cubic-bezier(.34, 1.56, .64, 1), visibility 0s .4s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; transition-delay: 0s; }

/* ---------- 12b. Lecture à voix haute ---------- */
.btn-listen {
  --b: #fff;
  --b-d: rgba(0, 0, 0, .18);
  --c: #271f4d;
  margin-top: 14px;
}
body.no-tts .btn-listen, body.no-tts .say { display: none; }

.say {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  margin-left: 8px;
  padding: 0;
  vertical-align: middle;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 15%, var(--surface));
  color: inherit;
  font-size: 14px; line-height: 1;
  cursor: pointer;
  transition: transform .2s, background .2s;
}
.say:hover { transform: scale(1.15); background: color-mix(in srgb, var(--accent) 28%, var(--surface)); }
.sec-title .say { width: 36px; height: 36px; font-size: 17px; }
.quiz-tag .say, .ex-head .say { width: 28px; height: 28px; font-size: 13px; }

.say-able { transition: outline-color .3s; outline: 3px solid transparent; outline-offset: 8px; border-radius: 14px; }
.say-able.reading { outline-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.reading .say { background: var(--accent); animation: beat 1s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.18); } }

.reader {
  position: fixed; left: 50%; bottom: 18px; z-index: 140;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 16px;
  border-radius: 999px;
  background: #271f4d;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: var(--shadow-lg);
  animation: pop .35s cubic-bezier(.34, 1.56, .64, 1);
  max-width: calc(100vw - 24px);
}
.reader-label { font-weight: 800; white-space: nowrap; }
.reader-wave { display: flex; align-items: center; gap: 3px; height: 22px; }
.reader-wave i { width: 4px; height: 100%; border-radius: 4px; background: var(--yellow); animation: wave-bar .9s ease-in-out infinite; }
.reader-wave i:nth-child(2) { animation-delay: -.2s; background: var(--pink); }
.reader-wave i:nth-child(3) { animation-delay: -.4s; background: var(--green); }
.reader-wave i:nth-child(4) { animation-delay: -.6s; background: #7cc7ff; }
.reader.is-paused .reader-wave i { animation-play-state: paused; }
@keyframes wave-bar { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
.rd-btn {
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: inherit;
  font-size: 16px;
  cursor: pointer;
}
.rd-btn:hover { background: rgba(255, 255, 255, .26); }
.reader select {
  height: 38px;
  border: 0; border-radius: 99px;
  padding: 0 12px;
  background: rgba(255, 255, 255, .14);
  color: inherit;
  font: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
  max-width: 150px;
}
.reader select option { color: #271f4d; background: #fff; }
body.reading-on #toast { bottom: 90px; }
body.reading-on .main { padding-bottom: 120px; }

/* ---------- 12c. Les assistants : Codi et Claude ---------- */
.codi-fab, .codi-panel, .codi-sel { --cp-a: var(--violet); --cp-b: var(--pink); --cp-d: var(--violet-d); }
.is-claude { --cp-a: #d97757; --cp-b: #eda15f; --cp-d: #b4583c; }
.codi-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 130;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px 8px 8px;
  border: 0; border-radius: 999px;
  background: linear-gradient(135deg, var(--cp-a), var(--cp-b));
  color: #fff;
  font: 800 16px var(--font);
  cursor: pointer;
  box-shadow: 0 6px 0 var(--cp-d), 0 18px 34px -12px var(--cp-a);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), bottom .3s;
}
.codi-fab:hover { transform: translateY(-3px) scale(1.03); }
.codi-fab:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--cp-d); }
.fab-bot {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  font-size: 24px;
  animation: float 3s ease-in-out infinite;
}
body.assistant-open .codi-fab { display: none; }
body.reading-on .codi-fab { bottom: 86px; }

.codi-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 135;
  width: min(420px, calc(100vw - 36px));
  height: min(640px, calc(100vh - var(--topbar) - 36px));
  display: flex; flex-direction: column;
  border-radius: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg), 0 0 0 6px color-mix(in srgb, var(--cp-a) 10%, transparent);
  overflow: hidden;
  animation: pop .3s cubic-bezier(.34, 1.56, .64, 1);
}
body.reading-on .codi-panel { bottom: 84px; height: min(600px, calc(100vh - var(--topbar) - 104px)); }

.cp-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 14px;
  background: linear-gradient(135deg, var(--cp-a), var(--cp-b));
  color: #fff;
  flex: none;
}
.cp-title { flex: 1; min-width: 0; line-height: 1.2; }
.cp-title b { display: block; font-family: var(--font-title); font-size: 19px; }
.cp-title small { font-weight: 700; opacity: .92; cursor: help; }
.cp-avatar {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 24px;
  background: rgba(255, 255, 255, .22);
}
.cp-avatar.sm { width: 32px; height: 32px; border-radius: 11px; font-size: 18px; background: color-mix(in srgb, var(--cp-a) 14%, var(--surface)); }
.cp-icon {
  width: 36px; height: 36px;
  border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.cp-icon:hover { background: rgba(255, 255, 255, .3); }

.cp-msgs {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex; flex-direction: column; gap: 12px;
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--pink) 8%, transparent), transparent 40%),
    var(--bg);
  scrollbar-width: thin;
}
.cp-msg { display: flex; gap: 8px; align-items: flex-end; animation: slidein .25s ease-out; }
.cp-msg.me { justify-content: flex-end; }
.cp-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.cp-msg.me .cp-bubble { background: var(--cp-a); color: #fff; border-bottom-right-radius: 6px; }
.cp-msg.me small { display: block; opacity: .8; font-size: 12px; }
.cp-msg.bot .cp-bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm); }
.cp-bubble p { margin: 0 0 8px; }
.cp-bubble p:last-of-type { margin-bottom: 0; }
.cp-bubble code { white-space: normal; }
.cp-list { margin: 6px 0; padding-left: 20px; }
.cp-list li { margin-bottom: 4px; }
.cp-code, .cp-bubble pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--code-bg);
  color: var(--code-ink);
  font: 13px/1.6 var(--font-code);
  overflow-x: auto;
  white-space: pre;
}
.cp-code code { all: unset; font: inherit; white-space: pre; }
.cp-link { display: inline-block; margin-top: 8px; font-weight: 800; font-size: 14px; text-decoration: none; }
.cp-tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.cp-say {
  border: 0;
  background: var(--surface-2);
  color: var(--ink-soft);
  font: 800 12px var(--font);
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
}
.cp-say:hover { background: var(--surface-3); }
.cp-bubble.reading .cp-say { background: var(--cp-a); color: #fff; }
.cp-source { margin-left: auto; font-size: 11px; font-weight: 800; color: var(--muted); }
.cp-note { align-self: center; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); padding: 2px 10px; }

.cp-thinking .cp-bubble { display: flex; gap: 5px; padding: 14px 16px; }
.cp-thinking .cp-bubble span { width: 8px; height: 8px; border-radius: 50%; background: var(--cp-a); animation: bounce 1s infinite; }
.cp-thinking .cp-bubble span:nth-child(2) { animation-delay: .15s; background: var(--pink); }
.cp-thinking .cp-bubble span:nth-child(3) { animation-delay: .3s; background: var(--yellow); }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-7px); } }

.cp-chips {
  display: flex; gap: 6px;
  padding: 8px 12px 0;
  overflow-x: auto;
  flex: none;
  scrollbar-width: none;
  background: var(--surface);
}
.cp-chips:empty { display: none; }
.cp-chip {
  flex: none;
  border: 1px solid color-mix(in srgb, var(--cp-a) 30%, var(--line));
  background: color-mix(in srgb, var(--cp-a) 8%, var(--surface));
  color: var(--ink);
  font: 700 13px var(--font);
  padding: 6px 12px;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
}
.cp-chip:hover { background: color-mix(in srgb, var(--cp-a) 18%, var(--surface)); }

.cp-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px 12px; background: var(--surface); flex: none; }
.cp-form textarea {
  flex: 1;
  resize: none;
  min-height: 44px; max-height: 120px;
  padding: 11px 14px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: 600 15px/1.4 var(--font);
  outline: none;
}
.cp-form textarea:focus { border-color: var(--cp-a); }
.cp-send {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 14px;
  background: var(--cp-a);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--cp-d);
}
.cp-send:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cp-d); }
.codi-panel.is-busy .cp-send { opacity: .5; pointer-events: none; }

/* bouton qui apparaît sur un mot sélectionné */
.codi-sel {
  position: fixed; z-index: 120;
  border: 0;
  padding: 8px 14px;
  border-radius: 99px;
  background: #271f4d;
  color: #fff;
  font: 800 14px var(--font);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  animation: pop .25s cubic-bezier(.34, 1.56, .64, 1);
}
.codi-sel::after {
  content: "";
  position: absolute; left: 50%; bottom: -6px;
  width: 12px; height: 12px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
  z-index: -1;
}

/* mots de code cliquables */
code.gloss {
  cursor: help;
  border-bottom: 2px dotted color-mix(in srgb, var(--accent) 60%, transparent);
  transition: background .2s;
}
code.gloss:hover, code.gloss:focus-visible { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }

.log-help {
  margin-top: 6px;
  border: 0;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font: 800 12px var(--font);
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
}
.log-help:hover { background: rgba(255, 255, 255, .22); }
.log-help + .log-help { margin-left: 6px; }

/* Claude : bouton au-dessus de celui de Codi */
.codi-fab.is-claude { bottom: 96px; padding-right: 22px; }
.codi-fab.is-claude .fab-bot { animation: none; font-size: 22px; }
body.reading-on .codi-fab.is-claude { bottom: 160px; }
.cp-h { font-family: var(--font-title); font-weight: 800; font-size: 16px; margin: 10px 0 4px !important; color: var(--cp-a); }
ol.cp-list { padding-left: 22px; }

/* la bulle de sélection contient deux boutons : Codi et Claude */
.codi-sel { display: flex; gap: 4px; padding: 4px; }
.codi-sel[hidden] { display: none; }
.codi-sel button {
  border: 0;
  padding: 6px 12px;
  border-radius: 99px;
  background: transparent;
  color: #fff;
  font: 800 14px var(--font);
  cursor: pointer;
}
.codi-sel button:hover { background: rgba(255, 255, 255, .16); }
.codi-sel button[data-to="claude"] { background: #d97757; }
.codi-sel button[data-to="claude"]:hover { background: #e58a6b; }

/* ---------- 13. Responsive ---------- */

/* Mode tiroir : la barre latérale glisse depuis la gauche
   (sur petit écran, ou dans le labo pour avoir plus de place) */
body.drawer .layout { grid-template-columns: minmax(0, 1fr); }
body.drawer .burger { display: grid; }
body.drawer .sidebar {
  position: fixed; top: var(--topbar); left: 0; z-index: 60;
  width: min(320px, 86vw);
  background: var(--surface);
  transform: translateX(-105%);
  transition: transform .35s cubic-bezier(.4, 0, .2, 1);
  box-shadow: var(--shadow-lg);
}
body.drawer.drawer-open .sidebar { transform: none; }
body.drawer .scrim {
  display: block;
  position: fixed; inset: var(--topbar) 0 0; z-index: 55;
  background: rgba(15, 10, 40, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
body.drawer.drawer-open .scrim { opacity: 1; pointer-events: auto; }

@media (max-width: 1100px) {
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero-text { display: flex; flex-direction: column; align-items: center; }
  .hero-cta, .hero-stats { justify-content: center; }
  .hero-art { height: 360px; order: -1; }
  .lab-grid { grid-template-columns: 1fr; height: auto; }
  .lab-editors .code-window { height: 420px; flex: none; }
  .browser { height: 420px; flex: none; }
}

@media (max-width: 760px) {
  :root { --topbar: 62px; }
  body { font-size: 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .logo-bot { width: 38px; height: 38px; font-size: 22px; }
  .logo-text { font-size: 22px; }
  .topnav a { padding: 8px 10px; }
  .topnav .lbl { display: none; }
  .topnav .ico { font-size: 20px; }
  .top-progress { display: none; }
  .theme-toggle, .burger { width: 40px; height: 40px; }

  .main { padding: 22px 16px 60px; }
  .steps { grid-template-columns: 1fr; }
  .trio { grid-template-columns: 1fr; }
  .hero-art { height: 300px; transform: scale(.8); margin: -30px 0; }
  .float-chip.c1 { left: 10px; } .float-chip.c2 { right: 0; } .float-chip.c3 { left: 0; }

  .lesson-hero { flex-direction: column; text-align: center; }
  .lh-meta { justify-content: center; }
  .lh-emoji { width: 80px; height: 80px; font-size: 44px; }
  .lesson-body > p { font-size: 17px; }

  .example { padding: 14px; margin: 24px -4px; border-radius: 22px; }
  .editor { font-size: 13px; }
  .editor pre, .editor textarea { padding: 14px; }
  .kbd-hint, .cw-hint { display: none; }
  .ex-actions .btn { flex: 1 1 auto; }

  .challenge { flex-direction: column; }
  .err-grid { grid-template-columns: 1fr; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: auto; }
  .box { flex-direction: column; gap: 10px; }

  .lab-tools { width: 100%; }
  .lab-tools .select { flex: 1 1 100%; justify-content: space-between; }
  .select select { max-width: none; flex: 1; }
  .lab-tools .btn { flex: 1; }
  .lab-editors .code-window { height: 360px; }
  .browser { height: 340px; }

  .reader { gap: 6px; padding-left: 12px; }
  .reader-label, #rdVoice { display: none; }

  .codi-fab { right: 14px; bottom: 14px; padding: 6px; }
  .codi-fab.is-claude { bottom: 78px; padding: 6px; }
  body.reading-on .codi-fab.is-claude { bottom: 142px; }
  .fab-label { display: none; }
  .codi-panel, body.reading-on .codi-panel {
    inset: var(--topbar) 0 0 0;
    width: 100%; height: auto;
    border-radius: 0;
    border: 0;
  }
  body.reading-on .codi-panel { bottom: 76px; }
}

@media (max-width: 420px) {
  .logo-text { display: none; }
}

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