:root {
  color-scheme: dark;
  --bg: #0d0717;
  --ink: #f4eefc;
  --muted: #a898c9;
  --line: #3a2466;
  --p1: #ff4d5a;
  --p2: #3fa9ff;
  --help-height: 64px;
  --pad-size: clamp(44px, 14.5vw, 58px);
  --button-size: clamp(52px, 17vw, 70px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(ellipse at 50% 30%, #2a1450 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: system-ui, 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.arena {
  position: relative;
  width: min(100vw, calc((100vh - var(--help-height)) * 16 / 9), 1280px);
  width: min(100vw, calc((100dvh - var(--help-height)) * 16 / 9), 1280px);
  aspect-ratio: 16 / 9;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: #000;
  box-shadow: 0 0 0 2px var(--line), 0 18px 60px rgba(0, 0, 0, 0.6);
  touch-action: none;
}

.error {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: #5a0f1c;
  color: #fff;
  font-size: 14px;
}

.help {
  margin: 0;
  padding: 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.9;
  text-align: center;
}

.help .p1 {
  color: var(--p1);
}

.help .p2 {
  color: var(--p2);
}

.help .sep {
  margin: 0 8px;
  color: var(--line);
}

kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 1px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #1c0f36;
  color: var(--ink);
  font: 600 12px/1.4 ui-monospace, Consolas, monospace;
  text-align: center;
}

/* Controles táctiles */
.touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

.touch[hidden] {
  display: none;
}

.pad {
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.pad-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.tb.menu {
  width: 44px;
  aspect-ratio: auto;
  height: 34px;
  border-radius: 10px;
  font-size: 13px;
  pointer-events: auto;
}

.dpad {
  grid-template: 'left up right' var(--pad-size) 'left down right' var(--pad-size) / var(--pad-size) var(--pad-size) var(--pad-size);
  align-items: center;
}

.dpad .up { grid-area: up; }
.dpad .down { grid-area: down; }
.dpad .left { grid-area: left; }
.dpad .right { grid-area: right; }

.actions {
  grid-template-columns: repeat(3, var(--button-size));
}

/* En vertical no caben tres botones en fila: el especial baja a una segunda fila. */
@media (orientation: portrait) {
  .actions {
    grid-template-columns: repeat(2, var(--button-size));
  }

  .actions .special {
    grid-column: 1 / span 2;
    justify-self: center;
    width: var(--button-size);
  }
}

.tb {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font: 800 11px/1 system-ui, sans-serif;
  letter-spacing: 0.02em;
  touch-action: none;
}

.dpad .tb {
  font-size: 18px;
}

.tb.punch { border-color: #ffd23f; }
.tb.kick { border-color: var(--p1); }
.tb.special { border-color: #3fe0ff; }

.tb.is-down {
  background: rgba(255, 255, 255, 0.45);
  transform: scale(0.94);
}

@media (pointer: coarse) {
  :root {
    --help-height: 0px;
  }

  .help {
    display: none;
  }

  body {
    justify-content: flex-start;
    padding-top: env(safe-area-inset-top);
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  body {
    justify-content: center;
  }
}
