/* Jeu de plateforme rétro : écran 320 × 180 agrandi en pixels nets */
:root { --l: 960px; --h: 540px; --k: 3; --pixel: "Press Start 2P", "Courier New", monospace; --lecture: VT323, "Courier New", monospace; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
body { display: grid; place-items: center; font-family: var(--pixel); color: #fffdf7; }
.scene { position: relative; width: var(--l); height: var(--h); }
canvas#ecran { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
#annotations { display: block; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
[hidden] { display: none !important; }

/* Les chiffres sont composés par le navigateur à la résolution de l’écran. */
#interface-jeu {
  position: absolute; inset: 0; pointer-events: none; color: #fffdf7;
  font: 700 clamp(12px, calc(9px * var(--k)), 44px)/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.ligne-compteurs > span {
  position: absolute; top: 0; height: calc(23px * var(--k)); left: calc(var(--x) * var(--k));
  display: flex; align-items: center; white-space: nowrap;
}
.ligne-compteurs b {
  font-weight: inherit;
  -webkit-text-stroke: clamp(1px, calc(.65px * var(--k)), 3px) #243049;
  paint-order: stroke fill;
}
.ligne-compteurs .complet { color: #9be85a; }
.ligne-compteurs > .niveau { left: auto; right: calc(8px * var(--k)); }
.lecture-seule { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#legende-toxicite, #message-jeu {
  position: absolute; left: 0; width: 100%; text-align: center;
  font-size: max(11px, calc(7px * var(--k))); line-height: 1.18;
}
#legende-toxicite { top: 17%; width: auto; left: 50%; transform: translateX(-50%); background: #211b2d; color: #e7c9ff; padding: 0 .35em; }
#message-jeu { top: 39%; padding: .35em .5em; background: rgb(26 20 40 / 92%); color: #ffb07c; text-wrap: balance; }
#message-jeu.aide { top: 15%; color: #adf375; }
#message-jeu:empty { display: none; }
#legende-toxicite:not([hidden]) + #message-jeu.aide { top: 27%; }

/* Tailles exprimées en « pixels du jeu » × facteur d'agrandissement */
.couche { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: calc(4px * var(--k)); padding: calc(10px * var(--k)); }
.petit { margin: 0; font-size: calc(6px * var(--k)); letter-spacing: .1em; text-transform: uppercase; color: #ffe58a; text-shadow: calc(1px * var(--k)) calc(1px * var(--k)) 0 #1a1428; }

.titre {
  justify-content: flex-start; padding-top: calc(12px * var(--k));
  background: linear-gradient(to bottom, rgb(18 34 68 / 32%), transparent 58%, transparent 84%, rgb(18 26 34 / 58%));
}
.titre .petit { color: #fff7d6; text-shadow: none; }
.titre h1 {
  margin: calc(4px * var(--k)) 0 0;
  font: 700 calc(17px * var(--k))/1.07 "Press Start 2P", Silom, "Lucida Console", monospace;
  text-transform: uppercase; color: #ffda51;
  -webkit-text-stroke: calc(.8px * var(--k)) #263452;
  paint-order: stroke fill;
}
.titre .sous { margin: 0; font-size: calc(7px * var(--k)); font-weight: 700; color: #18223d; }
.commandes { position: absolute; bottom: calc(4px * var(--k)); left: 0; right: 0; margin: 0; font-family: var(--lecture); font-size: calc(7.5px * var(--k)); color: #fffdf7; }

.menu { list-style: none; margin: calc(6px * var(--k)) 0 0; padding: 0; display: grid; gap: calc(2px * var(--k)); }
.menu li { padding: calc(3px * var(--k)) calc(8px * var(--k)); font-size: calc(7px * var(--k)); background: rgba(26, 20, 40, .82); border: calc(1px * var(--k)) solid transparent; cursor: pointer; }
.menu li.sel { border-color: #ffcc3d; color: #ffcc3d; }
.menu li.sel::before { content: "▶ "; }

.carton { background: #1a1428; }
.carton h2 { margin: 0; font-size: calc(12px * var(--k)); color: #9be85a; }
.carton p { margin: 0; font-family: var(--lecture); font-size: calc(11px * var(--k)); }
.clignote { margin-top: calc(10px * var(--k)) !important; font-family: var(--pixel) !important; font-size: calc(6px * var(--k)) !important; animation: clignote 1s steps(2) infinite; }
@keyframes clignote { 50% { opacity: 0; } }

.voile { background: rgba(26, 20, 40, .85); gap: calc(2.5px * var(--k)); padding: calc(5px * var(--k)); }
.voile .menu { margin-top: calc(4px * var(--k)); }
.voile h2 { margin: 0; font-size: calc(10px * var(--k)); color: #9be85a; }
.stats { list-style: none; margin: calc(2px * var(--k)) 0; padding: 0; display: grid; gap: calc(1px * var(--k)); min-width: 60%; }
.stats li { display: flex; justify-content: space-between; gap: calc(12px * var(--k)); font-family: var(--lecture); font-size: calc(8.5px * var(--k)); line-height: 1; }
.stats b { color: #ffcc3d; font-weight: 400; }
.suite { margin: 0; font-family: var(--lecture); font-size: calc(8px * var(--k)); line-height: 1; color: #c4c0cf; }

/* Boîte de dialogue façon 16 bits */
.dialogue {
  position: absolute; left: calc(8px * var(--k)); right: calc(8px * var(--k)); bottom: calc(6px * var(--k));
  display: flex; gap: calc(6px * var(--k)); align-items: flex-start;
  min-height: calc(46px * var(--k)); padding: calc(5px * var(--k)) calc(7px * var(--k));
  background: linear-gradient(#2a3f9a, #1a2a6c); color: #fffdf7;
  border: calc(1px * var(--k)) solid #fffdf7; outline: calc(1px * var(--k)) solid #1a1428;
  box-shadow: inset 0 0 0 calc(1px * var(--k)) #5a7bd8;
}
.visage { flex: none; width: calc(30px * var(--k)); height: calc(30px * var(--k)); image-rendering: pixelated; background: #8fb8ff; border: calc(1px * var(--k)) solid #fffdf7; }
.dlg-corps { flex: 1; min-width: 0; }
.dlg-nom { margin: 0 0 calc(2px * var(--k)); font: 700 max(12px, calc(6.5px * var(--k)))/1.2 system-ui, sans-serif; color: #ffcc3d; }
.dlg-texte { margin: 0; font: 500 max(15px, calc(9px * var(--k)))/1.22 system-ui, sans-serif; }
.dlg-suite { position: absolute; right: calc(5px * var(--k)); bottom: calc(3px * var(--k)); font-size: calc(5px * var(--k)); animation: clignote .8s steps(2) infinite; }
.dlg-choix { list-style: none; margin: calc(3px * var(--k)) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: calc(3px * var(--k)) calc(8px * var(--k)); }
.dlg-choix li { font: 600 max(14px, calc(8.5px * var(--k)))/1.2 system-ui, sans-serif; padding: 0 calc(3px * var(--k)); }
.dlg-choix li.sel { background: #fffdf7; color: #1a2a6c; }
.dlg-choix li.sel::before { content: "▶ "; }

.rouge { color: #ff5a4a !important; }
.raison { margin: 0; font-family: var(--lecture); font-size: calc(10px * var(--k)); color: #fffdf7; }
.dlg-nom[data-statut="comestible"] { color: #9be85a; }
.dlg-nom[data-statut="toxique"] { color: #ff8a3d; }
.dlg-nom[data-statut="mortel"] { color: #ff5a4a; }

/* Cadenas des salles d'enquête */
.boite-code { display: grid; gap: calc(3px * var(--k)); justify-items: center; padding: calc(8px * var(--k)) calc(14px * var(--k)); background: #2a1e16; border: calc(1px * var(--k)) solid #ffcc3d; box-shadow: calc(3px * var(--k)) calc(3px * var(--k)) 0 #1a1428; }
.champ-code {
  width: calc(110px * var(--k)); padding: calc(3px * var(--k)); text-align: center; letter-spacing: .4em;
  font-family: var(--pixel); font-size: calc(12px * var(--k)); text-transform: uppercase;
  background: #1a1428; color: #ffcc3d; border: calc(1px * var(--k)) solid #fffdf7; outline: none;
}
.erreur-code { margin: 0; min-height: 1em; font-family: var(--lecture); font-size: calc(9px * var(--k)); color: #ff8a3d; max-width: calc(240px * var(--k)); }
.aide-code { margin: 0; font-family: var(--lecture); font-size: calc(8px * var(--k)); color: #c4c0cf; }
.secoue { animation: secoue .35s; }
@keyframes secoue { 25%, 75% { transform: translateX(calc(-4px * var(--k))); } 50% { transform: translateX(calc(4px * var(--k))); } }

/* Code de victoire */
.code { margin: calc(2px * var(--k)) 0; padding: calc(3px * var(--k)) calc(10px * var(--k)); border: calc(1px * var(--k)) dashed #ffcc3d; font-family: var(--lecture); font-size: calc(8px * var(--k)); color: #fffdf7; display: grid; gap: calc(1px * var(--k)); }
.code b { font-family: var(--pixel); font-size: calc(9px * var(--k)); color: #ffcc3d; letter-spacing: .08em; }
.code small { color: #c4c0cf; font-size: calc(7px * var(--k)); }

/* ---------- Manette tactile ---------- */
.manette { display: none; }
.commandes-tactiles { display: none; }
body.tactile .commandes-tactiles { display: block; }
body.tactile .commandes-clavier, body.tactile .aide-code { display: none; }
body.tactile { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; }
body.tactile .manette {
  display: flex; justify-content: space-between; align-items: flex-end;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  pointer-events: none;
}
.manette button {
  pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent;
  font-family: var(--pixel); color: #fffdf7; border: 3px solid #1a1428; cursor: pointer;
  box-shadow: 0 4px 0 #1a1428; transition: transform .05s;
}
.manette button.enfonce { transform: translateY(3px); box-shadow: 0 1px 0 #1a1428; filter: brightness(1.15); }
.croix { display: flex; gap: 8px; align-items: flex-end; }
.croix button { width: 64px; height: 64px; border-radius: 14px; background: rgba(42, 63, 154, .85); font-size: 20px; }
.croix .petit-bouton { width: 48px; height: 48px; font-size: 14px; background: rgba(42, 63, 154, .7); }
.actions { display: flex; gap: 12px; align-items: flex-end; }
.actions button { width: 72px; height: 72px; border-radius: 50%; font-size: 20px; display: grid; place-items: center; line-height: 1; }
.actions small { display: block; font-size: 7px; margin-top: -8px; }
.b-saut { background: rgba(70, 184, 58, .9); margin-bottom: 26px; }
.b-action { background: rgba(255, 79, 163, .85); }
.bouton-pause { align-self: flex-start; width: 44px; height: 32px; border-radius: 8px; background: rgba(26, 20, 40, .6); font-size: 10px; }

/* Paysage : boutons par-dessus le jeu, un peu transparents */
body.tactile:not(.portrait) .manette { opacity: .7; }
body.tactile:not(.portrait) .croix button { width: 56px; height: 56px; }
body.tactile:not(.portrait) .actions button { width: 62px; height: 62px; }
body.tactile:not(.portrait) .bouton-pause { position: fixed; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); }

/* Portrait : le jeu en haut, la manette en dessous */
body.tactile.portrait { place-items: start center; background: #1a1428; }
body.tactile.portrait .scene { margin-top: max(var(--marge-haut, 10px), env(safe-area-inset-top)); }
body.tactile.portrait .scene::after { content: "Astuce : tournez le téléphone pour jouer en grand"; position: absolute; left: 0; right: 0; top: calc(100% + 14px); text-align: center; font-family: var(--lecture); font-size: 15px; color: #8e8a9c; }
body.tactile.portrait .manette { height: 220px; align-items: center; background: linear-gradient(#1a1428, #2a2240); border-top: 2px solid #3d3756; }
body.tactile.portrait .bouton-pause { align-self: center; }

/* Cadenas : boutons pour le tactile (et la souris) */
.boutons-code { display: flex; gap: calc(6px * var(--k)); margin-top: calc(2px * var(--k)); }
.boutons-code button { font-family: var(--pixel); font-size: max(10px, calc(6px * var(--k))); padding: 8px 14px; border: 2px solid #fffdf7; background: #1a1428; color: #fffdf7; cursor: pointer; }
#saisie-valider { background: #46b83a; color: #1a1428; border-color: #1a1428; }
body.tactile .champ-code { font-size: max(16px, calc(12px * var(--k))); }
