:root {
  --primary: #FF8A3D;
  --primary-deep: #E46112;
  --primary-soft: #FFE1C6;
  --grass: #72C95C;
  --grass-deep: #2F7A39;
  --ink: #3B2B1B;
  --ink-soft: #806A52;
  --cream: #FFF8EC;
  --cream-deep: #F2E4CE;
  --coin: #FFC531;
  --life: #FF5B6E;
  --archer: #3E8ED0;
  --mage: #8659D6;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #265B2D;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(circle at 50% 18%, #3B7B42 0%, #1D4823 70%);
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: 3px solid #FFD08A;
  outline-offset: 2px;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ---------- 应用外壳 ---------- */
.app {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #4FA94A;
  touch-action: manipulation;
}

@media (min-width: 541px) {
  .app {
    box-shadow: 0 0 70px rgba(0, 0, 0, .5);
  }
}

/* ---------- 顶部状态 ---------- */
.hud {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 9px;
  padding: calc(7px + env(safe-area-inset-top)) 9px 7px;
  background: linear-gradient(180deg, #2F7A39 0%, #3D9145 100%);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .13), 0 6px 16px rgba(0, 0, 0, .12);
}

.pill {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--cream);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .16);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.pill .ic {
  width: 17px;
  height: 17px;
}

.pill b {
  font-size: 14px;
  line-height: 1;
}

.coin .ic {
  color: #DE9B00;
}

.coin b {
  color: #9A5D00;
}

.wave {
  padding: 0 8px;
  color: #385B31;
}

.wave .ic {
  color: #4F9A4D;
}

.wave b {
  margin: 0 2px;
  color: var(--ink);
}

.life {
  color: #A13442;
}

.life .ic {
  color: var(--life);
}

.life.low {
  background: #FFE1E4;
  animation: lifePulse .8s ease-in-out infinite;
}

.life.low .ic {
  color: #E11D35;
}

@keyframes lifePulse {
  0%, 100% { box-shadow: 0 3px 0 rgba(0, 0, 0, .16); }
  50% { box-shadow: 0 3px 0 rgba(0, 0, 0, .16), 0 0 0 4px rgba(255, 91, 110, .18); }
}

.hud-btns {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #A44E10;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .18), 0 4px 10px rgba(0, 0, 0, .12);
  transition: transform .08s ease, box-shadow .08s ease;
}

.icon-btn::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -4px;
  bottom: -4px;
  left: -4px;
  border-radius: 50%;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .18);
}

.icon-btn .ic {
  width: 19px;
  height: 19px;
}

/* ---------- 战场 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #68BF56;
}

#cv {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

/* 波次横幅 */
.wave-banner {
  position: absolute;
  left: 50%;
  top: 25%;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.86);
  transition: opacity .2s ease, transform .2s ease;
}

.wave-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.banner-inner {
  min-width: 136px;
  padding: 9px 22px 10px;
  border: 2px solid rgba(255, 226, 168, .58);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(77, 44, 14, .88), rgba(45, 25, 7, .94));
  box-shadow: 0 10px 28px rgba(0, 0, 0, .38);
  text-align: center;
}

.banner-inner span {
  display: block;
  color: #FFF4D4;
  font-size: 27px;
  font-weight: 900;
  letter-spacing: 3px;
  line-height: 1.15;
  text-shadow: 0 2px 0 #B4570F;
}

.banner-inner small {
  display: block;
  margin-top: 2px;
  color: #FFD79B;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
}

/* 轻提示 */
.toast {
  position: absolute;
  left: 50%;
  top: 12px;
  z-index: 9;
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(47, 31, 18, .92);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
  color: #FFF8E9;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 底部建造栏 ---------- */
.dock {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  padding: 7px 10px 9px;
  padding: 7px 10px calc(9px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #3D9145 0%, #296A31 100%);
  box-shadow: 0 -4px 0 rgba(0, 0, 0, .12), 0 -10px 26px rgba(0, 0, 0, .16);
}

.dock-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 3px 6px;
}

.dock-label {
  color: #D9F4CB;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.dock-hint {
  max-width: 68%;
  color: #BFE7B2;
  font-size: 10px;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tower-row {
  display: flex;
  gap: 8px;
}

.tower-card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 7px 7px 8px;
  border: 2px solid transparent;
  border-radius: 15px;
  background: var(--cream);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .18), 0 7px 14px rgba(0, 0, 0, .14);
  text-align: left;
  transition: transform .08s ease, border-color .12s ease, background .12s ease, box-shadow .12s ease;
}

.tower-card:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .18);
}

.tower-card.selected {
  border-color: var(--primary);
  background: #FFF0DF;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .18), 0 0 0 3px rgba(255, 138, 61, .3);
}

.tower-card.disabled {
  opacity: .52;
  filter: grayscale(.4);
}

.tower-ico {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16), 0 2px 5px rgba(0, 0, 0, .16);
}

.tower-ico .ic {
  width: 21px;
  height: 21px;
}

.archer-ico {
  background: linear-gradient(160deg, #69BEF0, #2E7FC4);
}

.mage-ico {
  background: linear-gradient(160deg, #B68AF0, #7546C9);
}

.tower-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.tower-name {
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
}

.tower-tag {
  color: #9A8268;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
}

.tower-cost {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 6px 3px 4px;
  border-radius: 999px;
  background: #FFF1C9;
  color: #C27A00;
  font-size: 12px;
  font-weight: 900;
}

.tower-cost .ic {
  width: 13px;
  height: 13px;
}

.tower-cost.lack {
  background: #FFE2E2;
  color: #B44747;
}

/* ---------- 开始 / 暂停 / 结算 ---------- */
.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #2F7A39 0%, #173E1D 100%);
}

.overlay.show {
  display: flex;
}

.overlay-art {
  position: absolute;
  top: -10%;
  left: 0;
  width: 100%;
  height: 110%;
  object-fit: cover;
  object-position: 40% 50%;
  pointer-events: none;
  -webkit-user-drag: none;
}

.overlay-scrim {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(180deg,
    rgba(8, 24, 10, .06) 0%,
    rgba(8, 24, 10, .16) 34%,
    rgba(8, 24, 10, .74) 70%,
    rgba(8, 24, 10, .95) 100%);
}

.overlay.no-art {
  background: linear-gradient(165deg, #3F8E46 0%, #23612B 62%, #163E1C 100%);
}

.overlay-body {
  position: relative;
  z-index: 2;
  width: 100%;
  margin-top: auto;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 14px;
  padding: 0 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.overlay-body::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.brand {
  flex: 0 0 auto;
  margin-bottom: 14px;
  text-align: center;
  color: #FFF6E3;
}

.brand-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  border-radius: 17px;
  background: linear-gradient(160deg, #FFB15C, #F06A1C);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 6px 0 rgba(150, 58, 8, .5), 0 10px 24px rgba(0, 0, 0, .32);
  transform: rotate(-4deg);
}

.brand-mark .ic {
  width: 29px;
  height: 29px;
}

.brand h1 {
  margin: 0;
  color: #FFF4D8;
  font-size: 37px;
  font-weight: 900;
  letter-spacing: 5px;
  line-height: 1.1;
  text-shadow: 0 3px 0 #B45309, 0 6px 0 rgba(120, 40, 0, .3), 0 12px 28px rgba(0, 0, 0, .55);
}

.brand p {
  margin: 7px 0 0;
  color: #FFE1B8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .62);
}

.sheet {
  flex: 0 0 auto;
  padding: 15px 14px 14px;
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 24px;
  background: rgba(255, 249, 238, .97);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .44);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.view h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  text-align: center;
}

.lead {
  margin: 0 0 12px;
  color: #755F47;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.65;
  text-align: center;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  margin: 0 0 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #F2E5D1;
  color: #6B533A;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.archer { background: var(--archer); }
.dot.mage { background: var(--mage); }
.dot.heart { background: var(--life); }

.btn {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 15px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  transition: transform .08s ease, box-shadow .08s ease;
}

.btn .ic {
  width: 20px;
  height: 20px;
}

.btn.primary {
  background: linear-gradient(180deg, #FFA45C 0%, #F0741F 100%);
  color: #fff;
  text-shadow: 0 1px 0 rgba(120, 40, 0, .35);
  box-shadow: 0 5px 0 #B94B09, 0 9px 18px rgba(180, 70, 10, .35);
}

.btn.primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #B94B09;
}

.btn.ghost {
  background: #F4E7D3;
  color: #7A5330;
  box-shadow: 0 4px 0 rgba(122, 83, 48, .24);
}

.btn.ghost:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(122, 83, 48, .24);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  flex: 1 1 0;
  min-height: 46px;
  font-size: 15px;
}

.over-emblem {
  width: 50px;
  height: 50px;
  margin: 0 auto 7px;
  border-radius: 50%;
  background: #FFE0E3;
  color: #E14B5A;
  display: flex;
  align-items: center;
  justify-content: center;
}

.over-emblem .ic {
  width: 26px;
  height: 26px;
}

.overlay.mode-pause .brand,
.overlay.mode-over .brand {
  display: none;
}

.overlay.mode-pause .overlay-body,
.overlay.mode-over .overlay-body {
  padding-bottom: 12vh;
  padding-bottom: calc(12vh + env(safe-area-inset-bottom));
}

/* ---------- 小屏适配 ---------- */
@media (max-height: 700px) {
  .brand {
    margin-bottom: 10px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    margin-bottom: 6px;
    border-radius: 14px;
  }

  .brand-mark .ic {
    width: 24px;
    height: 24px;
  }

  .brand h1 {
    font-size: 30px;
    letter-spacing: 4px;
  }

  .brand p {
    margin-top: 5px;
    font-size: 10px;
  }

  .sheet {
    padding: 12px 12px 11px;
    border-radius: 21px;
  }

  .lead {
    margin-bottom: 9px;
    font-size: 12px;
    line-height: 1.55;
  }

  .chips {
    margin-bottom: 9px;
  }

  .btn {
    min-height: 44px;
    font-size: 16px;
  }

  .overlay.mode-pause .overlay-body,
  .overlay.mode-over .overlay-body {
    padding-bottom: 8vh;
    padding-bottom: calc(8vh + env(safe-area-inset-bottom));
  }

  .tower-card {
    padding: 6px;
  }

  .tower-ico {
    flex-basis: 31px;
    width: 31px;
    height: 31px;
  }
}

@media (max-width: 350px) {
  .pill {
    padding: 0 7px;
    font-size: 12px;
  }

  .pill b {
    font-size: 13px;
  }

  .wave {
    padding: 0 6px;
  }

  .hud-btns {
    gap: 8px;
  }

  .icon-btn {
    width: 33px;
    height: 33px;
  }

  .tower-tag {
    display: none;
  }

  .brand h1 {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wave-banner,
  .toast,
  .btn,
  .icon-btn,
  .tower-card {
    transition: none;
  }

  .life.low {
    animation: none;
  }
}
