/* ===== 花园保卫战 - 样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #87CEEB 0%, #B8E0F5 40%, #8FBC8F 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  overflow: hidden; /* 缩放适配屏幕，不出滚动条 */
}

#game {
  position: relative;
  transform-origin: center center; /* JS 自适应缩放的原点 */
  flex-shrink: 0;
}

/* ===== 顶部栏 ===== */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #a0693a, #7d4f27);
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}

#sun-counter {
  background: #fff8dc;
  border: 3px solid #f0c040;
  border-radius: 12px;
  font-size: 22px;
  font-weight: bold;
  padding: 6px 14px;
  min-width: 110px;
  text-align: center;
  color: #8a6d1a;
  transition: transform .15s;
}
#sun-counter.bounce { transform: scale(1.15); }

#cards {
  display: flex;
  gap: 8px;
  flex: 1;
}

.card {
  background: #fdf3d8;
  border: 3px solid #c9a227;
  border-radius: 12px;
  width: 86px;
  padding: 4px 2px 6px;
  text-align: center;
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, opacity .2s;
  position: relative;
}
.card:hover { transform: translateY(-3px); }
.card .emoji { font-size: 30px; line-height: 1.1; }
.card .name { font-size: 12px; color: #6b4f1d; font-weight: bold; }
.card .cost { font-size: 13px; color: #b8860b; font-weight: bold; }
.card.selected {
  border-color: #ff6b35;
  box-shadow: 0 0 12px #ff9f43;
  transform: translateY(-3px) scale(1.05);
}
.card.disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(.7);
}
.card.shake { animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.ctrl-btn {
  font-size: 22px;
  background: #fdf3d8;
  border: 3px solid #c9a227;
  border-radius: 10px;
  width: 46px;
  height: 46px;
  cursor: pointer;
  transition: transform .1s;
}
.ctrl-btn:hover { transform: scale(1.1); }
.ctrl-btn.active {
  border-color: #ff6b35;
  box-shadow: 0 0 10px #ff9f43;
}

/* ===== 波次进度条 ===== */
#wave-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 2px;
}
#wave-label {
  font-size: 16px;
  font-weight: bold;
  color: #4a6b2a;
  background: rgba(255,255,255,.75);
  padding: 3px 12px;
  border-radius: 10px;
  white-space: nowrap;
}
#wave-progress {
  flex: 1;
  height: 14px;
  background: rgba(255,255,255,.5);
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(74,107,42,.4);
}
#wave-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8bc34a, #ff9800, #f44336);
  border-radius: 8px;
  transition: width .4s;
}

/* ===== 游戏棋盘 ===== */
#board {
  position: relative;
  width: 880px;
  height: 500px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 5px 16px rgba(0,0,0,.35);
  border: 4px solid #6b4f1d;
}

#house {
  position: absolute;
  left: 0; top: 0;
  width: 64px;
  height: 100%;
  background: linear-gradient(90deg, #d7a86e, #c68f4e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  border-right: 4px dashed rgba(107,79,29,.5);
  z-index: 1;
}

#grid {
  position: absolute;
  left: 64px; top: 0;
  display: grid;
  grid-template-columns: repeat(9, 90px);
  grid-template-rows: repeat(5, 100px);
}

.cell {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 交替的草地颜色（像草坪条纹） */
.cell.even { background: #9ccc65; }
.cell.odd  { background: #8bc34a; }
.cell:hover { filter: brightness(1.12); }
.cell.highlight {
  box-shadow: inset 0 0 0 4px rgba(255,235,59,.9);
  filter: brightness(1.15);
}

.plant {
  font-size: 52px;
  pointer-events: none;
  transition: transform .1s;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,.25));
}
.plant.hurt { filter: grayscale(.5) brightness(.8); }
.plant.producing { animation: glow 1s; }
@keyframes glow {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.25); filter: drop-shadow(0 0 12px gold); }
}

/* ===== 动态实体 ===== */
.enemy {
  position: absolute;
  font-size: 50px;
  z-index: 5;
  transform: translate(-50%, -50%);
  transition: filter .2s;
  pointer-events: none;
}
.enemy .hp-bar {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 6px;
  background: rgba(0,0,0,.3);
  border-radius: 3px;
  overflow: hidden;
}
.enemy .hp-fill {
  height: 100%;
  background: #4caf50;
  border-radius: 3px;
  transition: width .15s;
}
.enemy.slowed { filter: hue-rotate(160deg) brightness(1.2); }
.enemy.hit-flash { filter: brightness(2) saturate(.3); }

.projectile {
  position: absolute;
  font-size: 26px;
  z-index: 4;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sun-token {
  position: absolute;
  font-size: 42px;
  z-index: 20;
  transform: translate(-50%, -50%);
  cursor: pointer;
  animation: sunPulse 1.6s infinite;
  filter: drop-shadow(0 0 8px gold);
}
@keyframes sunPulse {
  0%,100% { transform: translate(-50%,-50%) scale(1); }
  50% { transform: translate(-50%,-50%) scale(1.15); }
}
.sun-token.fly {
  transition: left .5s ease-in, top .5s ease-in, opacity .5s, font-size .5s;
  animation: none;
  pointer-events: none;
}

.mower {
  position: absolute;
  font-size: 40px;
  z-index: 3;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.explosion {
  position: absolute;
  font-size: 110px;
  z-index: 15;
  transform: translate(-50%, -50%);
  animation: explode .6s forwards;
  pointer-events: none;
}
@keyframes explode {
  0% { transform: translate(-50%,-50%) scale(.3); opacity: 1; }
  70% { transform: translate(-50%,-50%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1.5); opacity: 0; }
}

/* ===== 提示横幅 ===== */
#banner {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 42px;
  font-weight: bold;
  color: #fff;
  background: rgba(230, 81, 0, .92);
  padding: 14px 40px;
  border-radius: 20px;
  z-index: 30;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  animation: bannerIn .4s;
  pointer-events: none;
  white-space: nowrap;
}
#banner.good { background: rgba(56, 142, 60, .92); }
@keyframes bannerIn {
  0% { transform: translate(-50%,-50%) scale(.5); opacity: 0; }
  100% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}
.hidden { display: none !important; }

/* ===== 大消息遮罩 ===== */
#overlay {
  position: absolute;
  inset: 0;
  top: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: 14px;
}
#overlay-content {
  background: linear-gradient(180deg, #fffde7, #fff9c4);
  border: 5px solid #f0c040;
  border-radius: 24px;
  padding: 32px 48px;
  text-align: center;
  max-width: 640px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: popIn .35s;
}
@keyframes popIn {
  0% { transform: scale(.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
#overlay-content h1 { font-size: 40px; color: #558b2f; margin-bottom: 10px; }
#overlay-content h2 { font-size: 30px; color: #558b2f; margin-bottom: 12px; }
#overlay-content p { font-size: 17px; color: #6d4c41; margin: 8px 0; line-height: 1.6; }
#overlay-content .big-emoji { font-size: 64px; margin: 8px 0; }
#overlay-content .roles {
  background: rgba(139,195,74,.18);
  border-radius: 12px;
  padding: 10px 16px;
  margin: 12px 0;
  font-size: 16px;
}
.menu-btn {
  font-size: 22px;
  font-weight: bold;
  font-family: inherit;
  background: linear-gradient(180deg, #8bc34a, #689f38);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 12px 34px;
  margin: 8px 6px 0;
  cursor: pointer;
  box-shadow: 0 4px 0 #4a7023;
  transition: transform .1s, box-shadow .1s;
}
.menu-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #4a7023; }
.menu-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #4a7023; }
.menu-btn.secondary { background: linear-gradient(180deg, #64b5f6, #1e88e5); box-shadow: 0 4px 0 #12579e; }
.menu-btn.secondary:hover { box-shadow: 0 6px 0 #12579e; }

/* 胜利彩带 */
.confetti {
  position: absolute;
  top: -30px;
  font-size: 28px;
  z-index: 60;
  animation: fall linear forwards;
  pointer-events: none;
}
@keyframes fall {
  to { transform: translateY(620px) rotate(720deg); }
}
