:root {
  --bg: #14161d;
  --panel: #1c2029;
  --line: #2c313d;
  --fg: #e7e9ee;
  --dim: #929aab;
  --accent: #ffd453;
  --sv: #ff9f6b;
  --lc: #6bc6ff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

#app {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  position: relative;
  min-width: 0;
}

canvas {
  image-rendering: pixelated;
  background: #000;
  border: 3px solid #333844;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.45);
}

#hud {
  position: absolute;
  top: 22px;
  left: 22px;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #d8ffd0;
  background: rgb(8 12 8 / 0.66);
  border: 1px solid #2f4a2f;
  border-radius: 4px;
  padding: 6px 9px;
  white-space: pre;
  pointer-events: none;
}

#keys {
  margin: 0;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
}

kbd {
  background: #262b36;
  border: 1px solid #3b4250;
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  margin: 0 1px;
  font: 11px ui-monospace, monospace;
  color: var(--accent);
}

#panel {
  width: 340px;
  flex: none;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  max-height: 100vh;
}

#panel h1 {
  margin: 0 0 4px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.status {
  margin: 0 0 14px;
  font: 11px ui-monospace, monospace;
  color: var(--dim);
}
.status.ok {
  color: #7fdc8a;
}
.status.ko {
  color: #ff7b6b;
}

.block {
  margin-bottom: 14px;
}

.tune {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

label {
  display: block;
  font-size: 12px;
  color: var(--fg);
  margin-bottom: 5px;
}

.tune .row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tune input[type='range'] {
  flex: 1;
  accent-color: var(--accent);
  min-width: 0;
}

.tune .val {
  font: 11px ui-monospace, monospace;
  color: var(--accent);
  min-width: 62px;
  text-align: right;
}

.tune .help {
  margin: 5px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--dim);
}

.tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 6px;
  vertical-align: 1px;
}
.sv {
  color: var(--sv);
}
.lc {
  color: var(--lc);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toggle input {
  accent-color: var(--accent);
}
.toggle label {
  margin: 0;
}

input[type='text'],
select,
button {
  width: 100%;
  background: #12151c;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  font: 12px inherit;
}

button {
  cursor: pointer;
  margin-top: 10px;
}
button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.note {
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 14px;
}

@media (max-width: 900px) {
  #app {
    flex-direction: column;
  }
  #panel {
    width: 100%;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

/* ------------------------------------------------------------------ plein ecran
   Mode "zen" : on masque les reglages et les rappels de touches, le canvas prend
   toute la fenetre. Il est independant du plein ecran NATIF du navigateur (qui
   peut etre refuse) : les deux sont demandes ensemble, mais zen fonctionne seul. */

#go-zen {
  margin-bottom: 14px;
}

#quit-zen {
  display: none;
  position: absolute;
  top: 14px;
  right: 16px;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--dim);
  background: rgb(8 12 8 / 0.62);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  /* Seule porte de sortie visible : discret, mais jamais illisible sur une carte
     claire (0.35 disparaissait sur le sable). */
  opacity: 0.55;
  transition: opacity 0.15s;
}
#quit-zen:hover {
  opacity: 1;
  color: var(--fg);
}

body.zen #panel,
body.zen #keys {
  display: none;
}
body.zen #quit-zen {
  display: flex;
}
body.zen #stage {
  padding: 0;
  gap: 0;
}
body.zen canvas {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* ------------------------------------------------------------------- dialogue
   Posee sur le canvas, en bas, comme dans les jeux d'origine. Elle reste visible
   en plein ecran (c'est le seul moment ou l'on a besoin de lire). */

#dialog {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 40px));
  padding: 14px 16px 10px;
  background: rgb(12 16 22 / 0.94);
  border: 2px solid #6a7688;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  z-index: 20;
}
#dialog[hidden] {
  display: none;
}
#dialog-who {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffd453;
}
#dialog-text {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.45;
}
#dialog-choices {
  display: flex;
  gap: 10px;
}
#dialog-choices button {
  flex: 1;
  padding: 8px 0;
  font-size: 14px;
  color: var(--fg);
  background: #232a36;
  border: 2px solid #3b465a;
  border-radius: 5px;
  cursor: pointer;
}
#dialog-choices button[aria-selected='true'] {
  border-color: #ffd453;
  background: #35405400;
  background: #2f3a4c;
  color: #fff;
}
#dialog .hint {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--dim);
  text-align: center;
}

/* ------------------------------------------------------------ ecran d'accueil
   Pose par-dessus le jeu, qui tourne deja derriere. Le splash sert de fond, avec
   un voile sombre : sans lui le texte devient illisible des que l'image est
   claire, et une image de jeu est rarement uniforme. */

#title-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(12, 18, 26, 0.72), rgba(12, 18, 26, 0.88)),
    url('/assets/splash.jpg') center / cover no-repeat;
}
#title-screen[hidden] { display: none; }
/* `hidden` est une regle du navigateur a tres faible priorite : n'importe quel
   `display` de classe l'ecrase. On le retablit explicitement, sinon un bloc
   masque en JavaScript reste visible — ce qui est arrive aux liens de compte. */
#title-screen [hidden] { display: none !important; }

.t-carte {
  width: min(440px, 100%);
  text-align: center;
  color: #f4f1ea;
  background: rgba(20, 28, 38, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  padding: 32px 28px;
  backdrop-filter: blur(3px);
}
.t-carte h1 { font-size: 22px; margin: 0 0 10px; line-height: 1.25; }
.t-carte p { margin: 0 0 20px; color: #b9c2cf; line-height: 1.5; }
.t-carte form { display: grid; gap: 6px; text-align: left; margin-bottom: 14px; }
.t-carte label { font-size: 13px; color: #b9c2cf; }
.t-carte input {
  font: inherit;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #f4f1ea;
  margin-bottom: 6px;
}
.t-carte input:focus { outline: 2px solid #5fa85a; outline-offset: 1px; }

.t-cta {
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  width: 100%;
  padding: 15px 24px;
  border: 0;
  border-radius: 11px;
  background: #3f8f4f;
  color: #fff;
  cursor: pointer;
}
.t-cta:hover { background: #47a058; }
.t-cta:disabled { opacity: 0.6; cursor: progress; }

.t-liens { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 16px 0 0; font-size: 14px; }
.t-lien {
  font: inherit;
  font-size: 14px;
  background: none;
  border: 0;
  color: #8fd3f0;
  cursor: pointer;
  padding: 6px 4px;
  text-decoration: underline;
}
.t-lien:hover { color: #b6e4f7; }

.t-profils { display: grid; gap: 8px; margin-bottom: 12px; }
.profil {
  font: inherit;
  font-size: 16px;
  padding: 13px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #f4f1ea;
  cursor: pointer;
}
.profil:hover { background: rgba(255, 255, 255, 0.12); }
.profil.actif { border-color: #5fa85a; }

.t-gros { font-size: 34px; margin: 0 0 8px; }
.t-petit { font-size: 13px; color: #8b95a3; }
.t-erreur { color: #e8a0a0; margin: 14px 0 0; font-size: 14px; }
