html, body {
  margin: 0;
  height: 100%;
  background: #000;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* La scène garde le format d'origine (350×490) et occupe le plus de place possible. */
#game {
  --pad-h: 0px;
  position: relative;
  grid-area: game;
  width: min(100vw, calc((100dvh - 36px - env(safe-area-inset-top) - var(--pad-h)) * 350 / 490));
  aspect-ratio: 350 / 490;
  background: #fff;
  overflow: hidden;
}

.stage {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
}

#loading {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  font: 20px/1 sans-serif;
  letter-spacing: 0.1em;
}

/* --- Contrôles tactiles : seulement sur écran tactile -------------------------------------- */

.pad { display: none; }


@media (pointer: coarse), (hover: none) {
  body:not(.no-touch) .pad { display: grid; }
}
body.touch .pad { display: grid; }

#app {
  display: grid;
  grid-template-areas: "head head" "game game" "move act";
  grid-template-columns: 1fr 1fr;
  justify-items: center;
  align-items: center;
  height: 100dvh;
  width: 100vw;
  align-content: center;
}

.pad {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.pad button {
  appearance: none;
  border: 2px solid #555;
  border-radius: 14px;
  background: #222;
  color: #eee;
  font: 600 15px/1.1 system-ui, sans-serif;
  touch-action: none;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 0;
}
.pad button small { display: block; font-weight: 400; font-size: 11px; opacity: 0.6; margin-top: 2px; }
.pad button.on { background: #e8e8e8; color: #111; border-color: #fff; }

.pad-move {
  grid-area: move;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 46px);
  grid-template-areas: ". up ." "left . right" ". down .";
}
.pad-move button { font-size: 20px; }
.pad-move .up { grid-area: up; }
.pad-move .down { grid-area: down; }
.pad-move .left { grid-area: left; }
.pad-move .right { grid-area: right; }

.pad-act {
  grid-area: act;
  grid-template-columns: 76px 76px;
  grid-template-rows: 64px 40px;
}
.pad-act .big { border-radius: 50%; width: 72px; height: 64px; justify-self: center; }
.pad-act .grappin { border-color: #6a8; }
.pad-act .graine { border-color: #a86; }
.pad-act .small { font-size: 13px; border-radius: 10px; }

/* Portrait tactile : la scène laisse la place aux boutons en dessous. */
@media (pointer: coarse) and (orientation: portrait), (hover: none) and (orientation: portrait) {
  #game { --pad-h: 170px; }
}
body.touch #game { --pad-h: 170px; }

/* Paysage tactile : boutons de chaque côté de la scène. */
@media (orientation: landscape) {
  #app {
    grid-template-areas: "head head head" "move game act";
    grid-template-columns: 1fr auto 1fr;
  }
  #game { --pad-h: 0px !important; }
}

/* --- Les créateurs (les bios de l'ancienne page opniyama.free.fr) ------------------------- */

#topbar {
  grid-area: head;
  justify-self: stretch;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 36px;
  box-sizing: border-box;
  padding: 0 calc(8px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
  margin-top: env(safe-area-inset-top);
}

#credits-btn {
  appearance: none;
  border: 1px solid #666;
  border-radius: 6px;
  background: #000;
  color: #ccc;
  font: 12px/1 "Courier New", Courier, monospace;
  padding: 6px 9px;
  cursor: pointer;
}
#credits-btn:hover { color: #fff; border-color: #ccc; }

#credits {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  box-sizing: border-box;
  border: 1px solid #ccc;
  background: #000;
  color: #fff;
  padding: 20px 24px;
  font: 15px/1.5 Georgia, serif;
}
#credits::backdrop { background: rgba(0, 0, 0, 0.75); }
#credits h1 { font-size: 20px; margin: 0 0 12px; }
#credits h2 { font-size: 16px; margin: 18px 0 4px; }
#credits h2 small { font-weight: normal; color: #999; }
#credits p { margin: 0; }
#credits a { color: #999; }
#credits .copyright { margin-top: 20px; font: 11px "Courier New", Courier, monospace; text-align: center; }
#credits form { position: absolute; top: 8px; right: 10px; }
#credits .close {
  appearance: none; border: 0; background: none; color: #ccc;
  font-size: 26px; line-height: 1; cursor: pointer; padding: 4px;
}
#copyright {
  margin: 0;
  color: #fff;
  font: 11px/1.2 "Courier New", Courier, monospace;
}
#copyright a { color: #999; }
@media (max-width: 600px) { #copyright .long { display: none; } }
