/* ============================================================
   僵尸围城 · 竖屏塔防 H5
   纯原生 CSS，无外链资源
   ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #080e18; color: #F4F8FF;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
body { -webkit-user-select: none; user-select: none; }
button { font-family: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus { outline: none; }
[hidden] { display: none !important; }
img, svg { display: block; max-width: 100%; }

.app {
  position: relative;
  width: 100%;
  max-width: 540px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d1524;
  box-shadow: 0 0 80px rgba(0, 0, 0, .75);
  isolation: isolate;
}

/* ============================ 战场 ============================ */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #8FD3F5;
}
.field-bg, .bg-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 22;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-row + .hud-row { margin-top: 8px; }
.hud-right { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 11px;
  border-radius: 999px;
  background: rgba(11, 23, 41, .58);
  border: 1px solid rgba(255, 255, 255, .22);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  color: #fff; font-size: 12px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(3, 10, 22, .25), inset 0 1px 0 rgba(255, 255, 255, .12);
  white-space: nowrap;
}
.wave-chip {
  height: 36px; padding: 0 12px 0 6px;
  background: linear-gradient(180deg, #FFB25E, #F97316);
  border: 1.5px solid #873D00;
  color: #2B1600;
  box-shadow: 0 4px 0 #A34200, 0 8px 18px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .5);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
.wave-flag {
  width: 25px; height: 25px; border-radius: 50%;
  background: rgba(43, 22, 0, .18);
  display: grid; place-items: center;
}
.wave-flag i { width: 15px; height: 15px; color: #3D1D00; }
.wave-k { font-size: 8px; letter-spacing: .8px; color: rgba(43, 22, 0, .72); margin-right: -2px; }
.wave-chip b { font-size: 19px; line-height: 1; }
.wave-total { font-size: 10px; opacity: .7; }
.coin-chip { height: 34px; padding: 0 12px; }
.coin-chip b { font-size: 14px; color: #FFE29A; text-shadow: 0 1px 0 rgba(0, 0, 0, .4); }
.coin, .coin-mini {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #FFF8C9 0%, #FFD24D 42%, #E08A00 100%);
  border: 1.5px solid #A65E00;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .9), 0 1px 3px rgba(0, 0, 0, .35);
  position: relative; flex: 0 0 auto;
}
.coin { width: 19px; height: 19px; }
.coin::after { content: ""; position: absolute; inset: 4.5px; border-radius: 50%; border: 1.5px solid rgba(146, 84, 0, .6); }
.coin-mini { width: 11px; height: 11px; border-width: 1px; }
.coin-mini::after { content: ""; position: absolute; inset: 2.5px; border-radius: 50%; border: 1px solid rgba(146, 84, 0, .55); }
.round-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(11, 23, 41, .6);
  border: 1px solid rgba(255, 255, 255, .24);
  color: #EAF3FF;
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  box-shadow: 0 4px 12px rgba(3, 10, 22, .3), inset 0 1px 0 rgba(255, 255, 255, .14);
  transition: transform .08s, background .2s;
}
.round-btn i { width: 17px; height: 17px; }
.round-btn:active { transform: scale(.92); background: rgba(11, 23, 41, .85); }

.hp-wrap {
  display: flex; align-items: center; gap: 7px;
  width: 172px; max-width: 56%; height: 22px;
  padding: 0 3px;
  pointer-events: none;
}
.hp-ico { width: 17px; height: 17px; color: #FFD166; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .55)); flex: 0 0 auto; }
.hp-track {
  flex: 1; height: 10px; border-radius: 99px; overflow: hidden;
  background: rgba(7, 15, 27, .68);
  border: 1px solid rgba(255, 255, 255, .26);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .55);
}
.hp-fill {
  height: 100%; width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #63E6A0, #28C76F);
  box-shadow: 0 0 8px rgba(56, 220, 130, .65);
  transition: width .3s ease, background .3s ease;
}
.hp-text { font-size: 11px; font-weight: 800; color: #EAF2FF; text-shadow: 0 1px 2px rgba(0, 0, 0, .65); white-space: nowrap; }
.hp-text span { opacity: .6; font-weight: 600; }
.hp-wrap.low .hp-fill { background: linear-gradient(90deg, #FFB25E, #FF5A5F); box-shadow: 0 0 8px rgba(255, 90, 95, .7); }
.hp-wrap.hurt { animation: hpShake .32s; }
@keyframes hpShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  55% { transform: translateX(4px); }
  80% { transform: translateX(-2px); }
}

/* ---------- 炮塔位 ---------- */
.slots-layer { position: absolute; inset: 0; z-index: 10; }
.slot {
  position: absolute;
  width: 64px; height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 18px;
}
.slot-pad {
  position: absolute; inset: 0;
  border-radius: 16px;
  background: rgba(13, 26, 43, .3);
  border: 2px dashed rgba(255, 255, 255, .58);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .22), inset 0 0 0 4px rgba(255, 255, 255, .07);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  transition: background .15s, border-color .15s, transform .12s;
}
.slot-pad::before {
  content: "+";
  font-size: 28px; font-weight: 300; line-height: 1;
  margin-top: -3px;
  text-shadow: 0 2px 3px rgba(0, 0, 0, .5);
}
.slot:active .slot-pad { transform: scale(.94); }
.slot.armed .slot-pad {
  border-color: #FFD166;
  background: rgba(255, 138, 61, .28);
  animation: slotPulse 1.15s ease-in-out infinite;
}
.slot.armed .slot-pad::before { color: #FFE9A8; }
@keyframes slotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, .5), 0 4px 10px rgba(0, 0, 0, .22); }
  50% { box-shadow: 0 0 0 8px rgba(255, 209, 102, 0), 0 4px 14px rgba(0, 0, 0, .3); }
}
.slot-cost {
  position: absolute; left: 50%; bottom: -9px;
  transform: translateX(-50%);
  display: none; align-items: center; gap: 2px;
  padding: 2px 7px; border-radius: 99px;
  background: #FFD166; color: #3A2200;
  font-size: 9px; font-weight: 900;
  border: 1px solid #9A5A00;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  white-space: nowrap;
}
.slot.armed .slot-cost { display: flex; }

.tower { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.tower-art {
  position: relative; width: 60px; height: 60px;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, .35));
}
.tower-art::after {
  content: ""; position: absolute; left: 50%; bottom: -4px;
  width: 48px; height: 12px; margin-left: -24px;
  border-radius: 50%;
  background: rgba(7, 14, 24, .3);
  filter: blur(2px);
  z-index: -1;
}
.turret-head {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  margin: -28px 0 0 -28px;
  transform-origin: 50% 55%;
  transition: transform .1s linear;
  will-change: transform;
}
.turret-head svg { width: 100%; height: 100%; }
.turret-head .muzzle {
  position: absolute; left: 50%; top: -8px;
  width: 18px; height: 18px; margin-left: -9px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFFBD0 0%, #FFC24D 38%, rgba(255, 122, 26, 0) 72%);
  opacity: 0; pointer-events: none;
}
.turret-head.firing .muzzle { animation: muzzleFlash .18s ease-out; }
@keyframes muzzleFlash {
  0% { opacity: 1; transform: scale(.45); }
  45% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1.45); }
}
.tower-lv {
  position: absolute; left: 50%; bottom: -7px;
  transform: translateX(-50%);
  font-size: 8px; font-weight: 900;
  letter-spacing: .4px;
  color: #2B1B00;
  background: linear-gradient(#FFE9A8, #FFC24D);
  border: 1px solid #9A5A00;
  border-radius: 20px;
  padding: 1px 5px;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .22);
}
.tower-up {
  position: absolute; right: -6px; top: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(#4BE08A, #20B865);
  border: 2px solid #0C2B1B;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  animation: upBob 1s ease-in-out infinite;
}
.tower-up::before {
  content: ""; width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid #fff;
  margin-top: -1px;
}
.slot.can-up .tower-up { display: flex; }
@keyframes upBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.slot.flash .tower-art { animation: towerPop .3s ease-out; }
.slot.built::before {
  content: ""; position: absolute;
  left: 50%; bottom: -7px;
  width: 72px; height: 26px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(8, 17, 29, .55) 0%, rgba(8, 17, 29, .25) 45%, rgba(8, 17, 29, 0) 72%);
  pointer-events: none;
}
@keyframes towerPop {
  0% { transform: scale(.55); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------- 僵尸 ---------- */
.zombie-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.zombie {
  position: absolute; left: 0; top: 0;
  width: 76px; height: 95px;
  transform: translate(-50%, -100%) scale(var(--s, 1));
  transform-origin: 50% 100%;
  will-change: transform, left, top;
}
.z-art {
  width: 100%; height: 100%;
  animation: zWalk .78s ease-in-out infinite alternate;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .28));
  transition: filter .1s;
}
.z-art svg { width: 100%; height: 100%; overflow: visible; }
@keyframes zWalk {
  0% { transform: rotate(-2.4deg) translateY(0); }
  100% { transform: rotate(2.4deg) translateY(-3px); }
}
.zombie.hit .z-art { filter: brightness(2.4) saturate(.7) drop-shadow(0 0 7px #fff); }
.zombie.frozen .z-art { filter: hue-rotate(150deg) brightness(1.18) drop-shadow(0 0 9px #7FDFFF); }
.zombie.boss .z-art { filter: drop-shadow(0 0 10px rgba(255, 90, 90, .55)); }
.zombie.dying {
  animation: zDie .5s ease-in forwards;
  z-index: 9;
}
@keyframes zDie {
  0% { opacity: 1; transform: translate(-50%, -100%) scale(var(--s, 1)) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -86%) scale(var(--s, 1)) rotate(68deg); }
}
.z-hp {
  position: absolute; left: 50%; top: -8px;
  width: 72%; height: 5px;
  transform: translateX(-50%);
  border-radius: 99px; overflow: hidden;
  background: rgba(8, 14, 24, .8);
  border: 1px solid rgba(255, 255, 255, .5);
  opacity: 0; transition: opacity .15s;
}
.zombie.damaged .z-hp { opacity: 1; }
.z-hp i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #7CFF9A, #2ED573);
  border-radius: 99px;
  transition: width .12s linear;
}
.zombie.tank .z-hp i { background: linear-gradient(90deg, #FFE08A, #FF9F1A); }
.zombie.boss .z-hp { width: 90%; height: 7px; top: -12px; }
.zombie.boss .z-hp i { background: linear-gradient(90deg, #FFB3B3, #FF4D4D); }
.z-badge {
  position: absolute; left: 50%; bottom: -4px;
  transform: translateX(-50%);
  font-size: 7px; font-weight: 900; letter-spacing: .5px;
  color: #FFE1B0; background: rgba(20, 10, 4, .75);
  border: 1px solid rgba(255, 160, 80, .5);
  border-radius: 4px; padding: 1px 4px;
  white-space: nowrap;
}

/* ---------- 特效 ---------- */
.fx-layer { position: absolute; inset: 0; z-index: 16; pointer-events: none; overflow: hidden; }
.tracer {
  position: absolute; height: 3px; border-radius: 3px;
  transform-origin: 0 50%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), #FFFFFF 18%, #FFE28A 70%, rgba(255, 226, 138, 0));
  box-shadow: 0 0 7px rgba(255, 214, 110, .95);
  animation: tracerFade .17s linear forwards;
}
.tracer.frost { background: linear-gradient(90deg, rgba(160, 240, 255, 0), #E9FDFF 20%, #6FD8FF 70%, rgba(111, 216, 255, 0)); box-shadow: 0 0 8px rgba(111, 216, 255, .95); }
.tracer.cannon { height: 5px; background: linear-gradient(90deg, rgba(255, 120, 60, 0), #FFE0A0 20%, #FF8A3D 70%, rgba(255, 138, 61, 0)); box-shadow: 0 0 9px rgba(255, 138, 61, .95); }
@keyframes tracerFade { 0% { opacity: 1; } 70% { opacity: .9; } 100% { opacity: 0; } }
.explosion {
  position: absolute; width: 86px; height: 86px; margin: -43px 0 0 -43px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFFBD0 0%, #FFD35C 30%, #FF8A3D 55%, rgba(255, 90, 30, 0) 72%);
  animation: boom .6s ease-out forwards;
}
.explosion.frost { background: radial-gradient(circle, #FFFFFF 0%, #C9F4FF 30%, #5BC8FF 55%, rgba(91, 200, 255, 0) 72%); }
@keyframes boom {
  0% { transform: scale(.2); opacity: 1; }
  55% { opacity: 1; }
  100% { transform: scale(1.9); opacity: 0; }
}
.shockwave {
  position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%; border: 3px solid rgba(255, 225, 160, .9);
  animation: shock .5s ease-out forwards;
}
@keyframes shock {
  0% { transform: scale(.3); opacity: 1; }
  100% { transform: scale(3.2); opacity: 0; }
}
.float-txt {
  position: absolute; z-index: 18;
  font-size: 15px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55), 0 0 6px rgba(0, 0, 0, .35);
  animation: floatUp .8s ease-out forwards;
  white-space: nowrap;
}
.float-txt.gold { color: #FFE08A; }
.float-txt.hurt { color: #FF8A8A; font-size: 13px; }
.float-txt.frost { color: #B9F3FF; font-size: 12px; }
.float-txt.big { font-size: 20px; color: #FFD166; }
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(.7); opacity: 0; }
  18% { opacity: 1; transform: translate(-50%, -12px) scale(1.12); }
  100% { transform: translate(-50%, -50px) scale(.98); opacity: 0; }
}
.smoke {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: rgba(210, 210, 210, .5);
  filter: blur(3px);
  animation: smokeUp .8s ease-out forwards;
}
@keyframes smokeUp {
  0% { transform: scale(.6) translateY(0); opacity: .75; }
  100% { transform: scale(1.9) translateY(-28px); opacity: 0; }
}

/* ---------- 防线工事 ---------- */
.base-barricade {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 66px; z-index: 12;
  pointer-events: none;
  transition: opacity .25s ease;
}
.base-barricade svg { width: 100%; height: 100%; }

/* ---------- 波次横幅 ---------- */
.banner {
  position: absolute; left: 50%; top: 35%;
  transform: translate(-50%, -50%) scale(.9);
  z-index: 26; text-align: center;
  opacity: 0; pointer-events: none;
}
.banner.show { animation: bannerIn 2.1s ease forwards; }
.banner b {
  display: block;
  font-size: clamp(30px, 9vw, 40px);
  font-weight: 900; letter-spacing: 2px;
  color: #FFF6D6;
  text-shadow: 0 3px 0 #9A3D00, 0 7px 18px rgba(0, 0, 0, .6);
  white-space: nowrap;
}
.banner small {
  display: inline-block; margin-top: 3px;
  padding: 3px 13px; border-radius: 99px;
  background: rgba(255, 138, 61, .95);
  border: 1px solid rgba(90, 35, 0, .5);
  color: #2B1600; font-weight: 900; font-size: 11px; letter-spacing: 1px;
  box-shadow: 0 3px 0 rgba(120, 50, 0, .5);
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.65); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  22% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -52%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.96); }
}

.next-wave {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 94px);
  transform: translateX(-50%);
  z-index: 23;
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(9, 20, 37, .78);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #DDEBFF; font-size: 11px; font-weight: 800;
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
  white-space: nowrap;
}
.next-wave b { color: #FFD166; font-size: 14px; }

.hurt-flash {
  position: absolute; inset: 0; z-index: 30;
  pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 50% 88%, rgba(255, 50, 50, 0) 35%, rgba(255, 40, 40, .48) 100%);
  transition: opacity .14s ease;
}
.hurt-flash.on { opacity: 1; }

.stage.shake { animation: shake .34s linear; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  18% { transform: translate(-5px, 2px); }
  38% { transform: translate(5px, -2px); }
  58% { transform: translate(-3px, -1px); }
  78% { transform: translate(3px, 1px); }
}

/* ============================ 建造栏 ============================ */
.dock {
  position: relative; z-index: 35;
  flex: 0 0 auto;
  padding: 9px 14px calc(env(safe-area-inset-bottom) + 10px);
  background: linear-gradient(180deg, #1D273C 0%, #131B2C 62%, #0F1626 100%);
  border-top: 1px solid rgba(255, 255, 255, .13);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 28px rgba(0, 0, 0, .42), inset 0 1px 0 rgba(255, 255, 255, .09);
  transition: opacity .25s ease;
}
.dock-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 16px; }
.dock-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 900; letter-spacing: .6px; color: #EAF1FF; }
.dock-title i { width: 3px; height: 12px; border-radius: 2px; background: #FF8A3D; box-shadow: 0 0 8px #FF8A3D; }
.dock-tip { font-size: 10px; font-weight: 600; color: #8FA1BC; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-tip.hot { color: #FFC24D; }
.dock-body { display: flex; gap: 8px; margin-top: 6px; }
.build-cards { flex: 1 1 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.build-card {
  position: relative;
  min-height: 78px;
  border-radius: 13px;
  background: linear-gradient(180deg, #26324A, #1B2538);
  border: 1px solid #3A4864;
  box-shadow: 0 3px 0 #0B1220, inset 0 1px 0 rgba(255, 255, 255, .07);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 5px 3px;
  color: #EAF1FF;
  transition: transform .09s ease, border-color .15s, background .15s, opacity .15s;
}
.build-card:active { transform: translateY(2px); box-shadow: 0 1px 0 #0B1220, inset 0 1px 0 rgba(255, 255, 255, .07); }
.build-card.selected {
  border-color: #FF8A3D;
  background: linear-gradient(180deg, #3A2A1E, #261B14);
  box-shadow: 0 0 0 2px rgba(255, 138, 61, .32), 0 3px 0 #0B1220, inset 0 1px 0 rgba(255, 255, 255, .12);
  transform: translateY(-2px);
}
.build-card.poor { opacity: .5; }
.bc-ico {
  width: 29px; height: 29px; border-radius: 9px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .09);
}
.bc-ico i { width: 19px; height: 19px; }
.bc-ico.gun i { color: #FFB25E; }
.bc-ico.frost i { color: #7FDFFF; }
.bc-ico.cannon i { color: #FF7A7E; }
.bc-name { font-size: 11px; font-weight: 900; letter-spacing: .3px; }
.bc-cost { display: flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 900; color: #FFD166; }
.bc-cost b { font-size: 10px; }
.bc-lock { position: absolute; inset: 0; border-radius: 13px; pointer-events: none; }
.build-card.selected .bc-lock { box-shadow: inset 0 0 18px rgba(255, 138, 61, .18); }
.build-cards.nudge .build-card:first-child {
  border-color: #FF8A3D;
  animation: cardNudge .9s ease-in-out 3;
}
@keyframes cardNudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.skill {
  position: relative;
  flex: 0 0 66px;
  min-height: 78px;
  border-radius: 13px;
  overflow: hidden;
  background: linear-gradient(180deg, #3B2F6E, #241C47);
  border: 1px solid #6C5AA8;
  box-shadow: 0 3px 0 #0A101D, inset 0 1px 0 rgba(255, 255, 255, .13);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: transform .09s ease, filter .2s;
}
.skill:active { transform: translateY(2px); }
.skill-ico {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #A58FFF, #5B41D6);
  box-shadow: 0 0 12px rgba(124, 92, 255, .55), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.skill-ico i { width: 17px; height: 17px; color: #fff; }
.skill-name { font-size: 11px; font-weight: 900; color: #EFEBFF; letter-spacing: .5px; }
.skill-state { font-size: 8px; font-weight: 800; color: #B9AAFF; }
.skill.ready {
  border-color: #A18CFF;
  box-shadow: 0 0 0 2px rgba(124, 92, 255, .28), 0 3px 0 #0A101D;
  animation: skillGlow 1.8s ease-in-out infinite;
}
.skill.ready .skill-ico { animation: upBob 1.4s ease-in-out infinite; }
.skill.ready .skill-state { color: #7DFFB2; }
.skill.cooling { filter: saturate(.55) brightness(.85); }
.skill > .skill-ico, .skill > .skill-name, .skill > .skill-state { position: relative; z-index: 2; }
.skill-shade {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0%;
  background: rgba(3, 7, 16, .72);
  pointer-events: none;
  z-index: 1;
  transition: height .25s linear;
}
@keyframes skillGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(124, 92, 255, .22), 0 3px 0 #0A101D; }
  50% { box-shadow: 0 0 0 4px rgba(124, 92, 255, .12), 0 0 18px rgba(124, 92, 255, .55), 0 3px 0 #0A101D; }
}

/* ============================ 提示 ============================ */
.toast {
  position: absolute; left: 50%; bottom: calc(124px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  z-index: 70;
  max-width: 86%;
  padding: 9px 16px;
  border-radius: 99px;
  background: rgba(10, 19, 34, .95);
  border: 1px solid rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 12px; font-weight: 700; text-align: center;
  opacity: 0; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { border-color: rgba(255, 194, 77, .55); color: #FFE6B0; }
.toast.good { border-color: rgba(90, 230, 150, .5); color: #D8FFEA; }

/* ============================ 开始界面 ============================ */
.overlay { position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; }
.start-screen {
  z-index: 55;
  padding: calc(env(safe-area-inset-top) + 12px) 18px calc(env(safe-area-inset-bottom) + 14px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  background:
    radial-gradient(115% 62% at 50% -8%, rgba(255, 138, 61, .22), rgba(8, 20, 36, 0) 60%),
    radial-gradient(120% 70% at 50% 108%, rgba(25, 77, 110, .55), rgba(5, 12, 24, 0) 65%),
    linear-gradient(180deg, rgba(9, 22, 40, .82) 0%, rgba(7, 16, 30, .95) 45%, rgba(4, 9, 18, .99) 100%);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.start-glow {
  position: absolute; left: 50%; top: 8%;
  width: 120%; height: 40%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 160, 60, .18), rgba(255, 160, 60, 0) 68%);
  pointer-events: none;
}
.start-top { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.player-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 99px;
  background: rgba(9, 21, 38, .6);
  border: 1px solid rgba(255, 255, 255, .17);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  min-width: 0;
}
.avatar {
  width: 35px; height: 35px; border-radius: 50%;
  flex: 0 0 auto;
  background: linear-gradient(150deg, #FFB25E, #FF7A18);
  border: 2px solid rgba(255, 255, 255, .55);
  display: grid; place-items: center;
  color: #fff;
  background-size: cover; background-position: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
  overflow: hidden;
}
.avatar i { width: 21px; height: 21px; }
.player-meta { display: flex; flex-direction: column; min-width: 0; }
.player-meta b { font-size: 12px; color: #fff; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 132px; }
.player-meta small { font-size: 9px; color: #9FB3CE; line-height: 1.3; white-space: nowrap; }
.player-meta small b { display: inline; font-size: 10px; color: #FFD166; max-width: none; }
.sound-toggle {
  display: flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 11px;
  border-radius: 99px;
  background: rgba(9, 21, 38, .6);
  border: 1px solid rgba(255, 255, 255, .17);
  color: #D5E4F6; font-size: 10px; font-weight: 700;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  flex: 0 0 auto;
}
.sound-toggle i { width: 15px; height: 15px; }
.sound-toggle:active { transform: scale(.95); }

.start-main {
  position: relative; z-index: 2;
  flex: 1 1 auto;
  width: 100%; max-width: 400px;
  margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px;
  padding: 8px 0 2px;
}
.title-badge {
  font-size: 9px; font-weight: 900; letter-spacing: 4px;
  color: #FFC24D;
  padding: 4px 13px 4px 16px;
  border-radius: 99px;
  border: 1px solid rgba(255, 194, 77, .35);
  background: rgba(255, 138, 61, .13);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}
.game-title {
  margin: 0;
  font-size: clamp(42px, 11.5vw, 55px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 3px;
  transform: rotate(-2deg);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .35));
}
.game-title span {
  color: #FFD166;
  -webkit-text-stroke: 2px #5A2A00;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #B14A00, 0 6px 0 #7A3200;
}
.game-sub { margin: 0; font-size: 11px; letter-spacing: 1.6px; color: #A9BED8; font-weight: 600; }

.hero-art {
  position: relative;
  width: min(100%, 356px);
  aspect-ratio: 3 / 2;
  margin: 1px 0;
  border-radius: 24px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .28);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(255, 255, 255, .16);
  background: #8FD3F5;
  flex: 0 1 auto;
}
.hero-bg { width: 100%; height: 100%; }
.hs-z { position: absolute; bottom: 2%; width: 23%; max-width: 86px; filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .32)); animation: hsBob 1.35s ease-in-out infinite alternate; transform-origin: 50% 100%; }
.hs-z svg { width: 100%; height: auto; overflow: visible; }
.hs-z1 { right: 18%; bottom: 1%; width: 23%; animation-delay: -.25s; }
.hs-z2 { right: 32%; bottom: 13%; width: 15%; animation-delay: -.85s; opacity: .96; }
.hs-z3 { right: 42%; bottom: 22%; width: 11%; opacity: .72; animation-delay: -.55s; }
@keyframes hsBob {
  0% { transform: rotate(-2deg) translateY(0); }
  100% { transform: rotate(2deg) translateY(-5px); }
}
.hs-flash { animation: hsFlash 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes hsFlash {
  0%, 100% { opacity: .25; transform: scale(.8); }
  45% { opacity: 1; transform: scale(1.06); }
  60% { opacity: .65; transform: scale(.94); }
}

.start-feats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.start-feats span {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; color: #C6D7EA;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  padding: 4px 9px; border-radius: 99px;
  white-space: nowrap;
}
.start-feats i { width: 13px; height: 13px; color: #FFC24D; }

.btn-start {
  position: relative;
  width: min(100%, 322px);
  min-height: 62px;
  border-radius: 20px;
  background: linear-gradient(180deg, #FFC24D 0%, #FF8A3D 55%, #F26A0C 100%);
  border: 2px solid #8A3B00;
  box-shadow: 0 6px 0 #A34200, 0 14px 28px rgba(255, 120, 20, .3), inset 0 2px 0 rgba(255, 255, 255, .55);
  display: flex; align-items: center; justify-content: center; gap: 9px;
  color: #3A1B00;
  font-size: 22px; font-weight: 900; letter-spacing: 2px;
  overflow: hidden;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn-start:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #A34200, 0 6px 12px rgba(255, 120, 20, .28), inset 0 2px 0 rgba(255, 255, 255, .45);
}
.btn-start .play {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .38);
  border: 2px solid rgba(120, 52, 0, .32);
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.btn-start .play i { width: 21px; height: 21px; color: #4A2100; }
.btn-start b { text-shadow: 0 1px 0 rgba(255, 255, 255, .45); }
.btn-start .shine {
  position: absolute; top: -50%; left: -40%;
  width: 22%; height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent);
  transform: rotate(18deg);
  animation: shine 3.6s 1.2s infinite;
  pointer-events: none;
}
@keyframes shine {
  0% { left: -40%; }
  52% { left: 135%; }
  100% { left: 135%; }
}
.btn-start.small { min-height: 52px; font-size: 17px; border-radius: 16px; width: 100%; }
.btn-start.small .play { width: 30px; height: 30px; }
.btn-start.small .play i { width: 19px; height: 19px; }
.start-foot { margin: 0; font-size: 9px; letter-spacing: 2px; color: #6E829E; font-weight: 700; }

/* ============================ 结算 / 暂停 ============================ */
.result-screen {
  z-index: 58;
  align-items: center; justify-content: center;
  padding: 24px 18px calc(env(safe-area-inset-bottom) + 24px);
  background: rgba(4, 9, 18, .78);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  overflow-y: auto;
}
.result-card {
  width: 100%; max-width: 350px;
  border-radius: 26px;
  padding: 22px 18px 18px;
  background: linear-gradient(180deg, #1E2A42, #111A2B);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 255, 255, .1);
  text-align: center;
  animation: popIn .38s cubic-bezier(.2, 1.3, .5, 1) both;
}
.result-badge {
  width: 64px; height: 64px;
  margin: -46px auto 6px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #FF8A3D, #D84315);
  border: 3px solid #2A1600;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .3), 0 0 26px rgba(255, 110, 40, .45);
}
.result-badge i { width: 34px; height: 34px; color: #FFF6D6; }
.result-screen.victory .result-badge { background: linear-gradient(160deg, #FFE08A, #FFA000); }
.result-screen.victory .result-badge i { color: #4A2A00; }
.result-card h2 { margin: 6px 0 2px; font-size: 27px; letter-spacing: 2px; color: #FFF3D6; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.result-card > p { margin: 0; color: #91A6C2; font-size: 11px; line-height: 1.5; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 16px 0 10px; }
.result-stats div {
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 13px;
  padding: 9px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.result-stats span { font-size: 9px; color: #8FA2BC; }
.result-stats b { font-size: 20px; color: #FFD166; line-height: 1.2; }
.result-stats small { font-size: 9px; color: #7F93AE; }
.result-best { font-size: 10px; color: #8FA2BC; margin-bottom: 12px !important; }
.result-card .btn-start { margin-top: 2px; }
.btn-ghost {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 42px;
  margin-top: 8px;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, .17);
  background: rgba(255, 255, 255, .04);
  color: #B9CBE2;
  font-size: 13px; font-weight: 800; letter-spacing: 1px;
  transition: background .15s, transform .08s;
}
.btn-ghost:active { transform: translateY(2px); background: rgba(255, 255, 255, .09); }
@keyframes popIn {
  from { opacity: 0; transform: scale(.86) translateY(14px); }
  to { opacity: 1; transform: none; }
}

.pause-screen {
  z-index: 57;
  align-items: center; justify-content: center;
  padding: 24px 18px;
  background: rgba(4, 9, 18, .76);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  overflow-y: auto;
}
.pause-card {
  width: 100%; max-width: 320px;
  border-radius: 24px;
  padding: 24px 18px 18px;
  background: linear-gradient(180deg, #1E2A42, #111A2B);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 255, 255, .1);
  text-align: center;
  animation: popIn .32s cubic-bezier(.2, 1.3, .5, 1) both;
}
.pause-ico {
  width: 54px; height: 54px; margin: 0 auto 8px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .13);
  color: #FFC24D;
}
.pause-ico i { width: 28px; height: 28px; }
.pause-card h2 { margin: 0 0 3px; font-size: 26px; letter-spacing: 3px; color: #FFF3D6; }
.pause-card p { margin: 0 0 16px; font-size: 11px; color: #91A6C2; }
.sound-line {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; min-height: 40px; margin-top: 8px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, .16);
  color: #9FB3CE; font-size: 12px; font-weight: 700;
}
.sound-line i { width: 16px; height: 16px; }

/* ============================ 状态隐藏 ============================ */
body[data-state="home"] .hud,
body[data-state="home"] .dock,
body[data-state="home"] .base-barricade,
body[data-state="home"] .hud .next-wave { opacity: 0; pointer-events: none; }

/* ============================ 响应式 ============================ */
@media (max-height: 720px) {
  .start-main { gap: 7px; padding-top: 4px; }
  .game-title { font-size: 43px; }
  .hero-art { width: min(100%, 306px); }
  .btn-start { min-height: 56px; font-size: 20px; }
  .start-feats span { padding: 3px 8px; }
  .start-foot { display: none; }
  .dock { padding-top: 7px; }
  .build-card, .skill { min-height: 72px; }
  .bc-ico { width: 26px; height: 26px; }
  .bc-ico i { width: 17px; height: 17px; }
}
@media (max-height: 620px) {
  .hero-art { width: min(100%, 240px); }
  .game-sub { display: none; }
  .game-title { font-size: 38px; }
  .start-main { gap: 8px; }
  .start-feats { display: none; }
  .start-foot { display: none; }
}
@media (max-width: 355px) {
  .dock { padding-left: 10px; padding-right: 10px; }
  .dock-body { gap: 6px; }
  .build-cards { gap: 5px; }
  .build-card { min-height: 70px; }
  .bc-name { font-size: 10px; }
  .skill { flex-basis: 58px; min-height: 70px; }
  .slot { width: 58px; height: 58px; }
  .tower-art { width: 54px; height: 54px; }
  .turret-head { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
  .player-meta b { max-width: 100px; }
}
