:root {
  --ink: #e8f0ff;
  --gold: #ffd166;
  --cyan: #00f0ff;
  --red: #ff0055;
  --panel: rgba(8, 16, 28, 0.82);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: "Jua", system-ui, sans-serif;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(0, 240, 255, 0.18), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(255, 0, 85, 0.22), transparent 60%),
    linear-gradient(180deg, #050811 0%, #0c1626 50%, #050811 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.stage {
  position: relative;
  width: min(100vw, calc(100dvh * 0.557), 480px);
  height: min(100dvh, calc(100vw / 0.557), calc(480px / 0.557));
  max-width: 480px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 45px rgba(0, 240, 255, 0.2);
  border: 2px solid rgba(0, 240, 255, 0.35);
}

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 0px));
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 3;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 12px;
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: clamp(11px, 2.8vw, 13px);
  color: var(--ink);
  max-width: 48%;
}

.panel.right {
  align-items: flex-end;
}

.panel b {
  color: var(--gold);
}

.hud-shop {
  pointer-events: auto;
  margin-top: 4px;
  appearance: none;
  border: 1px solid rgba(255, 209, 102, 0.55);
  background: rgba(255, 158, 0, 0.18);
  color: #ffd166;
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.hud-shop:active {
  transform: scale(0.97);
}

.shop-coins {
  margin: 0 0 12px;
  font-size: 15px;
  color: #ffd166;
}

.shop-coins b {
  font-size: 18px;
  color: #fff;
}

.stage-tag b {
  color: var(--cyan);
}

.vehicle-bar {
  position: absolute;
  top: 66px;
  left: 12px;
  right: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 12px;
  padding: 6px 10px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vehicle-bar.hidden {
  display: none;
}

.boss-bar {
  position: absolute;
  top: 114px;
  left: 12px;
  right: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 0, 85, 0.55);
  border-radius: 12px;
  padding: 6px 10px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 0 18px rgba(255, 0, 85, 0.25);
}

.boss-bar.hidden {
  display: none;
}

.boss-bar .v-info {
  color: var(--red);
  font-weight: bold;
}

.bar-bg.boss > i {
  background: linear-gradient(90deg, #ff0055, #ff6b9d, #ffd166);
}

.v-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--gold);
}

.bar-bg {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.bar-bg > i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff0055, #ffd166, #00f0ff);
  transition: width 0.15s ease;
}

.dist-meter {
  position: absolute;
  top: 104px;
  left: 12px;
  right: 12px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  z-index: 3;
  pointer-events: none;
}

.dist-meter > i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--cyan);
  transition: width 0.1s linear;
}

.hint {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  z-index: 3;
  pointer-events: none;
  font-size: clamp(10px, 2.6vw, 11px);
  color: rgba(232, 240, 255, 0.85);
  background: rgba(5, 8, 17, 0.65);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 240, 255, 0.2);
  text-align: center;
  white-space: normal;
  line-height: 1.3;
}

.controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pad {
  flex: 1 1 0;
  min-width: 0;
  height: clamp(48px, 12vw, 56px);
  appearance: none;
  border: 1px solid rgba(0, 240, 255, 0.35);
  background: rgba(8, 16, 32, 0.88);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-family: inherit;
  font-size: clamp(15px, 4vw, 18px);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}

.pad.missile {
  flex: 1.35 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-color: rgba(255, 158, 0, 0.65);
  background: rgba(40, 18, 0, 0.88);
  color: #ffd166;
  font-size: clamp(11px, 2.8vw, 13px);
  line-height: 1.1;
  padding: 4px 2px;
}

.pad.missile .missile-label {
  font-size: clamp(16px, 4.2vw, 20px);
  line-height: 1;
}

.pad.missile .missile-count {
  font-size: clamp(11px, 2.8vw, 13px);
  font-weight: bold;
  color: #ff9e00;
}

.pad.missile:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.fire {
  width: 100%;
  height: clamp(48px, 12vw, 56px);
  appearance: none;
  border: none;
  background: linear-gradient(180deg, #ffd166 0%, #e09f00 100%);
  color: #1a0f00;
  font-family: inherit;
  font-size: clamp(15px, 4vw, 17px);
  font-weight: bold;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 #9e6f00, 0 0 20px rgba(255, 209, 102, 0.4);
  touch-action: manipulation;
}

.pad:active,
.fire:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(5, 8, 17, 0.92);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  overflow-y: auto;
}

.overlay.hidden {
  display: none;
}

#shop {
  z-index: 6;
}

.badge {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--cyan);
  border: 1px solid rgba(0, 240, 255, 0.4);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.hero-art {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 20px;
  border: none;
  box-shadow: none;
  margin: 0;
}

.title-cover {
  position: relative;
  width: min(78vw, 280px);
  margin: 0 auto 14px;
  padding: 3px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.95), rgba(255, 0, 85, 0.75), rgba(255, 209, 102, 0.85));
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.55),
    0 0 32px rgba(0, 240, 255, 0.22);
}

.title-cover::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 19px;
  pointer-events: none;
  box-shadow: inset 0 0 24px rgba(0, 240, 255, 0.12);
}

.title-cover .hero-art {
  border-radius: 19px;
}

h1, h2 {
  font-family: "Black Han Sans", sans-serif;
  margin: 4px 0;
  font-size: 28px;
  color: #ffffff;
}

h1 em {
  font-style: normal;
  color: var(--gold);
}

p {
  font-size: 13px;
  color: rgba(232, 240, 255, 0.8);
  margin: 6px 0 14px;
  line-height: 1.4;
}

.hero-select-title {
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 8px;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin-bottom: 16px;
}

.hero-card {
  background: rgba(15, 25, 45, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.hero-card .emoji,
.hero-card .hero-preview {
  margin-bottom: 4px;
}

.hero-card .hero-preview {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.hero-card .emoji {
  font-size: 28px;
}

.hero-card b {
  font-size: 14px;
  color: #ffffff;
}

.hero-card small {
  font-size: 11px;
  color: rgba(0, 240, 255, 0.8);
}

.hero-card.active {
  border-color: var(--cyan);
  background: rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.3);
  transform: scale(1.03);
}

.btn-group {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn {
  flex: 1;
  height: 48px;
  appearance: none;
  border: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(180deg, #00f0ff 0%, #0088cc 100%);
  color: #001a26;
  box-shadow: 0 4px 0 #005f8c;
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn:active {
  transform: translateY(2px);
}

.back-link {
  margin-top: 14px;
  color: rgba(232, 240, 255, 0.6);
  font-size: 13px;
  text-decoration: none;
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-bottom: 16px;
}

.shop-item {
  background: rgba(15, 25, 45, 0.85);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shop-item .info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.shop-item b {
  font-size: 14px;
  color: #ffffff;
}

.shop-item span {
  font-size: 12px;
  color: var(--cyan);
}

.shop-buy-btn {
  appearance: none;
  border: none;
  background: linear-gradient(180deg, #ffd166 0%, #e09f00 100%);
  color: #1a0f00;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.shop-buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-height: 520px) and (orientation: landscape) {
  .hint {
    display: none;
  }

  .controls-row .pad,
  .fire {
    height: 44px;
  }

  .hint {
    bottom: calc(108px + env(safe-area-inset-bottom, 0px));
  }

  .dist-meter {
    top: 88px;
  }

  .vehicle-bar {
    top: 52px;
  }

  .boss-bar {
    top: 98px;
  }
}

@media (min-width: 768px) {
  .stage {
    border-radius: 24px;
  }

  .controls-row .pad,
  .fire {
    height: 58px;
  }
}
