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

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  width: min(100vw, calc(100vh * 4 / 3));
  height: auto;
  background: #000;
  box-shadow: 0 0 40px rgba(79, 195, 247, 0.25);
}

/* ---------- celular / tablet ---------- */
body.touch {
  height: 100dvh;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch canvas {
  width: min(100vw, calc(100dvh * 4 / 3));
  touch-action: none;
}

/* em pé: jogo em cima, controles embaixo (som, pausa e menu também embaixo, fora do jogo) */
@media (orientation: portrait) {
  body.touch { align-items: flex-start; }
  body.touch canvas { margin-top: max(8px, env(safe-area-inset-top)); }
  body.touch .tbtn.small, body.touch .tbtn.pill { top: auto; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 170px); }
}

#touch {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.tbtn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-sizing: border-box;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: bold 13px "Trebuchet MS", "Segoe UI", sans-serif;
  text-shadow: none;
  -webkit-user-select: none;
  user-select: none;
}
.tbtn.on { background: rgba(255, 235, 59, 0.45); }

/* direcional (esquerda) */
#tDpad {
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 150px;
  height: 150px;
}
#tDpad span {
  position: absolute;
  font-size: 22px;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}
#tDpad span.on { color: #ffeb3b; }
#tDpad .up { top: 10px; left: 50%; transform: translateX(-50%); }
#tDpad .down { bottom: 10px; left: 50%; transform: translateX(-50%); }
#tDpad .left { left: 12px; top: 50%; transform: translateY(-50%); }
#tDpad .right { right: 12px; top: 50%; transform: translateY(-50%); }

/* botões de ação (direita): A = ESPAÇO, B = CTRL */
#tA {
  right: max(20px, env(safe-area-inset-right));
  bottom: max(34px, env(safe-area-inset-bottom));
  width: 86px;
  height: 86px;
  background: rgba(105, 240, 174, 0.28);
  border-color: rgba(105, 240, 174, 0.8);
}
#tB {
  right: calc(max(20px, env(safe-area-inset-right)) + 96px);
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 68px;
  height: 68px;
  background: rgba(255, 82, 82, 0.28);
  border-color: rgba(255, 138, 128, 0.85);
}
#tA.on { background: rgba(105, 240, 174, 0.65); }
#tB.on { background: rgba(255, 82, 82, 0.65); }

/* pausa, menu (na pausa) e som (em cima) */
.tbtn.small { width: 44px; height: 44px; font-size: 18px; top: max(10px, env(safe-area-inset-top)); }
#tPause { right: max(10px, env(safe-area-inset-right)); }
#tMute { left: max(10px, env(safe-area-inset-left)); display: flex; }
.tbtn.pill {
  border-radius: 22px;
  width: 90px;
  height: 44px;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  background: rgba(79, 195, 247, 0.35);
}
