:root {
  --navy: #14213d;
  --navy-2: #1f3264;
  --gold: #fca311;
  --gold-soft: #ffd27a;
  --paper: #fffaf0;
  --ink: #1b1b1b;
  --muted: #5d6472;
  --ok: #2e9d4f;
  --ko: #c93c3c;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--navy); color: var(--ink); }
body { touch-action: none; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- Écran titre ---------- */
.screen { position: fixed; inset: 0; }
#title-screen {
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #2b4a8a 0%, var(--navy) 65%);
  overflow-y: auto;
}
.title-card {
  width: min(460px, 100%); text-align: center; color: #fff; padding: 24px 20px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px; backdrop-filter: blur(4px);
}
.title-logo { width: 150px; height: auto; display: block; margin: 0 auto 4px; }
.title-card h1 { margin: 4px 0 0; font-size: 56px; letter-spacing: 6px; color: var(--gold); text-shadow: 0 4px 0 #b06d00; }
.title-card h2 { margin: 2px 0 6px; font-size: 20px; font-weight: 600; }
.slogan { margin: 0 0 18px; color: var(--gold-soft); font-size: 14px; letter-spacing: 1px; }
.title-menu { display: flex; flex-direction: column; gap: 10px; }
.edition { margin: 18px 0 0; font-size: 12px; opacity: 0.7; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 16px;
  background: #e9edf5; color: var(--navy);
}
.btn.primary { background: var(--gold); color: var(--navy); }
.btn.ghost { background: transparent; color: inherit; border: 1px solid currentColor; }
.btn.danger { background: var(--ko); color: #fff; }
.btn:focus-visible, .mbtn:focus-visible, .abtn:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 2px; }

.new-game { text-align: left; display: flex; flex-direction: column; gap: 12px; }
.new-game label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.new-game input[type=text], .new-game #in-name {
  padding: 10px 12px; border-radius: 10px; border: 0; font-size: 16px; -webkit-user-select: text; user-select: text;
}
.new-game fieldset { border: 1px solid rgba(255,255,255,0.25); border-radius: 12px; padding: 8px 12px 12px; }
.new-game legend { font-weight: 600; padding: 0 6px; }
.choice { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 6px; margin-right: 16px; font-weight: 500 !important; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color-dot { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.color-dot.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }
.row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.form-error { color: #ffb4b4; margin: 0; font-size: 14px; }

/* ---------- HUD ---------- */
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #e8d3a1; }
.hud {
  position: absolute; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; background: rgba(20,33,61,0.85); color: #fff; border-radius: var(--radius);
  pointer-events: none; flex-wrap: wrap;
}
.hud-logo { width: 46px; height: auto; }
.hud-block { display: flex; flex-direction: column; min-width: 120px; flex: 1; }
.hud-name { font-weight: 700; font-size: 15px; }
.hud-rank { font-size: 12px; color: var(--gold-soft); }
.xpbar { height: 6px; background: rgba(255,255,255,0.2); border-radius: 4px; margin-top: 3px; overflow: hidden; max-width: 220px; }
#hud-xpfill { height: 100%; width: 0; background: var(--gold); transition: width .4s; }
.hud-stat { font-weight: 700; font-size: 15px; background: rgba(255,255,255,0.1); padding: 4px 10px; border-radius: 10px; }

.objective {
  position: absolute; top: 74px; left: 8px; max-width: min(420px, calc(100% - 16px));
  background: rgba(255,250,240,0.95); border-left: 5px solid var(--gold); padding: 8px 12px;
  border-radius: 10px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); pointer-events: none;
}
.objective b { color: var(--navy-2); }
.prompt {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  background: rgba(20,33,61,0.92); color: #fff; padding: 8px 14px; border-radius: 20px; font-weight: 600;
  pointer-events: none; white-space: nowrap; font-size: 14px;
}
.toasts { position: absolute; top: 74px; right: 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  background: var(--navy-2); color: #fff; padding: 10px 14px; border-radius: 12px; font-weight: 600; font-size: 14px;
  border: 2px solid var(--gold); box-shadow: 0 6px 16px rgba(0,0,0,0.3); animation: toastIn .3s ease-out;
  max-width: 280px;
}
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.menu-bar {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px;
  background: rgba(20,33,61,0.9); padding: 6px; border-radius: 16px;
}
.mbtn {
  border: 0; background: transparent; color: #fff; display: flex; flex-direction: column; align-items: center;
  font-size: 20px; padding: 4px 10px; border-radius: 10px; min-width: 60px;
}
.mbtn span { font-size: 11px; font-weight: 600; margin-top: 2px; }
.mbtn:hover { background: rgba(255,255,255,0.12); }

/* ---------- Contrôles tactiles ---------- */
.touch-controls { position: absolute; left: 0; right: 0; bottom: 78px; display: flex; justify-content: space-between; padding: 0 16px; pointer-events: none; }
.touch-controls .dpad { visibility: hidden; }
.touch-controls.show .dpad { visibility: visible; }
.dpad { position: relative; width: 138px; height: 138px; pointer-events: auto; }
.dbtn {
  position: absolute; width: 46px; height: 46px; border-radius: 12px; border: 0;
  background: rgba(20,33,61,0.75); color: #fff; font-size: 18px;
}
.dbtn.up { left: 46px; top: 0; } .dbtn.down { left: 46px; bottom: 0; }
.dbtn.left { left: 0; top: 46px; } .dbtn.right { right: 0; top: 46px; }
.dbtn.on { background: var(--gold); color: var(--navy); }
.actions { display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
.abtn {
  width: 66px; height: 66px; border-radius: 50%; border: 0; background: rgba(20,33,61,0.85); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px;
}
.abtn span { font-size: 10px; font-weight: 700; }

/* ---------- Modale ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,16,32,0.6); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50;
}
.modal {
  width: min(560px, 100%); max-height: calc(100% - 32px); display: flex; flex-direction: column;
  background: var(--paper); border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,0.4); overflow: hidden;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--navy); color: #fff; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x { border: 0; background: transparent; color: #fff; font-size: 20px; padding: 2px 8px; }
.modal-body { padding: 16px; overflow-y: auto; line-height: 1.5; font-size: 15px; -webkit-user-select: text; user-select: text; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid #eadfc8; }
.modal-foot:empty { display: none; }

.speaker { display: flex; gap: 12px; align-items: flex-start; }
.avatar { flex: none; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 20px; }
.say { margin: 0; }
.clue-box { background: #fff3d6; border: 2px dashed var(--gold); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-weight: 600; }
.question { font-weight: 700; color: var(--navy-2); }
.fields { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field label { flex: 1 1 160px; font-weight: 600; }
.field input { width: 140px; padding: 9px 10px; font-size: 16px; border-radius: 10px; border: 2px solid #cfc3a8; -webkit-user-select: text; user-select: text; }
.field input.ok { border-color: var(--ok); background: #eaf7ee; }
.field input.ko { border-color: var(--ko); background: #fdecec; }
.unit { color: var(--muted); font-weight: 600; min-width: 46px; }
.feedback { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 600; }
.feedback.ok { background: #eaf7ee; color: #1d6b35; }
.feedback.ko { background: #fdecec; color: #8f2222; }
.hint { background: #eef3ff; border-left: 4px solid #4a6fd1; padding: 8px 10px; border-radius: 8px; margin-top: 8px; }
.hint b { color: #2c4aa0; }

.reward { text-align: center; }
.reward .big { font-size: 54px; line-height: 1; animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { from { filter: drop-shadow(0 0 4px var(--gold)); } to { filter: drop-shadow(0 0 18px var(--gold)); } }
.reward-list { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.chip { background: var(--navy); color: #fff; padding: 6px 12px; border-radius: 20px; font-weight: 700; font-size: 14px; }
.page { background: #f6ecd6; border: 1px solid #d9c59b; border-radius: 12px; padding: 12px; text-align: left; margin-top: 10px; }
.page h4 { margin: 0 0 6px; color: #6b4a12; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: #fff; border: 1px solid #eadfc8; }
.item .ico { font-size: 24px; width: 34px; text-align: center; }
.item .txt { flex: 1; }
.item .txt small { color: var(--muted); display: block; }
.item button { flex: none; }
.status { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; white-space: nowrap; }
.status.done { background: #eaf7ee; color: #1d6b35; }
.status.todo { background: #fff3d6; color: #8a5a00; }
.status.lock { background: #eceff3; color: #5d6472; }
.section-title { margin: 14px 0 8px; font-size: 15px; color: var(--navy-2); }
.section-title:first-child { margin-top: 0; }
.comp { margin-bottom: 8px; }
.comp-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.comp-bar { height: 10px; background: #eadfc8; border-radius: 6px; overflow: hidden; }
.comp-bar div { height: 100%; background: var(--ok); }
.minimap { width: 100%; height: auto; border-radius: 12px; border: 2px solid var(--navy); display: block; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin-top: 8px; color: var(--muted); }
kbd { background: #eee; border: 1px solid #ccc; border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 13px; }

@media (max-width: 640px) {
  .hud-stat { font-size: 13px; padding: 3px 7px; }
  .hud-logo { width: 36px; }
  .mbtn { min-width: 50px; padding: 4px 6px; }
  .objective { top: 96px; font-size: 13px; }
  .toasts { top: 150px; }
  .prompt { bottom: 236px; }
}

/* ---------- V0.3 : choix multiples et remise en ordre ---------- */
.field.choice { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; border-radius: 12px; background: #fff; border: 1px solid #eadfc8; }
.flabel { font-weight: 600; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; border-radius: 10px; padding: 2px; border: 2px solid transparent; }
.opt { border: 2px solid #cfc3a8; background: #fffdf8; color: var(--ink); border-radius: 18px; padding: 6px 12px; font-size: 14px; font-weight: 600; }
.opt:hover { border-color: var(--gold); }
.opt.sel { background: var(--navy); border-color: var(--navy); color: #fff; }
.opt:focus-visible, .obtn:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }
.opts.ok { border-color: var(--ok); background: #eaf7ee; }
.opts.ko { border-color: var(--ko); background: #fdecec; }
.order-list { list-style: none; counter-reset: frag; margin: 10px 0 0; padding: 4px; display: flex; flex-direction: column; gap: 6px; border-radius: 12px; border: 2px solid transparent; }
.order-list li { counter-increment: frag; display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #eadfc8; border-radius: 10px; padding: 8px 8px 8px 10px; }
.order-list li::before { content: counter(frag); flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; }
.otxt { flex: 1; min-width: 0; }
.obtns { display: flex; flex-direction: column; gap: 4px; }
.obtn { border: 0; background: #eef1f7; color: var(--navy); border-radius: 8px; width: 34px; height: 26px; font-size: 12px; }
.obtn:hover { background: var(--gold-soft); }
.order-list.ok { border-color: var(--ok); background: #eaf7ee; }
.order-list.ko { border-color: var(--ko); background: #fdecec; }

/* V0.5 : épreuves du final et certificat */
.stage-dots { display: flex; justify-content: center; gap: 8px; margin: 0 0 12px; flex-wrap: wrap; }
.sdot { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; background: #e4e7ee; color: #5b6478; border: 2px solid transparent; }
.sdot.done { background: #2e9d4f; color: #fff; }
.sdot.cur { background: #fca311; color: #14213d; border-color: #14213d; }
.cert { text-align: center; background: #fffaf0; border: 6px double #14213d; outline: 2px solid #fca311; outline-offset: -12px; border-radius: 10px; padding: 22px 18px; color: #14213d; }
.cert-logo { width: 110px; height: auto; display: block; margin: 0 auto 6px; }
.cert-kicker { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }
.cert-title { font-family: Georgia, serif; font-size: 26px; margin: 8px 0 4px; }
.cert-small { font-style: italic; color: #555; margin: 4px 0; }
.cert-name { font-family: Georgia, serif; font-size: 32px; font-weight: 700; color: #b5651d; margin: 4px 0 10px; word-break: break-word; }
.cert-date { font-family: Georgia, serif; font-style: italic; margin-top: 6px; }
@media (max-width: 480px) { .cert-title { font-size: 21px; } .cert-name { font-size: 26px; } .cert { padding: 18px 10px; } }

/* V0.6 : boutons d'action visibles sur PC, tutoriel guidé */
.abtn em.key { font-style: normal; }
.touch-controls.show .abtn em.key { display: none; }
.touch-controls:not(.show) .abtn { width: 78px; height: 78px; }
.abtn.ready { background: var(--gold); color: var(--navy); box-shadow: 0 0 0 4px rgba(252,163,17,0.35); animation: readyPulse 1s ease-in-out infinite alternate; }
@keyframes readyPulse { from { box-shadow: 0 0 0 3px rgba(252,163,17,0.25); } to { box-shadow: 0 0 0 9px rgba(252,163,17,0.5); } }
.coach {
  position: absolute; left: 50%; bottom: 196px; transform: translateX(-50%); width: min(560px, calc(100% - 32px));
  background: #fffaf0; border: 3px solid var(--gold); border-radius: 14px; padding: 10px 14px; text-align: center;
  font-size: 15px; line-height: 1.4; color: var(--navy); box-shadow: 0 8px 20px rgba(0,0,0,0.3); pointer-events: none;
}
.coach b { color: #b06d00; }
.coach kbd { color: var(--navy); }
@media (max-width: 640px) { .coach { bottom: 282px; font-size: 14px; } }

.tuto-link { display: inline-block; margin-top: 14px; color: var(--gold-soft); font-weight: 700; text-decoration: none; border-bottom: 2px solid rgba(255,210,122,.5); }
.tuto-link:hover { color: #fff; border-color: #fff; }
