:root {
  --orange: #FF8A3D;
  --gold: #FFD27A;
  --rose: #FF5F87;
  --ink: #2A1435;
  --card: rgba(46, 22, 62, .62);
  --line: rgba(255, 208, 150, .28);
  --txt: #FFF3E2;
  --muted: rgba(255, 236, 212, .62);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c0718;
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

#stageWrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 30%, #2a1642 0%, #0c0718 70%);
}

#stage {
  position: relative;
  flex: none;
  overflow: hidden;
  background: #0d0820;
  will-change: transform;
  transform-origin: 50% 50%;
  box-shadow: 0 0 90px rgba(0, 0, 0, .65);
}

#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(0, 0, 0, 0) 52%, rgba(9, 4, 20, .34) 100%),
    linear-gradient(180deg, rgba(10, 5, 22, .18), rgba(10, 5, 22, 0) 22%);
}

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

/* ---------- 顶部悬浮 HUD ---------- */
.hud {
  position: absolute;
  z-index: 7;
  top: calc(6px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(10px + env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  gap: 7px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.sunPill {
  flex: none;
  height: clamp(30px, calc(var(--sh) * .086), 40px);
  min-width: clamp(58px, calc(var(--sh) * .17), 78px);
  padding: 0 clamp(8px, 1.1vw, 12px) 0 clamp(5px, .8vw, 8px);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #7A3510;
  font-size: clamp(13px, calc(var(--sh) * .038), 17px);
  font-weight: 900;
  background: linear-gradient(180deg, #FFF7DE 0%, #FFE3AA 58%, #FFD083 100%);
  border: 1px solid rgba(255, 248, 220, .95);
  box-shadow:
    0 2px 0 rgba(155, 78, 26, .45),
    0 6px 16px rgba(24, 8, 38, .38),
    inset 0 1px 0 #fff;
}
.sunPill .mp-icon {
  width: clamp(15px, calc(var(--sh) * .042), 20px);
  height: clamp(15px, calc(var(--sh) * .042), 20px);
  color: #F19A1F;
  filter: drop-shadow(0 1px 0 #fff2c8);
}
.sunPill.pop { animation: sunPop .3s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes sunPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.cards { display: flex; gap: 6px; align-items: flex-start; flex: none; }

.card {
  position: relative;
  height: clamp(42px, calc(var(--sh) * .14), 60px);
  aspect-ratio: .94;
  padding: 0;
  border-radius: 12px;
  border: 1.5px solid rgba(255, 246, 220, .72);
  background: linear-gradient(180deg, #FFF4D9 0%, #F3D3A2 72%, #E8B979 100%);
  box-shadow:
    0 3px 0 rgba(112, 57, 24, .4),
    0 6px 14px rgba(18, 6, 30, .36),
    inset 0 1px 0 rgba(255, 255, 255, .9);
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
  font-family: inherit;
}
.card canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.card .cost {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: clamp(9px, calc(var(--sh) * .026), 11px);
  font-weight: 900;
  color: #5E2A10;
  background: linear-gradient(180deg, rgba(255, 248, 226, .1), rgba(255, 230, 185, .93));
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
}
.card .cost .mp-icon {
  width: 11px; height: 11px;
  color: #E8891C;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.7));
}
.card .cool {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0;
  background: rgba(20, 10, 30, .66);
  pointer-events: none;
  transition: height .1s linear;
}
.card:active { transform: scale(.94); }
.card.disabled { filter: saturate(.55) brightness(.82); }
.card.selected {
  transform: translateY(-2px);
  border-color: #FFE9A9;
  box-shadow:
    0 0 0 2px rgba(255, 146, 60, .75),
    0 0 20px rgba(255, 178, 78, .85),
    0 3px 0 rgba(112, 57, 24, .4);
}
.card.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 245, 200, .8);
  pointer-events: none;
}
.card.shake { animation: cardShake .32s ease; }
@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px) rotate(-2deg); }
  60% { transform: translateX(3px) rotate(2deg); }
}

.hudRight {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  flex: none;
}
.hearts {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 2px;
}
.hearts .mp-icon {
  width: clamp(13px, calc(var(--sh) * .037), 18px);
  height: clamp(13px, calc(var(--sh) * .037), 18px);
  color: #FF5577;
  filter: drop-shadow(0 0 6px rgba(255, 70, 110, .7)) drop-shadow(0 1px 0 rgba(80, 10, 30, .6));
  transition: color .2s, filter .2s, transform .2s;
}
.hearts .mp-icon.lost {
  color: rgba(255, 235, 240, .2);
  filter: none;
  transform: scale(.86);
}

.wavePill {
  height: clamp(26px, calc(var(--sh) * .074), 34px);
  min-width: clamp(58px, calc(var(--sh) * .18), 82px);
  padding: 0 8px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(9px, calc(var(--sh) * .027), 12px);
  font-weight: 800;
  letter-spacing: .2px;
  color: #FFE7BE;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px rgba(12, 4, 24, .35), inset 0 1px 0 rgba(255, 255, 255, .09);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
}

.iconBtn {
  position: relative;
  width: clamp(28px, calc(var(--sh) * .078), 34px);
  height: clamp(28px, calc(var(--sh) * .078), 34px);
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFE8C4;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 3px 10px rgba(12, 4, 24, .35), inset 0 1px 0 rgba(255, 255, 255, .08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  font-family: inherit;
}
.iconBtn .mp-icon { width: 55%; height: 55%; }
.iconBtn:active { transform: scale(.9); }
.iconBtn .ic-off { display: none; }
.iconBtn.muted .ic-on { display: none; }
.iconBtn.muted .ic-off { display: inline-block; color: rgba(255, 214, 190, .7); }

/* ---------- 提示与波次横幅 ---------- */
.toast {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  max-width: 92%;
  padding: 7px 15px;
  border-radius: 999px;
  font-size: clamp(10px, calc(var(--sh) * .03), 13px);
  font-weight: 600;
  letter-spacing: .2px;
  color: #FFEBC9;
  background: rgba(37, 16, 49, .74);
  border: 1px solid rgba(255, 206, 145, .28);
  box-shadow: 0 8px 24px rgba(8, 2, 18, .4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.waveBanner {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 39%;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  filter: drop-shadow(0 3px 0 rgba(104, 32, 26, .9)) drop-shadow(0 0 22px rgba(255, 140, 60, .65));
}
.waveBanner.show { animation: bannerIn 1.8s cubic-bezier(.2, .8, .2, 1) forwards; }
.waveBanner .b-main {
  font-family: "STKaiti", "KaiTi", "Songti SC", "SimSun", serif;
  font-size: clamp(26px, calc(var(--sh) * .09), 54px);
  font-weight: 700;
  color: #FFF6DA;
  letter-spacing: 2px;
  line-height: 1.05;
}
.waveBanner .b-sub {
  margin-top: 4px;
  font-size: clamp(9px, calc(var(--sh) * .026), 13px);
  font-weight: 700;
  letter-spacing: 3px;
  color: #FFD59A;
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.72); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
  24% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(1.02); }
}

/* ---------- 弹层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background:
    radial-gradient(ellipse at 50% 36%, rgba(108, 50, 90, .34), rgba(10, 5, 22, .82) 70%),
    rgba(10, 5, 22, .42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .24s ease, visibility .24s;
}
.overlay.show { opacity: 1; visibility: visible; }

.panel {
  position: relative;
  width: min(540px, 88%);
  max-height: 88%;
  overflow: auto;
  padding: clamp(16px, calc(var(--sh) * .04), 28px) clamp(18px, 3.2vw, 36px) clamp(14px, calc(var(--sh) * .03), 22px);
  border-radius: 24px;
  text-align: center;
  color: var(--txt);
  background:
    linear-gradient(180deg, rgba(58, 28, 76, .94), rgba(26, 11, 39, .97));
  border: 1px solid rgba(255, 198, 128, .34);
  box-shadow:
    0 26px 70px rgba(0, 0, 0, .58),
    inset 0 1px 0 rgba(255, 255, 255, .12),
    inset 0 0 60px rgba(255, 138, 61, .06);
  transform: translateY(10px) scale(.97);
  transition: transform .28s cubic-bezier(.2, 1.2, .4, 1);
  animation: panelIn .3s cubic-bezier(.2, 1.2, .4, 1) both;
}
.overlay.show .panel { transform: translateY(0) scale(1); }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.panel::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -120px;
  width: 340px;
  height: 260px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(255, 157, 80, .24), rgba(255, 157, 80, 0) 70%);
  pointer-events: none;
}
.panel.lose::before {
  background: radial-gradient(ellipse, rgba(255, 78, 105, .2), rgba(255, 78, 105, 0) 70%);
}
.panel > * { position: relative; }

.panel .kicker {
  font-size: clamp(8px, calc(var(--sh) * .022), 11px);
  font-weight: 800;
  letter-spacing: 4px;
  color: rgba(255, 178, 108, .92);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.panel h2 {
  margin: 0 0 6px;
  font-family: "STKaiti", "KaiTi", "Songti SC", "SimSun", serif;
  font-size: clamp(27px, calc(var(--sh) * .078), 46px);
  line-height: 1.08;
  letter-spacing: 2px;
  color: #FFF3D2;
  text-shadow: 0 3px 0 rgba(120, 42, 40, .55), 0 0 28px rgba(255, 160, 80, .35);
}
.panel h2.grad {
  background: linear-gradient(180deg, #FFF6C9 6%, #FFC46B 55%, #FF7C5A 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 3px 0 rgba(120, 42, 40, .45));
}
.panel p {
  margin: 0 auto;
  max-width: 380px;
  font-size: clamp(11px, calc(var(--sh) * .03), 14px);
  line-height: 1.6;
  color: rgba(255, 236, 214, .72);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 13px 0 14px;
}
.stat {
  padding: 7px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(255, 205, 145, .16);
}
.stat b {
  display: block;
  font-size: clamp(16px, calc(var(--sh) * .042), 26px);
  line-height: 1.15;
  color: #FFD98C;
  font-weight: 900;
}
.stat span {
  display: block;
  margin-top: 1px;
  font-size: clamp(8px, calc(var(--sh) * .021), 10px);
  letter-spacing: 1px;
  color: rgba(255, 236, 214, .55);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
.btn {
  height: clamp(38px, calc(var(--sh) * .112), 50px);
  padding: 0 clamp(18px, 3vw, 28px);
  border: 0;
  border-radius: 14px;
  font-family: inherit;
  font-size: clamp(12px, calc(var(--sh) * .033), 15px);
  font-weight: 900;
  letter-spacing: .5px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn.primary {
  color: #4C1B05;
  background: linear-gradient(180deg, #FFD07B 0%, #FF9A4A 58%, #FF7B3B 100%);
  box-shadow: 0 5px 0 #B34A1E, 0 10px 24px rgba(255, 123, 59, .35), inset 0 1px 0 #FFF1CB;
}
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #B34A1E, 0 5px 12px rgba(255, 123, 59, .3); }
.btn.ghost {
  color: #FFE7C6;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 205, 145, .28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07);
}
.btn.ghost:active { transform: scale(.96); }

.panel .tiny {
  margin-top: 10px;
  font-size: clamp(8px, calc(var(--sh) * .021), 10px);
  letter-spacing: 1px;
  color: rgba(255, 236, 214, .4);
}
.panel .bestLine {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: clamp(9px, calc(var(--sh) * .024), 12px);
  color: #FFD18A;
}
.panel .bestLine .mp-icon { width: 13px; height: 13px; color: #FFBE56; }

@media (max-width: 720px) {
  .card { border-radius: 10px; }
  .card .cost { height: 14px; }
  .hudRight { gap: 4px; }
}
@media (max-height: 360px) {
  .panel { padding-top: 12px; padding-bottom: 12px; border-radius: 18px; }
  .stats { margin: 8px 0 10px; }
  .panel p { line-height: 1.45; }
}
