/* Bridge Battle — playful, rounded, vibrant kids UI. The canvas renders the
   world; everything here is menus and HUD. */
:root {
  --blue: #3079e0;
  --blue-dark: #1d54a8;
  --blue-light: #63a4ff;
  --gold: #ffc400;
  --red: #e04338;
  --green: #00c853;
  --ink: #20222e;
  --card: rgba(22, 26, 44, 0.82);
  --font: 'Nunito', 'Trebuchet MS', 'Comic Sans MS', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background: #10121e;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
}

#ui { position: fixed; inset: 0; pointer-events: none; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: opacity 0.25s ease;
}
.screen.center { justify-content: center; gap: 14px; padding: 24px; }
.screen > * { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- typography ---------- */

h1.title {
  font-size: clamp(2.4rem, 9vw, 4rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 var(--blue-dark), 0 8px 22px rgba(0, 0, 0, 0.45);
  letter-spacing: 1px;
  transform: rotate(-2deg);
}
.subtitle {
  color: #eaf4ff;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
h2 {
  color: #fff;
  font-weight: 900;
  font-size: 1.7rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.hint { color: rgba(255, 255, 255, 0.8); font-size: 0.85rem; text-shadow: 0 1px 4px rgba(0,0,0,0.5); }

/* ---------- buttons ---------- */

.btn {
  font-family: var(--font);
  font-weight: 900;
  font-size: 1rem;
  color: #fff;
  border: none;
  border-radius: 18px;
  padding: 12px 26px;
  cursor: pointer;
  background: linear-gradient(180deg, #5a6478 0%, #3c4358 100%);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 8px 18px rgba(0, 0, 0, 0.3);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(3px) scale(0.98); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.btn:disabled { filter: grayscale(0.7) brightness(0.7); cursor: default; }
.btn.big { font-size: 1.25rem; padding: 15px 34px; min-width: 230px; }
.btn.primary {
  background: linear-gradient(180deg, #4cd964 0%, #00a844 100%);
  box-shadow: 0 5px 0 #006b2c, 0 10px 22px rgba(0, 0, 0, 0.35);
}
.btn.danger { background: linear-gradient(180deg, #ff6a5c 0%, #c62f24 100%); box-shadow: 0 4px 0 #7c1610, 0 8px 18px rgba(0,0,0,0.3); }
.btn.round {
  border-radius: 50%;
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 0.9rem;
  background: linear-gradient(180deg, #5a6478 0%, #3c4358 100%);
}
.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

/* ---------- pills & icons ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(20, 24, 40, 0.72);
  border-radius: 999px;
  padding: 7px 16px 7px 9px;
  color: #fff;
  font-weight: 900;
  font-size: 1.05rem;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12), 0 4px 10px rgba(0, 0, 0, 0.3);
}
.ico { width: 20px; height: 20px; border-radius: 50%; display: inline-block; }
.ico.coin { background: radial-gradient(circle at 35% 30%, #ffea8c, #ffd23f 55%, #d8a200); box-shadow: 0 0 6px rgba(255, 210, 63, 0.8); }
.ico.key { border-radius: 6px; background: radial-gradient(circle at 35% 30%, #fff3c0, #ffe07a 55%, #c79400); }
.ico.shield { border-radius: 6px 6px 10px 10px; background: linear-gradient(180deg, var(--blue-light), var(--blue-dark)); }
.ico.enemy { border-radius: 6px 6px 10px 10px; background: linear-gradient(180deg, #ff7a63, #a32218); }

/* Army pill signals whether the squad likely outnumbers the end fight. */
#hud-army-pill.win { box-shadow: inset 0 0 0 2px #4cd964, 0 4px 10px rgba(0, 0, 0, 0.3); }
#hud-army-pill.lose { box-shadow: inset 0 0 0 2px #ff5a4a, 0 4px 10px rgba(0, 0, 0, 0.3); }

/* ---------- HUD ---------- */

.hud { pointer-events: none; }
.hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.hud-top .army { margin-left: auto; }
.hud-top .btn { pointer-events: auto; }
.hud-bottom {
  position: absolute;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}
.progress {
  width: 100%;
  max-width: 420px;
  height: 14px;
  border-radius: 999px;
  background: rgba(20, 24, 40, 0.72);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
#hud-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4cd964, #b6ff7a);
  transition: width 0.2s linear;
}
.progress.battle #hud-progress-fill { background: linear-gradient(90deg, #ff6a5c, #ffc400); }
.hud-level { color: #fff; font-weight: 800; font-size: 0.82rem; text-shadow: 0 1px 4px rgba(0,0,0,0.6); }
.hud-powers { font-size: 1.1rem; min-height: 1.3em; letter-spacing: 3px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }

.pill.pulse { animation: coinpulse 0.3s ease; }
@keyframes coinpulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* ---------- overlays & cards ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 20, 0.55);
  pointer-events: auto;
  backdrop-filter: blur(3px);
}
.card {
  background: var(--card);
  border-radius: 26px;
  padding: 26px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), inset 0 0 0 2px rgba(255, 255, 255, 0.1);
  max-width: min(92vw, 420px);
}
.card h2 { font-size: 1.4rem; }

/* ---------- level grid ---------- */

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  max-width: 400px;
  width: 90vw;
  max-height: 55vh;
  overflow-y: auto;
  padding: 6px;
}
.level-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #4a90e8, #2358a8);
  color: #fff;
  font-family: var(--font);
  font-weight: 900;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 3px 0 #143a6e, 0 6px 12px rgba(0, 0, 0, 0.3);
}
.level-cell:active { transform: translateY(2px); }
.level-cell .lv { font-size: 1.2rem; }
.level-cell .stars { font-size: 0.62rem; color: var(--gold); letter-spacing: 1px; }
/* Shooter levels: archer green, same color as the squad in those levels. */
.level-cell.shooter {
  background: linear-gradient(180deg, #17c974, #0a7a44);
  box-shadow: 0 3px 0 #06522d, 0 6px 12px rgba(0, 0, 0, 0.3);
}
.level-cell.locked {
  background: linear-gradient(180deg, #4c5162, #33374a);
  color: rgba(255, 255, 255, 0.35);
  cursor: default;
  box-shadow: 0 3px 0 #202433;
}
.level-cell.locked .stars { visibility: hidden; }

/* ---------- upgrades ---------- */

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(92vw, 440px);
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px;
}
.upgrade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}
.shop-header {
  color: #fff;
  font-weight: 900;
  font-size: 1rem;
  text-align: left;
  margin: 8px 2px 0;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}
.shop-icon {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 3px 8px rgba(0, 0, 0, 0.3);
}
.power-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.power-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 18px;
  padding: 14px 10px 12px;
  color: #fff;
  text-align: center;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}
.power-card strong { font-size: 0.92rem; }
.power-card small { color: rgba(255, 255, 255, 0.65); font-size: 0.7rem; min-height: 2.2em; }
.power-card .btn.buy { width: 100%; min-width: 0; }
.power-card.pet-owned { box-shadow: inset 0 0 0 2px var(--gold); }
.btn.buy.owned {
  background: linear-gradient(180deg, #4cd964, #00a844);
  box-shadow: 0 3px 0 #006b2c;
  cursor: default;
  pointer-events: none;
}
.owned-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  background: linear-gradient(180deg, #ffe45c, #e0a000);
  color: #4a3000;
  font-weight: 900;
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 2px 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}
.upgrade-info { display: flex; flex-direction: column; gap: 3px; color: #fff; text-align: left; flex: 1; min-width: 0; }
.upgrade-info strong { font-size: 1rem; }
.upgrade-info small { color: rgba(255, 255, 255, 0.65); font-size: 0.74rem; }
.pips { display: flex; gap: 3px; margin-top: 3px; }
.pips i {
  width: 12px;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
}
.pips i.on { background: linear-gradient(180deg, #ffe45c, #ffab00); }
.btn.buy { display: flex; flex-direction: column; gap: 2px; padding: 9px 18px; font-size: 0.9rem; min-width: 92px;
  background: linear-gradient(180deg, #ffc93f, #e08700); box-shadow: 0 4px 0 #8a5200, 0 8px 16px rgba(0,0,0,0.3); }
.btn.buy .cost { font-size: 0.8rem; opacity: 0.9; }
.btn.buy .cost::before { content: '● '; color: #fff3b0; }

/* ---------- scoreboard ---------- */

.score-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: min(92vw, 420px);
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px;
}
.score-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border-radius: 14px;
  padding: 9px 14px;
  color: #fff;
  font-weight: 800;
}
.score-row .rank { color: rgba(255, 255, 255, 0.6); }
.score-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row .lvl { font-size: 0.76rem; color: rgba(255, 255, 255, 0.6); }
.score-row .pts { color: var(--gold); }
.score-row.top1 { box-shadow: inset 0 0 0 2px var(--gold); }
.score-row.top1 .rank { color: var(--gold); }
.score-row.top2 { box-shadow: inset 0 0 0 2px #cfd8e6; }
.score-row.top3 { box-shadow: inset 0 0 0 2px #d8925a; }
.score-empty { color: #fff; opacity: 0.8; padding: 20px; text-align: center; }

/* ---------- settings ---------- */

.settings-card { min-width: min(88vw, 340px); align-items: stretch; }
.settings-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
}
.settings-card label.row { flex-direction: row; justify-content: space-between; align-items: center; }
input[type='range'] { accent-color: var(--gold); height: 26px; }
input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--gold); }

/* ---------- result ---------- */

.result-card { min-width: min(90vw, 360px); }
#result-title { font-size: 2.2rem; font-weight: 900; }
#result-title.win { color: #ffe45c; text-shadow: 0 3px 0 #a06a00, 0 6px 18px rgba(0,0,0,0.4); }
#result-title.lose { color: #ff8a7a; text-shadow: 0 3px 0 #6e1710; }
.stars-big { display: flex; gap: 10px; font-size: 2.6rem; }
.stars-big span {
  color: rgba(255, 255, 255, 0.14);
  transform: scale(0.6);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s;
}
.stars-big span.on {
  color: var(--gold);
  transform: scale(1);
  text-shadow: 0 0 18px rgba(255, 196, 0, 0.7);
}
.reward-label { color: rgba(255, 255, 255, 0.7); font-weight: 700; font-size: 0.85rem; margin-bottom: -10px; }
.reward-coins { color: var(--gold); font-size: 1.9rem; font-weight: 900; }
.result-score { color: #9fe0ff; font-weight: 900; }
.chest { color: #ffe45c; font-weight: 900; animation: pop 0.5s ease; }
.result-buttons { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.result-buttons .btn { width: 100%; }
.score-save { display: flex; gap: 8px; width: 100%; }
.score-save input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}
.score-save .btn { font-size: 0.85rem; padding: 10px 14px; white-space: nowrap; }

@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* Victory confetti rain + golden rays behind the title */
.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.confetti i {
  position: absolute;
  top: -4%;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  opacity: 0;
  animation: confetti-fall linear infinite;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  8% { opacity: 0.95; }
  100% { transform: translateY(110vh) rotate(560deg); opacity: 0.7; }
}
.screen.victory #result-title { position: relative; }
.screen.victory #result-title::before {
  content: '';
  position: absolute;
  inset: -70px -90px;
  background: repeating-conic-gradient(rgba(255, 214, 64, 0.16) 0deg 12deg, transparent 12deg 30deg);
  border-radius: 50%;
  animation: rays-spin 14s linear infinite;
  z-index: -1;
}
@keyframes rays-spin {
  to { transform: rotate(360deg); }
}

.menu-coins-pill { margin-bottom: 4px; }

/* ---------- debug ---------- */

.debug {
  position: fixed;
  top: 4px;
  left: 6px;
  z-index: 99;
  color: #8f8;
  font: 11px monospace;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
