:root {
  --orange: #FF8A3D;
  --orange-deep: #E2651C;
  --ink: #432C18;
  --cream: #FFF8EA;
  --wood: #6E4426;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #6FAE4E;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #6FAE4E;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: calc(var(--safe-t) + 9px);
  left: 11px;
  right: 11px;
  display: flex;
  align-items: center;
  gap: 7px;
  pointer-events: none;
  z-index: 3;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 11px 0 6px;
  border-radius: 999px;
  background: rgba(255, 251, 242, 0.96);
  border: 2px solid #FFFFFF;
  box-shadow: 0 4px 0 rgba(73, 47, 24, 0.22), 0 5px 12px rgba(53, 38, 19, 0.16);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--ink);
  white-space: nowrap;
}

.stat .mp-icon {
  width: 22px;
  height: 22px;
  padding: 4px;
  border-radius: 50%;
}

.stat.gold .mp-icon { color: #B96A12; background: #FFE2B0; }
.stat.life .mp-icon { color: #E95243; background: #FFDCD6; }
.stat.wave { margin-left: auto; padding: 0 12px 0 7px; }
.stat.wave .mp-icon { color: #FFFFFF; background: var(--orange); }
.stat.wave span { font-size: 13px; }

/* ---------- banner / toast ---------- */
.banner {
  position: absolute;
  left: 50%;
  top: 21%;
  z-index: 4;
  transform: translate(-50%, -8px) scale(0.92);
  padding: 9px 22px;
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.96);
  border: 2px solid #FFFFFF;
  box-shadow: 0 6px 0 rgba(91, 55, 23, 0.22), 0 10px 22px rgba(51, 35, 16, 0.2);
  color: var(--orange-deep);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.banner.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast {
  position: absolute;
  left: 50%;
  top: 47%;
  z-index: 5;
  transform: translate(-50%, 6px) scale(0.95);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(58, 38, 19, 0.9);
  box-shadow: 0 8px 20px rgba(38, 24, 10, 0.25);
  color: #FFF6E5;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------- bottom command bar ---------- */
.bottom {
  position: relative;
  flex: 0 0 auto;
  padding: 7px 11px calc(9px + var(--safe-b));
  background: linear-gradient(180deg, #5E442B 0%, #4A3420 100%);
  border-top: 3px solid #3A2817;
  box-shadow: inset 0 2px 0 rgba(255, 220, 170, 0.18);
  z-index: 6;
}

.bar-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 0 0 6px;
  color: rgba(255, 239, 213, 0.78);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-tip .mp-icon {
  width: 15px;
  height: 15px;
  color: #FFC183;
}

.shop-row {
  display: grid;
  grid-template-columns: 1fr 1fr 94px;
  gap: 7px;
  align-items: stretch;
}

.shop-card {
  position: relative;
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-content: center;
  min-width: 0;
  height: 70px;
  padding: 7px 8px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  background: linear-gradient(180deg, #FFF9EC 0%, #FFECD0 100%);
  box-shadow: 0 4px 0 #2E2012, 0 6px 12px rgba(18, 11, 4, 0.28);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.1s ease;
}
.shop-card:active { transform: translateY(2px); box-shadow: 0 2px 0 #2E2012; }
.shop-card.is-active {
  border-color: #FFB15F;
  background: linear-gradient(180deg, #FFF4DB 0%, #FFDDAF 100%);
  box-shadow: 0 4px 0 #B35316, 0 0 0 3px rgba(255, 138, 61, 0.38), 0 6px 14px rgba(18, 11, 4, 0.28);
}
.shop-card.is-poor { filter: saturate(0.55) brightness(0.92); }
.shop-card.is-poor .shop-cost { color: #B23B2D; }

.shop-ic {
  grid-row: 1 / 3;
  align-self: center;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: #FFFFFF;
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}
.shop-ic .mp-icon { width: 21px; height: 21px; }
.shop-ic.arrow { background: linear-gradient(180deg, #7FC25B, #4C9A36); }
.shop-ic.cannon { background: linear-gradient(180deg, #7B8D9E, #4F6172); }

.shop-info {
  align-self: end;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.shop-info b {
  font-size: 15px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.3px;
}
.shop-info small {
  margin-top: 2px;
  font-size: 9.5px;
  font-weight: 600;
  color: #8A6643;
  white-space: nowrap;
}
.shop-cost {
  align-self: start;
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 1px;
  color: #C36516;
  font-size: 11.5px;
  font-weight: 900;
}
.shop-cost .mp-icon { width: 13px; height: 13px; }

.wave-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 70px;
  padding: 0;
  border: 2px solid #FFC28F;
  border-radius: 16px;
  background: linear-gradient(180deg, #FFA75E 0%, #FF7A28 100%);
  box-shadow: 0 4px 0 #963F0E, inset 0 1px 0 rgba(255, 255, 255, 0.55);
  color: #FFFFFF;
  font-family: inherit;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(115, 48, 5, 0.4);
}
.wave-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #963F0E; }
.wave-btn span {
  font-size: 18px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 1px;
}
.wave-btn small {
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.88;
  letter-spacing: 0.4px;
}
.wave-btn:disabled {
  background: linear-gradient(180deg, #9A8568, #7A674D);
  border-color: #A9977D;
  box-shadow: 0 4px 0 #4E3E2A;
  color: #E7DAC6;
  text-shadow: none;
  cursor: default;
}

/* ---------- result ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(35, 24, 12, 0.58);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.result {
  width: min(316px, 100%);
  padding: 24px 20px 20px;
  border-radius: 27px;
  border: 3px solid #FFFFFF;
  background: linear-gradient(180deg, #FFFBF1 0%, #FFE9C9 100%);
  box-shadow: 0 10px 0 rgba(62, 39, 17, 0.3), 0 24px 50px rgba(24, 15, 5, 0.4), inset 0 0 0 3px rgba(255, 193, 131, 0.45);
  text-align: center;
  animation: pop 0.26s cubic-bezier(0.2, 1.35, 0.4, 1);
}
@keyframes pop {
  from { transform: scale(0.86) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.result-badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: -50px auto 10px;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFB267, #FF7A28);
  border: 3px solid #FFFFFF;
  box-shadow: 0 5px 0 #B35316;
  color: #FFFFFF;
}
.result-badge .mp-icon { width: 34px; height: 34px; }
.result-badge.lost {
  background: linear-gradient(180deg, #9A9A9A, #666666);
  box-shadow: 0 5px 0 #3E3E3E;
}
.result h2 {
  margin: 2px 0 6px;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--ink);
}
.result p {
  margin: 0 0 18px;
  color: #85613D;
  font-size: 13px;
  line-height: 1.65;
  font-weight: 600;
}
.result .primary {
  width: 100%;
  height: 50px;
  border: 2px solid #FFC99C;
  border-radius: 15px;
  background: linear-gradient(180deg, #FFA75E, #FF7A28);
  box-shadow: 0 4px 0 #A8490F, inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: #FFFFFF;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(115, 48, 5, 0.4);
}
.result .primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #A8490F; }

@media (max-height: 700px) {
  .bottom { padding-top: 5px; }
  .bar-tip { margin-bottom: 4px; font-size: 10px; }
  .shop-card, .wave-btn { height: 62px; }
  .shop-card { grid-template-columns: 30px 1fr; column-gap: 6px; padding: 5px 7px; }
  .shop-ic { width: 30px; height: 30px; border-radius: 9px; }
  .shop-ic .mp-icon { width: 19px; height: 19px; }
  .shop-info b { font-size: 14px; }
  .hero-hint { display: none; }
}

@media (max-width: 350px) {
  .shop-row { grid-template-columns: 1fr 1fr 84px; gap: 6px; }
  .shop-card { grid-template-columns: 29px 1fr; column-gap: 5px; padding: 6px; }
  .shop-ic { width: 29px; height: 29px; }
  .shop-info b { font-size: 13.5px; }
  .shop-info small { font-size: 9px; }
  .stat { font-size: 13px; padding-right: 9px; }
}
