:root {
  --bg: #0a0b0d;
  --surface: #121317;
  --elevated: #1a1c22;
  --fg: #f2f3f5;
  --muted: #8b909a;
  --border: #2a2d34;
  --accent: #7ee8d4;
  --accent-fg: #08110f;
  --danger: #e35d6a;
  --warn: #e0b15a;
}
* { box-sizing: border-box; }
html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--fg);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }
#app {
  display: grid;
  min-height: 100vh;
  padding: 16px;
  place-items: center;
}
#game-shell {
  position: relative;
  width: min(1100px, 100%);
  aspect-ratio: 16 / 9;
  min-height: 200px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #21113a;
  user-select: none;
  touch-action: none;
}
canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #21113a;
  cursor: crosshair;
}
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.hud-panel {
  position: absolute;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(10, 11, 13, 0.8);
}
#status { top: 12px; left: 12px; min-width: 208px; }
#wave-box { top: 12px; right: 12px; min-width: 160px; text-align: right; }
#weapon-box { right: 12px; bottom: 12px; min-width: 192px; text-align: right; }
#help {
  bottom: 12px;
  left: 12px;
  max-width: 420px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.value { font-size: 18px; font-weight: 600; }
.cyan { color: var(--accent); }
.red { color: var(--danger); }
.good { color: var(--accent); }
.bar {
  width: 210px;
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--elevated);
}
.fill {
  width: 100%;
  height: 100%;
  background: var(--danger);
}
#ammo { font-size: 30px; font-weight: 600; letter-spacing: -1px; line-height: 1; }
#ammo small { color: var(--muted); font-size: 14px; letter-spacing: 0; }
#reload {
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--elevated);
}
#reload-fill { width: 0; height: 100%; background: var(--accent); }
#message {
  position: absolute;
  top: 16%;
  left: 50%;
  width: 90%;
  transform: translateX(-50%);
  text-align: center;
  font-size: clamp(16px, 3vw, 24px);
  font-weight: 600;
  letter-spacing: 0.18em;
  opacity: 0;
}
#message.show { opacity: 1; }
#rest-banner {
  position: absolute;
  top: 28%;
  left: 50%;
  display: none;
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 1px solid rgba(126, 232, 212, 0.4);
  border-radius: 6px;
  background: rgba(10, 11, 13, 0.85);
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
#rest-banner.show { display: block; }
#menu, #shop {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  padding: 20px;
  place-items: center;
  background: rgba(10, 11, 13, 0.75);
}
#menu.hidden, #shop.hidden { display: none; }
.menu-card, .shop-card {
  width: min(460px, 100%);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
}
.shop-card { width: min(520px, 100%); max-height: 90%; overflow: auto; text-align: left; }
h1 {
  margin: 8px 0 0;
  font-size: clamp(40px, 7vw, 60px);
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-weight: 600;
}
h1 span { color: var(--accent); }
h2 { margin: 4px 0 0; font-size: 24px; font-weight: 600; }
.subtitle {
  max-width: 380px;
  margin: 16px auto 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0 0;
  text-align: left;
  font-size: 12px;
}
.control {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--elevated);
  color: var(--muted);
}
kbd {
  display: inline-block;
  padding: 1px 5px;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--elevated);
  font: inherit;
}
.primary-btn, .ghost-btn, .buy-btn {
  padding: 14px 22px;
  border: 0;
  border-radius: 6px;
  color: var(--bg);
  background: var(--fg);
  font-size: 14px;
  font-weight: 600;
}
.primary-btn:hover, .buy-btn:hover { filter: brightness(1.08); }
.ghost-btn {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}
.buy-btn {
  min-width: 80px;
  padding: 8px 12px;
  font-size: 13px;
}
.buy-btn:disabled { cursor: default; opacity: 0.4; }
.shop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.shop-list { display: grid; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--elevated);
}
.shop-item-main { display: flex; align-items: center; gap: 12px; }
.shop-icon { width: 20px; height: 20px; color: var(--accent); flex: 0 0 auto; }
.shop-item h3 { margin: 0; font-size: 14px; font-weight: 600; }
.shop-item p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
#shop-note { min-height: 18px; margin: 12px 0 0; color: var(--accent); font-size: 13px; }
#next-wave {
  width: 100%;
  margin-top: 16px;
  background: var(--accent);
  color: var(--accent-fg);
}
#open-armory {
  position: absolute;
  top: 58%;
  left: 50%;
  z-index: 3;
  display: none;
  transform: translate(-50%, 0);
  pointer-events: auto;
  align-items: center;
  gap: 8px;
  background: var(--elevated);
  color: var(--fg);
  border: 1px solid var(--border);
}
#open-armory.show { display: inline-flex; }
#touch-controls { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.touch-btn {
  position: absolute;
  display: none;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(26, 28, 34, 0.8);
  color: var(--fg);
  pointer-events: auto;
}
.touch-btn svg { width: 28px; height: 28px; }
#left-btn { bottom: 96px; left: 16px; }
#right-btn { bottom: 96px; left: 80px; }
#kick-btn { right: 16px; bottom: 160px; }
#reload-btn { right: 80px; bottom: 96px; }
#shop-btn { right: 16px; bottom: 96px; }
@media (pointer: coarse) {
  .touch-btn { display: grid; place-items: center; }
  #help { display: none; }
  canvas { cursor: default; }
}
@media (max-width: 620px) {
  #app { padding: 0; }
  #game-shell {
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
  }
  #status { top: 10px; left: 10px; transform: scale(0.84); transform-origin: top left; }
  #wave-box { top: 10px; right: 10px; transform: scale(0.84); transform-origin: top right; }
  #weapon-box { right: 10px; bottom: 10px; transform: scale(0.84); transform-origin: bottom right; }
  .controls { grid-template-columns: 1fr; }
  .menu-card, .shop-card { padding: 24px 20px; }
}

/* v20 shop stats panel */
.shop-card-wide { max-width: 920px; width: min(920px, 100%); }
.shop-body { display: flex; gap: 16px; align-items: flex-start; margin-top: 12px; }
.shop-stats {
  flex: 0 0 200px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(126,232,212,0.25);
  border-radius: 8px;
  padding: 12px 14px;
  min-height: 180px;
}
.shop-stats .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: #c8cdd8;
}
.shop-stats .stat-row span:last-child { color: #7ee8d4; font-variant-numeric: tabular-nums; }
.shop-list { flex: 1; max-height: 360px; overflow-y: auto; }
@media (max-width: 720px) {
  .shop-body { flex-direction: column; }
  .shop-stats { flex: 1 1 auto; width: 100%; }
}
