html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  background: #000;
  box-shadow: 0 0 60px rgba(200, 30, 10, 0.25);
}

/* ---------- Controles táctiles ---------- */
#touch {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  font-family: Impact, 'Arial Black', sans-serif;
}
#touch[hidden] { display: none; }

#touch button {
  font-family: inherit;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

#dpad {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(36vmin, 190px);
  height: min(36vmin, 190px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.25);
  pointer-events: auto;
  touch-action: none;
}
.arr {
  position: absolute;
  color: rgba(255, 255, 255, 0.5);
  font-size: min(5.5vmin, 28px);
  line-height: 1;
  transform: translate(-50%, -50%);
}
.arr.up    { left: 50%; top: 15%; }
.arr.down  { left: 50%; top: 85%; }
.arr.left  { left: 15%; top: 50%; }
.arr.right { left: 85%; top: 50%; }
.arr.on    { color: #ffd84a; text-shadow: 0 0 10px #ff8a1a; }
#knob {
  position: absolute;
  width: 38%;
  height: 38%;
  left: 31%;
  top: 31%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.45);
}

#pad {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, min(16vmin, 84px));
  grid-template-rows: min(16vmin, 84px) min(16vmin, 84px) min(10vmin, 50px);
  gap: min(2.6vmin, 14px);
  pointer-events: auto;
}
.b {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  font-size: min(4.6vmin, 24px);
  text-shadow: 0 1px 2px #000;
  opacity: 0.75;
}
.b.hp { background: rgba(216, 38, 44, 0.55); }
.b.hk { background: rgba(47, 134, 240, 0.55); }
.b.lp { background: rgba(242, 160, 27, 0.55); }
.b.lk { background: rgba(56, 192, 64, 0.55); }
.b.bl {
  grid-column: 1 / span 2;
  border-radius: 999px;
  background: rgba(200, 200, 200, 0.3);
  font-size: min(3.6vmin, 18px);
}
.b.down { transform: scale(0.9); filter: brightness(1.7); opacity: 1; }

#sys {
  position: absolute;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
#sys button {
  min-width: 46px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.45);
  color: #ffd84a;
  font-size: 15px;
  opacity: 0.8;
}

/* Aviso para girar el teléfono */
#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 10;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #000;
    color: #ffd84a;
    font: 26px Impact, 'Arial Black', sans-serif;
    text-align: center;
  }
  #rotate .icon { font-size: 80px; animation: spin 2s ease-in-out infinite; }
}
@keyframes spin { 0%, 30% { transform: rotate(0); } 70%, 100% { transform: rotate(90deg); } }
