/* ---------- 战场 ---------- */
#field {
  position: relative;
  border-radius: 20px;
  border: 3px solid #3a2a12;
  overflow: hidden;
  background: #74b64e;
  min-width: 0;
  --base-w: 128px;
}
.lanes { position: absolute; inset: 0; }
.lane { position: absolute; left: 0; right: 0; }
.lane:nth-child(odd) { background: #7cc355; }
.lane:nth-child(even) { background: #68aa45; }
.lane::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
}
.grass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(115deg, rgba(6, 48, 16, 0.1) 0 2px, transparent 2px 17px),
    repeating-linear-gradient(25deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 23px);
}
.base-shade {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--base-w);
  background: linear-gradient(90deg, rgba(28, 18, 6, 0.42), rgba(28, 18, 6, 0.18) 70%, rgba(28, 18, 6, 0));
}
.lane-numbers { position: absolute; inset: 0; pointer-events: none; }
.lane-number {
  position: absolute;
  right: 6px;
  width: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}
.base {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: calc(var(--base-w) - 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.house {
  width: calc(var(--base-w) - 20px);
  height: calc(var(--base-w) - 20px);
  object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
}
.house.hurt { animation: houseShake 0.34s ease-in-out, houseHurt 0.3s ease-out; }
@keyframes houseHurt {
  0% { filter: brightness(1.2) sepia(1) saturate(9) hue-rotate(-30deg) drop-shadow(0 0 12px rgba(255, 45, 25, 0.95)); }
  100% { filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35)); }
}
@keyframes houseShake {
  0% { transform: rotate(0deg); }
  18% { transform: rotate(-7deg); }
  42% { transform: rotate(6deg); }
  66% { transform: rotate(-4deg); }
  100% { transform: rotate(0deg); }
}
.hp-label {
  font-size: 15px;
  color: #ffe9b0;
  text-shadow: 0 1px 0 #000, 0 0 4px rgba(0, 0, 0, 0.7);
}
.hp-bar {
  width: 70px;
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  width: 100%;
  background: #6ee34f;
  transition: width 0.25s, background-color 0.25s;
}
.fence {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--base-w) - 1px);
  width: 2px;
  background: rgba(255, 255, 255, 0.28);
}
.units { position: absolute; inset: 0; pointer-events: none; }
.damage-overlay {
  position: absolute;
  inset: 0;
  background: #ff1e14;
  opacity: 0;
  pointer-events: none;
}
.damage-overlay.on { animation: damageFlash 0.5s ease-out; }
@keyframes damageFlash {
  0% { opacity: 0.42; }
  100% { opacity: 0; }
}

/* ---------- 单位 ---------- */
.unit { position: absolute; transform: translate(-50%, -50%); }
.plant { width: 52px; height: 52px; z-index: 3; }
.plant-sprite {
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  animation: plantPop 0.26s ease-out;
}
@keyframes plantPop {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.unit-shadow {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.34), transparent 70%);
  pointer-events: none;
}
.plant .unit-shadow { bottom: -12px; width: 58px; height: 14px; }
.plant.dying { animation: plantDie 0.3s ease-out forwards; }
@keyframes plantDie {
  0% { opacity: 1; transform: translate(-50%, -50%); }
  15% { transform: translate(-58%, -50%); }
  30% { transform: translate(-42%, -50%); }
  45% { transform: translate(-56%, -50%); }
  60% { transform: translate(-44%, -50%); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.35); }
}
.zombie { width: 96px; height: 96px; z-index: 2; }
.zombie-sprite {
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  animation: zombieBob 0.6s ease-in-out infinite;
}
.zombie-sprite.hit { animation: zombieBob 0.6s ease-in-out infinite, zombieHitFlash 0.16s ease-out; }
@keyframes zombieHitFlash {
  0% { filter: brightness(0) invert(1) drop-shadow(0 0 6px #fff); }
  100% { filter: none; }
}
@keyframes zombieBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.zombie .unit-shadow { bottom: -2px; width: 72px; height: 16px; }
.pips {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
}
.pip { width: 6px; height: 3px; border-radius: 1px; background: #ff4f4f; }
.pip.off { display: none; }
.zombie.dying { animation: zombieDie 0.35s ease-out forwards; }
@keyframes zombieDie {
  0% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 14px)); }
}
.bullet { width: 30px; height: 30px; z-index: 4; }
.bullet-sprite {
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

/* ---------- 命中 / 特效 ---------- */
.hit-flash, .plant-puff {
  position: absolute;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 6;
}
.hit-flash {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.5) 35%, transparent 70%);
  animation: flashPop 0.25s ease-out forwards;
}
.plant-puff {
  background: radial-gradient(circle, rgba(120, 255, 110, 0.9) 0%, rgba(90, 220, 80, 0.35) 45%, transparent 70%);
  animation: flashPop 0.28s ease-out forwards;
}
@keyframes flashPop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}
.float-tip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  animation: floatUp 0.9s ease-out forwards;
  z-index: 7;
}
@keyframes floatUp {
  0% { opacity: 1; margin-top: 0; }
  100% { opacity: 0; margin-top: -46px; }
}
