@font-face {
  font-family: "SG Sans";
  src: url("assets/NotoSansSC.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --orange: #ff8a3d;
  --orange-deep: #ef651c;
  --gold: #ffcf7a;
  --gold-bright: #ffe4ac;
  --ink: #20150d;
  --paper: #fff3dc;
  --panel: rgba(29, 19, 12, 0.9);
  --line: rgba(255, 196, 120, 0.24);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: #120d0a;
  color: var(--paper);
  font-family: "SG Sans", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background:
    radial-gradient(80% 60% at 50% 30%, #2d2117 0%, #170f0a 60%, #0b0806 100%);
}

#stage {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background: #14201c;
  box-shadow: 0 0 0 1px rgba(255, 190, 120, 0.08), 0 24px 70px rgba(0, 0, 0, 0.7);
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 560px) {
  #stage { border-radius: 26px; height: min(940px, 96dvh); align-self: center; }
}

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

.sky-shade {
  position: absolute;
  inset: 0 0 auto;
  height: 130px;
  background: linear-gradient(180deg, rgba(8, 11, 17, 0.62) 0%, rgba(8, 11, 17, 0.18) 55%, transparent 100%);
  pointer-events: none;
  z-index: 1;
}

.vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 48%, transparent 50%, rgba(6, 8, 10, 0.34) 100%),
    linear-gradient(180deg, transparent 72%, rgba(9, 7, 5, 0.42) 100%);
  pointer-events: none;
  z-index: 2;
}

/* ---------- top HUD ---------- */
#hud {
  position: absolute;
  z-index: 6;
  top: calc(8px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.hud-stats { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(36, 25, 17, 0.82), rgba(20, 14, 10, 0.8));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 225, 180, 0.12), 0 4px 12px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.stat-val { font-variant-numeric: tabular-nums; color: #ffe8c2; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

.stat .mp-icon { width: 16px; height: 16px; }
.stat-wave .mp-icon { color: var(--gold); }
.stat-life .mp-icon { color: #ff6d55; filter: drop-shadow(0 0 5px rgba(255, 90, 60, 0.5)); }
.stat-life.is-low .stat-val { color: #ff8c75; }

.coin {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff3b8 0%, #ffcf5e 38%, #e69319 78%, #ad650d 100%);
  box-shadow: inset 0 0 0 1.5px rgba(120, 69, 8, 0.45), 0 0 7px rgba(255, 186, 70, 0.45);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.coin i {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: #9b5c0c;
  box-shadow: inset 0 0 0 1px rgba(70, 38, 4, 0.7);
}

.icon-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(36, 25, 17, 0.82), rgba(20, 14, 10, 0.8));
  color: #ffe2b2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 225, 180, 0.12), 0 4px 12px rgba(0, 0, 0, 0.28);
  transition: transform 0.12s ease, background 0.2s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn .mp-icon { width: 19px; height: 19px; }
.icon-btn .snd-off { display: none; }
.icon-btn.muted .snd-on { display: none; }
.icon-btn.muted .snd-off { display: inline-block; }

/* ---------- wave banner ---------- */
.wave-banner {
  position: absolute;
  z-index: 9;
  left: 0;
  right: 0;
  top: 27%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) scale(0.94);
}
.wave-banner.show { animation: bannerIn 1.9s cubic-bezier(0.2, 0.9, 0.2, 1) both; }
.wb-kicker {
  font-size: 11px;
  letter-spacing: 0.28em;
  color: #ffd28a;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}
.wb-main {
  font-family: "SG Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 30px;
  font-weight: 900;
  color: #fff4d6;
  letter-spacing: 0.14em;
  text-shadow:
    0 0 18px rgba(255, 138, 61, 0.62),
    0 2px 0 #9c3f11,
    0 5px 14px rgba(0, 0, 0, 0.85);
}
.wave-banner::before,
.wave-banner::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 70px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 196, 120, 0.75));
}
.wave-banner::before { left: 10%; }
.wave-banner::after { right: 10%; transform: scaleX(-1); }

@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(12px) scale(0.92); }
  14% { opacity: 1; transform: translateY(0) scale(1); }
  76% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-12px) scale(1.02); }
}

/* ---------- bottom dock ---------- */
#dock {
  position: absolute;
  z-index: 7;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background:
    linear-gradient(180deg, rgba(36, 25, 17, 0.84) 0%, rgba(22, 15, 10, 0.96) 42%, rgba(14, 10, 7, 0.99) 100%);
  border-top: 1px solid rgba(255, 190, 110, 0.32);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -14px 38px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 226, 180, 0.14);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
#dock::before {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 220, 160, 0.8), transparent);
}
.dock-glow {
  position: absolute;
  inset: -20px 0 auto;
  height: 40px;
  background: radial-gradient(60% 100% at 50% 100%, rgba(255, 138, 61, 0.18), transparent 75%);
  pointer-events: none;
}

.dock-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
}
.dock-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 224, 184, 0.82);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hint-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange);
  animation: dotPulse 1.8s ease-in-out infinite;
}
@keyframes dotPulse { 0%, 100% { opacity: 0.45; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.15); } }

.wave-btn {
  flex: 0 0 auto;
  min-width: 104px;
  height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffa758 0%, #ff8a3d 38%, #ed6319 100%);
  color: #3a1a05;
  box-shadow: 0 5px 0 #a9420c, 0 8px 18px rgba(255, 110, 35, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s;
  position: relative;
  overflow: hidden;
}
.wave-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 32%, rgba(255, 255, 255, 0.34) 46%, transparent 60%);
  transform: translateX(-120%);
  animation: btnSheen 3.4s ease-in-out infinite;
}
@keyframes btnSheen { 0%, 62% { transform: translateX(-120%); } 84%, 100% { transform: translateX(120%); } }
.wave-btn .wb-label { font-size: 14px; font-weight: 900; line-height: 1.05; letter-spacing: 0.06em; }
.wave-btn .wb-sub { font-size: 9px; font-weight: 700; opacity: 0.8; letter-spacing: 0.03em; line-height: 1.15; }
.wave-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a9420c, 0 4px 10px rgba(255, 110, 35, 0.25); }
.wave-btn.busy {
  background: linear-gradient(180deg, #58493c, #3a2f26);
  color: #d8c3a5;
  box-shadow: 0 4px 0 #241c16, inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: default;
}
.wave-btn.busy::after { display: none; }

.wave-track {
  height: 3px;
  margin: 7px 2px 8px;
  border-radius: 2px;
  background: rgba(255, 220, 170, 0.12);
  overflow: hidden;
}
.wave-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #ffb35e, #ff7b2e);
  box-shadow: 0 0 8px rgba(255, 138, 61, 0.65);
  transition: width 0.25s ease;
}

.hero-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hero-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 68px;
  padding: 7px 7px 7px 8px;
  border: 1px solid rgba(255, 196, 126, 0.18);
  border-radius: 15px;
  background:
    radial-gradient(120% 100% at 20% 0%, rgba(255, 182, 110, 0.14), transparent 55%),
    linear-gradient(160deg, rgba(76, 52, 32, 0.92), rgba(36, 25, 17, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 231, 190, 0.12), 0 4px 12px rgba(0, 0, 0, 0.25);
  color: var(--paper);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s, box-shadow 0.2s, filter 0.2s;
}
.hero-card:active { transform: scale(0.965); }
.hero-card.selected {
  border-color: rgba(255, 196, 105, 0.95);
  background:
    radial-gradient(120% 120% at 30% 0%, rgba(255, 186, 110, 0.32), transparent 62%),
    linear-gradient(160deg, #76502f 0%, #3d2918 100%);
  box-shadow: 0 0 0 1px rgba(255, 190, 100, 0.36), 0 0 18px rgba(255, 138, 61, 0.4), inset 0 1px 0 rgba(255, 240, 200, 0.25);
  transform: translateY(-3px);
}
.hero-card.locked { filter: saturate(0.55) brightness(0.72); }
.hero-card.locked .hero-cost { color: #ff9b82; }

.hero-portrait {
  width: 45px;
  height: 45px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  border: 1.5px solid rgba(255, 208, 140, 0.55);
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 214, 150, 0.38), transparent 62%),
    linear-gradient(180deg, #7a5330, #2f2014);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45), 0 0 10px rgba(255, 160, 70, 0.16);
}
.hero-portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1.04);
}
.hero-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 -8px 10px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}
.hero-meta { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.hero-name { font-size: 14px; font-weight: 900; letter-spacing: 0.02em; line-height: 1.1; white-space: nowrap; }
.hero-role { font-size: 10px; color: rgba(255, 220, 176, 0.6); white-space: nowrap; letter-spacing: 0.03em; }
.hero-cost {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffd388;
  line-height: 1.2;
}
.hero-cost .coin { width: 11px; height: 11px; box-shadow: inset 0 0 0 1px rgba(120, 69, 8, 0.4); }
.hero-cost .coin i { width: 4px; height: 4px; border-radius: 1px; }
.hero-lock {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ff7059;
  box-shadow: 0 0 6px rgba(255, 100, 80, 0.7);
  display: none;
}
.hero-card.locked .hero-lock { display: block; }

/* ---------- tower panel ---------- */
.tower-panel {
  position: absolute;
  z-index: 8;
  left: 12px;
  right: 12px;
  bottom: calc(var(--dock-h, 152px) + 8px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px 9px 9px;
  border-radius: 16px;
  border: 1px solid rgba(255, 196, 120, 0.38);
  background:
    radial-gradient(100% 120% at 20% 0%, rgba(255, 176, 98, 0.2), transparent 58%),
    linear-gradient(180deg, rgba(48, 33, 21, 0.98), rgba(22, 15, 10, 0.98));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 240, 200, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform-origin: 50% 100%;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.tower-panel.hidden { opacity: 0; transform: translateY(8px) scale(0.97); pointer-events: none; }
.tp-portrait {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 206, 140, 0.45);
  background: radial-gradient(circle at 50% 34%, #7d5734, #2b1d13);
  background-size: cover;
  background-position: center;
}
.tp-info { min-width: 0; flex: 1; }
.tp-name-row { display: flex; align-items: baseline; gap: 6px; }
.tp-name-row b { font-size: 15px; font-weight: 900; letter-spacing: 0.04em; }
.tp-lv { font-size: 9px; font-weight: 800; color: #3a1a05; background: linear-gradient(180deg, #ffd98d, #e9a63e); border-radius: 999px; padding: 1px 6px; }
.tp-stats { font-size: 10px; color: rgba(255, 222, 180, 0.62); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-actions { display: flex; flex-direction: column; gap: 5px; flex: 0 0 auto; }
.tp-btn {
  min-width: 86px;
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 190, 110, 0.28);
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s;
}
.tp-btn:active { transform: scale(0.95); }
.tp-up { background: linear-gradient(180deg, #ffb25e, #f27a24); color: #3a1a05; border: 0; box-shadow: 0 2px 0 #a9470c; }
.tp-up.max { background: #4c3a2a; color: #b7a288; box-shadow: none; cursor: default; }
.tp-sell { background: rgba(255, 255, 255, 0.06); color: #ffc6a0; }
.tp-close {
  position: absolute;
  top: -8px;
  right: -5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 196, 120, 0.4);
  background: #2c1e14;
  color: #ffd7a3;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tp-close .mp-icon { width: 13px; height: 13px; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: calc(var(--dock-h, 152px) + 22px + var(--safe-bottom));
  transform: translate(-50%, 10px);
  max-width: 84%;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(24, 16, 11, 0.94);
  border: 1px solid rgba(255, 194, 116, 0.38);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  font-weight: 700;
  color: #ffe0b1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.panel-open { bottom: calc(var(--dock-h, 152px) + 96px + var(--safe-bottom)); }
.toast.warn { color: #ffb9a4; border-color: rgba(255, 120, 90, 0.45); }

/* ---------- result ---------- */
.result {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: radial-gradient(80% 60% at 50% 42%, rgba(50, 28, 14, 0.68), rgba(6, 5, 4, 0.9));
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  transition: opacity 0.25s ease;
}
.result.hidden { opacity: 0; pointer-events: none; }
.result-card {
  position: relative;
  width: 100%;
  max-width: 330px;
  padding: 26px 22px 22px;
  border-radius: 24px;
  border: 1px solid rgba(255, 198, 120, 0.45);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 168, 86, 0.2), transparent 55%),
    linear-gradient(180deg, #3d2919 0%, #24170e 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), 0 26px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 232, 190, 0.2);
  text-align: center;
  animation: cardIn 0.45s cubic-bezier(0.2, 1.2, 0.35, 1) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(0.94); } to { opacity: 1; transform: translateY(0) scale(1); } }
.result-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 18px;
  border: 1px solid rgba(255, 208, 140, 0.14);
  pointer-events: none;
}
.result-emblem {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 40% 32%, #ffe6a8, #eaa13a 55%, #8f4d0e 100%);
  box-shadow: 0 0 0 5px rgba(255, 190, 100, 0.12), 0 0 28px rgba(255, 150, 60, 0.45);
  color: #4a2606;
}
.result-emblem .mp-icon { width: 36px; height: 36px; }
.result.lost .result-emblem { background: radial-gradient(circle at 40% 32%, #cdb9a5, #7a5c44 55%, #3c2a1d 100%); color: #21160d; box-shadow: 0 0 0 5px rgba(200, 160, 120, 0.08); }
.result-kicker { font-size: 10px; letter-spacing: 0.28em; color: rgba(255, 210, 150, 0.62); }
.result-card h2 {
  margin: 6px 0 6px;
  font-family: "SG Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 32px;
  letter-spacing: 0.12em;
  color: #fff0cf;
  text-shadow: 0 0 20px rgba(255, 150, 70, 0.4), 0 2px 0 #8f3d0c;
}
.result-card p { margin: 0; font-size: 12px; line-height: 1.6; color: rgba(255, 226, 190, 0.66); }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 18px 0 18px;
  padding: 12px 0;
  border-top: 1px solid rgba(255, 200, 130, 0.16);
  border-bottom: 1px solid rgba(255, 200, 130, 0.16);
}
.result-stats div { display: flex; flex-direction: column; gap: 2px; }
.result-stats b { font-size: 21px; color: #ffd58e; font-variant-numeric: tabular-nums; }
.result-stats span { font-size: 10px; color: rgba(255, 222, 180, 0.55); letter-spacing: 0.12em; }
.restart-btn {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffb25e, #ff8a3d 45%, #ea6118);
  color: #3a1a05;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.12em;
  box-shadow: 0 5px 0 #a9420c, 0 10px 24px rgba(255, 110, 35, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.restart-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a9420c; }

.hidden { display: none !important; }
.tower-panel.hidden { display: flex !important; }

@media (max-width: 360px) {
  .hero-card { gap: 5px; padding: 6px; }
  .hero-portrait { width: 40px; height: 40px; }
  .hero-name { font-size: 13px; }
  .hero-role { font-size: 9px; }
  .hero-cost { font-size: 10px; }
  .stat { padding: 0 9px; font-size: 12px; height: 32px; }
  .wave-btn { min-width: 90px; padding: 0 10px; }
  .tp-btn { min-width: 70px; }
  .wb-main { font-size: 27px; }
}
