/* =========================================================
   Bases du Web — styles du cours
   ========================================================= */
:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f0f1f7;
  --text: #1c1d26; --muted: #5d6075; --border: #e2e4ee;
  --accent: #5b5bf0; --html: #e2522c; --css: #2f6bef; --js: #d9a400; --proj: #16a37b; --vsc: #0078d4;
  --ok: #1b9a5a; --ok-bg: #e8f7ef; --ko: #d23f3f; --ko-bg: #fdecec;
  --tip: #2f6bef; --tip-bg: #edf3ff; --warn: #b86f00; --warn-bg: #fff5e1;
  --code-bg: #1d1f2b; --code-bar: #151620; --code-text: #e4e6f0; --inline-code: #eceef6;
  --shadow: 0 1px 2px rgb(20 20 40 / .06), 0 6px 20px rgb(20 20 40 / .05);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --sec: var(--accent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131a; --surface: #1a1b24; --surface-2: #22242f;
    --text: #e7e8ef; --muted: #9a9db2; --border: #2c2e3b;
    --accent: #8b8bff; --html: #ff7a52; --css: #6b9bff; --js: #f2c94c; --proj: #3ccf9f; --vsc: #4aa8ff;
    --ok: #4cd38a; --ok-bg: #15291f; --ko: #ff7676; --ko-bg: #2d1719;
    --tip: #7ea6ff; --tip-bg: #18223a; --warn: #f2b64c; --warn-bg: #2d2415;
    --inline-code: #262836; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12131a; --surface: #1a1b24; --surface-2: #22242f;
  --text: #e7e8ef; --muted: #9a9db2; --border: #2c2e3b;
  --accent: #8b8bff; --html: #ff7a52; --css: #6b9bff; --js: #f2c94c; --proj: #3ccf9f; --vsc: #4aa8ff;
  --ok: #4cd38a; --ok-bg: #15291f; --ko: #ff7676; --ko-bg: #2d1719;
  --tip: #7ea6ff; --tip-bg: #18223a; --warn: #f2b64c; --warn-bg: #2d2415;
  --inline-code: #262836; --shadow: none; color-scheme: dark;
}
body[data-section="html"] { --sec: var(--html); }
body[data-section="css"]  { --sec: var(--css); }
body[data-section="js"]   { --sec: var(--js); }
body[data-section="projet"] { --sec: var(--proj); }
body[data-section="vscode"] { --sec: var(--vsc); }

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 20px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.65 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
img { max-width: 100%; }

/* ---------- Mise en page ---------- */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 22px 16px 30px; display: flex; flex-direction: column; gap: 18px;
}
.content { padding: 28px clamp(16px, 4vw, 56px) 80px; min-width: 0; }
.content > main, .content > .pager, .content > .topbar { max-width: 1040px; margin-inline: auto; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 750; font-size: 1.1rem; }
.brand .logo {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--html), var(--css) 55%, var(--js));
  color: #fff; font: 700 14px var(--mono);
}
.progress small { color: var(--muted); font-size: .8rem; }
.progress .bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 4px; }
.progress .bar span { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .4s; }

.nav-sec h4 {
  margin: 0 0 6px; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: 8px;
}
.nav-sec h4::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--c); }
.nav-sec ol { list-style: none; margin: 0; padding: 0; counter-reset: l; }
.nav-sec li a {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: .92rem; line-height: 1.35;
}
.nav-sec li a:hover { background: var(--surface-2); }
.nav-sec li a.current { background: color-mix(in srgb, var(--c) 14%, transparent); font-weight: 650; }
.nav-sec li a .st {
  flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border);
  display: grid; place-items: center; font-size: 11px; color: #fff;
}
.nav-sec li a.done .st { background: var(--ok); border-color: var(--ok); }
.nav-sec li a.done .st::after { content: "✓"; }
.side-foot { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.side-foot .author { flex-basis: 100%; margin: 4px 2px 0; font-size: .8rem; color: var(--muted); }
.side-foot .author a { color: var(--text); font-weight: 600; }
.btn.support { background: #ffc439; border-color: #f0b429; color: #1c1d26; }
.btn.support:hover { background: #ffd261; }
.soutien { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; justify-content: space-between; }
.soutien p { margin: 4px 0 0; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 600 .88rem var(--font); padding: 8px 14px; border-radius: 9px; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--sec); border-color: var(--sec); color: #fff; }
body[data-section="js"] .btn.primary { color: #1c1d26; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn:disabled { opacity: .6; cursor: progress; }

.topbar { display: none; align-items: center; gap: 12px; margin-bottom: 18px; }
.menu-btn { font-size: 1.2rem; padding: 6px 12px; }
.scrim { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 290px; z-index: 50;
    transform: translateX(-105%); transition: transform .25s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 40; }
  .topbar { display: flex; }
}

/* ---------- Typographie de la leçon ---------- */
.lesson h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.15; margin: 6px 0 10px; letter-spacing: -.02em; }
.kicker {
  display: inline-block; font: 700 .75rem var(--font); letter-spacing: .08em; text-transform: uppercase;
  color: var(--sec); background: color-mix(in srgb, var(--sec) 12%, transparent);
  padding: 4px 10px; border-radius: 99px;
}
.lead { font-size: 1.12rem; color: var(--muted); max-width: 70ch; margin-top: 0; }
.lesson h2 {
  font-size: 1.45rem; margin: 52px 0 12px; padding-top: 22px; border-top: 1px solid var(--border);
  letter-spacing: -.01em;
}
.lesson h2 .num { color: var(--sec); margin-right: 6px; }
.lesson h3 { font-size: 1.12rem; margin: 26px 0 8px; }
.lesson p, .lesson li { max-width: 75ch; }
.lesson ul, .lesson ol { padding-left: 1.3em; }
.lesson li { margin: 3px 0; }

code {
  font: .88em var(--mono); background: var(--inline-code); padding: .12em .4em; border-radius: 5px;
}
pre.code {
  background: var(--code-bg); color: var(--code-text); padding: 14px 18px; border-radius: 10px;
  overflow-x: auto; font: 14px/1.55 var(--mono); margin: 14px 0;
}
pre.code code { background: none; padding: 0; font: inherit; }
pre.code .c { color: #7f8499; font-style: italic; }
kbd {
  font: 600 .8em var(--mono); background: var(--surface); border: 1px solid var(--border);
  border-bottom-width: 3px; padding: 1px 6px; border-radius: 6px;
}

.tip, .warn {
  border-left: 4px solid var(--tip); background: var(--tip-bg); padding: 10px 16px;
  border-radius: 0 10px 10px 0; margin: 16px 0; max-width: 75ch;
}
.warn { border-color: var(--warn); background: var(--warn-bg); }
.tip > b:first-child, .warn > b:first-child { color: var(--tip); margin-right: 4px; }
.warn > b:first-child { color: var(--warn); }

/* Grille de mini-fiches */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin: 16px 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card h4 { margin: 0 0 4px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: .92rem; }
.card code { font-size: .85em; }

/* Tableau de référence */
.ref { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: .93rem; background: var(--surface); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.ref th, .ref td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ref th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ref tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* À retenir */
.recap {
  background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--sec);
  border-radius: var(--radius); padding: 16px 22px; margin: 40px 0 10px; box-shadow: var(--shadow);
}
.recap h2 { border: 0; margin: 0 0 6px; padding: 0; font-size: 1.15rem; }
.recap ul { margin: 0; }

/* ---------- Playground (éditeur + aperçu) ---------- */
.pg {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); height: var(--h, 280px);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  margin: 16px 0; background: var(--surface); box-shadow: var(--shadow);
}
.pg { transition: height .2s ease; }
.pg.stack { grid-template-columns: 1fr; grid-template-rows: var(--h-ed, var(--h)) var(--h-out, var(--h)); height: auto; }
.pg-editor { display: flex; flex-direction: column; background: var(--code-bg); min-height: 0; min-width: 0; }
.pg-tabs { display: flex; align-items: flex-end; gap: 2px; padding: 6px 6px 0; background: var(--code-bar); }
.pg-tab {
  border: 0; background: transparent; color: #9097b3; cursor: pointer;
  font: 700 12px var(--mono); padding: 7px 14px 6px; border-radius: 7px 7px 0 0;
}
.pg-tab:hover { color: #fff; }
.pg-tab.active { background: var(--code-bg); color: #fff; }
.pg-tab.active[data-lang="html"] { box-shadow: inset 0 2px #ff7a52; }
.pg-tab.active[data-lang="css"] { box-shadow: inset 0 2px #6b9bff; }
.pg-tab.active[data-lang="js"] { box-shadow: inset 0 2px #f2c94c; }
.pg-tools { margin-left: auto; display: flex; gap: 4px; padding-bottom: 5px; }
.pg-tools button {
  border: 0; background: #262939; color: #c9cde0; cursor: pointer; border-radius: 6px;
  font: 600 12px var(--font); padding: 4px 10px;
}
.pg-tools button:hover { background: #33374b; color: #fff; }
.pg-tools .run { background: #2b7a4b; color: #fff; }
.pg-tools .run:hover { background: #33935a; }
.pg-panes { position: relative; flex: 1; min-height: 0; }
.pg-panes textarea {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: 0;
  background: transparent; color: var(--code-text); caret-color: #fff;
  font: 14px/1.6 var(--mono); padding: 12px 14px; tab-size: 2; white-space: pre; overflow: auto;
}
.pg-panes textarea::selection { background: #3d4466; }
.pg-panes textarea:not(.active) { display: none; }
.pg-output { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-left: 1px solid var(--border); }
.pg.stack .pg-output { border-left: 0; border-top: 1px solid var(--border); }
.pg-bar {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--border);
  font: 700 11px var(--font); letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2);
}
.pg-bar .dots { display: flex; gap: 5px; }
.pg-bar .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.pg-bar input[type="range"] { margin-left: auto; width: 140px; }
.pg-bar output { font: 600 12px var(--mono); text-transform: none; letter-spacing: 0; min-width: 52px; text-align: right; }
.pg-frame { flex: 1; min-height: 0; overflow: auto; background: #fff; }
.pg-frame iframe { display: block; border: 0; width: 100%; height: 100%; background: #fff; }
.pg-resizable .pg-frame { background: repeating-linear-gradient(45deg, var(--surface-2) 0 8px, var(--surface) 8px 16px); }
.pg-resizable .pg-frame iframe { box-shadow: 0 0 0 1px var(--border); }
.pg-console {
  margin: 0; overflow: auto; background: #11121a; color: #d7dae6;
  font: 13px/1.55 var(--mono); padding: 6px 0; flex: 0 0 130px; min-height: 60px;
}
.pg-console-only .pg-console { flex: 1; }
.pg-console-only .pg-frame { display: none; }
.pg-console .line { padding: 1px 12px; white-space: pre-wrap; word-break: break-word; border-bottom: 1px solid #1c1e2a; }
.pg-console .line::before { content: "› "; color: #5c627d; }
.pg-console .empty { color: #5c627d; padding: 2px 12px; font-style: italic; }
.pg-console .error { color: #ff8a8a; background: #2a1518; }
.pg-console .warn { color: #f2c94c; }
.pg-console .info { color: #8fb4ff; }

@media (max-width: 760px) {
  .pg { grid-template-columns: 1fr; grid-template-rows: var(--h-ed, var(--h)) var(--h-out, var(--h)); height: auto; }
  .pg-output { border-left: 0; border-top: 1px solid var(--border); }
}

/* ---------- Exercices ---------- */
.exercise {
  position: relative; margin: 28px 0; padding: 18px 20px 16px; background: var(--surface);
  border: 1px solid var(--border); border-left: 5px solid var(--sec); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.ex-label {
  display: inline-flex; align-items: center; gap: 6px;
  font: 800 .72rem var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--sec);
}
.exercise.done .ex-label::after {
  content: "✓ réussi"; background: var(--ok); color: #fff; padding: 1px 8px; border-radius: 99px; letter-spacing: .04em;
}
.exercise h3 { margin: 2px 0 6px; }
.exercise > p { margin: 6px 0; }
.exercise .todo { margin: 8px 0; padding-left: 1.2em; }
.exercise .todo li::marker { content: "☐  "; color: var(--muted); }
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ex-results { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.ex-results li { padding: 6px 12px; border-radius: 8px; font-size: .93rem; max-width: none; }
.ex-results li.ok { background: var(--ok-bg); color: var(--ok); }
.ex-results li.ko { background: var(--ko-bg); color: var(--ko); }
.ex-results li.ok::before { content: "✓  "; font-weight: 800; }
.ex-results li.ko::before { content: "✗  "; font-weight: 800; }
.ex-results li.bravo { background: var(--ok); color: #fff; font-weight: 700; }
.ex-results li.bravo::before { content: "🎉  "; }
.hints { display: grid; gap: 6px; margin: 12px 0 2px; }
details.hint { border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); max-width: 75ch; }
details.hint summary { cursor: pointer; color: var(--muted); font-weight: 650; font-size: .9rem; padding: 7px 12px; list-style-position: inside; }
details.hint summary::before { content: "💡 "; }
details.hint summary:hover { color: var(--text); }
details.hint[open] { background: var(--tip-bg); border-color: color-mix(in srgb, var(--tip) 35%, transparent); }
details.hint[open] summary { color: var(--tip); }
details.hint > :not(summary) { margin: 0 14px 10px; }
details.hint > .txt { display: block; }
details.hint pre.code { margin-top: 6px; font-size: 13px; }

/* ---------- Quiz ---------- */
.quiz {
  margin: 22px 0; padding: 16px 20px; background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.quiz .q { font-weight: 650; margin: 0 0 10px; }
.quiz .q::before { content: "❓ "; }
.quiz .opts { display: grid; gap: 6px; }
.quiz .opts button {
  text-align: left; cursor: pointer; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); padding: 8px 14px; border-radius: 9px;
}
.quiz .opts button:hover:not(:disabled) { border-color: var(--sec); }
.quiz .opts button:disabled { cursor: default; }
.quiz .opts button.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 650; }
.quiz .opts button.wrong { background: var(--ko-bg); border-color: var(--ko); color: var(--ko); text-decoration: line-through; }
.quiz .explain { display: none; margin: 10px 0 0; color: var(--muted); font-size: .94rem; }
.quiz.answered .explain { display: block; }

/* ---------- Démo interactive (contrôles → CSS) ---------- */
.demo {
  display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 0; margin: 18px 0;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface);
  box-shadow: var(--shadow);
}
.demo-controls { padding: 14px 16px; display: grid; gap: 12px; align-content: start; border-right: 1px solid var(--border); background: var(--surface-2); }
.demo-controls label { display: grid; gap: 3px; font: 600 12px var(--mono); color: var(--muted); }
.demo-controls label span { display: flex; justify-content: space-between; }
.demo-controls output { color: var(--sec); }
.demo-controls select, .demo-controls input[type="text"] {
  font: 13px var(--mono); padding: 5px 8px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.demo-controls input[type="color"] { width: 100%; height: 30px; border: 0; background: none; padding: 0; }
.demo-main { display: flex; flex-direction: column; min-width: 0; }
.demo-stage { flex: 1; padding: 18px; min-height: 200px; overflow: auto; }
.demo-code { margin: 0; border-radius: 0; font-size: 13px; }
@media (max-width: 700px) {
  .demo { grid-template-columns: 1fr; }
  .demo-controls { border-right: 0; border-bottom: 1px solid var(--border); }
}
/* éléments génériques pour les scènes */
.demo-stage .box {
  background: color-mix(in srgb, var(--sec) 22%, var(--surface)); border: 2px solid var(--sec);
  border-radius: 8px; padding: 10px 14px; font: 700 14px var(--mono); color: var(--text);
  display: grid; place-items: center;
}
.demo-stage .container { background: var(--surface-2); border: 2px dashed var(--border); border-radius: 10px; padding: 8px; min-height: 180px; }

/* ---------- Pager ---------- */
.pager {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px;
  margin-top: 56px; padding-top: 22px; border-top: 1px solid var(--border);
}
.pager a.nav {
  display: grid; gap: 2px; text-decoration: none; color: var(--text); padding: 10px 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-width: 180px;
}
.pager a.nav:hover { border-color: var(--sec); }
.pager a.nav small { color: var(--muted); font-size: .78rem; }
.pager a.next { text-align: right; }

/* ---------- Accueil ---------- */
.hero { padding: 26px 0 8px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: 10px 0; letter-spacing: -.03em; line-height: 1.08; }
.hero h1 .g { background: linear-gradient(90deg, var(--html), var(--css), var(--js)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.steps { counter-reset: s; }
.steps .card { position: relative; padding-left: 58px; }
.steps .card::before {
  counter-increment: s; content: counter(s); position: absolute; left: 16px; top: 14px;
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800;
}
.toc { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; margin: 18px 0; }
.toc-sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); border-top: 5px solid var(--c); }
.toc-sec h3 { margin: 0 0 2px; }
.toc-sec p { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
.toc-sec ol { margin: 0; padding-left: 1.4em; }
.toc-sec li { margin: 4px 0; }
.toc-sec li.done a::after { content: " ✓"; color: var(--ok); font-weight: 800; }

/* Pas de ligatures dans le code (=> doit rester =>) */
code, pre, pre *, textarea, kbd, .demo-controls, .pg-console { font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; }

/* ---------- Mission (étapes à cocher sur son ordinateur) ---------- */
.mission {
  list-style: none; padding: 16px 18px 12px; margin: 16px 0 6px; background: var(--surface);
  border: 2px dashed color-mix(in srgb, var(--sec) 45%, var(--border)); border-radius: var(--radius);
  display: grid; gap: 4px;
}
.mission::before { content: "🎯 Mission sur ton ordinateur"; font: 800 .75rem var(--font); letter-spacing: .07em; text-transform: uppercase; color: var(--sec); margin-bottom: 4px; }
.mission li { margin: 0; max-width: none; }
.mission label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 5px 8px; border-radius: 8px; }
.mission label:hover { background: var(--surface-2); }
.mission input { width: 18px; height: 18px; margin-top: 3px; flex: none; accent-color: var(--ok); }
.mission input:checked + * , .mission li:has(input:checked) label { color: var(--muted); }
.mission li:has(input:checked) label { text-decoration: line-through; text-decoration-color: var(--muted); }
.mission.complete { border-style: solid; border-color: var(--ok); }
.mission-status { margin: 0 0 16px; font-weight: 650; color: var(--muted); font-size: .92rem; }
.mission.complete + .mission-status { color: var(--ok); }
.card.soutien + .card.soutien { margin-top: 12px; }
