* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0d0b1a;
  color: #cfc9e8;
  font-family: "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  overflow: hidden;
}

#marco {
  border: 3px solid #3b3466;
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(90, 70, 190, 0.35);
  line-height: 0;
  background: #000;
}

#pantalla {
  display: block;
  /* Escala el canvas manteniendo la resolución interna de 480x272 */
  width: min(96vw, calc(96vh * 480 / 272));
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#ayuda {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.2px;
  opacity: 0.75;
  text-align: center;
  padding: 0 12px;
}

#ayuda b {
  color: #ffd97d;
  font-weight: 600;
}

/* ============================================================
   Controles táctiles — solo aparecen en dispositivos con dedo.
   ============================================================ */

#controles { display: none; }

body.tactil {
  gap: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body.tactil #ayuda { display: none; }

body.tactil #marco {
  border: none;
  box-shadow: none;
  border-radius: 0;
}

body.tactil #pantalla {
  width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

body.tactil #controles {
  display: block;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#controles .grupo { position: absolute; pointer-events: none; }

#controles .izq {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 168px;
  height: 112px;
}

#controles .der {
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 150px;
  height: 130px;
}

#controles .sup {
  right: max(12px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  display: flex;
}

.tb {
  position: absolute;
  pointer-events: auto;
  border: 1px solid rgba(200, 190, 240, 0.35);
  background: rgba(20, 16, 36, 0.45);
  color: #d8d3ee;
  font-family: "Courier New", monospace;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  transition: background 60ms linear, transform 60ms linear;
}

.tb.apretado {
  background: rgba(255, 210, 63, 0.45);
  border-color: rgba(255, 240, 190, 0.85);
  transform: scale(0.94);
}

.tb.grande { width: 78px; height: 78px; font-size: 13px; }
.tb.chico { width: 48px; height: 48px; font-size: 11px; }

.p-izq   { left: 0;    bottom: 0; }
.p-der   { left: 112px; bottom: 0; }
.p-abajo { left: 56px; bottom: 0; }

.p-salto  { right: 0;   bottom: 6px; background: rgba(60, 40, 100, 0.5); }
.p-correr { right: 86px; bottom: 30px; }

.p-ok    { position: relative; width: 52px; height: 40px; font-size: 12px; }
.p-pausa { position: relative; width: 44px; height: 40px; margin-left: 8px; }

#rotar { display: none; }

@media (orientation: portrait) {
  body.tactil #rotar {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 20;
    align-items: center;
    justify-content: center;
    background: rgba(8, 6, 16, 0.92);
    color: #ffd23f;
    font-family: "Courier New", monospace;
    font-size: 18px;
    letter-spacing: 1px;
    text-align: center;
  }
}
