:root {
  --bg: #111214;
  --panel: #1b1d21;
  --ink: #f2f1ec;
  --muted: #9a9ca3;
  --aura: #40aaff;
  --aura-soft: rgba(64, 170, 255, 0.18);
  --line: rgba(255, 255, 255, 0.14);
  --stage: #f1f0ec;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: none;              /* no pinch / double-tap zoom, no scroll */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body.fighting { background: var(--stage); }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

/* ------------------------------------------------------------------ screens */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(3vh, 22px);
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 40%, #1d2633 0%, var(--bg) 70%);
  z-index: 10;
}
.screen[hidden], #pad[hidden], .pause-btn[hidden] { display: none; }
.screen.dim { background: rgba(10, 11, 13, 0.78); }

h1 {
  margin: 0;
  font-size: clamp(44px, 12vh, 110px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 0.95;
  text-align: center;
}
h1 span {
  display: block;
  color: var(--aura);
  text-shadow: 0 0 18px rgba(64, 170, 255, 0.7), 0 0 42px rgba(64, 170, 255, 0.35);
}
h2 { margin: 0; font-size: clamp(22px, 6vh, 44px); font-weight: 800; letter-spacing: 0.04em; }

button {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 22px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover, button:focus-visible { border-color: var(--aura); outline: none; }
button.big {
  font-size: clamp(18px, 4.5vh, 28px);
  padding: 14px 40px;
  background: linear-gradient(180deg, #2a3442, #1b2028);
  border-color: rgba(64, 170, 255, 0.55);
  box-shadow: 0 0 24px var(--aura-soft);
}
.row { display: flex; gap: 12px; }
.keys { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }
.keys b { color: var(--ink); }
.error { color: #ff7a6b; white-space: pre-wrap; font-size: 13px; max-width: 90vw; }
body.touch .only-pc { display: none; }

/* ------------------------------------------------------------------ select grid (3 × 4) */
.grid {
  --cell: min(19vh, 13vw, 150px);
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  gap: min(1.6vh, 12px);
}
.cell {
  position: relative;
  border-radius: 10px;
  background: var(--panel);
  border: 2px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.cell canvas { width: 100%; height: 100%; display: block; }
.cell.empty { color: #3a3d44; font-size: calc(var(--cell) * 0.4); font-weight: 900; cursor: default; }
.cell.cursor { border-color: var(--aura); box-shadow: 0 0 16px rgba(64, 170, 255, 0.5) inset; }
.cell .tag {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--aura);
}
.select-bar { display: flex; align-items: center; gap: 18px; min-height: 40px; }
#select-name { font-weight: 800; font-size: 20px; letter-spacing: 0.05em; }

/* ------------------------------------------------------------------ pause button */
.pause-btn {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 5;
  padding: 6px 12px;
  font-size: 16px;
  color: #333;
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.2);
}

/* ------------------------------------------------------------------ touch pads */
#pad {
  position: fixed;
  inset: auto 0 0 0;
  height: 0;
  z-index: 4;
}
.dpad {
  --s: min(38vh, 190px);
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: var(--s);
  height: var(--s);
  display: grid;
  grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
  touch-action: none;
}
.dpad .arrow, .dpad .hub {
  background: rgba(30, 30, 34, 0.32);
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.dpad .arrow.on { background: rgba(64, 170, 255, 0.75); }
.dpad .up    { grid-area: 1 / 2; border-radius: 8px 8px 0 0; }
.dpad .left  { grid-area: 2 / 1; border-radius: 8px 0 0 8px; }
.dpad .hub   { grid-area: 2 / 2; border-radius: 0; }
.dpad .right { grid-area: 2 / 3; border-radius: 0 8px 8px 0; }
.dpad .down  { grid-area: 3 / 2; border-radius: 0 0 8px 8px; }
.dpad .arrow::after {
  content: "";
  display: block;
  margin: 35% auto 0;
  width: 0;
  height: 0;
  border: calc(var(--s) * 0.05) solid transparent;
}
.dpad .up::after    { border-bottom-color: rgba(255, 255, 255, 0.85); margin-top: 20%; }
.dpad .down::after  { border-top-color: rgba(255, 255, 255, 0.85); margin-top: 45%; }
.dpad .left::after  { border-right-color: rgba(255, 255, 255, 0.85); margin-left: 15%; }
.dpad .right::after { border-left-color: rgba(255, 255, 255, 0.85); margin-left: 45%; }

.btns {
  --s: min(40vh, 200px);
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: var(--s);
  height: var(--s);
  display: grid;
  grid-template: 1fr 1fr 1fr / 1fr 1fr 1fr;
}
.btns button {
  border-radius: 50%;
  padding: 0;
  font-size: calc(var(--s) * 0.13);
  font-weight: 900;
  color: #fff;
  background: rgba(30, 30, 34, 0.38);
  border: 2px solid rgba(0, 0, 0, 0.25);
  touch-action: none;
}
.btns button.on { background: rgba(64, 170, 255, 0.8); transform: scale(0.94); }
.btns .b-aura  { grid-area: 1 / 2; border-color: rgba(64, 170, 255, 0.8); }
.btns .b-punch { grid-area: 2 / 1; }
.btns .b-kick  { grid-area: 2 / 3; }
.btns .b-def   { grid-area: 3 / 2; }

/* ------------------------------------------------------------------ rotate overlay */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  color: var(--ink);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-weight: 700;
}
#rotate .phone {
  width: 50px;
  height: 86px;
  border: 4px solid var(--aura);
  border-radius: 10px;
  animation: turn 1.8s ease-in-out infinite;
}
@keyframes turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}
