/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: #1d2b18;
  background-image: radial-gradient(circle at 50% 0%, #35512c 0%, #16210f 75%);
  font-family: "Trebuchet MS", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #fff;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
#game-shell {
  position: relative;
  width: 960px;
  transform-origin: center center;
  padding: 10px 14px 14px;
  background: linear-gradient(#6b4a2a, #4a3018);
  border: 5px solid #2e1d0d;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,.65), inset 0 2px 0 rgba(255,255,255,.12);
}

/* ============ 顶栏 ============ */
#topbar {
  display: flex; align-items: center; gap: 10px;
  height: 84px; margin-bottom: 6px;
}
#sun-panel {
  flex: 0 0 92px; height: 72px; position: relative;
  background: linear-gradient(#f7e7b0, #d9bf7a);
  border: 3px solid #7a5a26; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 2px 6px rgba(255,255,255,.7), 0 3px 6px rgba(0,0,0,.35);
}
.sun-glyph {
  position: absolute; left: 6px; top: 18px; width: 36px; height: 36px;
  background: radial-gradient(circle, #fff9a8 0%, #ffd83d 55%, #f5a623 100%);
  border-radius: 50%; box-shadow: 0 0 12px #ffe45c, 0 0 0 3px rgba(255,190,40,.55);
}
.sun-glyph::before {
  content: ''; position: absolute; inset: -9px;
  background: repeating-conic-gradient(#ffd83d 0deg 12deg, transparent 12deg 30deg);
  border-radius: 50%; z-index: -1;
}
#sun-count {
  position: relative; margin-left: 34px; font-size: 24px; font-weight: 900;
  color: #6b3d0c; text-shadow: 0 1px 0 #fff2c4;
}

#seed-bank {
  flex: 1; display: flex; gap: 5px; align-items: center;
  height: 76px; padding: 6px 8px;
  background: linear-gradient(#9c7a4c, #6d502d);
  border: 3px solid #3d2a12; border-radius: 10px;
  box-shadow: inset 0 2px 5px rgba(255,255,255,.25), 0 3px 6px rgba(0,0,0,.35);
}
.seed-slot {
  position: relative; width: 62px; height: 64px; flex: 1 1 0; max-width: 68px;
  background: linear-gradient(#e8d6a8, #c5a86a);
  border: 2px solid #6b4d24; border-radius: 7px;
  cursor: pointer; overflow: hidden;
  transition: transform .08s, box-shadow .12s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 3px rgba(0,0,0,.3);
}
.seed-slot:hover { transform: translateY(-3px); }
.seed-slot.selected {
  border-color: #ffe45c; box-shadow: 0 0 0 3px #ffd83d, 0 0 14px #ffd83d;
}
.seed-slot.disabled { filter: grayscale(.7) brightness(.75); cursor: not-allowed; }
.seed-art { position: absolute; inset: 1px 1px 12px; }
.seed-art svg { width: 100%; height: 100%; display: block; }
.seed-cost {
  position: absolute; bottom: 0; left: 0; right: 0; height: 15px;
  background: rgba(40,25,10,.65); color: #ffdf7a;
  font-size: 12px; font-weight: 800; line-height: 15px; text-align: center;
}
.seed-cd {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(10,20,30,.62); height: 0%; pointer-events: none;
  border-top: 2px solid rgba(255,255,255,.25);
}

#top-actions { display: flex; flex-direction: column; gap: 5px; }
#top-actions button {
  width: 58px; height: 21px; font-size: 12px; font-weight: 700;
  color: #3b2410; background: linear-gradient(#f0dfae, #c9a96d);
  border: 2px solid #6b4d24; border-radius: 6px; cursor: pointer;
}
#top-actions button:hover { filter: brightness(1.08); }
#top-actions button.active { background: #ffd83d; border-color: #fff2a8; }

/* ============ 进度条 ============ */
#progress-wrap {
  height: 26px; margin: 0 0 6px 92px; display: flex; align-items: center; gap: 8px;
}
#progress-track {
  flex: 1; height: 14px; position: relative;
  background: #2c1f10; border: 2px solid #1a1108; border-radius: 8px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6);
}
#progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, #7cc243, #c8e35a);
  border-radius: 6px; transition: width .3s linear;
}
#progress-head {
  position: absolute; top: -7px; left: 0%; width: 20px; height: 24px;
  margin-left: -8px; transition: left .3s linear;
  background: radial-gradient(circle at 50% 35%, #a8c98a 0 30%, #6f9151 32% 100%);
  border: 2px solid #33421f; border-radius: 50% 50% 42% 42%;
  font-size: 11px; text-align: center; line-height: 22px;
}
#progress-head::after { content: '🧟'; position: absolute; inset: -2px; font-size: 14px; line-height: 22px; }
#wave-label { font-size: 12px; font-weight: 700; color: #e8d9a8; min-width: 48px; text-align: right; }

/* ============ 草坪 ============ */
#playfield {
  position: relative; width: 930px; height: 500px; overflow: hidden;
  border: 4px solid #3a2a12; border-radius: 6px;
  box-shadow: inset 0 0 18px rgba(0,0,0,.45);
}
#house {
  position: absolute; left: 0; top: 0; width: 90px; height: 100%;
  background:
    linear-gradient(90deg, rgba(0,0,0,.28), transparent 70%),
    repeating-linear-gradient(0deg, #8a6a3f 0 46px, #75562f 46px 50px);
  border-right: 3px solid #5c4122; z-index: 1;
}
#house::after {
  content: ''; position: absolute; right: 6px; top: 0; bottom: 0; width: 6px;
  background: repeating-linear-gradient(0deg, #4d3618 0 8px, #6b4b24 8px 16px);
  opacity: .7;
}
#lawn {
  position: absolute; left: 90px; top: 0; width: 720px; height: 500px;
  display: grid; grid-template-columns: repeat(9, 80px); grid-template-rows: repeat(5, 100px);
  background: #79c043;
}
.cell {
  border: 1px solid rgba(40,90,20,.10);
  box-shadow: inset 0 0 12px rgba(20,60,10,.06);
}
.cell.dark { background: #6eb23a; }
.cell.light { background: #7dc745; }
.cell.hover-ok { background: rgba(255,255,180,.45); box-shadow: inset 0 0 0 3px rgba(255,240,140,.8); }
.cell.hover-bad { background: rgba(220,60,40,.35); box-shadow: inset 0 0 0 3px rgba(255,90,60,.7); }

#entity-layer, #fx-layer, #mower-layer { position: absolute; inset: 0; pointer-events: none; }
#entity-layer { z-index: 5; }
#fx-layer { z-index: 8; }
#mower-layer { z-index: 4; }

.plant, .zombie, .bullet, .sun-drop, .mower, .fx {
  position: absolute; pointer-events: none;
}
.plant svg, .zombie svg, .sun-drop svg, .mower svg { width: 100%; height: 100%; display: block; }
.plant { width: 78px; height: 96px; }
.zombie { width: 72px; height: 100px; }
.bullet {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #d6ff9e 0%, #6ecb32 55%, #37841c 100%);
  box-shadow: 0 0 5px rgba(90,200,50,.8);
}
.bullet.snow {
  background: radial-gradient(circle at 35% 32%, #e6fbff 0%, #7cd8f5 55%, #2e91c6 100%);
  box-shadow: 0 0 7px rgba(120,220,255,.9);
}
.sun-drop {
  width: 62px; height: 62px; cursor: pointer; pointer-events: auto;
  filter: drop-shadow(0 0 9px rgba(255,215,60,.95));
  animation: sunspin 9s linear infinite;
}
@keyframes sunspin { 0% { transform: rotate(0deg) scale(1); } 50% { transform: rotate(18deg) scale(1.06); } 100% { transform: rotate(0deg) scale(1); } }
.sun-drop:active { transform: scale(.88); }
.mower { width: 74px; height: 60px; }
.mower.active { animation: mowerrun .12s linear infinite; }
@keyframes mowerrun { 0% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-3px) rotate(-3deg); } 100% { transform: translateY(0) rotate(0); } }

.zombie.walking svg { animation: zwalk .5s ease-in-out infinite alternate; }
@keyframes zwalk { from { transform: rotate(-2deg) translateY(0); } to { transform: rotate(2deg) translateY(-2px); } }
.zombie.slowed { filter: drop-shadow(0 0 6px #6dd8ff) saturate(.7); }
.zombie.hit svg { animation: zhit .15s ease-out; }
@keyframes zhit { 0% { filter: brightness(2.4); } 100% { filter: none; } }
.plant.shoot svg { animation: pshoot .16s ease-out; }
@keyframes pshoot { 0% { transform: translateX(4px) scaleX(.9); } 60% { transform: translateX(-4px) scaleX(1.08); } 100% { transform: none; } }
.plant.hurt svg { animation: phurt .18s ease-out; }
@keyframes phurt { 0% { filter: brightness(1.9); } 100% { filter: none; } }

.hpbar {
  position: absolute; left: 12%; width: 76%; height: 5px; top: -7px;
  background: rgba(0,0,0,.6); border: 1px solid #222; border-radius: 3px;
}
.hpbar > i { display: block; height: 100%; background: #6ee347; border-radius: 2px; }

.fx { font-size: 26px; font-weight: 900; color: #fff; text-shadow: 0 2px 4px #000; }
.explosion {
  border-radius: 50%;
  background: radial-gradient(circle, #fffbd0 0%, #ffd03d 28%, #ff6a1e 62%, rgba(200,40,0,0) 72%);
  animation: boom .55s ease-out forwards;
}
@keyframes boom { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.9); opacity: 0; } }
.damage-num { animation: dnum .8s ease-out forwards; }
@keyframes dnum { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-40px); opacity: 0; } }

#preview-ghost {
  position: absolute; width: 78px; height: 96px; display: none;
  opacity: .55; pointer-events: none; z-index: 9;
}
#preview-ghost svg { width: 100%; height: 100%; }
#preview-ghost.shovel { opacity: .9; font-size: 52px; text-align: center; line-height: 96px; }

#hint-bar {
  margin-top: 8px; text-align: center; font-size: 12px; color: #d8c79a;
  text-shadow: 0 1px 2px #000;
}

/* ============ 遮罩 ============ */
#overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(8,16,6,.76); z-index: 50; border-radius: 8px;
  backdrop-filter: blur(3px);
}
#overlay.show { display: flex; }
#overlay-card {
  width: 430px; padding: 26px 30px 30px; text-align: center;
  background: linear-gradient(#4b7a2a, #2d5519);
  border: 5px solid #1c3510; border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0,0,0,.6), inset 0 2px 0 rgba(255,255,255,.18);
}
#overlay-title {
  font-size: 34px; color: #ffe36b; letter-spacing: 2px;
  text-shadow: 0 3px 0 #7a4a10, 0 5px 10px rgba(0,0,0,.5);
  margin-bottom: 12px;
}
#overlay-desc { font-size: 14px; line-height: 1.8; color: #e7f5d2; margin-bottom: 16px; }
#overlay-tips {
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
  font-size: 12px; color: #dff0c4; margin-bottom: 20px; text-align: left;
}
#overlay-tips div { background: rgba(0,0,0,.18); padding: 6px 9px; border-radius: 6px; }
#start-btn {
  padding: 12px 42px; font-size: 20px; font-weight: 900; cursor: pointer;
  color: #4a2c08; background: linear-gradient(#ffef8a, #f5b62c);
  border: 3px solid #8b5a13; border-radius: 10px;
  box-shadow: 0 5px 0 #7a4a10, 0 8px 16px rgba(0,0,0,.4);
}
#start-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #7a4a10; }
#start-btn:hover { filter: brightness(1.07); }

@media (max-width: 980px) { #game-shell { zoom: .82; } }
@media (max-width: 800px) { #game-shell { zoom: .65; } }
@media (max-width: 600px) { #game-shell { zoom: .5; } }
