/* 保卫萝卜差不多 —— 横屏塔防 H5
   舞台固定 1600 x 760 逻辑像素，由 app.js 等比缩放到视口。 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1d3a18;
  color: #4a2a0e;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 90% at 50% 8%, rgba(255, 214, 130, .16), transparent 62%),
    radial-gradient(90% 90% at 50% 108%, rgba(12, 34, 10, .85), transparent 65%),
    linear-gradient(160deg, #2e5626 0%, #1c3a17 55%, #142b12 100%);
}

#viewport {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  overflow: hidden;
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1600px;
  height: 760px;
  transform-origin: 0 0;
  will-change: transform;
}

#game {
  display: block;
  width: 1600px;
  height: 760px;
  border-radius: 2px;
}

#ui {
  position: absolute;
  left: 0;
  top: 0;
  width: 1600px;
  height: 760px;
  pointer-events: none;
}

#ui button {
  font-family: inherit;
  border: 0;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.ui-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(23, 46, 14, .32) 0%, rgba(23, 46, 14, 0) 17%, rgba(23, 46, 14, 0) 62%, rgba(23, 46, 14, .30) 100%);
}

/* ------------------------------ HUD ------------------------------ */
.hud {
  position: absolute;
  left: 26px;
  right: 26px;
  top: 16px;
  height: 74px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.hud-left {
  display: flex;
  gap: 14px;
}

.pill {
  height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px 0 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fffdf4 0%, #fff2cf 58%, #ffe2a9 100%);
  border: 4px solid rgba(255, 255, 255, .92);
  box-shadow:
    0 5px 0 rgba(139, 82, 24, .32),
    0 10px 22px rgba(26, 52, 16, .26),
    inset 0 -3px 0 rgba(206, 145, 63, .22);
  color: #5a3210;
  font-weight: 900;
  letter-spacing: .01em;
}

.pill-ico {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18), inset 0 2px 0 rgba(255, 255, 255, .45);
}

.pill-ico .mp-icon {
  width: 28px;
  height: 28px;
  color: #fff;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .22));
}

.coin-ico { background: linear-gradient(160deg, #ffd45e, #f5a11a 70%, #d97b08); }
.life-ico { background: linear-gradient(160deg, #ff8b8b, #ef3f52 70%, #c41f37); }
.wave-ico { background: linear-gradient(160deg, #ffb25c, #ff7a1f 70%, #d9550a); }

.pill-val {
  font-size: 34px;
  line-height: 1;
  min-width: 54px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.coin-pill .pill-val { color: #8a4a05; }
.life-pill .pill-val { color: #b32230; }

.pill.bump { animation: bump .26s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.wave-pill {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  padding-right: 20px;
  gap: 10px;
}

.wave-txt {
  font-size: 29px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.wave-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: 2px;
}

.wave-dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(178, 132, 64, .34);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .16);
}

.wave-dots i.done {
  background: linear-gradient(180deg, #ffc247, #f07c12);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .7), 0 2px 4px rgba(150, 80, 5, .35);
}

.wave-dots i.now {
  background: #fff8e0;
  box-shadow: 0 0 0 2px #ff9a2e;
  animation: dotPulse 1s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.45); }
}

.hud-right { display: flex; gap: 12px; }

.round-btn {
  width: 66px;
  height: 62px;
  border-radius: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fffdf4 0%, #fff2cf 60%, #ffe0a4 100%);
  border: 4px solid rgba(255, 255, 255, .92) !important;
  box-shadow: 0 5px 0 rgba(139, 82, 24, .32), 0 10px 20px rgba(26, 52, 16, .24);
  color: #8a4a05;
  transition: transform .07s ease, box-shadow .07s ease;
}

.round-btn .mp-icon { width: 34px; height: 34px; }
.round-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(139, 82, 24, .32), 0 4px 10px rgba(26, 52, 16, .2);
}

/* ------------------------------ 提示 / 波次横幅 ------------------------------ */
.toast {
  position: absolute;
  left: 50%;
  top: 96px;
  transform: translateX(-50%) translateY(-12px);
  max-width: 780px;
  padding: 13px 26px;
  border-radius: 999px;
  background: rgba(35, 70, 24, .9);
  border: 2px solid rgba(255, 245, 208, .5);
  color: #fff9e4;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: .02em;
  box-shadow: 0 8px 22px rgba(20, 42, 12, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  white-space: nowrap;
}

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

.wave-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-size: 82px;
  font-weight: 900;
  letter-spacing: .06em;
  color: #fff6d6;
  text-shadow:
    0 4px 0 #b9540e,
    0 8px 0 #8b3a05,
    0 12px 26px rgba(50, 22, 4, .55),
    0 0 30px rgba(255, 192, 84, .65);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.wave-banner.show { animation: banner 1.45s cubic-bezier(.2, .9, .25, 1) forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.55); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  30% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.04) translateY(-18px); }
}

/* ------------------------------ 底部建造栏 ------------------------------ */
.dock {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  height: 108px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px 12px 14px;
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(255, 253, 242, .98) 0%, rgba(255, 241, 213, .98) 55%, rgba(255, 225, 172, .98) 100%);
  border: 4px solid rgba(255, 255, 255, .9);
  box-shadow:
    0 7px 0 rgba(120, 68, 18, .3),
    0 16px 34px rgba(23, 45, 13, .35),
    inset 0 -4px 0 rgba(206, 145, 63, .22);
  pointer-events: auto;
}

.dock::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 22px;
  border: 2px dashed rgba(196, 139, 62, .3);
  pointer-events: none;
}

.tower-cards {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tower-card {
  position: relative;
  width: 194px;
  height: 80px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px 6px 6px;
  border-radius: 20px;
  background: linear-gradient(180deg, #fffefa 0%, #fff6df 100%);
  border: 3px solid #f0d3a0 !important;
  box-shadow: 0 3px 0 rgba(153, 96, 36, .22), inset 0 2px 0 #fff;
  transition: transform .1s ease, box-shadow .1s ease, border-color .1s ease, filter .1s ease;
  overflow: hidden;
}

.tower-card .thumb-wrap {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 15px;
  background: radial-gradient(circle at 50% 38%, #fff8de, #ffe8b8 62%, #f7d69a);
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: inset 0 -3px 6px rgba(160, 100, 30, .16);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tower-card canvas {
  width: 62px;
  height: 62px;
  display: block;
}

.tower-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.tname {
  font-size: 27px;
  font-weight: 900;
  color: #57330f;
  line-height: 1.05;
  white-space: nowrap;
}

.tcost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 22px;
  font-weight: 900;
  color: #a05c0d;
  font-variant-numeric: tabular-nums;
}

.tcost .mp-icon {
  width: 18px;
  height: 18px;
  color: #f0a11a;
}

.tower-card.selected {
  border-color: #ff8a2e !important;
  background: linear-gradient(180deg, #fffdf0 0%, #ffe9bd 100%);
  box-shadow:
    0 0 0 4px rgba(255, 151, 55, .3),
    0 0 22px rgba(255, 148, 40, .55),
    0 3px 0 rgba(153, 96, 36, .2);
  transform: translateY(-4px);
}

.tower-card.poor { filter: saturate(.55); opacity: .72; }
.tower-card.poor .tcost { color: #c0392b; }

.tower-card:active { transform: translateY(1px) scale(.98); }

.dock-right {
  width: 300px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

.wave-hint {
  height: 24px;
  font-size: 21px;
  font-weight: 800;
  color: #8b5a22;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 24px;
  letter-spacing: .01em;
}

.start-btn {
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffbd5e 0%, #ff8a2e 45%, #f26a12 100%);
  border: 3px solid rgba(255, 255, 255, .85) !important;
  box-shadow:
    0 5px 0 #b5470f,
    0 9px 18px rgba(126, 55, 4, .35),
    inset 0 2px 0 rgba(255, 255, 255, .5);
  color: #fff;
  font-size: 31px;
  font-weight: 900;
  letter-spacing: .04em;
  text-shadow: 0 2px 0 rgba(150, 60, 0, .45);
  transition: transform .07s ease, box-shadow .07s ease, filter .15s ease;
}

.start-btn .mp-icon {
  width: 28px;
  height: 28px;
  color: #fff;
  filter: drop-shadow(0 1px 0 rgba(120, 50, 0, .4));
}

.start-btn:not(.disabled):active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #b5470f, 0 4px 9px rgba(126, 55, 4, .3);
}

.start-btn.disabled {
  filter: grayscale(.25) saturate(.75);
  opacity: .78;
  cursor: default;
  box-shadow: 0 5px 0 #9b6a3e, 0 8px 14px rgba(80, 50, 20, .2);
}

.start-btn.ready { animation: readyGlow 1.7s ease-in-out infinite; }
@keyframes readyGlow {
  0%, 100% { box-shadow: 0 5px 0 #b5470f, 0 9px 18px rgba(126, 55, 4, .35), 0 0 0 0 rgba(255, 178, 70, .55); }
  55% { box-shadow: 0 5px 0 #b5470f, 0 9px 18px rgba(126, 55, 4, .35), 0 0 0 9px rgba(255, 178, 70, 0); }
}

/* ------------------------------ 炮塔信息面板 ------------------------------ */
.tower-panel {
  position: absolute;
  left: 50%;
  bottom: 132px;
  transform: translateX(-50%);
  width: 630px;
  min-height: 118px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 54px 12px 14px;
  border-radius: 26px;
  background: linear-gradient(180deg, #fffdf3 0%, #fff2d3 100%);
  border: 4px solid rgba(255, 255, 255, .92);
  box-shadow: 0 7px 0 rgba(120, 68, 18, .28), 0 16px 32px rgba(23, 45, 13, .34);
  pointer-events: auto;
  animation: panelIn .18s ease-out;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(.97); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.tp-thumb {
  width: 86px;
  height: 86px;
  flex: none;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 40%, #fffbe9, #ffe8b5 60%, #f7d494);
  border: 3px solid #f3d8a8;
  box-shadow: inset 0 -4px 8px rgba(160, 100, 30, .16);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tp-thumb canvas { width: 82px; height: 82px; display: block; }

.tp-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tp-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 31px;
  font-weight: 900;
  color: #57330f;
  line-height: 1.1;
  white-space: nowrap;
}

.tp-title em {
  font-style: normal;
  font-size: 21px;
  color: #fff;
  background: linear-gradient(180deg, #ffb14e, #f07a16);
  border-radius: 999px;
  padding: 2px 10px;
  box-shadow: 0 2px 0 rgba(160, 80, 10, .3);
}

.tp-stats {
  font-size: 21px;
  color: #8d5f28;
  font-weight: 700;
  white-space: nowrap;
}

.tp-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 150px;
}

.tp-btn {
  height: 46px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  padding: 0 8px;
  white-space: nowrap;
  transition: transform .07s ease, filter .1s ease;
}

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

.tp-btn.up {
  background: linear-gradient(180deg, #ffb754, #f07812);
  border: 2px solid rgba(255, 255, 255, .8) !important;
  box-shadow: 0 3px 0 #ad4a0c;
}

.tp-btn.sell {
  background: linear-gradient(180deg, #9fd8f2, #4aa9d8);
  border: 2px solid rgba(255, 255, 255, .8) !important;
  box-shadow: 0 3px 0 #2a7da6;
}

.tp-btn:active { transform: translateY(2px); filter: brightness(.96); }
.tp-btn.disabled { filter: grayscale(.6); opacity: .62; }

.tp-close {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f3dcc0;
  color: #8a5a26;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tp-close .mp-icon { width: 20px; height: 20px; }

/* ------------------------------ 遮罩 / 弹窗 ------------------------------ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 38, 12, .58);
  pointer-events: auto;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 640px;
  padding: 30px 36px 28px;
  border-radius: 34px;
  background:
    radial-gradient(120% 100% at 50% 0%, #fffef7 0%, #fff6de 55%, #ffe9ba 100%);
  border: 7px solid rgba(255, 255, 255, .95);
  box-shadow:
    0 10px 0 rgba(117, 68, 18, .28),
    0 34px 70px rgba(12, 28, 6, .55),
    inset 0 -6px 0 rgba(217, 158, 77, .2);
  text-align: center;
  animation: pop .3s cubic-bezier(.2, .9, .3, 1.15);
}

@keyframes pop {
  0% { transform: scale(.82); opacity: 0; }
  70% { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1); }
}

.overlay.paused .modal-card { width: 580px; }

.m-kicker {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #ffb04b, #ef7a16);
  box-shadow: 0 3px 0 rgba(165, 82, 10, .3);
  letter-spacing: .08em;
}

.m-title {
  margin: 12px 0 4px;
  font-size: 54px;
  line-height: 1.12;
  font-weight: 900;
  color: #57330f;
  letter-spacing: .02em;
  text-shadow: 0 3px 0 #fff, 0 5px 0 rgba(196, 137, 58, .18);
}

.m-sub {
  font-size: 24px;
  color: #8b5a22;
  font-weight: 700;
  line-height: 1.5;
  margin: 4px 0 0;
}

.m-stars {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 18px 0 6px;
  height: 66px;
}

.m-stars i {
  width: 62px;
  height: 62px;
  color: #e6cfa9;
  filter: drop-shadow(0 3px 0 rgba(150, 100, 40, .22));
}

.m-stars i.on {
  color: #ffbd3d;
  filter: drop-shadow(0 3px 0 rgba(184, 107, 8, .4)) drop-shadow(0 0 14px rgba(255, 196, 70, .65));
  animation: starPop .5s cubic-bezier(.2, .9, .3, 1.4) both;
}

.m-stars i.on:nth-child(2) { animation-delay: .12s; }
.m-stars i.on:nth-child(3) { animation-delay: .24s; }

@keyframes starPop {
  0% { transform: scale(.2) rotate(-30deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.m-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 16px 0 20px;
}

.m-stat {
  flex: 1;
  max-width: 170px;
  padding: 10px 6px 9px;
  border-radius: 18px;
  background: rgba(255, 255, 255, .72);
  border: 2px solid #f0d7ad;
  box-shadow: inset 0 -3px 0 rgba(203, 148, 72, .12);
}

.m-stat b {
  display: block;
  font-size: 19px;
  color: #a3763e;
  font-weight: 800;
  margin-bottom: 2px;
}

.m-stat span {
  display: block;
  font-size: 32px;
  font-weight: 900;
  color: #5d3610;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.m-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 4px;
}

.btn {
  min-width: 220px;
  height: 72px;
  padding: 0 26px;
  border-radius: 22px;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: .04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .07s ease, box-shadow .07s ease, filter .1s ease;
}

.btn .mp-icon { width: 26px; height: 26px; }

.btn.primary {
  background: linear-gradient(180deg, #ffbd5e 0%, #ff8a2e 48%, #f26a12 100%);
  color: #fff;
  border: 3px solid rgba(255, 255, 255, .9) !important;
  box-shadow: 0 6px 0 #b5470f, 0 11px 20px rgba(126, 55, 4, .32);
  text-shadow: 0 2px 0 rgba(150, 60, 0, .4);
}

.btn.ghost {
  background: linear-gradient(180deg, #fffdf5, #ffedcc);
  color: #8a5420;
  border: 3px solid #efd3a4 !important;
  box-shadow: 0 5px 0 rgba(160, 103, 40, .22);
}

.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(120, 70, 20, .3); }

.m-best {
  margin-top: 14px;
  font-size: 20px;
  font-weight: 800;
  color: #a3763e;
  letter-spacing: .05em;
}

.m-sound {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  border: 2px solid #efd7ae !important;
  color: #7a5223;
  font-size: 21px;
  font-weight: 800;
}

.m-sound .mp-icon { width: 22px; height: 22px; color: #b2762c; }

.m-tips {
  margin-top: 14px;
  font-size: 20px;
  color: #9b7443;
  line-height: 1.6;
  font-weight: 600;
}

/* ------------------------------ 竖屏兜底 ------------------------------ */
.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  background: #24451d;
}

@media (max-height: 300px) {
  #viewport { overflow: hidden; }
}
