/* Controles de toque — Arcade em Casa */
.touch-controls {
  display: none;
  position: fixed;
  inset: auto 0 0 0;
  z-index: 25;
  pointer-events: none;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.35));
}

.touch-controls .dpad,
.touch-controls .steer,
.touch-controls .actions {
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.touch-controls .dpad {
  grid-template-columns: 64px 64px 64px;
  grid-template-rows: 64px 64px 64px;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
}

.touch-controls .steer {
  grid-template-columns: 88px 88px;
}

.touch-controls .actions {
  grid-auto-flow: row;
  justify-items: end;
}

.touch-controls button {
  width: 64px;
  height: 64px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.touch-controls .steer button {
  width: 88px;
  height: 88px;
  font-size: 36px;
  border-radius: 22px;
}

.touch-controls .actions button {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  background: rgba(249, 115, 22, 0.85);
  font-size: 16px;
  letter-spacing: 0.02em;
}

.touch-controls .actions button.secondary {
  width: 72px;
  height: 72px;
  background: rgba(56, 189, 248, 0.85);
  font-size: 14px;
}

.touch-controls button:active,
.touch-controls button.is-down {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  background: rgba(255, 255, 255, 0.4);
}

.touch-controls .actions button:active,
.touch-controls .actions button.is-down {
  background: rgba(251, 146, 60, 1);
}

.touch-controls [data-dir="up"],
.touch-controls [data-key="KeyW"] {
  grid-area: up;
}
.touch-controls [data-dir="left"],
.touch-controls [data-key="KeyA"] {
  grid-area: left;
}
.touch-controls [data-dir="right"],
.touch-controls [data-key="KeyD"] {
  grid-area: right;
}
.touch-controls [data-dir="down"],
.touch-controls [data-key="KeyS"] {
  grid-area: down;
}

@media (pointer: coarse), (max-width: 900px) {
  .touch-controls:not(.hidden) {
    display: flex;
  }

  .touch-controls.hidden {
    display: none !important;
  }

  .overlay button {
    min-height: 52px;
    font-size: clamp(18px, 4.5vw, 26px);
    padding: 14px 28px;
  }

  .hud-box {
    font-size: 15px !important;
    max-width: calc(100vw - 24px);
  }

  .hint,
  .footer {
    font-size: 15px !important;
    padding: 0 12px;
  }

  h1 {
    font-size: clamp(32px, 10vw, 52px) !important;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .touch-controls {
    padding-bottom: 8px;
  }

  .touch-controls .dpad {
    grid-template-columns: 52px 52px 52px;
    grid-template-rows: 52px 52px 52px;
  }

  .touch-controls button {
    width: 52px;
    height: 52px;
    font-size: 22px;
  }

  .touch-controls .steer button {
    width: 72px;
    height: 72px;
  }

  .touch-controls .actions button {
    width: 76px;
    height: 76px;
    font-size: 13px;
  }
}
