/* Trapped Among the Hordes. Estilo de 2022 (botón rojo, título, escenario)
   y, desde 2026, pantallas como capas, barra de opciones, controles
   táctiles y diseño para teléfono en vertical y horizontal. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* Espacio vertical que el escenario deja para la barra y el título. */
  --reserve: 150px;
  --cream: blanchedalmond;
}

body {
  margin: 0;
  min-height: 100svh;
  background: #07080f url("./assets/Cover-2.jpg") center / cover fixed;
  color: var(--cream);
  font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
  /* Sin "rebote" ni recarga al arrastrar el dedo en el borde. */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Escenario ----------------------------------------------------------- */

.stage {
  min-height: 100svh;
  display: grid;
  grid-template-areas: "canvas" "controls" "name";
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 60px 12px 16px;
}

/* Tamaño de 2022 (1027 × 769) como máximo; si no cabe, el escenario se
   reduce entero para verse completo. */
#canvas {
  grid-area: canvas;
  background-color: rgb(255, 255, 255);
  background-image: url("./assets/EscenarioFinal.png");
  background-size: 100% 100%;
  width: min(1027px, 96vw, calc((100svh - var(--reserve)) * 1027 / 769));
  height: auto;
  aspect-ratio: 1027 / 769;
  /* Los dedos sobre el juego no desplazan ni hacen zoom en la página. */
  touch-action: none;
}

.name {
  grid-area: name;
  margin: 0;
  font-size: 36px;
}

/* ---- Barra de opciones (pausa, música, efectos) --------------------------- */

.hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  gap: 6px;
}

.hud-button {
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid rgba(255, 235, 205, 0.55);
  border-radius: 8px;
  background: rgba(9, 11, 30, 0.8);
  color: var(--cream);
  font: bold 14px/1 monospace;
  cursor: pointer;
}

.hud-button[hidden] {
  display: none;
}

.hud-button .state,
.hud-button .key {
  margin-left: 4px;
  opacity: 0.75;
}

.hud-button[aria-pressed="false"] .state {
  text-decoration: line-through;
}

#musicButton[aria-pressed="false"],
#sfxButton[aria-pressed="false"] {
  opacity: 0.7;
  border-style: dashed;
}

.hud-button:focus-visible,
.touch-btn:focus-visible {
  outline: 3px solid gold;
  outline-offset: 2px;
}

/* ---- Controles táctiles ---------------------------------------------------- */

.touch-controls {
  grid-area: controls;
  display: none;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.touch-move {
  display: flex;
  gap: 14px;
}

.touch-btn {
  width: 76px;
  height: 76px;
  border: 2px solid rgba(255, 235, 205, 0.6);
  border-radius: 50%;
  background: rgba(20, 24, 48, 0.8);
  color: var(--cream);
  font-size: 30px;
  line-height: 1;
  /* Mantener pulsado: sin selección de texto, menú ni zoom. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-btn.is-down {
  background: rgba(250, 39, 7, 0.85);
  border-color: gold;
}

.touch-fire {
  width: 96px;
  height: 96px;
  background: linear-gradient(#fa2707, #b30000);
  font: 24px/1 Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 1px;
}

.touch-fire.is-down {
  background: gold;
  color: #3a0000;
}

/* Teléfono o tableta (dedo como puntero principal), o en cuanto alguien
   toca un botón táctil en un portátil con pantalla táctil. */
@media (hover: none) and (pointer: coarse) {
  :root {
    --reserve: 200px;
  }
  .touch-controls {
    display: flex;
  }
  .name {
    display: none;
  }
}

body[data-touch="true"] .touch-controls {
  display: flex;
}

/* Teléfono en horizontal: botones de mover a la izquierda del escenario
   y el de disparar a la derecha, para jugar con los dos pulgares. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .stage {
    grid-template-areas: "move canvas fire";
    grid-template-columns: auto minmax(0, auto) auto;
    align-items: center;
    gap: 12px;
    padding: 56px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  }
  .touch-controls,
  body[data-touch="true"] .touch-controls {
    display: contents;
  }
  .touch-move {
    grid-area: move;
    align-self: end;
    gap: 10px;
    margin-bottom: 12px;
  }
  .touch-btn {
    width: 68px;
    height: 68px;
  }
  .touch-fire {
    grid-area: fire;
    align-self: end;
    width: 92px;
    height: 92px;
    margin-bottom: 8px;
  }
  #canvas {
    width: min(100%, calc((100svh - 64px) * 1027 / 769));
  }
}

/* ---- Pantallas: inicio, pausa y "You are dead" ------------------------------ */

.menu {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 8px 8px;
  background: rgba(4, 5, 12, 0.55);
}

body[data-state="menu"] .startMenu,
body[data-state="paused"] .pauseMenu,
body[data-state="over"] .endMenu {
  display: flex;
}

.menu-card {
  position: relative;
  width: min(1131px, 100%, calc((100svh - 80px) * 1131 / 800));
}

.cover {
  display: block;
  width: 100%;
  height: auto;
}

.MenuButton {
  align-items: center;
  background-color: initial;
  background-image: linear-gradient(#fa2707, #ff0000);
  border-radius: 8px;
  border-width: 0;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.05);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(20px, 3.4vw, 30px);
  height: clamp(48px, 8vw, 75px);
  justify-content: center;
  line-height: 1;
  margin: 0;
  outline: none;
  padding: 0 clamp(18px, 3vw, 32px);
  white-space: nowrap;
  transition: box-shadow 150ms;
  position: absolute;
  z-index: 1;
  top: 62%;
  left: 50%;
  transform: translate(-50%, 0);
}

.MenuButton--inline {
  position: static;
  transform: none;
}

.MenuButton:hover {
  box-shadow: rgba(255, 0, 0, 0.986) 0 2px 8px;
}

.MenuButton:focus-visible {
  box-shadow: rgba(255, 215, 0, 0.9) 0 0 0 4px;
}

.pause-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 36px;
  border: 2px solid rgba(255, 235, 205, 0.5);
  border-radius: 12px;
  background: rgba(9, 11, 30, 0.9);
  text-align: center;
}

.pause-title {
  margin: 0;
  font: 44px/1 Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  letter-spacing: 2px;
}

.pause-hint,
.touch-hint {
  margin: 0;
  font-size: 15px;
}

.touch-hint {
  display: none;
  max-width: 34ch;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .touch-hint {
    display: block;
  }
  .pause-hint {
    display: none;
  }
}

/* En pantallas bajas (teléfono en horizontal) la frase no cabe; los
   botones ya están a la vista junto al escenario. */
@media (max-height: 460px) {
  .touch-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .MenuButton {
    transition: none;
  }
}
