* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #8CCB77;
  color: #4A3524;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

#game { position: fixed; inset: 0; overflow: hidden; }

#stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ── 顶部状态 ───────────────────────────── */
.hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}

.hp-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 156px;
  padding: 7px 10px 8px;
  border-radius: 15px;
  background: rgba(255, 248, 230, 0.94);
  border: 2px solid #EBD3A8;
  box-shadow: 0 3px 0 rgba(105, 74, 38, 0.16);
}

.hp-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #FFE4C2;
  color: #C25B14;
}
.hp-icon .mp-icon { width: 20px; height: 20px; }

.hp-main { flex: 1; min-width: 0; }

.hp-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #8A6A45;
  line-height: 1.2;
}
.hp-line b { font-size: 14px; color: #4A3524; font-weight: 900; }

.hp-bar {
  height: 8px;
  margin-top: 4px;
  border-radius: 99px;
  background: #E7D6B8;
  overflow: hidden;
}
.hp-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(180deg, #7FD06E, #46A84B);
  transition: width 0.18s ease, background 0.18s ease;
}
.hp-bar i.low { background: linear-gradient(180deg, #FF9A6B, #E4482E); }

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 27px;
  padding: 0 10px;
  border-radius: 99px;
  background: rgba(255, 248, 230, 0.94);
  border: 2px solid #EBD3A8;
  box-shadow: 0 2px 0 rgba(105, 74, 38, 0.14);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.chip .mp-icon { width: 15px; height: 15px; }
.chip.gold { color: #A96210; }
.chip.gold b { font-size: 14px; color: #4A3524; font-weight: 900; }
.chip.wave { color: #5E7A46; }
.chip.wave .mp-icon { color: #FF8A3D; }

/* ── 提示 ──────────────────────────────── */
.toast {
  position: absolute;
  top: calc(78px + env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -6px);
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(58, 42, 25, 0.9);
  color: #FFF6E2;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 9;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 底部操作台 ────────────────────────── */
.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #FFF9EC 0%, #FAEDD3 100%);
  border-top: 2px solid #F3DFBC;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 22px rgba(71, 48, 25, 0.18);
}

.build-row {
  display: flex;
  align-items: stretch;
  gap: 7px;
  max-width: 480px;
  margin: 0 auto;
}

.tcard {
  flex: 1 1 0;
  min-width: 0;
  height: 66px;
  padding: 7px 4px 6px;
  border: 2px solid #EAD7B4;
  border-radius: 15px;
  background: #FFFDF7;
  box-shadow: 0 3px 0 #E2CBA3;
  color: #4A3524;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}
.tcard:active { transform: translateY(2px); box-shadow: 0 1px 0 #E2CBA3; }
.tcard.active {
  border-color: #FF8A3D;
  background: #FFF1DC;
  box-shadow: 0 3px 0 #F3B476;
}

.tc-ico {
  width: 27px;
  height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: #FFFDF7;
}
.tc-ico .mp-icon { width: 18px; height: 18px; }
.tc-ico.arrow { background: #58B368; }
.tc-ico.cannon { background: #F08A3C; }
.tc-ico.ice { background: #5FB7E8; }

.tc-name { font-size: 12px; font-weight: 800; line-height: 1.1; }

.tc-cost {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 800;
  color: #A96210;
  line-height: 1.1;
}
.tc-cost i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #FFC94A;
  border: 1.5px solid #E1A21C;
}
.tcard.poor { opacity: 0.55; }

.skill-btn {
  position: relative;
  flex: 0 0 62px;
  width: 62px;
  height: 66px;
  padding: 0;
  border: 2px solid #FFB27A;
  border-radius: 15px;
  background: linear-gradient(180deg, #FF9E54 0%, #F06F1C 100%);
  box-shadow: 0 3px 0 #C45512;
  color: #FFFDF7;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  overflow: hidden;
}
.skill-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #C45512; }
.skill-btn .mp-icon { width: 23px; height: 23px; position: relative; z-index: 1; }
.skill-btn b { font-size: 10px; font-weight: 900; position: relative; z-index: 1; line-height: 1.15; }
.skill-btn em { font-style: normal; font-size: 9px; opacity: 0.82; position: relative; z-index: 1; line-height: 1.15; }
.skill-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: conic-gradient(transparent var(--deg, 360deg), rgba(46, 28, 12, 0.55) 0);
  pointer-events: none;
  z-index: 0;
}
.skill-btn.ready { animation: skillGlow 1.8s ease-in-out infinite; }
@keyframes skillGlow {
  0%, 100% { box-shadow: 0 3px 0 #C45512, 0 0 0 0 rgba(255, 160, 70, 0.0); }
  50% { box-shadow: 0 3px 0 #C45512, 0 0 0 5px rgba(255, 160, 70, 0.22); }
}

.wave-row {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 480px;
  margin: 9px auto 0;
}

.wave-info {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  color: #8A6A45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.start-btn {
  flex: 0 0 auto;
  min-width: 116px;
  height: 38px;
  padding: 0 16px;
  border: 2px solid #FFB27A;
  border-radius: 99px;
  background: linear-gradient(180deg, #FF9E54 0%, #F2781F 100%);
  box-shadow: 0 3px 0 #C45512;
  color: #FFFDF7;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: 0.02em;
}
.start-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #C45512; }
.start-btn:disabled {
  background: #D8C5A4;
  border-color: #D8C5A4;
  box-shadow: 0 3px 0 #BBA57F;
  color: #FFF8E8;
}

/* ── 塔详情卡 ──────────────────────────── */
.tower-pop {
  position: absolute;
  left: 50%;
  bottom: 152px;
  transform: translateX(-50%);
  z-index: 7;
  width: min(330px, calc(100% - 28px));
  padding: 11px 12px 12px;
  border: 2px solid #EBD3A8;
  border-radius: 17px;
  background: #FFF9EC;
  box-shadow: 0 8px 24px rgba(61, 42, 20, 0.24);
}

.tp-head { display: flex; align-items: center; gap: 7px; }

.tp-dot { width: 10px; height: 10px; border-radius: 50%; background: #58B368; }
.tp-head b { font-size: 15px; font-weight: 900; }
.tp-lv {
  font-size: 10.5px;
  font-weight: 900;
  color: #A96210;
  background: #FFE8C4;
  border-radius: 6px;
  padding: 2px 6px;
}
.tp-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: #F1E3C7;
  color: #7A5A38;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tp-close .mp-icon { width: 17px; height: 17px; }

.tp-stats {
  margin: 7px 0 9px;
  font-size: 12px;
  font-weight: 600;
  color: #8A6A45;
}

.tp-up {
  width: 100%;
  height: 40px;
  border: 2px solid #FFB27A;
  border-radius: 11px;
  background: linear-gradient(180deg, #FF9E54, #F2781F);
  box-shadow: 0 3px 0 #C45512;
  color: #FFFDF7;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 900;
}
.tp-up:active { transform: translateY(2px); box-shadow: 0 1px 0 #C45512; }
.tp-up:disabled {
  background: #E0CFAE;
  border-color: #E0CFAE;
  box-shadow: 0 2px 0 #C4AE86;
  color: #FFF8E8;
}

/* ── 结束弹层 ──────────────────────────── */
.over {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(34, 40, 25, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.over-card {
  width: min(310px, 100%);
  padding: 24px 22px 22px;
  border: 3px solid #F0D6A8;
  border-radius: 24px;
  background: linear-gradient(180deg, #FFFCF2, #FBEDD1);
  box-shadow: 0 14px 40px rgba(30, 22, 12, 0.35);
  text-align: center;
}
.over-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 19px;
  background: #FFE4C2;
  color: #D9611A;
}
.over-icon .mp-icon { width: 32px; height: 32px; }
.over-kicker {
  margin: 12px 0 2px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #B08A5C;
}
.over-card h2 {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #4A3524;
}
.over-line { margin: 0; font-size: 14px; font-weight: 600; color: #7A5A38; }
.over-line b { font-size: 22px; color: #E56A1B; font-weight: 900; }
.over-best { margin: 6px 0 18px; font-size: 12px; font-weight: 600; color: #9C7A52; }
.over-best b { color: #4A3524; }

.again-btn {
  width: 100%;
  height: 46px;
  border: 2px solid #FFB27A;
  border-radius: 13px;
  background: linear-gradient(180deg, #FF9E54, #F2781F);
  box-shadow: 0 4px 0 #C45512;
  color: #FFFDF7;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.again-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #C45512; }
.again-btn .mp-icon { width: 20px; height: 20px; }

@media (max-height: 700px) {
  .tcard, .skill-btn { height: 60px; }
  .tc-ico { width: 24px; height: 24px; }
  .start-btn { height: 34px; font-size: 12.5px; }
  .tower-pop { bottom: 140px; }
}
