* { box-sizing: border-box; letter-spacing: 0; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a120e;
  color: #fff;
  font-family: system-ui, -apple-system, "PingFang SC", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
#game {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #1a120e;
}
#scene, #arena {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#scene {
  z-index: 0;
  object-fit: cover;
  object-position: center top;
  background: #1a120e;
  background-repeat: no-repeat;
}
#scene.bad { visibility: hidden; }
#arena { z-index: 1; background: transparent; }
.hud {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  width: 100%;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr);
  gap: 6px 8px;
  pointer-events: none;
}
.fighter-status { min-width: 0; text-shadow: 0 2px 0 #000; }
.fighter-status strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fighter-status span { display: block; margin-top: 3px; font-size: 12px; font-weight: 700; }
.health {
  height: 14px;
  border: 2px solid #fff8;
  border-radius: 6px;
  background: #291c29;
  overflow: hidden;
}
.health > div { height: 100%; width: 100%; background: #70e6a5; }
.enemy-status { text-align: right; }
.enemy-status .health > div { background: #ff8a3d; margin-left: auto; }
.wave { text-align: center; }
.wave button {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 1px solid #fff8;
  border-radius: 8px;
  background: #12131acc;
  font-weight: 900;
  font-size: 16px;
}
#progress {
  grid-column: 1 / -1;
  margin: 0 auto;
  padding: 4px 12px;
  border-radius: 6px;
  background: #1d1926e8;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  text-shadow: 0 2px 3px #000;
}
#announcement {
  position: absolute;
  z-index: 3;
  top: calc(96px + env(safe-area-inset-top));
  left: 8%;
  width: 84%;
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 900;
  color: #ffe08a;
  text-shadow: 0 3px 0 #14121b;
  pointer-events: none;
  min-height: 28px;
}
.controls {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(168px + env(safe-area-inset-bottom));
  pointer-events: none;
}
#joystick {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: min(30vw, 19vh, 132px);
  height: min(30vw, 19vh, 132px);
  border-radius: 50%;
  border: 3px solid #c8d4df99;
  background: radial-gradient(circle, #333946e0 0 48%, #171c26f0 50%);
  pointer-events: auto;
  touch-action: none;
}
#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: #ff8a3d;
  border: 3px solid #ffd19a;
  pointer-events: none;
}
.direction {
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  pointer-events: none;
}
.north { top: 8px; left: 50%; margin-left: -5px; border-width: 0 5px 8px 5px; border-color: transparent transparent #d5e2ee transparent; }
.south { bottom: 8px; left: 50%; margin-left: -5px; border-width: 8px 5px 0 5px; border-color: #d5e2ee transparent transparent transparent; }
.west { left: 8px; top: 50%; margin-top: -5px; border-width: 5px 8px 5px 0; border-color: transparent #d5e2ee transparent transparent; }
.east { right: 8px; top: 50%; margin-top: -5px; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent #d5e2ee; }
#attack {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(36px + env(safe-area-inset-bottom));
  width: min(23vw, 16vh, 88px);
  height: min(23vw, 16vh, 88px);
  border-radius: 50%;
  border: 3px solid #fff9;
  background: #ff8a3d;
  color: #24160f;
  font-size: 18px;
  font-weight: 800;
  box-shadow: 0 4px 0 #8b461e;
  pointer-events: auto;
}
#attack.active { filter: brightness(1.18); transform: translateY(2px); }
#overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0a0c17b8;
  overflow-y: auto;
}
#overlay[hidden] { display: none; }
.dialog {
  width: 100%;
  max-width: 300px;
  text-align: center;
  background: #20232e;
  border: 2px solid #ff8a3d;
  border-radius: 8px;
  padding: 24px 20px;
}
.dialog p { margin: 0; color: #c8ceda; font-size: 14px; }
.dialog h1 { margin: 10px 0 18px; font-size: 32px; }
.dialog button {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 0;
  border-radius: 8px;
  background: #ff8a3d;
  color: #24160f;
  font-weight: 800;
}
.dialog #resume { background: #e7edf3; }
.dialog button[hidden] { display: none; }
@media (max-height: 640px) {
  #joystick { width: 104px; height: 104px; }
  #attack { width: 68px; height: 68px; font-size: 16px; }
}
