:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffd23f;
  --lime: #8cf04a;
  --red: #ff5a6e;
  --stage-w: 832px;
  --stage-h: 520px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  min-height: 100vh;
  padding: 10px;
  background:
    radial-gradient(110% 70% at 50% 0%, #1b2440 0%, rgba(15, 16, 32, 0) 60%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: #2f3048;
  box-shadow: 0 2px 0 #0a0b16;
  font: inherit;
  font-size: 0.85em;
  color: #e6e7f5;
}
[hidden] {
  display: none !important;
}

.shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.brand-icon {
  width: 38px;
  height: 38px;
  filter: drop-shadow(0 3px 6px rgba(111, 210, 60, 0.45));
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #f4ffe0, #b6f57a 55%, #6fd23c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26273b, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
}
.chip span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  display: inline-block;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip svg {
  width: 18px;
  height: 18px;
}
.chip-wave strong {
  color: var(--lime);
}
.chip-coins strong,
.chip-best strong {
  color: var(--gold);
}
.chip.pop strong {
  animation: pop 0.3s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}
.hud-buttons {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

/* ---------- Pills ---------- */
.pill {
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.pill:active {
  transform: translateY(2px);
}
.pill:disabled {
  opacity: 0.45;
  cursor: default;
}
.pill-primary {
  background: linear-gradient(180deg, #8a6bff, var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #3d22b3,
    0 10px 24px rgba(104, 66, 255, 0.45);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #13141f;
}
.pill-big {
  min-height: 58px;
  min-width: 190px;
  font-size: 23px;
}
.pill-small {
  min-height: 40px;
  padding: 0 18px;
  font-size: 15px;
}
.icon-pill {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}
.icon-pill svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
#mute .ico-muted,
#mute[aria-pressed="true"] .ico-sound {
  display: none;
}
#mute[aria-pressed="true"] .ico-muted {
  display: block;
}

/* ---------- Play area ---------- */
.play-area {
  display: grid;
  justify-items: center;
  gap: 10px;
}
.stage {
  grid-area: 1 / 1;
  position: relative;
  width: var(--stage-w);
  height: var(--stage-h);
  max-width: 100%;
  border-radius: 20px;
  overflow: hidden;
  background: #3f8f3a;
  box-shadow:
    0 0 0 3px #2a5c26,
    0 0 0 6px #1a1b28,
    0 18px 40px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
  outline: none;
}
.stage.placing canvas,
.stage.idle canvas {
  cursor: pointer;
}
.stage canvas:focus-visible {
  box-shadow: inset 0 0 0 3px var(--gold);
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(12, 13, 28, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.stage.dim::after {
  opacity: 1;
}

/* in-stage HUD */
.stage-hud {
  position: absolute;
  inset: 8px 8px auto 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.hp {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 1 220px;
  min-width: 110px;
}
.hp-heart {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  fill: var(--red);
  filter: drop-shadow(0 2px 0 #8a1f2e);
}
.hp.hurt .hp-heart {
  animation: pop 0.3s;
}
.hp-bar {
  position: relative;
  flex: 1 1 auto;
  height: 20px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.72);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.12),
    0 2px 0 rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.hp-fill {
  position: absolute;
  inset: 3px auto 3px 3px;
  width: calc(100% - 6px);
  border-radius: 999px;
  background: linear-gradient(180deg, #ff9aa6, var(--red) 55%, #d93550);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: width 0.2s;
  transform-origin: left;
}
.hp-fill.low {
  animation: blink 0.6s infinite alternate;
}
@keyframes blink {
  to {
    filter: brightness(1.6);
  }
}
.hp-bar span {
  position: relative;
  display: block;
  text-align: center;
  font-size: 12px;
  line-height: 20px;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.left-chip,
.weapon-chip {
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.72);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.1);
  font-size: 13px;
  white-space: nowrap;
}
.left-chip {
  margin-left: auto;
}
.left-chip strong {
  color: var(--lime);
}
.weapon-chip {
  color: var(--gold);
}

/* wave banner */
.banner {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.banner span {
  display: block;
  padding: 10px 28px;
  border-radius: 999px;
  font-size: clamp(22px, 5vw, 44px);
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #8a6bff, var(--accent));
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.25),
    0 6px 0 #3d22b3,
    0 16px 40px rgba(0, 0, 0, 0.45);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.banner.boss span {
  background: linear-gradient(180deg, #ff8a5c, #ff3d6e);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.3),
    0 6px 0 #9e1f45,
    0 16px 40px rgba(0, 0, 0, 0.45);
}
.banner.clear span {
  background: linear-gradient(180deg, #9cf56a, #3cbf4a);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.3),
    0 6px 0 #1f7a2c,
    0 16px 40px rgba(0, 0, 0, 0.45);
}
.banner.show {
  animation: banner 1.8s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
@keyframes banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  25%,
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.95);
  }
}

/* placement bar */
.placebar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 16px);
  padding: 6px 6px 6px 16px;
  border-radius: 999px;
  background: rgba(21, 22, 38, 0.9);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.1),
    0 8px 20px rgba(0, 0, 0, 0.4);
}
.placebar p {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

/* ---------- Overlay ---------- */
.play-area {
  position: relative;
}
.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 4;
  width: var(--stage-w);
  max-width: 100%;
  transform: translateX(-50%);
  border-radius: 20px;
  display: grid;
  place-items: center;
  padding: 14px;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(21, 22, 40, 0.55),
    rgba(10, 11, 22, 0.85)
  );
  overflow: auto;
}
.card-panel {
  width: min(460px, 100%);
  padding: 22px 22px 18px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, #25263a, var(--panel));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    0 8px 0 #0b0c18,
    0 24px 50px rgba(0, 0, 0, 0.5);
  animation: panel-in 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes panel-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.panel-kicker {
  margin: 0;
  color: var(--lime);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.panel-title {
  margin: 2px 0 6px;
  font-size: clamp(34px, 7vw, 54px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  background: linear-gradient(180deg, #ffffff, #d7ffb0 45%, #6fd23c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #1f5a14)
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.4));
}
.panel-copy {
  margin: 0 auto 14px;
  max-width: 36ch;
  color: #d4d6e6;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 700;
}
.final {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 10px;
}
.final-stat {
  flex: 1 1 0;
  max-width: 120px;
  padding: 8px 6px;
  border-radius: 16px;
  background: var(--panel-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.final-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.final-stat strong {
  font-size: 26px;
  font-weight: 900;
  color: var(--gold);
}
.badge {
  display: inline-block;
  margin: 0 0 12px;
  padding: 5px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff09a, var(--gold));
  color: #4a3200;
  font-size: 14px;
  font-weight: 900;
  animation: pop 0.6s 0.2s both cubic-bezier(0.3, 1.8, 0.5, 1);
}
.panel-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}
.panel-keys {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.8;
}

/* ---------- Shop ---------- */
.shop {
  grid-area: 1 / 1;
  align-self: center;
  z-index: 2;
  width: min(640px, calc(var(--stage-w) - 24px));
  max-height: calc(var(--stage-h) - 20px);
  overflow: auto;
  padding: 16px;
  border-radius: 24px;
  background: linear-gradient(
    180deg,
    rgba(37, 38, 58, 0.97),
    rgba(26, 27, 40, 0.97)
  );
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    0 8px 0 #0b0c18,
    0 24px 50px rgba(0, 0, 0, 0.55);
  animation: panel-in 0.35s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.play-area.shop-below .shop {
  grid-area: 2 / 1;
  width: 100%;
  max-height: none;
}
.shop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.shop-kicker {
  margin: 0;
  color: var(--lime);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.shop h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.shop-wallet {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: #2a2b3d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.shop-wallet svg {
  width: 22px;
  height: 22px;
}
.shop-wallet strong {
  font-size: 22px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 10px;
  align-items: center;
  min-height: 92px;
  padding: 10px 12px;
  border: 0;
  border-radius: 18px;
  text-align: left;
  cursor: pointer;
  background: linear-gradient(180deg, #2f3048, #25263a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    0 4px 0 #111220;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.card:hover:not(:disabled) {
  filter: brightness(1.12);
}
.card:active:not(:disabled) {
  transform: translateY(2px);
}
.card:disabled {
  cursor: default;
}
.card:disabled .card-ico,
.card:disabled .card-name {
  opacity: 0.5;
}
.card.bought {
  animation: pop 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.card-ico {
  grid-row: 1 / 4;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.2),
    0 3px 8px rgba(0, 0, 0, 0.3);
}
.card-ico svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  color: #fff;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.25));
}
.ico-weapon {
  background: linear-gradient(180deg, #7ae0ff, #2a9bd6);
}
.ico-damage {
  background: linear-gradient(180deg, #ffb46a, #ff6a2a);
}
.ico-rate {
  background: linear-gradient(180deg, #fff07a, #f5b400);
}
.ico-health {
  background: linear-gradient(180deg, #ff9aa6, #e8354f);
}
.ico-heal {
  background: linear-gradient(180deg, #9cf56a, #34b04a);
}
.ico-barricade {
  background: linear-gradient(180deg, #e6b27a, #a8652a);
}
.card-name {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
}
.card-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}
.pips {
  display: flex;
  gap: 3px;
  padding: 3px 0;
}
.pips i {
  width: 12px;
  height: 7px;
  border-radius: 4px;
  background: #3a3b55;
}
.pips i.on {
  background: linear-gradient(180deg, #b9ff8a, #5ccf2e);
}
.card-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: start;
  padding: 2px 9px 2px 4px;
  border-radius: 999px;
  background: rgba(255, 210, 63, 0.14);
  color: var(--gold);
  font-size: 14px;
  font-weight: 900;
}
.card-price svg {
  width: 15px;
  height: 15px;
}
.card-price.maxed {
  padding: 2px 9px;
  background: rgba(140, 240, 74, 0.14);
  color: var(--lime);
}
.card-price.poor {
  color: #c79a9f;
  background: rgba(255, 90, 110, 0.12);
}
.shop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.shop-tip {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}
.pill-go {
  flex: 0 0 auto;
  min-height: 52px;
  font-size: 18px;
}

/* ---------- Touch pads ---------- */
.pads {
  grid-area: 3 / 1;
  display: none;
  width: 100%;
  max-width: 560px;
  justify-content: space-between;
  gap: 16px;
  padding: 0 6px;
}
.touch .pads {
  display: flex;
}
.pad {
  position: relative;
  width: 138px;
  height: 138px;
  border-radius: 50%;
  touch-action: none;
  background: radial-gradient(
    circle at 50% 45%,
    rgba(104, 66, 255, 0.18),
    rgba(26, 27, 40, 0.9) 70%
  );
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.1),
    0 6px 16px rgba(0, 0, 0, 0.4);
}
.pad::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translate(-50%, 100%);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pad-fire {
  background: radial-gradient(
    circle at 50% 45%,
    rgba(255, 90, 110, 0.2),
    rgba(26, 27, 40, 0.9) 70%
  );
}
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 30%,
    #c3b3ff,
    var(--accent) 60%,
    #4520cf
  );
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 5px 0 #2d178f,
    0 10px 20px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.pad-fire .knob {
  background: radial-gradient(circle at 35% 30%, #ffc2ca, #ff5a6e 60%, #c9304a);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 5px 0 #8a1f2e,
    0 10px 20px rgba(0, 0, 0, 0.4);
}
.pad.active {
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.28),
    0 6px 16px rgba(0, 0, 0, 0.4);
}
/* landscape phones: pads float over the arena corners */
@media (orientation: landscape) and (max-height: 520px) {
  .touch .pads {
    grid-area: 1 / 1;
    align-self: end;
    z-index: 1;
    max-width: none;
    width: var(--stage-w);
    padding: 0 10px 10px;
    pointer-events: none;
  }
  .touch .pad {
    width: 116px;
    height: 116px;
    pointer-events: auto;
    opacity: 0.85;
  }
  .touch .pad::after {
    display: none;
  }
  .touch .play-area:not(.playing) .pads {
    display: none;
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  body {
    padding: 8px;
  }
  .hud {
    flex-wrap: wrap;
    gap: 6px;
  }
  .brand h1 {
    font-size: 20px;
  }
  .brand-icon {
    width: 32px;
    height: 32px;
  }
  .hud-buttons {
    margin-left: auto;
  }
  .chips {
    order: 3;
    flex-basis: 100%;
    justify-content: space-between;
    gap: 4px;
  }
  .chip {
    padding: 6px 9px;
    gap: 4px;
  }
  .chip span {
    font-size: 10px;
  }
  .chip strong {
    font-size: 16px;
  }
  .stage {
    border-radius: 14px;
  }
  .stage-hud {
    inset: 5px 5px auto 5px;
    gap: 4px;
  }
  .hp {
    min-width: 90px;
    flex-basis: 130px;
  }
  .hp-heart {
    width: 18px;
    height: 18px;
  }
  .hp-bar {
    height: 16px;
  }
  .hp-bar span {
    font-size: 10px;
    line-height: 16px;
  }
  .left-chip,
  .weapon-chip {
    padding: 2px 8px;
    font-size: 11px;
  }
  .shop {
    padding: 12px;
  }
  .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .card {
    min-height: 80px;
    padding: 8px;
    column-gap: 8px;
  }
  .card-ico {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }
  .card-ico svg {
    width: 24px;
    height: 24px;
  }
  .card-name {
    font-size: 14px;
  }
  .shop-foot {
    flex-direction: column;
    align-items: stretch;
  }
  .placebar p {
    font-size: 12px;
  }
  .card-panel {
    padding: 16px 14px 14px;
  }
  .panel-copy {
    font-size: 13.5px;
  }
}
@media (max-width: 360px) {
  .chip-best span,
  .chip-score span {
    display: none;
  }
  .pad {
    width: 124px;
    height: 124px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.shop:not([hidden]) ~ .pads {
  display: none;
}
