:root {
  --ink: #f6f1e7;
  --dark: rgba(14, 12, 22, 0.72);
  --perfect: #3dff7a;
  --good: #9fb7d9;
  --miss: #ff6262;
  --accent: #ffd36b;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0d0b12; color: var(--ink);
  font-family: var(--sans); touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
canvas { display: block; }
#scene, #fx { position: fixed; inset: 0; width: 100%; height: 100%; }
#fx { z-index: 1; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed; z-index: 3; top: 0; left: 0; right: 0; display: flex; align-items: flex-start;
  justify-content: space-between; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 0; pointer-events: none;
}
#count {
  pointer-events: none; background: var(--dark); border-radius: 12px; padding: 6px 12px; display: flex;
  align-items: baseline; gap: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
#count span { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
#count b { font-size: 22px; font-variant-numeric: tabular-nums; }
#count.bump b { animation: bump 0.25s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--perfect); } }
.btns { display: flex; gap: 6px; pointer-events: auto; }
.btns button {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--dark); font-size: 16px;
}
#slogan {
  position: fixed; z-index: 2; top: calc(112px + var(--safe-t)); left: 50%; transform: translateX(-50%) scale(0.9);
  font-weight: 900; font-size: clamp(22px, 6vw, 40px); letter-spacing: 0.04em; white-space: nowrap;
  text-shadow: 0 3px 0 #1b1620, 0 0 18px rgba(0, 0, 0, 0.5); opacity: 0; transition: 0.2s; pointer-events: none;
}
#slogan.show { opacity: 1; transform: translateX(-50%) scale(1); }
#slogan span { color: rgba(255, 255, 255, 0.45); transition: color 0.1s; }
#slogan span.perfect { color: var(--perfect); }
#slogan span.good { color: var(--good); }
#slogan span.miss { color: var(--miss); text-decoration: line-through; }
#slogan i { font-style: normal; opacity: 0.4; margin: 0 0.2em; }

/* Story text */
#card {
  position: fixed; z-index: 2; top: 22%; left: 0; right: 0; text-align: center; font-family: var(--serif);
  font-style: italic; font-size: clamp(20px, 4.4vw, 36px); text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
  opacity: 0; transform: translateY(8px); transition: opacity 0.6s, transform 0.6s; pointer-events: none; padding: 0 16px;
}
#card.show { opacity: 1; transform: none; }
#sub {
  position: fixed; z-index: 2; left: 50%; bottom: calc(190px + var(--safe-b)); width: min(560px, calc(100% - 32px));
  transform: translateX(-50%) translateY(6px); background: rgba(250, 245, 232, 0.94); color: #2a2430;
  border-radius: 14px; padding: 16px 18px 12px; font-size: 17px; line-height: 1.35; opacity: 0;
  transition: opacity 0.3s, transform 0.3s; pointer-events: none; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
#sub.show { opacity: 1; transform: translateX(-50%); }
#sub .who {
  position: absolute; top: -12px; left: 14px; background: #d9c38e; color: #3a2f20; font-size: 13px;
  font-weight: 700; padding: 3px 12px; border-radius: 999px;
}
#hint {
  position: fixed; z-index: 2; left: 50%; top: calc(172px + var(--safe-t)); transform: translateX(-50%);
  background: var(--accent); color: #2a2018; font-weight: 700; font-size: 14px; padding: 7px 14px;
  border-radius: 999px; max-width: calc(100% - 32px); text-align: center; opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
#hint.show { opacity: 1; }
body.touch #sub { bottom: calc(300px + var(--safe-b)); }
#shout {
  position: fixed; z-index: 2; top: 38%; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0;
}
#shout.show { animation: shout 2.6s ease-out forwards; }
#shout b { display: block; font-size: clamp(28px, 8vw, 64px); font-weight: 900; text-shadow: 0 4px 0 #1b1620, 0 0 24px rgba(255, 90, 100, 0.6); }
#shout small { display: block; margin-top: 6px; font-size: 16px; font-weight: 700; color: var(--perfect); text-shadow: 0 2px 6px #000; }
@keyframes shout { 0% { opacity: 0; transform: scale(0.6); } 12% { opacity: 1; transform: scale(1.08); } 20% { transform: scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }

/* Touch pad */
#pad {
  position: fixed; z-index: 3; left: 0; right: 0; bottom: 0; display: none; justify-content: center; gap: 10px;
  padding: 10px 12px calc(12px + var(--safe-b)); opacity: 0.35; transition: opacity 0.3s;
}
body.touch #pad { display: flex; }
body.lane #pad { opacity: 1; }
#pad button {
  flex: 1; max-width: 76px; height: 64px; border-radius: 16px; border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(14, 12, 22, 0.66); font-size: 26px; font-weight: 800; touch-action: none;
}
#pad button[data-k="up"] { color: #ff8a7f; } #pad button[data-k="down"] { color: #6fc2ff; }
#pad button[data-k="left"] { color: #ffd36b; } #pad button[data-k="right"] { color: #c7a8ff; }
#pad button.tap { max-width: 96px; color: #f5efe0; }
#pad button.down { background: rgba(255, 255, 255, 0.28); transform: scale(0.96); }

/* Screens */
.screen {
  position: fixed; z-index: 5; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(13, 11, 18, 0.35), rgba(13, 11, 18, 0.85));
}
.panel { text-align: center; max-width: 440px; }
/* Short screens (a phone held sideways): every panel scrolls instead of spilling out. */
.screen > .panel { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.kicker { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.75; margin: 0 0 8px; }
h1 { font-size: clamp(44px, 13vw, 84px); letter-spacing: 0.12em; margin: 0; font-weight: 900; text-shadow: 0 4px 0 #b8402f, 0 8px 30px rgba(0, 0, 0, 0.6); }
h2 { font-size: 30px; margin: 0 0 12px; }
.subtitle { font-family: var(--serif); font-style: italic; font-size: 22px; margin: 6px 0 26px; }
.screen button {
  display: block; width: 100%; min-height: 54px; margin: 10px 0; border: 0; border-radius: 14px;
  background: var(--accent); color: #2a2018; font-weight: 800; font-size: 18px;
}
.screen button:disabled { opacity: 0.6; cursor: progress; }
.screen button.ghost { background: rgba(255, 255, 255, 0.12); color: var(--ink); }
.tip { font-size: 14px; opacity: 0.85; }
.credit { font-size: 11px; opacity: 0.6; margin-top: 18px; }
.err { color: var(--miss); font-size: 13px; }
#results .big { font-size: 20px; margin: 4px 0; }
#results .big b { font-size: 44px; color: var(--perfect); display: block; }
#results .big.lose b { color: #ff8a6a; }
#results > .panel:not(.res) {
  width: min(460px, 100%); background: rgba(14, 12, 22, 0.93); border-radius: 18px; padding: 14px 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
#results .grades.next { color: var(--accent); font-weight: 700; }
#results .stars { font-size: 40px; color: var(--accent); margin: 6px 0; letter-spacing: 0.1em; }
#results .stars span { color: rgba(255, 255, 255, 0.18); }
#results .grades { font-size: 14px; }
#results .shots { display: flex; justify-content: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
#results .shots figure { margin: 0; width: min(120px, 28vw); background: #f4efe2; padding: 6px 6px 4px; border-radius: 3px; transform: rotate(-1.5deg); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45); }
#results .shots figure:nth-child(2) { transform: rotate(1.8deg); }
#results .shots img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
#results .shots figcaption { color: #2a2430; font-size: 11px; line-height: 1.2; margin-top: 4px; text-align: center; }
.pf { color: var(--perfect); } .gd { color: var(--good); } .ms { color: var(--miss); }

/* Chapter list */
.panel.wide { max-width: 560px; width: 100%; }
#chapterList { display: grid; gap: 10px; margin: 8px 0 6px; max-height: 64vh; overflow-y: auto; }
#chapterList .ch {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; min-height: 0; margin: 0;
  padding: 12px 16px; background: rgba(255, 255, 255, 0.1); color: var(--ink); font-weight: 400; font-size: 15px;
}
#chapterList .ch b { font-size: 18px; font-weight: 800; }
#chapterList .ch .meta { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; }
#chapterList .ch .best { grid-row: 1 / span 3; grid-column: 2; align-self: center; color: var(--accent); font-size: 18px; letter-spacing: 0.08em; }
#chapterList .ch .best span { color: rgba(255, 255, 255, 0.18); }
#chapterList .ch:hover { background: rgba(255, 255, 255, 0.18); }
#chapterList .ch.soon { opacity: 0.55; cursor: default; }
#chapter { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#chapter > * { pointer-events: auto; }
body.chapter #hud, body.chapter #pad, body.chapter #card, body.chapter #sub, body.chapter #hint, body.chapter #shout { display: none !important; }

/* Tuning panel */
#debug {
  position: fixed; z-index: 6; top: calc(62px + var(--safe-t)); right: 12px; width: min(360px, calc(100% - 24px));
  background: rgba(14, 12, 22, 0.9); border-radius: 12px; padding: 10px 12px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
#debug .row { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
#debug .row.wrap { flex-wrap: wrap; }
#debug .row b:first-child { flex: 1; }
#debug button { border: 0; border-radius: 8px; padding: 6px 9px; background: rgba(255, 255, 255, 0.12); min-height: 32px; }
#debug button.on { background: var(--accent); color: #2a2018; }
#debug .info { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: #cfe; }
#debug .note { opacity: 0.7; font-size: 11px; margin: 4px 0 0; }

#toast {
  position: fixed; z-index: 4; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%);
  background: var(--dark); padding: 7px 14px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none;
}
#toast.show { animation: toast 3s ease-out forwards; }
@keyframes toast { 10%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* Out of a game: no HUD, no pad. */
body:not(.ingame) #hud, body:not(.ingame) #pad { display: none !important; }

/* Boot: the first tap */
#boot { background: #0b0a10; cursor: pointer; }
#boot .press { font-size: 20px; font-weight: 700; letter-spacing: 0.04em; animation: blink 1.8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

/* Intro cards */
#intro {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 72px 20px 96px;
  background: rgba(9, 8, 14, 0.8); transition: background 0.8s; cursor: pointer;
}
#intro.dark, #intro.note { background: rgba(4, 4, 6, 0.96); }
#intro .skip, #video .skip {
  position: fixed; z-index: 2; top: calc(12px + var(--safe-t)); right: 12px; min-height: 44px; padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 999px; background: rgba(14, 12, 22, 0.6); font-weight: 700;
}
#intro .card { max-width: 640px; text-align: center; }
#intro .card.in { animation: cardIn 0.7s ease-out; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } }
#intro .kicker { font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin: 0 0 18px; opacity: 1; }
#intro .lines p {
  font-family: var(--serif); font-size: clamp(19px, 4.6vw, 28px); line-height: 1.4; margin: 0 0 14px;
  opacity: 0; transform: translateY(6px); transition: opacity 0.8s, transform 0.8s; text-shadow: 0 2px 10px #000;
}
#intro .lines p.on { opacity: 1; transform: none; }
#intro.note .lines p { font-size: clamp(16px, 3.8vw, 20px); font-style: italic; color: #cfc8bb; }
#intro .big { margin: 0 0 20px; }
#intro .big b { display: block; font-size: clamp(44px, 13vw, 84px); font-weight: 900; font-variant-numeric: tabular-nums; color: #ffd36b; text-shadow: 0 0 30px rgba(255, 180, 60, 0.4); }
#intro .big small { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
#intro .phones { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; max-width: 360px; margin: 0 auto 22px; }
#intro .phones i {
  aspect-ratio: 9 / 16; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.4); animation: pop 0.35s ease-out;
  background: linear-gradient(hsl(var(--h) 45% 45%), hsl(calc(var(--h) + 40) 40% 25%));
}
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
#intro .ticker {
  position: fixed; left: 0; right: 0; bottom: calc(40px + var(--safe-b)); overflow: hidden; white-space: nowrap;
  background: #b8302b; color: #fff; font-weight: 800; font-size: 14px; letter-spacing: 0.05em; padding: 7px 0;
  opacity: 0; transition: opacity 0.6s;
}
#intro .ticker.show { opacity: 1; }
#intro .ticker span { display: inline-block; padding-left: 100%; animation: ticker 26s linear infinite; }
@keyframes ticker { to { transform: translateX(-100%); } }
#intro .dots { position: fixed; bottom: calc(14px + var(--safe-b)); left: 0; right: 0; display: flex; justify-content: center; gap: 6px; }
#intro .dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); }
#intro .dots i.on { background: var(--accent); }

/* Video cutscenes */
#video { position: fixed; inset: 0; z-index: 7; background: #000; display: grid; place-items: center; }
#video video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#video .cap {
  position: fixed; z-index: 1; left: 50%; bottom: calc(56px + var(--safe-b)); transform: translate(-50%, 6px);
  max-width: min(88vw, 420px); text-align: center; font-family: var(--serif); font-size: clamp(18px, 4.4vw, 24px);
  text-shadow: 0 2px 10px #000; opacity: 0; transition: opacity 0.6s, transform 0.6s; pointer-events: none;
}
#video .cap.on { opacity: 1; transform: translate(-50%, 0); }
#video .cap.sms {
  font-family: var(--sans); font-size: clamp(16px, 4vw, 19px); text-shadow: none; text-align: left;
  background: #2f7cf6; color: #fff; padding: 10px 14px; border-radius: 18px 18px 18px 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* Title and menu */
#menu { background: linear-gradient(rgba(13, 11, 18, 0.15), rgba(13, 11, 18, 0.75)); }
#menu nav { display: grid; gap: 2px; margin-top: 28px; }
#menu.reveal h1 { animation: logo 1.4s cubic-bezier(.2, .8, .2, 1); }
#menu.reveal .subtitle, #menu.reveal nav { animation: fadeUp 1s 0.6s both; }
@keyframes logo { from { opacity: 0; letter-spacing: 0.5em; filter: blur(8px); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } }

/* Settings */
#settings .panel { width: min(420px, 100%); text-align: left; }
#settings h2 { text-align: center; }
.set { margin: 16px 0; }
.set label { display: block; font-weight: 700; margin-bottom: 8px; }
.set .help { font-size: 12px; opacity: 0.65; margin: 6px 0 0; }
.seg { display: flex; align-items: center; gap: 6px; }
.screen .seg button { flex: 1; margin: 0; min-height: 44px; font-size: 14px; background: rgba(255, 255, 255, 0.12); color: var(--ink); }
.screen .seg button.on { background: var(--accent); color: #2a2018; }
.seg b { min-width: 70px; text-align: center; }
.set input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }
#menu .panel { max-width: 640px; width: 100%; }
#menu nav { max-width: 360px; margin-left: auto; margin-right: auto; }
#menu h1 { white-space: nowrap; font-size: clamp(38px, 12.5vw, 96px); }

/* ---- Marianne gameplay: Ferveur, score, feedback (chapters/marianne) ---- */
#hud .meters { display: flex; flex-direction: column; gap: 6px; }
#hud .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#ferveur {
  width: 150px; background: var(--dark); border-radius: 10px; padding: 5px 9px 6px; display: grid;
  grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; opacity: 0; transition: opacity 0.4s;
}
body.meters #ferveur, body.meters #score { opacity: 1; }
#ferveur span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
#ferveur em { font-style: normal; font-size: 11px; font-weight: 700; text-align: right; }
#ferveur i { grid-column: 1 / -1; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
#ferveur i b { display: block; height: 100%; width: 50%; border-radius: 4px; background: #ffd36b; transition: width 0.25s, background 0.4s; }
#ferveur.low i b { background: #8f93ad; }
#ferveur.low em { color: #b9bdd6; animation: blink 1.2s ease-in-out infinite; }
#ferveur.high i b { background: linear-gradient(90deg, #ffb057, #ff6a3d); box-shadow: 0 0 10px #ff8a4d; }
#ferveur.high em { color: #ffb057; }
#score {
  background: var(--dark); border-radius: 10px; padding: 4px 10px; display: flex; align-items: baseline; gap: 6px;
  opacity: 0; transition: opacity 0.4s;
}
#score b { font-size: 16px; font-variant-numeric: tabular-nums; }
#score span { font-size: 12px; font-weight: 800; opacity: 0.5; }
#score span.on { opacity: 1; color: var(--accent); }
.btns button#bHelp { font-weight: 900; font-size: 19px; }

#vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; --fire: 0;
  background: radial-gradient(ellipse at 50% 120%, rgba(255, 110, 50, var(--fire)), transparent 55%);
}
#vignette::after {
  content: ''; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(255, 50, 60, 0.45));
}
#vignette.miss::after { animation: missFlash 0.35s ease-out; }
@keyframes missFlash { 0% { opacity: 1; } 100% { opacity: 0; } }
body:not(.ingame) #vignette { display: none; }

#slogan small {
  display: block; text-align: center; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 2px; text-shadow: 0 2px 4px #000;
}
#slogan span.now { color: #fff; }
#slogan span.on { color: rgba(255, 255, 255, 0.85); }
#slogan span.call { color: #cfc8ff; }
#slogan span.hide { color: rgba(255, 255, 255, 0.25); }
#slogan.falter span { animation: falter 0.5s ease-in-out infinite alternate; opacity: 0.7; }
#slogan.falter span:nth-of-type(2n) { animation-delay: 0.2s; }
@keyframes falter { to { transform: translateY(3px) rotate(-3deg); } }
#slogan span { display: inline-block; }
#shout.low b { font-size: clamp(22px, 6vw, 44px); opacity: 0.75; text-shadow: 0 3px 0 #1b1620; }
#shout.low small { color: #c8cbe0; }

/* Facile: only ← ● → on the pad, bigger buttons. */
body.lv-facile #pad button[data-k="up"], body.lv-facile #pad button[data-k="down"] { display: none; }
body.lv-facile #pad button { max-width: 110px; }
/* Phones held sideways: ← ↑ under the left thumb, ↓ → under the right one. */
@media (orientation: landscape) and (max-height: 520px) {
  body.touch #pad { gap: 8px; padding-left: calc(12px + env(safe-area-inset-left, 0px)); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
  body.touch #pad button { height: 60px; max-width: 72px; }
  body.touch #pad button[data-k="up"] { margin-right: auto; }
  body.touch #pad button[data-k="down"] { margin-left: auto; }
  body.lv-facile.touch #pad button[data-k="left"] { margin-right: auto; }
  body.lv-facile.touch #pad button[data-k="right"] { margin-left: auto; }
  body.touch #sub { bottom: auto; top: calc(56px + var(--safe-t)); width: min(460px, calc(100% - 340px)); font-size: 15px; padding: 12px 14px 9px; }
  #hint { top: calc(60px + var(--safe-t)); max-width: calc(100% - 360px); }
  #slogan { top: calc(10px + var(--safe-t)); font-size: 28px; }
  #ferveur { width: 130px; }
}

/* Level choice */
#levelList { display: grid; gap: 10px; margin: 8px 0 6px; }
#levelList .lv {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; margin: 0; padding: 12px 16px;
  background: rgba(255, 255, 255, 0.1); color: var(--ink); font-weight: 400; font-size: 14px; min-height: 64px;
  border: 2px solid transparent;
}
#levelList .lv.on { border-color: var(--accent); }
#levelList .lv:hover { background: rgba(255, 255, 255, 0.18); }
#levelList .lv b { font-size: 19px; font-weight: 800; }
#levelList .lv > span:not(.best) { grid-column: 1; opacity: 0.85; }
#levelList .lv .best { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; font-size: 13px; color: var(--accent); white-space: nowrap; }
#levelList .lv .best span { color: rgba(255, 255, 255, 0.18); }
#levelList .lv .best.none { color: rgba(255, 255, 255, 0.45); font-size: 12px; }
#levelList .g { font-size: 17px; margin-right: 4px; }
.gS { color: #ffd36b; } .gA { color: #3dff7a; } .gB { color: #9fb7d9; } .gC { color: #c8a8a8; }

/* Comment jouer */
#howto { z-index: 6; overflow-y: auto; align-items: start; }
.hw-card {
  width: min(520px, 100%); margin: auto; background: rgba(22, 19, 32, 0.96); border-radius: 18px; padding: 16px 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); text-align: left; font-size: 14px; line-height: 1.4;
}
.hw-head { display: flex; gap: 12px; align-items: center; }
.hw-face { width: 64px; height: 64px; border-radius: 50%; background: #3a3348 center 18% / 170% no-repeat; border: 2px solid var(--accent); flex: none; }
.hw-role { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
.hw-name { font-size: 24px; font-weight: 900; }
.hw-gauge { font-size: 13px; color: var(--accent); }
.hw-goal { margin: 10px 0 6px; font-weight: 600; }
.hw-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.hw-steps li { display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: center; }
.hw-g { display: flex; gap: 3px; justify-content: center; }
.hn {
  font-style: normal; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--c); color: #1b1620; font-weight: 900; font-size: 13px; border: 2px solid #1b1620;
}
.hn.bar { width: auto; border-radius: 12px; padding: 0 6px; font-size: 11px; }
.hn.call { background: rgba(20, 16, 30, 0.6); color: var(--c); border: 2px dashed var(--c); }
.hn.duo { width: auto; height: auto; background: none; border: 0; display: inline-flex; flex-direction: column; gap: 1px; }
.hn.duo b { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--c); font-size: 10px; border: 2px solid #1b1620; }
.hw-tip { font-size: 13px; opacity: 0.85; margin: 10px 0 8px; }
.hw-practice { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 10px; }
.hw-ph { font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.hw-ph span { opacity: 0.7; }
.hw-lane { position: static; display: block; width: 100%; height: 64px; margin: 6px 0 2px; touch-action: none; cursor: pointer; }
.hw-advice { font-size: 12.5px; margin: 4px 0 0; min-height: 36px; }
.screen .hw-advice button { display: inline-block; width: auto; min-height: 36px; margin: 4px 0 0; padding: 0 12px; font-size: 13px; }
.screen .hw-ok { margin-top: 12px; }

/* Results */
#results { overflow-y: auto; align-items: start; }
#results .panel.res { width: min(460px, 100%); margin: auto; }
#results h2 { font-size: clamp(20px, 5.4vw, 28px); }
.res-top { display: flex; align-items: center; justify-content: center; gap: 18px; }
.res-top .big { margin: 0; }
.res-top .stars { margin: 2px 0 0; font-size: 30px; }
.grade { display: grid; place-items: center; width: 92px; height: 92px; border-radius: 20px; background: rgba(255, 255, 255, 0.08); border: 2px solid currentColor; }
.grade b { font-size: 50px; line-height: 1; font-weight: 900; }
.grade span { font-size: 11px; font-weight: 700; margin-top: -6px; }
.record { color: var(--perfect); font-weight: 800; margin: 8px 0 0; animation: blink 1s ease-in-out 3; }
.prev { font-size: 13px; opacity: 0.7; margin: 8px 0 0; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0 6px; }
.res-grid div { background: rgba(255, 255, 255, 0.08); border-radius: 10px; padding: 6px 8px; }
.res-grid span { display: block; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }
.res-grid b { font-size: 20px; font-variant-numeric: tabular-nums; }
.res-curve { margin: 8px 0 4px; background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 4px 4px 2px; }
.res-curve > span { display: block; text-align: left; padding: 0 4px 2px; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }
.curve { display: block; width: 100%; height: 62px; overflow: visible; }
.curve polyline { fill: none; stroke: #ffb057; stroke-width: 2; vector-effect: non-scaling-stroke; }
.curve line { stroke: rgba(255, 255, 255, 0.2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.curve text { fill: rgba(255, 255, 255, 0.55); font-size: 9px; font-family: var(--sans); }
.res-lines { list-style: none; padding: 0; margin: 6px 0; font-size: 13.5px; display: grid; gap: 2px; }
.res-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.res-btns button { margin: 0; min-height: 50px; font-size: 16px; }
.res-btns button:first-child { grid-column: 1 / -1; }
.res-lines { font-size: 13px; }
#results .panel.res { background: rgba(14, 12, 22, 0.82); border-radius: 18px; padding: 14px 16px; max-width: none; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
@media (min-width: 700px) and (max-height: 560px), (min-width: 900px) and (max-height: 860px) {
  #results .panel.res { width: min(780px, 100%); display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; align-items: start; }
  #results .panel.res > .kicker, #results .panel.res > h2 { grid-column: 1 / -1; }
  .res-b { padding-top: 4px; }
  .res-btns { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .res-btns button:first-child { grid-column: auto; }
  .res-btns button { font-size: 15px; }
}
@media (max-height: 520px) {
  #results { padding: 8px; }
  #results .panel.res { padding: 8px 14px; }
  #results h2 { font-size: 20px; margin-bottom: 4px; }
  #results .kicker { margin-bottom: 2px; }
  .grade { width: 70px; height: 70px; border-radius: 16px; }
  .grade b { font-size: 38px; }
  #results .big b { font-size: 32px; }
  .res-top .stars { font-size: 24px; }
  .record, .prev { margin-top: 2px; }
  .res-grid { margin: 6px 0 2px; gap: 4px; }
  .res-grid div { padding: 3px 8px; display: flex; justify-content: space-between; align-items: baseline; }
  .res-grid b { font-size: 16px; }
  #results .grades { margin: 4px 0; }
  .curve { height: 50px; }
  .res-lines { font-size: 12px; margin: 2px 0; }
  .res-btns button { min-height: 44px; }
}

/* Hosted chapters' results on short screens (a phone held sideways). */
@media (max-height: 520px) {
  #results > .panel:not(.res) { padding: 0 8px; }
  #results > .panel:not(.res) h2 { font-size: 22px; margin-bottom: 4px; }
  #results > .panel:not(.res) .big b { font-size: 34px; }
  #results > .panel:not(.res) .stars { font-size: 28px; margin: 2px 0; }
  #results > .panel:not(.res) .grades { margin: 4px 0; }
  #results > .panel:not(.res) button { min-height: 46px; margin: 6px 0; }
  .screen > .panel h2 { font-size: 24px; }
  .screen > .panel { max-height: calc(100dvh - 16px); }
  .screen { padding: 8px 16px; }
  #menu nav { margin-top: 12px; }
  #menu h1 { font-size: min(12.5vw, 16dvh); }
  #menu .subtitle { font-size: 18px; margin-top: 2px; }
  #menu .credit { margin-top: 8px; }
  #menu .subtitle { margin-bottom: 10px; }
  .screen button { min-height: 48px; margin: 6px 0; }
}

/* ---- Shell round 3: menu « Continuer », loading, settings, preferences ---- */
#bPlay small { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; opacity: 0.75; }
#boot.loading .press { animation: none; opacity: 0.7; font-weight: 600; }
#boot.loading { cursor: progress; }

/* Chapter loading */
#loading {
  position: fixed; z-index: 6; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(ellipse at center, rgba(13, 11, 18, 0.55), rgba(13, 11, 18, 0.9)); pointer-events: auto;
  animation: fadeIn 0.3s ease-out;
}
#loading p { margin: 0; text-align: center; font-weight: 700; font-size: 16px; }
#loading p b { display: block; margin-top: 4px; font-family: var(--serif); font-style: italic; font-weight: 400; color: var(--accent); font-size: 18px; }
#loading .spin {
  width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } }

/* Settings: groups and on/off switches */
.set-h { margin: 22px 0 4px; font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); opacity: 0.9; }
#settings h2 + .set-h { margin-top: 6px; }
.set.tog { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; }
.set.tog label { margin: 0; }
.set.tog .help { grid-column: 1 / -1; }
.screen button.sw {
  position: relative; width: 64px; min-height: 44px; margin: 0; padding: 0; background: none; border-radius: 22px; flex: none;
}
.sw::before {
  content: ''; position: absolute; left: 6px; right: 6px; top: 7px; bottom: 7px; border-radius: 15px;
  background: rgba(255, 255, 255, 0.18); transition: background 0.2s;
}
.sw::after {
  content: ''; position: absolute; left: 10px; top: 11px; width: 22px; height: 22px; border-radius: 50%;
  background: #f6f1e7; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); transition: transform 0.2s;
}
.sw[aria-checked="true"]::before { background: var(--accent); }
.sw[aria-checked="true"]::after { transform: translateX(22px); background: #2a2018; }
.sw:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.screen .seg button { padding: 0 4px; }
.help.speed { min-height: 2.6em; font-family: var(--serif); font-size: 14px; opacity: 0.85; }

/* Menu with many entries on a phone held sideways: secondary buttons in two columns. */
@media (max-height: 520px) {
  #menu nav { grid-template-columns: 1fr 1fr; column-gap: 8px; max-width: 520px; }
  #menu nav #bPlay { grid-column: 1 / -1; }
  #menu nav button.ghost { font-size: 15px; min-height: 44px; margin: 3px 0; }
}

/* Larger text (Réglages › Taille du texte). Chapters read ctx.prefs.textLarge. */
body.text-large .screen .panel > button, body.text-large #menu nav button, body.text-large .res-btns button { font-size: 20px; }
body.text-large .screen .seg button { font-size: 15.5px; }
body.text-large .set .help, body.text-large .tip { font-size: 15px; }
body.text-large .set label { font-size: 18px; }
body.text-large #chapterList .ch { font-size: 17px; }
body.text-large #chapterList .ch .meta { font-size: 13.5px; }
body.text-large #levelList .lv { font-size: 16px; }
body.text-large #results .grades, body.text-large .res-lines { font-size: 16px; }
body.text-large .credit { font-size: 13px; }
body.text-large #sub { font-size: 20px; }
body.text-large #hint { font-size: 16px; }
body.text-large #toast { font-size: 15px; }
body.text-large .hw-card { font-size: 16px; }
body.text-large .hw-tip { font-size: 15px; }
body.text-large #intro .lines p { font-size: clamp(22px, 5.4vw, 32px); }
body.text-large #video .cap { font-size: clamp(21px, 5vw, 28px); }
body.text-large #bPlay small { font-size: 14.5px; }

/* Fewer animations (Réglages › Réduire les animations). Chapters read
   ctx.prefs.reduceMotion; the host also caps full-screen flashes. */
body.reduce-motion #menu.reveal h1, body.reduce-motion #menu.reveal .subtitle, body.reduce-motion #menu.reveal nav { animation: none; }
body.reduce-motion #boot .press, body.reduce-motion #ferveur.low em, body.reduce-motion .record { animation: none; }
body.reduce-motion #count.bump b, body.reduce-motion #slogan.falter span { animation: none; }
body.reduce-motion #shout.show { animation-name: shoutFade; }
@keyframes shoutFade { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }
body.reduce-motion #vignette::after { background: radial-gradient(ellipse at center, transparent 60%, rgba(255, 50, 60, 0.16)); }
body.reduce-motion #intro .card.in, body.reduce-motion #intro .phones i { animation: none; }
body.reduce-motion #loading .spin { animation-duration: 2.4s; }

/* Colour-blind friendly judgements (Réglages › Couleurs adaptées): Parfait
   stays bright green, the miss colour moves away from red, and each judgement
   gets a shape: a solid underline (Parfait), a dotted one (Bien), a strike
   (Raté), and ✓ ● ✕ marks in the results. Chapters read ctx.prefs.colorBlind. */
body.colorblind { --miss: #ff6bd6; --good: #8fb8ff; }
body.colorblind #slogan span.perfect { text-decoration: underline solid 0.12em; text-underline-offset: 0.16em; }
body.colorblind #slogan span.good { text-decoration: underline dotted 0.12em; text-underline-offset: 0.16em; }
body.colorblind #slogan span.miss { text-decoration: line-through 0.14em; }
body.colorblind .pf::before { content: '✓ '; }
body.colorblind .gd::before { content: '● '; font-size: 0.8em; }
body.colorblind .ms::before { content: '✕ '; }

/* ---- QA round 3: short screens and long lists ---- */
/* Intro cards on a phone held sideways: smaller numbers and lines, the
   ticker slimmer and lower, the phone wall in two rows. */
@media (max-height: 520px) {
  #intro { padding: 54px 24px 58px; }
  #intro .kicker { margin-bottom: 8px; font-size: 12px; }
  #intro .big { margin-bottom: 8px; }
  #intro .big b { font-size: min(13vw, 13dvh); }
  #intro .big small { font-size: 11px; }
  #intro .lines p { font-size: min(19px, 4.6dvh); line-height: 1.32; margin-bottom: 6px; }
  #intro.note .lines p { font-size: min(17px, 4.4dvh); }
  #intro .card { max-width: 720px; }
  #intro .phones { grid-template-columns: repeat(12, 1fr); max-width: 330px; gap: 4px; margin-bottom: 10px; }
  #intro .ticker { bottom: calc(22px + var(--safe-b)); font-size: 12px; padding: 4px 0; }
  #intro .dots { bottom: calc(8px + var(--safe-b)); }
  body.text-large #intro .lines p { font-size: min(21px, 5.2dvh); }
}

/* Free play: the list takes the room between the title and « Retour ». */
#chapters > .panel.wide { display: flex; flex-direction: column; overflow: hidden; }
#chapterList { flex: 1 1 auto; min-height: 0; max-height: none; grid-auto-rows: max-content; align-content: start; overscroll-behavior: contain; touch-action: pan-y; padding-bottom: 4px; }
#chapters #bChaptersBack { flex: none; }
@media (max-height: 520px) {
  #chapterList { grid-template-columns: 1fr 1fr; -webkit-mask-image: linear-gradient(#000 85%, transparent); mask-image: linear-gradient(#000 85%, transparent); padding-bottom: 18px; }
  #chapters > .panel.wide { max-width: 760px; }
}

/* Level choice on a phone held sideways: the three levels side by side. */
@media (max-height: 520px) {
  #levels .panel.wide { max-width: 760px; }
  #levelList { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  #levelList .lv { grid-template-columns: 1fr; padding: 8px 10px; min-height: 0; }
  #levelList .lv .best { grid-row: auto; grid-column: 1; text-align: left; }
  #levels h2 { margin-bottom: 4px; }
  #levels #bHowto, #levels #bLevelsBack { display: inline-block; width: calc(50% - 6px); margin: 6px 2px 0; }
}

/* Primary buttons stay in view on short screens: a sticky footer inside the
   scrolling panel (settings « Retour », hosted results). */
@media (max-height: 520px) {
  #settings #bBack { position: sticky; bottom: 0; box-shadow: 0 -10px 16px rgba(13, 11, 18, 0.85); }
  #results .res-act { position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 6px 0 2px; background: rgba(14, 12, 22, 0.96); }
  #results .res-act button { margin: 0; }
}

/* Mode test (Réglages › Histoire, or ?test=1 in the address). */
body:not(.test-mode) .test-only { display: none !important; }
