/* Layout : carte du donjon fixe à gauche (repliée en barre sur mobile), une colonne de lecture ~68ch à droite. */
:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --sunken: #e4e7ee;
  --ink: #1a1d27;
  --muted: #586074;
  --line: #d3d7e1;
  --torch: #b0530a;      /* accent : la torche */
  --torch-soft: #fbe9d7;
  --mana: #2b62d1;       /* liens, infos */
  --mana-soft: #e3ebfb;
  --hp: #b8322a;         /* pièges, erreurs */
  --hp-soft: #f9e2e0;
  --xp: #237a4b;         /* réussite */
  --xp-soft: #dcf1e5;
  --code-bg: #1d2030;
  --code-ink: #e3e6f0;
  --c-kw: #ff9e64;
  --c-str: #9ece6a;
  --c-num: #e0af68;
  --c-com: #7a819c;
  --c-fn: #7aa2f7;
  --c-bi: #bb9af7;

  --f-display: "Pixelify Sans", "Courier New", monospace;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2.25rem; --s-7: 3.5rem;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141b; --surface: #1a1d27; --sunken: #232736; --ink: #e7e9f0; --muted: #9ba2b5; --line: #2e3345;
    --torch: #f2a24a; --torch-soft: #3a2a1a; --mana: #84a9ff; --mana-soft: #1f2a45;
    --hp: #ff7a6e; --hp-soft: #3d2124; --xp: #62d394; --xp-soft: #1b3428;
    --code-bg: #0e1017; --code-ink: #e3e6f0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141b; --surface: #1a1d27; --sunken: #232736; --ink: #e7e9f0; --muted: #9ba2b5; --line: #2e3345;
  --torch: #f2a24a; --torch-soft: #3a2a1a; --mana: #84a9ff; --mana-soft: #1f2a45;
  --hp: #ff7a6e; --hp-soft: #3d2124; --xp: #62d394; --xp-soft: #1b3428;
  --code-bg: #0e1017; --code-ink: #e3e6f0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.0625rem/1.65 var(--f-body);
}
a { color: var(--mana); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--torch); outline-offset: 2px; }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: 18.5rem minmax(0, 1fr); min-height: 100vh; }
.map {
  position: sticky; top: env(safe-area-inset-top, 0px); height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: var(--s-5) var(--s-4); display: flex; flex-direction: column; gap: var(--s-4);
}
.brand { font-family: var(--f-display); font-size: 1.35rem; line-height: 1.15; color: var(--ink); text-decoration: none; display: block; }
.brand small { display: block; font-family: var(--f-body); font-size: .8rem; color: var(--muted); letter-spacing: .02em; margin-top: var(--s-1); }

.hud { background: var(--sunken); border-radius: var(--radius); padding: var(--s-3); display: grid; gap: var(--s-2); }
.hud-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-2); }
.hud-rank { font-family: var(--f-display); font-size: 1.05rem; color: var(--torch); }
.hud-xp { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); }
.bar { height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--torch); width: 0; transition: width .4s ease; }

.map nav { display: grid; gap: var(--s-4); }
.map h2 { font-family: var(--f-display); font-weight: 400; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 var(--s-1); }
.map ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.map li a {
  display: grid; grid-template-columns: 2.1rem minmax(0, 1fr); gap: var(--s-2); align-items: center;
  padding: .35rem .5rem; border-radius: 4px; color: var(--ink); text-decoration: none; font-size: .93rem; line-height: 1.3;
}
.map li a:hover { background: var(--sunken); }
.map li a[aria-current="page"] { background: var(--torch-soft); }
.room {
  font-family: var(--f-display); font-size: .8rem; text-align: center; padding: .15rem 0;
  border: 2px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--bg);
}
.room[data-state="started"] { border-color: var(--torch); color: var(--torch); }
.room[data-state="done"] { border-color: var(--xp); background: var(--xp); color: var(--surface); }
.map-foot { margin-top: auto; display: flex; gap: var(--s-2); flex-wrap: wrap; }
.btn-ghost { font: inherit; font-size: .8rem; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 4px; padding: .3rem .6rem; cursor: pointer; }
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); }

.topbar { display: none; }

main { padding-inline: clamp(1rem, 4vw, 3.5rem); padding-block: var(--s-6) var(--s-7); min-width: 0; }
.chapter { max-width: 46rem; margin-inline: auto; }
.chapter[hidden] { display: none; }

/* ---------- Typo ---------- */
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.2; }
.chapter > header { display: grid; gap: var(--s-2); margin-bottom: var(--s-5); }
.eyebrow { font-family: var(--f-display); color: var(--torch); font-size: .95rem; letter-spacing: .08em; text-transform: uppercase; }
.chapter h1 { font-family: var(--f-display); font-weight: 500; font-size: clamp(2rem, 5vw, 2.9rem); margin: 0; }
.chapter .lead { font-size: 1.15rem; color: var(--muted); margin: 0; }
.chapter h2 { font-size: 1.5rem; margin: var(--s-7) 0 var(--s-3); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.chapter h3 { font-size: 1.15rem; margin: var(--s-5) 0 var(--s-2); }
.chapter p, .chapter li { max-width: 68ch; }
.chapter ul, .chapter ol { padding-left: 1.3rem; }
.chapter li + li { margin-top: .25rem; }
code { font-family: var(--f-code); font-size: .88em; background: var(--sunken); padding: .08em .3em; border-radius: 3px; }
kbd { font-family: var(--f-code); font-size: .8em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 .3em; background: var(--surface); }
.objectifs { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
.objectifs li { margin: 0; font-size: .85rem; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: .15rem .7rem; }

table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.table-wrap { overflow-x: auto; margin: var(--s-4) 0; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }

/* ---------- Code ---------- */
.code { position: relative; margin: var(--s-4) 0; }
.code pre, pre.out {
  margin: 0; padding: var(--s-4); overflow-x: auto; border-radius: var(--radius);
  font: .88rem/1.55 var(--f-code); tab-size: 4;
}
.code pre { background: var(--code-bg); color: var(--code-ink); }
.code .label { position: absolute; top: 0; left: var(--s-4); transform: translateY(-50%); font: .72rem var(--f-code); background: var(--torch); color: var(--surface); padding: 0 .45rem; border-radius: 3px; }
.code.has-label pre { padding-top: calc(var(--s-4) + .4rem); }
.copy { position: absolute; top: .45rem; right: .45rem; font: .75rem var(--f-body); background: rgba(255,255,255,.08); color: var(--code-ink); border: 1px solid rgba(255,255,255,.18); border-radius: 4px; padding: .15rem .5rem; cursor: pointer; opacity: .75; }
.copy:hover { opacity: 1; }
.tok-kw { color: var(--c-kw); } .tok-str { color: var(--c-str); } .tok-num { color: var(--c-num); }
.tok-com { color: var(--c-com); font-style: italic; } .tok-fn { color: var(--c-fn); } .tok-bi { color: var(--c-bi); }
pre.out { background: var(--sunken); color: var(--ink); border: 1px dashed var(--line); }
pre.out::before { content: "Sortie"; display: block; font: .7rem var(--f-body); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }

.predict { margin: var(--s-5) 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
.predict-head { font-family: var(--f-display); color: var(--mana); font-size: .95rem; }
.predict .code { margin: 0; }
.btn {
  font: 600 .92rem var(--f-body); cursor: pointer; border-radius: 4px; padding: .45rem .9rem;
  background: var(--surface); color: var(--ink); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s; justify-self: start;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--torch); border-color: var(--torch); color: var(--surface); box-shadow: 3px 3px 0 var(--ink); }
.btn[aria-pressed="true"] { background: var(--xp); border-color: var(--xp); color: var(--surface); }

/* ---------- Encadrés ---------- */
aside.note { margin: var(--s-5) 0; padding: var(--s-3) var(--s-4); border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
aside.note > :first-child { margin-top: 0; } aside.note > :last-child { margin-bottom: 0; }
aside.note::before { display: block; font-family: var(--f-display); font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: .3rem; }
aside.lore { background: var(--mana-soft); border-color: transparent; } aside.lore::before { content: "Le saviez-vous ?"; color: var(--mana); }
aside.piege { background: var(--hp-soft); border-color: transparent; } aside.piege::before { content: "Piège !"; color: var(--hp); }
aside.astuce { background: var(--xp-soft); border-color: transparent; } aside.astuce::before { content: "Astuce de vétéran"; color: var(--xp); }
aside.retenir { border: 2px solid var(--ink); } aside.retenir::before { content: "À retenir"; color: var(--ink); }

.quete { position: relative; margin: 0 0 var(--s-5); padding: var(--s-4) var(--s-5); background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius); }
.quete::before { content: "Quête"; display: block; font-family: var(--f-display); color: var(--c-num); letter-spacing: .1em; text-transform: uppercase; font-size: .85rem; margin-bottom: .35rem; }
.quete p { margin: .4rem 0; max-width: 64ch; }
.quete em { color: var(--c-num); font-style: normal; }

/* ---------- Défis ---------- */
.defi { margin: var(--s-4) 0; padding: var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.defi.done { border-color: var(--xp); }
.defi-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2) var(--s-3); margin-bottom: var(--s-2); }
.defi-head h3 { margin: 0; font-size: 1.08rem; flex: 1 1 14rem; }
.stars { font-family: var(--f-display); color: var(--torch); letter-spacing: .1em; }
.xp-tag { font: .78rem var(--f-code); background: var(--torch-soft); color: var(--torch); padding: .05rem .45rem; border-radius: 3px; }
.defi > p:first-of-type { margin-top: 0; }
.defi details { margin-top: var(--s-2); border-top: 1px dashed var(--line); padding-top: var(--s-2); }
.defi summary { cursor: pointer; color: var(--mana); font-weight: 600; font-size: .92rem; }
.defi-foot { margin-top: var(--s-3); }

.boss { margin: var(--s-7) 0 var(--s-5); border: 3px solid var(--torch); border-radius: var(--radius); background: var(--surface); padding: var(--s-5); }
.boss > h2 { border: 0; margin-top: 0; padding-top: 0; font-family: var(--f-display); font-weight: 500; color: var(--torch); }
.boss > h2::before { content: "BOSS · "; color: var(--ink); }
.etapes { counter-reset: etape; list-style: none; padding: 0 !important; display: grid; gap: var(--s-2); }
.etapes > li { counter-increment: etape; position: relative; padding-left: 2.4rem; }
.etapes > li::before { content: counter(etape); position: absolute; left: 0; top: .05rem; width: 1.7rem; height: 1.7rem; display: grid; place-items: center; font-family: var(--f-display); background: var(--sunken); border-radius: 3px; }

/* ---------- Quiz ---------- */
.quiz { margin: var(--s-6) 0 var(--s-4); padding: var(--s-5); background: var(--sunken); border-radius: var(--radius); }
.quiz > h2 { margin-top: 0; padding-top: 0; border: 0; font-family: var(--f-display); font-weight: 500; }
.q { margin: var(--s-4) 0; }
.q > p:first-child { font-weight: 600; margin-bottom: var(--s-2); }
.q ol { display: none; }
.opts { display: grid; gap: var(--s-2); }
.opt { text-align: left; font: inherit; font-size: .97rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: .5rem .75rem; cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--ink); }
.opt:disabled { cursor: default; }
.opt.ok { border-color: var(--xp); background: var(--xp-soft); }
.opt.ko { border-color: var(--hp); background: var(--hp-soft); text-decoration: line-through; }
.q .why { display: none; font-size: .93rem; color: var(--muted); margin-top: var(--s-2); }
.q.answered .why { display: block; }
.quiz-score { font-family: var(--f-display); color: var(--torch); }

/* ---------- Accueil ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); margin-bottom: var(--s-6); }
.hero h1 { font-size: clamp(2.4rem, 7vw, 4rem); line-height: 1.02; }
.dungeon { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: var(--s-3); margin: var(--s-5) 0; }
.dungeon a {
  display: grid; gap: var(--s-1); padding: var(--s-3) var(--s-4); text-decoration: none; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 4px; min-height: 7rem;
}
.dungeon a:hover { border-color: var(--ink); }
.dungeon a[data-state="done"] { border-color: var(--xp); }
.dungeon a[data-state="started"] { border-color: var(--torch); }
.dungeon .lvl { font-family: var(--f-display); font-size: .85rem; color: var(--torch); }
.dungeon strong { font-size: 1.02rem; line-height: 1.25; }
.dungeon span.sub { font-size: .85rem; color: var(--muted); line-height: 1.35; }
.acts { display: grid; gap: var(--s-2); }
.acts h2 { margin-top: var(--s-6) !important; }
.canvas-wrap { margin: var(--s-4) 0; border-radius: var(--radius); overflow: hidden; background: var(--code-bg); max-width: 100%; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }

.toast { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); font-family: var(--f-display); padding: .55rem 1rem; border-radius: 4px; transform: translateY(150%); transition: transform .25s ease; z-index: 30; }
.toast.show { transform: none; }

.pager { display: flex; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-7); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.pager a { text-decoration: none; font-weight: 600; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .app { display: block; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
    padding: .6rem 1rem;
  }
  .topbar .brand { font-size: 1.05rem; }
  .topbar .hud-rank { font-size: .9rem; }
  .map { position: fixed; inset: 0; z-index: 25; height: 100%; transform: translateX(-100%); transition: transform .2s ease; padding-top: calc(var(--s-5) + env(safe-area-inset-top, 0px)); }
  .map.open { transform: none; }
  main { padding-block: var(--s-5) var(--s-7); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.map .topbar-only { display: none; }
@media (max-width: 860px) { .map .topbar-only { display: inline-block; } }
pre.mermaid { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s-4); overflow-x: auto; text-align: center; margin: var(--s-4) 0; }
.chapter .objectifs { padding: 0; }
/* Les chiffres de la police pixel se lisent mal en petit (5 ≈ S) : numéros en police de code */
.room, .eyebrow, .dungeon .lvl { font-family: var(--f-code); font-weight: 600; }
.eyebrow { font-size: .8rem; }
/* Pas de ligatures dans le code : >= != <= doivent s'afficher tels qu'on les tape, pas en ≥ ≠ ≤ */
code, kbd, pre, .code pre, pre.out, .xp-tag, .room, .eyebrow, .dungeon .lvl { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
