/* BLAST WORMS — Vibrant Classic Cartoon Artillery UI */
:root {
  --ink: #0f172a;
  --red: #dc2626;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #f59e0b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #1e60a8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  touch-action: none;
}

.hidden { display: none !important; }
body:not(.embed) .embed-only { display: none !important; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ==================== HUD ==================== */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 8px calc(var(--safe-bot) + 10px);
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  pointer-events: auto;
}

.team-bar {
  flex: 1;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid #0f172a;
  border-radius: 9px;
  padding: 4px 7px;
  color: #fff;
  min-width: 0;
}

.team-lbl {
  display: block;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.4px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-bar b {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  display: block;
  margin-top: 2px;
}

.hp-track {
  height: 7px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 2px;
}

.hp-fill {
  height: 100%;
  width: 100%;
  transition: width 0.25s ease;
}

.hp-fill.red { background: linear-gradient(90deg, #ef4444, #f97316); }
.hp-fill.blue { background: linear-gradient(90deg, #3b82f6, #38bdf8); }

.hud-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.turn-timer {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 900;
  background: #fde047;
  color: #0f172a;
  border: 2px solid #0f172a;
  border-radius: 8px;
  padding: 2px 9px;
  box-shadow: 0 2px 0 #0f172a;
}

.wind-box {
  background: rgba(15, 23, 42, 0.82);
  border: 1.5px solid #0f172a;
  border-radius: 6px;
  padding: 2px 5px;
  text-align: center;
  width: 76px;
}

.wind-box small {
  display: block;
  font-size: 8px;
  font-weight: 900;
  color: #bae6fd;
  letter-spacing: 0.5px;
}

.wind-track {
  position: relative;
  height: 5px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
  margin-top: 2px;
}

.wind-center {
  position: absolute;
  left: 50%;
  top: -1px;
  width: 2px;
  height: 7px;
  background: #fff;
  transform: translateX(-50%);
}

.wind-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: #38bdf8;
  border-radius: 99px;
}

.wind-fill.left { right: 50%; }
.wind-fill.right { left: 50%; }

.hud-pause-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 2px solid #0f172a;
  background: rgba(255, 255, 255, 0.92);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
}

.turn-pill {
  align-self: center;
  margin-top: 6px;
  background: rgba(15, 23, 42, 0.88);
  color: #fde047;
  border: 2px solid #fde047;
  border-radius: 99px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.4px;
}

/* Controls Dock */
.controls-dock {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-dock.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.weapon-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.wpn-active-btn {
  padding: 7px 12px;
  border-radius: 10px;
  border: 2px solid #0f172a;
  background: #fff;
  color: #0f172a;
  font-size: 12.5px;
  font-weight: 900;
  box-shadow: 0 3px 0 #0f172a;
  cursor: pointer;
}

.wpn-ad-btn {
  padding: 7px 10px;
  border-radius: 10px;
  border: 2px solid #0f172a;
  background: linear-gradient(180deg, #fde047, #f59e0b);
  color: #0f172a;
  font-size: 11px;
  font-weight: 900;
  box-shadow: 0 3px 0 #0f172a;
  cursor: pointer;
}

.controls-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

.ctrl-pad {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.aim-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.c-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 2.5px solid #0f172a;
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  font-size: 19px;
  font-weight: 900;
  box-shadow: 0 4px 0 #0f172a;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.c-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0f172a;
  background: #e2e8f0;
}

.c-aim {
  width: 48px;
  height: 40px;
  font-size: 15px;
}

.c-jump {
  background: #dcfce7;
}

.c-fire {
  width: 82px;
  height: 85px;
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  color: #fff;
  font-size: 11px;
  gap: 2px;
}

.c-fire.pressed {
  background: #991b1b;
}

.fire-ico {
  font-size: 24px;
  line-height: 1;
}

/* ==================== LOBBY ==================== */
.lobby {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(16, 48, 92, 0.55), rgba(15, 23, 42, 0.88));
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 14px calc(var(--safe-bot) + 14px);
  overflow-y: auto;
}

.lobby-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-pill {
  background: rgba(15, 23, 42, 0.85);
  color: #fde047;
  border: 2px solid #f59e0b;
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 900;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.top-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 2px solid #0f172a;
  background: #fff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.lobby-brand {
  text-align: center;
  margin: 18px 0 14px;
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fde047;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.brand-title {
  margin: 4px 0 0;
  font-size: 36px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 #0f172a;
}

.brand-title span {
  color: #fb923c;
}

.lobby-card {
  margin-top: auto;
  background: rgba(248, 250, 252, 0.96);
  border: 3px solid #0f172a;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 8px 0 #0f172a;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-big, .btn-med, .btn-sm {
  border-radius: 12px;
  border: 2.5px solid #0f172a;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 #0f172a;
}

.btn-big:active, .btn-med:active, .btn-sm:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0f172a;
}

.btn-big {
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 16px;
}

.btn-big small {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.9;
}

.btn-med {
  padding: 11px 10px;
  font-size: 12.5px;
}

.btn-sm {
  padding: 9px 12px;
  font-size: 12px;
}

.btn-online { background: linear-gradient(180deg, #ef4444, #b91c1c); color: #fff; }
.btn-green { background: linear-gradient(180deg, #22c55e, #15803d); color: #fff; }
.btn-amber { background: linear-gradient(180deg, #fde047, #f59e0b); color: #0f172a; }
.btn-blue { background: linear-gradient(180deg, #3b82f6, #1d4ed8); color: #fff; }
.btn-light { background: #e2e8f0; color: #0f172a; }
.btn-ghost { background: transparent; color: #475569; box-shadow: none; }
.full-w { width: 100%; }

.diff-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.diff-pill {
  padding: 7px 4px;
  border-radius: 9px;
  border: 2px solid #0f172a;
  background: #e2e8f0;
  color: #334155;
  font-size: 11.5px;
  font-weight: 900;
  cursor: pointer;
}

.diff-pill.active {
  background: #0f172a;
  color: #fde047;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.room-box {
  background: #e2e8f0;
  border: 2px solid #0f172a;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.room-title {
  font-size: 12px;
  font-weight: 900;
}

.room-row {
  display: flex;
  gap: 6px;
}

.room-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 9px;
  border: 2px solid #0f172a;
  background: #fff;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  user-select: text;
  -webkit-user-select: text;
}

/* ==================== MODALS ==================== */
.modal {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.72);
  display: grid;
  place-items: center;
  padding: 14px;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: #f8fafc;
  border: 3px solid #0f172a;
  border-radius: 15px;
  padding: 16px;
  box-shadow: 0 8px 0 #0f172a;
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: center;
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
}

.modal-sub {
  font-size: 12.5px;
  font-weight: 700;
  color: #475569;
}

.weapons-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
}

.close-x {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid #0f172a;
  background: #e2e8f0;
  font-weight: 900;
  cursor: pointer;
}

.weapons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.wpn-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 8px;
  border-radius: 10px;
  border: 2px solid #0f172a;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.wpn-tile.selected {
  background: #fef3c7;
  border-color: #dc2626;
}

.wpn-tile:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wpn-tile-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 900;
}

.wpn-tile-desc {
  font-size: 10px;
  color: #475569;
  line-height: 1.25;
}

.end-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.end-stat {
  background: #e2e8f0;
  border: 2px solid #0f172a;
  border-radius: 10px;
  padding: 7px;
}

.end-stat small { display: block; font-size: 10px; font-weight: 800; color: #475569; }
.end-stat b { font-family: ui-monospace, monospace; font-size: 16px; font-weight: 900; }

/* Rank (lobby and end screen); hidden when empty, e.g. after "2 players, 1 phone" */
.rank-badge {
  align-self: center;
  display: inline-block;
  margin-top: 6px;
  background: #0f172a;
  color: #fde047;
  border: 2px solid #f59e0b;
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 900;
}

.rank-badge.up {
  background: #f59e0b;
  color: #0f172a;
  border-color: #0f172a;
}

.rank-badge:empty { display: none; }

.rank-rule {
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 800;
  color: #fde047;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.subradar-pill {
  align-self: center;
  font-size: 11px;
  font-weight: 900;
  background: #0f172a;
  color: #fde047;
  border: 1.5px solid #f59e0b;
  border-radius: 99px;
  padding: 4px 12px;
}

.wait-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid #cbd5e1;
  border-top-color: #dc2626;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: absolute;
  bottom: calc(var(--safe-bot) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: #0f172a;
  color: #fff;
  border: 2px solid #fde047;
  border-radius: 99px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

/* ==================== SPRITES ====================
   renderer.js puts html.bw-spr-ui / html.bw-spr-wpn when ui.webp / weapon_icons.webp have loaded.
   Without the files nothing here applies: the old glyph buttons and emoji stay. */
.wpn-ico {
  font-style: normal;
}

html.bw-spr-wpn .wpn-ico {
  display: inline-block;
  width: 24px;
  height: 24px;
  margin: -6px 2px -6px 0;
  vertical-align: middle;
  font-size: 0;
  background: url('./assets/sprites/weapon_icons.webp') no-repeat;
  background-size: 600% 100%;
}
html.bw-spr-wpn .wpn-ico-bazooka { background-position: 0% 0; }
html.bw-spr-wpn .wpn-ico-grenade { background-position: 20% 0; }
html.bw-spr-wpn .wpn-ico-shotgun { background-position: 40% 0; }
html.bw-spr-wpn .wpn-ico-cluster { background-position: 60% 0; }
html.bw-spr-wpn .wpn-ico-airstrike { background-position: 80% 0; }
html.bw-spr-wpn .wpn-ico-holybomb { background-position: 100% 0; }
html.bw-spr-wpn .wpn-tile-top .wpn-ico {
  margin-right: 3px;
}

html.bw-spr-ui .c-btn:not(.c-fire),
html.bw-spr-ui .c-btn.pressed:not(.c-fire) {
  font-size: 0;
  background: none;
  border-color: transparent;
  box-shadow: none;
  padding: 0;
}
html.bw-spr-ui .c-btn:not(.c-fire)::before,
html.bw-spr-ui .fire-ico {
  content: '';
  display: block;
  height: 100%;
  aspect-ratio: 1;
  background: url('./assets/sprites/ui.webp') no-repeat;
  background-size: 800% 100%;
  filter: drop-shadow(0 3px 0 #0f172a);
}
html.bw-spr-ui .c-btn.pressed:not(.c-fire)::before {
  filter: drop-shadow(0 1px 0 #0f172a) brightness(0.9);
}
html.bw-spr-ui .c-btn[data-act='left']::before { background-position: 0% 0; }
html.bw-spr-ui .c-btn[data-act='right']::before { background-position: 14.2857% 0; }
html.bw-spr-ui .c-btn[data-act='jump']::before { background-position: 28.5714% 0; }
html.bw-spr-ui .c-btn[data-act='aimUp']::before { background-position: 42.8571% 0; }
html.bw-spr-ui .c-btn[data-act='aimDown']::before { background-position: 57.1429% 0; }
html.bw-spr-ui .fire-ico {
  height: 40px;
  font-size: 0;
  background-position: 71.4286% 0;
  filter: none;
}
