* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #2A1B12;
  color: #FFF6EC;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

.stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 0%, #4A2E1C 0%, #2A1B12 60%, #1B110B 100%);
}

#game {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  pointer-events: none;
  z-index: 5;
}
.hud-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px 0 9px;
  border-radius: 17px;
  background: rgba(38, 24, 16, 0.72);
  border: 1px solid rgba(255, 178, 110, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  font-size: 15px; font-weight: 700; letter-spacing: 0.02em;
  color: #FFE9D2;
}
.hud-pill .mp-icon { font-size: 18px; color: #FFB066; }
.hud-pill.gold .mp-icon { color: #FFD24A; }
.hud-pill.life .mp-icon { color: #FF6B6B; }
.hud-spacer { flex: 1; }
.hud-btn {
  pointer-events: auto;
  width: 38px; height: 38px; border-radius: 19px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(38, 24, 16, 0.72);
  border: 1px solid rgba(255, 178, 110, 0.35);
  color: #FFE9D2; font-size: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  transition: transform .12s ease, background .12s ease;
}
.hud-btn:active { transform: scale(0.92); background: rgba(255, 138, 61, 0.5); }
.hud-btn.on { background: rgba(255, 138, 61, 0.85); color: #2A1B12; border-color: #FFC08A; }

/* ---------- 建造面板 ---------- */
.dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: linear-gradient(180deg, rgba(30, 18, 11, 0) 0%, rgba(30, 18, 11, 0.82) 26%, rgba(24, 14, 9, 0.96) 100%);
  z-index: 6;
}
.dock-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.14em;
  color: #FFB066; text-transform: uppercase;
  margin: 0 0 8px 2px;
}
.dock-list {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.dock-list::-webkit-scrollbar { display: none; }
.tower-card {
  flex: 0 0 auto;
  width: 84px; padding: 8px 6px 7px;
  border-radius: 14px;
  background: linear-gradient(180deg, #4A3020 0%, #33200F 100%);
  border: 1.5px solid rgba(255, 178, 110, 0.28);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: #FFE9D2;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.tower-card:active { transform: scale(0.95); }
.tower-card.sel {
  border-color: #FF8A3D;
  box-shadow: 0 0 0 2px rgba(255, 138, 61, 0.45), 0 8px 18px rgba(255, 138, 61, 0.3);
  background: linear-gradient(180deg, #6B3E1E 0%, #40260F 100%);
}
.tower-card.poor { opacity: 0.45; }
.tower-card .tc-icon {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: rgba(255, 255, 255, 0.08);
}
.tower-card .tc-name { font-size: 12px; font-weight: 700; }
.tower-card .tc-cost {
  font-size: 11px; font-weight: 700; color: #FFD24A;
  display: inline-flex; align-items: center; gap: 2px;
}
.dock-tip {
  margin-top: 8px; font-size: 12px; color: #C9A98C; text-align: center;
  min-height: 16px;
}

/* ---------- 遮罩 ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px;
  background: radial-gradient(90% 70% at 50% 40%, rgba(60, 34, 18, 0.86) 0%, rgba(18, 10, 6, 0.94) 100%);
  backdrop-filter: blur(3px);
  transition: opacity .22s ease;
}
.overlay.hide { opacity: 0; pointer-events: none; }
.panel {
  width: 100%; max-width: 340px;
  padding: 22px 20px 20px;
  border-radius: 22px;
  text-align: center;
  background: linear-gradient(180deg, #FFF7EC 0%, #FFE8CE 100%);
  border: 2px solid #FFC08A;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 2px 0 #FFFFFF;
  color: #3A2415;
}
.panel-badge {
  width: 62px; height: 62px; margin: -46px auto 10px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #FFF3E2;
  background: linear-gradient(160deg, #FFA45C 0%, #FF7A2E 100%);
  border: 3px solid #FFF7EC;
  box-shadow: 0 8px 18px rgba(255, 122, 46, 0.45);
}
.panel-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: 0.01em; color: #3A2415; }
.panel-desc { margin: 8px 0 0; font-size: 13.5px; line-height: 1.6; color: #8A6A50; }
.panel-stats {
  margin: 14px 0 0; display: flex; gap: 8px; justify-content: center;
}
.panel-stats .st {
  flex: 1; padding: 8px 4px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #F0D6B8;
}
.panel-stats .st b { display: block; font-size: 17px; color: #FF7A2E; }
.panel-stats .st span { font-size: 11px; color: #9A7A5E; }
.btn-primary {
  margin-top: 16px; width: 100%; height: 50px;
  border: 0; border-radius: 25px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 16px; font-weight: 800; color: #FFF7EC;
  background: linear-gradient(180deg, #FFA45C 0%, #FF7A2E 100%);
  box-shadow: 0 8px 18px rgba(255, 122, 46, 0.42), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-primary:active { transform: translateY(2px) scale(0.98); box-shadow: 0 4px 10px rgba(255, 122, 46, 0.35); }
.btn-primary .mp-icon { font-size: 20px; }
.panel-foot { margin-top: 12px; font-size: 11.5px; color: #A98A6E; }
