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

:root {
  --ink: #1c2333;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff4757;
  --accent-dark: #d63447;
  --mustard: #ffd32a;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1322;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#frame {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}
#cv { width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- overlays ---------- */
#overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#overlay.gone { display: none; }

.panel {
  pointer-events: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 36px 44px;
  width: min(440px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255,255,255,0.6) inset;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.title {
  font-family: 'Titan One', 'Nunito', sans-serif;
  font-size: 50px;
  line-height: 0.95;
  color: var(--accent);
  text-shadow: 0 3px 0 var(--accent-dark), 0 8px 18px rgba(214, 52, 71, 0.35);
}
.title::after { content: " 🌭"; font-size: 38px; text-shadow: none; }

.tagline { font-weight: 700; color: #7a8296; font-size: 14px; }

input {
  font-family: inherit; font-weight: 800; font-size: 18px; text-align: center;
  padding: 13px 16px; border-radius: 14px; border: 3px solid #dfe4ee;
  background: #f4f6fb; color: var(--ink); width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #aab2c5; font-weight: 700; }
#codeInput { text-transform: uppercase; letter-spacing: 6px; width: 130px; }

.btn {
  font-family: inherit; font-weight: 900; font-size: 17px; letter-spacing: 0.5px;
  padding: 13px 22px; border: none; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark), 0 10px 20px rgba(214, 52, 71, 0.3);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { filter: grayscale(0.7) brightness(0.95); cursor: default; box-shadow: 0 4px 0 #9aa1b1; }
.btn.big { width: 100%; font-size: 20px; padding: 16px 22px; }
.btn.ghost { background: #eef1f8; color: #55607a; box-shadow: 0 3px 0 #d4dae8; font-size: 14px; padding: 10px 18px; }
.btn.ghost:active { box-shadow: 0 1px 0 #d4dae8; }

.divider { width: 100%; display: flex; align-items: center; gap: 10px; color: #aab2c5; font-weight: 700; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: #e6eaf3; border-radius: 2px; }
.joinrow { display: flex; gap: 10px; width: 100%; justify-content: center; }
.error { color: var(--accent-dark); font-weight: 800; font-size: 14px; }
.hint { color: #97a0b5; font-weight: 700; font-size: 13px; }

.lobbylabel { font-weight: 900; font-size: 13px; letter-spacing: 3px; color: #97a0b5; }
#codeBig { font-family: 'Titan One', sans-serif; font-size: 64px; letter-spacing: 14px; padding-left: 14px; line-height: 1; }
#playerList { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.prow { display: flex; align-items: center; gap: 12px; background: #f4f6fb; border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 16px; }
.pdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(0,0,0,0.08) inset; }
.pcrown { margin-left: auto; }

/* ---------- game over ---------- */
#overEmoji { font-size: 64px; }
#gameover h2 { font-family: 'Titan One', sans-serif; font-size: 30px; }
#overStats { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.srow { display: flex; gap: 10px; align-items: center; background: #f4f6fb; border-radius: 10px; padding: 8px 14px; font-weight: 800; font-size: 14px; }
.srow .skills { margin-left: auto; color: #7a8296; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }

#wavepill {
  position: absolute; top: 14px; left: 16px;
  background: rgba(13, 19, 34, 0.75); color: #fff;
  border-radius: 999px; padding: 8px 18px;
  font-weight: 900; font-size: 16px;
  display: flex; gap: 12px; align-items: baseline;
}
#waveNum { font-family: 'Titan One', sans-serif; letter-spacing: 1px; }
#waveLeft { color: #8fa0c4; font-size: 13px; }

#scorepill {
  position: absolute; top: 14px; right: 16px;
  background: rgba(13, 19, 34, 0.75); color: var(--mustard);
  border-radius: 999px; padding: 8px 18px;
  font-weight: 900; font-size: 16px;
}

#banner {
  position: absolute; top: 30%; left: 50%; transform: translateX(-50%);
  font-family: 'Titan One', sans-serif; font-size: 46px; color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 12px 30px rgba(0,0,0,0.4);
  animation: bannerIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  white-space: nowrap;
}
@keyframes bannerIn { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

#hpwrap {
  position: absolute; bottom: 18px; left: 16px;
  width: 260px; height: 24px; border-radius: 999px;
  background: rgba(13, 19, 34, 0.75);
  border: 2px solid rgba(255,255,255,0.2);
  overflow: hidden;
}
#hpbar { height: 100%; width: 100%; background: linear-gradient(90deg, #2ed573, #7bed9f); transition: width 0.25s; }
#hpwrap.low #hpbar { background: linear-gradient(90deg, #ff4757, #ff6b81); }
#hptext {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 13px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

#upgrades {
  position: absolute; bottom: 50px; left: 16px;
  display: flex; gap: 4px; flex-wrap: wrap; max-width: 300px;
}
.uicon {
  background: rgba(13, 19, 34, 0.75); border-radius: 8px;
  padding: 3px 6px; font-size: 16px;
  border: 1px solid rgba(255,255,255,0.15);
}

#toasts {
  position: absolute; bottom: 90px; right: 16px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.toast {
  background: rgba(13, 19, 34, 0.85); color: #fff;
  border-radius: 10px; padding: 8px 14px;
  font-weight: 800; font-size: 13px;
  animation: toastIn 0.25s ease-out;
}
@keyframes toastIn { from { transform: translateX(30px); opacity: 0; } }

#controlshint {
  position: absolute; bottom: 18px; right: 16px;
  color: rgba(255, 255, 255, 0.7); font-weight: 700; font-size: 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
#controlshint b { color: var(--mustard); }

/* ---------- shop ---------- */
#shop {
  position: absolute; inset: 0;
  background: rgba(13, 19, 34, 0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.shoptitle {
  font-family: 'Titan One', sans-serif; font-size: 34px; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.4);
}
.shoptimer { font-weight: 900; font-size: 20px; color: var(--mustard); }
#cards { display: flex; gap: 18px; }
.card {
  width: 200px; padding: 24px 18px;
  background: var(--panel); border: none; border-radius: 20px;
  font-family: 'Nunito', sans-serif; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  transition: transform 0.12s, box-shadow 0.12s;
}
.card:hover { transform: translateY(-6px) scale(1.03); box-shadow: 0 24px 50px rgba(0,0,0,0.55), 0 0 0 3px var(--mustard); }
.card.chosen { transform: scale(1.03); box-shadow: 0 0 0 4px #2ed573, 0 24px 50px rgba(0,0,0,0.55); }
.card.dim { opacity: 0.35; transform: none; pointer-events: none; }
.card .cicon { font-size: 44px; }
.card .clabel { font-weight: 900; font-size: 18px; color: var(--ink); }
.card .cdesc { font-weight: 700; font-size: 13px; color: #7a8296; }

/* ---------- survivors HUD ---------- */
#clock {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  font-family: 'Titan One', sans-serif; font-size: 34px; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.45), 0 8px 20px rgba(0,0,0,0.4);
  pointer-events: none;
}
#wavepill { top: 60px !important; }
#xpwrap {
  position: absolute; bottom: 18px; left: 288px;
  width: 170px; height: 24px; border-radius: 999px;
  background: rgba(13, 19, 34, 0.75);
  border: 2px solid rgba(94, 231, 255, 0.35);
  overflow: hidden;
}
#xpbar { height: 100%; width: 0%; background: linear-gradient(90deg, #2f7bd6, #5ee7ff); transition: width 0.25s; }
#xptext {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 12px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
#loadout {
  position: absolute; bottom: 50px; left: 16px;
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap; max-width: 340px;
  pointer-events: none;
}
.litem {
  position: relative;
  background: rgba(13, 19, 34, 0.78); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px; padding: 3px 6px; font-size: 17px;
}
.litem b {
  position: absolute; bottom: -5px; right: -4px;
  background: #ffd32a; color: #5c4a00; font-size: 9px; font-weight: 900;
  border-radius: 5px; padding: 0 3px;
}
.litem.evolved { border-color: #ffd32a; box-shadow: 0 0 8px rgba(255, 211, 42, 0.5); }
.litem.passive { opacity: 0.85; }
.lsep { width: 8px; }
#lvlup {
  position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 4;
}
#lvlTitle {
  font-family: 'Titan One', sans-serif; font-size: 20px; color: #ffd32a;
  text-shadow: 0 2px 0 rgba(0,0,0,0.5);
  animation: pulse 0.6s infinite alternate;
}
@keyframes pulse { to { transform: scale(1.08); } }
#lvlcards { display: flex; gap: 10px; }
.lvlcard {
  position: relative;
  width: 190px; padding: 12px 12px 10px;
  background: rgba(30, 22, 18, 0.95); border: 2px solid rgba(255, 71, 87, 0.5);
  border-radius: 14px; cursor: pointer; font-family: 'Nunito', sans-serif; text-align: center;
  display: flex; flex-direction: column; gap: 3px; align-items: center;
  color: #fff;
  transition: transform 0.1s, border-color 0.1s;
}
.lvlcard:hover { transform: translateY(-4px); border-color: #ffd32a; }
.lvlcard .lkey { position: absolute; top: -8px; left: -8px; background: #ffd32a; color: #5c4a00; font-size: 11px; font-weight: 900; border-radius: 6px; padding: 1px 6px; }
.lvlcard .licon { font-size: 30px; }
.lvlcard .llabel { font-weight: 900; font-size: 14px; }
.lvlcard .ldesc { font-weight: 700; font-size: 11px; color: #c9b8a8; line-height: 1.25; }
