:root {
  --bg-deep: #02060a;
  --bg-surface: rgba(7, 18, 26, 0.78);
  --bg-surface-strong: rgba(8, 22, 32, 0.92);
  --bg-card: linear-gradient(165deg, rgba(8, 36, 50, 0.92) 0%, rgba(4, 16, 24, 0.96) 100%);
  --line: rgba(124, 232, 255, 0.22);
  --line-strong: rgba(124, 232, 255, 0.48);
  --line-warn: rgba(255, 184, 77, 0.55);
  --cyan: #7ce8ff;
  --cyan-soft: #b1f1ff;
  --gold: #ffd166;
  --crimson: #ff5b6b;
  --magenta: #d97aff;
  --emerald: #5dffb1;
  --text: #f1faff;
  --text-muted: rgba(241, 250, 255, 0.62);
  --shadow-soft: 0 12px 36px rgba(0, 0, 0, 0.42);
  --shadow-strong: 0 22px 58px rgba(0, 0, 0, 0.55);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-stack: "SF Pro Display", "Inter", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 28%, rgba(34, 92, 110, 0.22), transparent 42%),
    radial-gradient(circle at 78% 12%, rgba(255, 184, 77, 0.07), transparent 22%),
    radial-gradient(circle at 14% 88%, rgba(217, 122, 255, 0.06), transparent 26%),
    var(--bg-deep);
  color: var(--text);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "tnum" 1;
  overflow: hidden;
  /* iOS Safari: stop double-tap zoom + tap highlight halo */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  /* Lock to dynamic viewport so notch + home indicator don't squeeze layout */
  height: 100dvh;
  height: 100vh; /* fallback */
}

button {
  font: inherit;
  color: inherit;
}

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  /* Padding doubles as the visible bezel around the stage on phones; iOS
     safe-area insets stack on top so the frame clears the notch + home bar. */
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

.stage {
  position: relative;
  /* 100% (not 100vw) so we respect .shell padding and the rounded border + ring
     shadow stay fully visible inside the iPhone viewport. dvh keeps the canvas
     within Safari's visible area when the URL bar collapses/expands. */
  width: min(100%, calc(100dvh * 9 / 16));
  max-width: 720px;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #01060a;
  border-radius: 14px;
  box-shadow:
    0 0 0 1px rgba(124, 232, 255, 0.18),
    0 32px 80px rgba(0, 0, 0, 0.78),
    inset 0 0 120px rgba(124, 232, 255, 0.04);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ───────────── HUD top — slim single-row bar ───────────── */
.hud-top {
  position: absolute;
  z-index: 3;
  /* iOS notch / Dynamic Island clearance */
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  display: grid;
  gap: 4px;
  pointer-events: none;
}

.hud-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(5, 14, 22, 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: var(--shadow-soft);
  pointer-events: auto;
}

.hud-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 8, 14, 0.42);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hud-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  opacity: 0.85;
}

.hud-health .hud-icon { color: var(--emerald); }
.hud-money .hud-icon { color: var(--gold); }
.hud-stage .hud-icon { color: var(--cyan); }
.hud-level .hud-icon { color: var(--magenta); }
.hud-kill .hud-icon { color: var(--crimson); }

.hud-stat.hud-theme {
  margin-left: auto;
  padding: 2px 8px 2px 4px;
  background: rgba(40, 16, 4, 0.5);
  border: 1px solid rgba(255, 184, 77, 0.32);
  color: #ffd28a;
  font-size: 11px;
}

.hud-theme img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(255, 184, 77, 0.45));
}

.hud-progress {
  position: relative;
  height: 4px;
  margin: 0 6px;
  border-radius: 999px;
  background: rgba(0, 6, 10, 0.78);
  border: 1px solid rgba(124, 232, 255, 0.18);
  overflow: hidden;
  pointer-events: auto;
}

.hud-progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  pointer-events: none;
  /* Move text below the bar so the bar stays slim */
  transform: translateY(11px);
}

.hud-progress-text .muted { color: var(--text-muted); }
.hud-progress-text #levelProgressText {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.hud-state {
  margin: 14px 8px 0;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  color: rgba(241, 250, 255, 0.72);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.muted {
  color: var(--text-muted);
}

#levelProgressFill {
  position: absolute;
  inset: 0;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #54f6ff 0%, #fff2a3 60%, var(--gold) 100%);
  box-shadow: 0 0 12px rgba(124, 232, 255, 0.55);
  transition: width 200ms ease-out;
}

/* Overlay & game-over panels still use these names */
.stat-key {
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 11px;
}

.stat-val {
  color: var(--text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ───────────── Boss panel ───────────── */
.boss-panel {
  position: absolute;
  z-index: 4;
  /* Slim HUD takes ~70px so boss panel sits at 76px */
  top: 76px;
  left: 50%;
  width: min(82%, 380px);
  transform: translateX(-50%);
  padding: 10px 14px 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-warn);
  background: linear-gradient(170deg, rgba(40, 11, 9, 0.85), rgba(14, 6, 4, 0.94));
  color: #fff4d0;
  box-shadow: var(--shadow-strong), inset 0 0 18px rgba(255, 91, 39, 0.12);
  backdrop-filter: blur(10px);
  animation: bossPanelIn 380ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

/* Boss intro banner — full-width drama on stage spawn */
/* Boss arrival / ultimate banner — pinned just above the bottom control bar
 * so it never covers the boss sprite or its ult animation. Slim horizontal
 * layout: small "BOSS APPROACHING" label, then name, then ability sub. */
.boss-banner {
  position: absolute;
  z-index: 9;
  /* Sit above the .controls bar (52px min-height + 12px bottom + 12px gap). */
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 76px);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 4px;
  justify-items: center;
  width: min(86%, 420px);
  padding: 10px 18px 12px;
  text-align: center;
  background: linear-gradient(180deg, rgba(48, 12, 14, 0.92) 0%, rgba(20, 4, 6, 0.96) 100%);
  border: 1px solid rgba(255, 91, 39, 0.78);
  border-radius: 10px;
  box-shadow:
    0 0 32px rgba(255, 91, 39, 0.45),
    inset 0 0 22px rgba(255, 91, 39, 0.16);
  pointer-events: none;
  animation: bossBannerIn 320ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

.boss-banner[hidden] {
  display: none;
}

@keyframes bossBannerIn {
  from {
    opacity: 0;
    transform: translate(-50%, 14px);
  }
}

.boss-banner-eyebrow {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  color: rgba(255, 240, 200, 0.82);
  text-shadow: 0 0 10px rgba(255, 100, 50, 0.6);
}

.boss-banner-name {
  font-size: clamp(18px, 4.6vw, 26px);
  font-weight: 900;
  letter-spacing: 0.05em;
  background: linear-gradient(120deg, #fff4c1, #ff8a3a 60%, #ffd28a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.05;
}

.boss-banner-sub {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 230, 200, 0.88);
  margin-top: 1px;
}

/* ───────────── Boss reveal cinematic ─────────────
 * Full-screen warning when a boss appears: red-tinted background,
 * black bars sliding in from top/bottom (cinematic letterbox), big
 * boss frame portrait, name + ability text. Auto-advances after
 * ~2.4 s, tap-to-skip. */
.boss-reveal {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 91, 39, 0.55) 0%, rgba(40, 4, 0, 0.92) 50%, rgba(0, 0, 0, 0.97) 100%);
  cursor: pointer;
  pointer-events: auto;
  animation: bossRevealIn 380ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
.boss-reveal[hidden] { display: none; }
@keyframes bossRevealIn { from { opacity: 0; } }

/* Sliding letterbox bars top + bottom — pure cinematic feel */
.boss-reveal-bars {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.boss-reveal-bars span {
  position: absolute;
  left: 0; right: 0;
  height: 64px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.85));
  animation: bossRevealBar 420ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}
.boss-reveal-bars span:first-child { top: 0; }
.boss-reveal-bars span:last-child  { bottom: 0; transform: rotate(180deg); animation-delay: 60ms; }
@keyframes bossRevealBar {
  from { transform: translateY(-100%); }
}
.boss-reveal-bars span:last-child { animation-name: bossRevealBarBottom; }
@keyframes bossRevealBarBottom { from { transform: translateY(100%); } }

.boss-reveal-frame {
  position: relative;
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(86%, 460px);
  padding: 18px 20px 22px;
  background: linear-gradient(165deg, rgba(40, 8, 8, 0.86) 0%, rgba(8, 4, 4, 0.95) 100%);
  border: 2px solid rgba(255, 91, 39, 0.85);
  box-shadow:
    0 0 64px rgba(255, 91, 39, 0.6),
    inset 0 0 40px rgba(255, 91, 39, 0.18);
  text-align: center;
  animation: bossRevealFrame 600ms 180ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

@keyframes bossRevealFrame {
  from { opacity: 0; transform: translateY(28px) scale(0.92); }
}

.boss-reveal-eyebrow {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.36em;
  color: rgba(255, 200, 130, 0.92);
  text-shadow: 0 0 16px rgba(255, 91, 39, 0.7);
  animation: bossRevealPulse 0.9s ease-in-out infinite alternate;
}

@keyframes bossRevealPulse {
  to { color: rgba(255, 240, 200, 1); text-shadow: 0 0 24px rgba(255, 91, 39, 0.95); }
}

.boss-reveal-portrait {
  width: min(220px, 60vw);
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 91, 39, 0.45);
  box-shadow: 0 0 28px rgba(255, 91, 39, 0.55);
}

.boss-reveal-portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.boss-reveal-name {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, #fff4c1, #ff8a3a 60%, #ffd28a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
  margin-top: 4px;
}

.boss-reveal-ability {
  font-family: "SF Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgba(255, 230, 200, 0.88);
  margin-top: 4px;
}

.boss-reveal-cta {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: rgba(255, 200, 130, 0.6);
  animation: heroIntroPulse 1.4s ease-in-out infinite;
}

/* ───────────── Phase 1: Hero comic overlay (fullscreen 4-panel) ───── */
.hero-comic-overlay {
  position: fixed;
  inset: 0;
  z-index: 51;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  cursor: pointer;
  animation: heroComicIn 400ms ease;
}
.hero-comic-overlay[hidden] { display: none; }
@keyframes heroComicIn { from { opacity: 0; } }

.hero-comic-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hero-comic-cta {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.2em;
}

/* ───────────── Phase 2: Hero join card ───────────── */
.hero-intro {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 40%, var(--hero-tint, rgba(124,232,255,0.15)) 0%, rgba(0,0,0,0.98) 60%);
  overflow: hidden;
  cursor: pointer;
  pointer-events: auto;
  animation: heroIntroIn 540ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
.hero-intro[hidden] { display: none; }
@keyframes heroIntroIn { from { opacity: 0; transform: scale(0.96); } }

.hero-intro-rays { display: none; }

.hero-intro-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(88%, 380px);
  text-align: center;
}

.hero-intro-portrait {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--hero-tint, var(--cyan));
  box-shadow: 0 0 40px var(--hero-tint, rgba(124,232,255,0.4));
  animation: heroPortraitPop 600ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
@keyframes heroPortraitPop {
  from { transform: scale(0.6); opacity: 0; }
}

.hero-intro-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-intro-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hero-intro-eyebrow {
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4em;
  color: var(--hero-tint, var(--cyan));
  text-transform: uppercase;
}

.hero-intro-name {
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 0 30px var(--hero-tint, rgba(199, 125, 255, 0.7));
  line-height: 1;
}

.hero-intro-country {
  font-family: "SF Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: rgba(255, 255, 255, 0.6);
}

.hero-intro-skills {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  text-align: left;
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}

.hero-intro-skill-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--cyan);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-top: 2px;
}

.hero-intro-skill,
.hero-intro-ult {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

.hero-intro-cta {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.7;
  animation: heroIntroPulse 1.6s ease-in-out infinite;
}

@keyframes heroIntroPulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.95; }
}

/* ───────────── Tutorial overlay (first-run only) ─────────────────
 * Spotlights an HUD element with a dimmed mask + radial cutout, and
 * shows a small card with one instruction step. Tap-anywhere advances
 * unless the step is "tap-ult" — that step waits for a real ult fire. */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  /* Don't block taps on the playfield by default — only the card area
     should capture pointer events. This lets players actually tap their
     hero portrait while the tutorial is up (esp. step 4). */
  pointer-events: none;
}
.tutorial-overlay[hidden] { display: none; }

.tutorial-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* Spotlight cutout — uses radial-gradient to "punch a hole" in the mask.
   Position is set in JS via CSS custom properties --spot-x/--spot-y/--spot-r. */
.tutorial-spotlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at var(--spot-x, 50%) var(--spot-y, 50%),
    transparent 0,
    transparent calc(var(--spot-r, 60px) - 4px),
    rgba(124, 232, 255, 0.45) calc(var(--spot-r, 60px) - 2px),
    rgba(124, 232, 255, 0.25) var(--spot-r, 60px),
    transparent calc(var(--spot-r, 60px) + 8px)
  );
  animation: tutorialPulse 1.4s ease-in-out infinite;
}
@keyframes tutorialPulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

.tutorial-card {
  position: absolute;
  bottom: calc(160px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(86%, 340px);
  padding: 18px 20px 16px;
  background: linear-gradient(180deg, rgba(20, 28, 44, 0.96) 0%, rgba(8, 12, 22, 0.96) 100%);
  border: 1px solid rgba(124, 232, 255, 0.5);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 24px rgba(124, 232, 255, 0.25);
  text-align: center;
  /* Card itself catches clicks (so the Next button works); the surrounding
     mask is passthrough so players can interact with the playfield. */
  pointer-events: auto;
  animation: tutorialCardIn 320ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
@keyframes tutorialCardIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
}

.tutorial-step {
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  color: var(--cyan);
  letter-spacing: 0.3em;
  margin-bottom: 6px;
}

.tutorial-title {
  font-size: 18px;
  font-weight: 900;
  color: #fff;
  margin-bottom: 8px;
}

.tutorial-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 14px;
}

.tutorial-next {
  appearance: none;
  border: 1px solid rgba(124, 232, 255, 0.6);
  background: rgba(124, 232, 255, 0.12);
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 9px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 160ms ease;
}
.tutorial-next:hover { background: rgba(124, 232, 255, 0.22); }
.tutorial-next:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* "Ready" pulse on hero portraits when ult is full but not fired */
.hero-roster-slot.is-ready {
  animation: heroReadyPulse 0.9s ease-in-out infinite;
}
@keyframes heroReadyPulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(255, 209, 102, 0.6)); }
  50%      { filter: drop-shadow(0 0 12px rgba(255, 209, 102, 1)); }
}

/* ───────────── 殷师傅 (Master Yin) unlock cinematic + HUD badge ─────────────
 * Fullscreen comic splash with story dialogue — same pattern as hero-intro
 * but with warm amber tones. */
.yin-intro {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
  cursor: pointer;
  pointer-events: auto;
  animation: heroIntroIn 540ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
.yin-intro[hidden] { display: none; }

.yin-intro-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.yin-intro-comic {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.yin-intro-comic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.yin-intro-meta {
  position: absolute;
  bottom: 80px;
  left: 0; right: 0;
  padding: 16px 20px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.5) 70%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--cyan-soft);
}

.yin-intro-name {
  font-size: clamp(18px, 4.2vw, 24px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow: 0 0 24px rgba(255, 178, 74, 0.7);
  line-height: 1;
}

.yin-intro-country {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: rgba(255, 255, 255, 0.7);
}

.yin-intro-dialogue {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  padding: 14px 20px 24px;
  background: rgba(0,0,0,0.88);
  border-top: 1px solid var(--line);
}

.yin-intro-speaker {
  font-size: 11px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.yin-intro-text {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}

.yin-intro-cta {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.7;
}

/* HUD badge — small framed portrait that lives in the lower-left of the
   stage once 殷师傅 is unlocked. Confirms the slow buff is active. */
.yin-badge {
  position: absolute;
  bottom: 86px;
  left: 14px;
  z-index: 6;
  display: grid;
  grid-template-columns: 32px auto;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: rgba(8, 8, 14, 0.78);
  border: 1px solid rgba(255, 178, 74, 0.55);
  border-radius: 18px;
  box-shadow: 0 0 14px rgba(255, 178, 74, 0.32);
  pointer-events: none;
}
.yin-badge[hidden] { display: none; }
.yin-badge img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  /* Show the chibi's face, not its boots — the panel is taller than it is
     wide, so a 1:1 cover crops to the middle (chest). object-position
     pulls the crop to the head. */
  object-position: top center;
  border-radius: 50%;
  border: 1px solid rgba(255, 178, 74, 0.55);
}
.yin-badge-tag {
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: rgba(255, 217, 168, 0.95);
}
/* Pre-unlock state: dimmed + grayscale to hint "locked goal", with a
   small 锁 marker. Post-unlock state: full color + soft pulse glow so
   the player knows the buff is live. */
.yin-badge.is-locked img {
  filter: grayscale(0.85) brightness(0.65);
}
.yin-badge.is-locked .yin-badge-tag::before {
  content: "🔒 ";
  letter-spacing: 0;
}
.yin-badge.is-locked .yin-badge-tag {
  color: rgba(255, 217, 168, 0.55);
}
.yin-badge.is-active {
  animation: yinBadgePulse 2.4s ease-in-out infinite;
}
@keyframes yinBadgePulse {
  0%, 100% { box-shadow: 0 0 14px rgba(255, 178, 74, 0.32); }
  50%      { box-shadow: 0 0 22px rgba(255, 178, 74, 0.65); }
}

@media (max-width: 410px) {
  .yin-intro-frame {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 16px 18px 18px;
  }
  .yin-intro-name { font-size: clamp(24px, 7.4vw, 36px); }
  .yin-intro-country { font-size: 10px; letter-spacing: 0.28em; }
}

/* ───────────── Prologue intro overlay ─────────────
 * Shown ONCE between ENGAGE click and gameplay. 7 narrator lines,
 * auto-advance with progress bar, tap-to-advance, long-press to skip. */
.prologue-overlay {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  cursor: pointer;
  animation: prologueIn 480ms cubic-bezier(0.22, 0.85, 0.32, 1);
}
.prologue-overlay[hidden] { display: none; }
@keyframes prologueIn { from { opacity: 0; } }

.prologue-comic-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: prologuePageIn 400ms ease;
}
@keyframes prologuePageIn {
  from { opacity: 0; transform: scale(0.97); }
}

.prologue-bottom-bar {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.prologue-page-dots {
  display: flex;
  gap: 6px;
}

.prologue-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  transition: background 200ms;
}
.prologue-dot.active {
  background: rgba(124,232,255,0.9);
  box-shadow: 0 0 6px rgba(124,232,255,0.6);
}

.prologue-skip {
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: rgba(241, 250, 255, 0.4);
}

/* ───────────── ULT cinematic ─────────────
 * Full-screen flash when a hero's ULT fires. Character portrait pops in,
 * ULT name slams across the screen in their signature color, plus a
 * radial flash + screen shake. ~1.4s total, then fades out and gameplay
 * continues. Z-index sits below modal panels but above gauges/dialogue. */
/* ULT cinematic — slim BOTTOM banner so the Three.js scene burst on the
 * canvas (radial shockwaves + glitter + per-defender explosion) is the
 * star, not a giant card blocking gameplay. The banner is just a label
 * "Lia · 巨陨炎涌" that pops in for ~1.4 s next to the controls. */
.ult-cinematic {
  position: absolute;
  z-index: 9;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 168px);
  pointer-events: none;
  display: flex;
  justify-content: center;
  animation: ultCinematicShake 1.4s cubic-bezier(0.22, 0.85, 0.32, 1);
}
.ult-cinematic[hidden] { display: none; }

@keyframes ultCinematicShake {
  0%, 100% { transform: translate(0, 0); }
  10%      { transform: translate(-2px, 1px); }
  20%      { transform: translate(2px, -1px); }
  30%      { transform: translate(-1px, 1px); }
}

/* Hide the old full-screen flash — the canvas-side burst (Three.js
 * shockwaves) is doing the visual heavy lift now. */
.ult-cinematic-flash { display: none; }

.ult-cinematic-frame {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px 9px;
  background: linear-gradient(120deg, rgba(2, 6, 14, 0.92) 0%, rgba(20, 8, 36, 0.96) 100%);
  border: 1.5px solid var(--ult-color, rgba(255, 209, 102, 0.95));
  border-radius: 999px;
  box-shadow: 0 0 32px var(--ult-color, rgba(255, 209, 102, 0.6));
  animation: ultCinematicFrame 1.4s cubic-bezier(0.22, 0.85, 0.32, 1);
}

@keyframes ultCinematicFrame {
  0%   { opacity: 0; transform: translateY(20px) scale(0.85); }
  18%  { opacity: 1; transform: translateY(0) scale(1.0); }
  85%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px) scale(0.96); }
}

/* Compact circle portrait beside the name (was a big 168 px panel). */
.ult-cinematic-frame img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--ult-color, rgba(255, 209, 102, 0.7));
  box-shadow: 0 0 12px var(--ult-color, rgba(255, 209, 102, 0.6));
}

.ult-cinematic-text {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  text-align: left;
}

.ult-cinematic-eyebrow {
  display: none; /* slim banner — eyebrow folded into the inline name line */
}

.ult-cinematic-name {
  font-size: clamp(15px, 4.4vw, 20px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ult-color, #ffd166);
  text-shadow: 0 0 14px var(--ult-color, rgba(255, 209, 102, 0.7));
  line-height: 1.1;
}

.ult-cinematic-hero {
  font-family: "SF Mono", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: rgba(255, 255, 255, 0.7);
}

@media (max-width: 410px) {
  .ult-cinematic-frame {
    padding: 7px 14px 8px;
    gap: 10px;
  }
  .ult-cinematic-frame img { width: 28px; height: 28px; }
  .ult-cinematic-name { font-size: clamp(13px, 4.2vw, 17px); }
  .ult-cinematic-hero { font-size: 9px; letter-spacing: 0.26em; }
  /* prologue is now full-page comic — no text override needed */
}

/* ───────────── Dialogue box (boss arrival, character banter) ─────────────
 * Sits one slot above the boss banner so when both fire on boss arrival
 * they stack cleanly: banner hugs the controls, dialogue sits 80px higher
 * with portrait + speaker. Hidden during modal panels (level-up / shop /
 * pause / game-over / victory / title / prologue) via JS isModalActive(). */
.dialogue-box {
  position: absolute;
  z-index: 8;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 168px);
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 10px 14px 12px;
  background: linear-gradient(180deg, rgba(8, 12, 24, 0.94) 0%, rgba(2, 6, 14, 0.96) 100%);
  border: 1px solid rgba(124, 232, 255, 0.55);
  border-radius: 10px;
  box-shadow:
    0 0 28px rgba(124, 232, 255, 0.25),
    inset 0 0 18px rgba(124, 232, 255, 0.08);
  pointer-events: auto;
  cursor: pointer;
  animation: dialogueIn 320ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

.dialogue-box[hidden] { display: none; }

@keyframes dialogueIn {
  from { opacity: 0; transform: translateY(14px); }
}

.dialogue-portrait {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(124, 232, 255, 0.4);
  flex-shrink: 0;
}

.dialogue-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dialogue-body {
  display: grid;
  gap: 4px;
  align-content: center;
  min-width: 0;
}

.dialogue-speaker {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: rgba(124, 232, 255, 0.9);
  text-transform: uppercase;
}

.dialogue-text {
  font-size: 14px;
  font-weight: 700;
  color: rgba(241, 250, 255, 0.95);
  line-height: 1.55;
  /* Mixed CN/EN: CJK wraps naturally at any character (word-break: normal),
     English wraps at spaces, and overflow-wrap kicks in for long ALL-CAPS
     tokens (BRIGHT.SUN, DIGIREPUB) that would otherwise overflow. The
     earlier `keep-all` rule turned each Chinese sentence into one giant
     "word" that ran off the box. */
  word-break: normal;
  overflow-wrap: anywhere;
  white-space: normal;
  hyphens: none;
  max-width: 100%;
}

.dialogue-skip {
  position: absolute;
  bottom: 4px;
  right: 10px;
  font-family: "SF Mono", monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: rgba(124, 232, 255, 0.42);
}

/* ───────────── ULT gauges row — one slot per active hero ─────────────
 * ULT gauge is now a circular SVG ring on each hero-roster portrait at
 * the bottom bar. The old top-pinned ult-gauges row is removed. */

/* Hero roster slot — wrapper around portrait + SVG ring */
.hero-roster-slot {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.hero-roster-slot .hero-roster-avatar {
  position: absolute;
  inset: 3px;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  border-radius: 50%;
  object-fit: cover;
  border: none;
  box-shadow: none;
}

.ult-ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ult-ring-fill {
  transition: stroke-dashoffset 200ms ease, stroke 200ms ease;
}

.hero-roster-slot.is-ready {
  animation: ultReady 0.9s ease-in-out infinite alternate;
}

.hero-roster-slot.is-active {
  transform: scale(1.15);
  filter: drop-shadow(0 0 8px rgba(199, 125, 255, 0.9));
}

@keyframes ultReady {
  to { filter: drop-shadow(0 0 10px rgba(255, 209, 102, 0.95)); transform: scale(1.05); }
}

.boss-panel[hidden] {
  display: none;
}

@keyframes bossPanelIn {
  from {
    opacity: 0;
    transform: translate(-50%, -8px) scale(0.96);
  }
}

.boss-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: clamp(12px, 2.3vw, 15px);
  font-weight: 800;
  line-height: 1.1;
}

#bossName {
  min-width: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  letter-spacing: 0.02em;
}

#bossHpText {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: #ffd28a;
}

.boss-hp-track {
  margin-top: 8px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 184, 77, 0.42);
  background: rgba(0, 0, 0, 0.62);
  overflow: hidden;
}

#bossHpFill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff3d2e, #ff9a3d 52%, #fff0a8);
  box-shadow: 0 0 16px rgba(255, 99, 45, 0.78);
  transition: width 120ms linear;
}

/* ───────────── Mini Boss tag (name + HP bar) ───────────── */
.mini-boss-tag {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  display: grid;
  gap: 3px;
  min-width: 92px;
  padding: 4px 8px 5px;
  border-radius: 6px;
  background: rgba(8, 26, 36, 0.92);
  border: 1px solid rgba(255, 184, 77, 0.6);
  color: #fff4d0;
  transform: translateX(-50%);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.mini-boss-tag[hidden] { display: none; }

.mini-boss-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.mini-boss-hp {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  border: 1px solid rgba(255, 184, 77, 0.32);
  overflow: hidden;
}

#miniBossHpFill {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff5b39, #ffb84d 65%, #fff4c1);
  box-shadow: 0 0 6px rgba(255, 99, 45, 0.7);
  transition: width 140ms linear;
}

/* ───────────── Floaters (kill +¥, damage numbers) ───────────── */
.floaters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.floater {
  position: absolute;
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.7), 0 1px 2px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: floaterRise 900ms cubic-bezier(0.22, 0.85, 0.32, 1) forwards;
  pointer-events: none;
}

.floater.is-money { color: #ffd166; }
.floater.is-kill { color: #b6f8ff; }
.floater.is-boss { color: #ff8a3a; font-size: 16px; }
.floater.is-damage { color: #ff5b6b; font-size: 12px; }

@keyframes floaterRise {
  0% { opacity: 0; transform: translate(-50%, -10%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(0.95); }
}

/* ───────────── Level Up panel ───────────── */
.level-panel,
.shop-panel {
  position: absolute;
  z-index: 5;
  left: 18px;
  right: 18px;
  pointer-events: none;
}

.level-panel {
  top: 110px;
  bottom: 96px;
  display: grid;
  align-items: center;
  pointer-events: auto;
}

.level-panel[hidden] {
  display: none;
}

.panel-shell {
  display: grid;
  gap: 16px;
  animation: panelIn 320ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
}

.level-title {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 14px 22px 16px;
  border-radius: var(--radius-md);
  background: linear-gradient(170deg, rgba(8, 36, 50, 0.95), rgba(4, 14, 22, 0.96));
  border: 1px solid rgba(124, 232, 255, 0.45);
  box-shadow:
    var(--shadow-strong),
    inset 0 0 24px rgba(124, 232, 255, 0.12);
}

.level-title-text {
  font-size: clamp(24px, 5.5vw, 36px);
  font-weight: 900;
  letter-spacing: 0.18em;
  background: linear-gradient(110deg, var(--cyan-soft), var(--cyan), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}

.level-title-sub {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.level-panel[data-source="boss"] .level-title {
  position: relative;
  overflow: hidden;
  border-color: rgba(255, 184, 77, 0.58);
  box-shadow:
    var(--shadow-strong),
    inset 0 0 26px rgba(255, 184, 77, 0.12);
}

.level-panel[data-source="boss"] .level-title::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 56px;
  height: 56px;
  transform: translateY(-50%);
  background: url("../assets/generated/polish/final/boss-weakpoint-core.webp?v=20260503-polish-runtime1") center / contain no-repeat;
  opacity: 0.74;
  filter: drop-shadow(0 0 16px rgba(255, 184, 77, 0.5));
  pointer-events: none;
}

.level-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  pointer-events: auto;
}

.level-cards.is-expanded {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
}

.shop-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* ───────────── Upgrade Cards ───────────── */
.upgrade-card {
  position: relative;
  display: grid;
  grid-template-rows: 22px 96px 18px 18px minmax(40px, auto) 44px;
  gap: 6px;
  min-width: 0;
  min-height: 280px;
  padding: 14px 12px 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transform: translateZ(0);
  transition:
    transform 140ms cubic-bezier(0.22, 0.85, 0.32, 1),
    border-color 140ms ease,
    box-shadow 140ms ease;
  box-shadow:
    var(--shadow-soft),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  animation: cardReveal 360ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.upgrade-card:nth-child(1) {
  animation-delay: 30ms;
}

.upgrade-card:nth-child(2) {
  animation-delay: 90ms;
}

.upgrade-card:nth-child(3) {
  animation-delay: 150ms;
}

.upgrade-card:nth-child(4) {
  animation-delay: 210ms;
}

.upgrade-card:nth-child(5) {
  animation-delay: 270ms;
}

@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.94);
  }
}

.upgrade-card::before {
  content: "";
  position: absolute;
  inset: 28px 0 auto 0;
  margin: 0 auto;
  width: 138px;
  height: 138px;
  background-image: var(--upgrade-vfx);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.32;
  animation: vfxPulse 2.6s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

.upgrade-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, transparent 22%);
}

.upgrade-card > * {
  position: relative;
  z-index: 1;
}

.upgrade-card:hover:not(:disabled) {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(124, 232, 255, 0.18);
}

.upgrade-card:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.upgrade-card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.upgrade-card:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  filter: grayscale(0.4);
}

.shop-lock {
  display: none;
  position: absolute;
  inset: 0;
  place-items: center;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(2, 8, 12, 0.2), rgba(0, 0, 0, 0.44));
}

.shop-lock img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  opacity: 0.92;
  filter: drop-shadow(0 0 14px rgba(255, 184, 77, 0.46));
}

.upgrade-card.shop-card.is-locked .shop-lock {
  display: grid;
}

.upgrade-card.is-rare {
  border-color: rgba(110, 198, 255, 0.55);
  box-shadow:
    var(--shadow-soft),
    inset 0 0 0 1px rgba(110, 198, 255, 0.12);
}

.upgrade-card.is-rare::before {
  filter: drop-shadow(0 0 12px rgba(110, 198, 255, 0.5));
}

.upgrade-card.is-epic {
  border-color: rgba(217, 122, 255, 0.6);
  box-shadow:
    var(--shadow-soft),
    inset 0 0 0 1px rgba(217, 122, 255, 0.14);
}

.upgrade-card.is-epic::before {
  filter: drop-shadow(0 0 14px rgba(217, 122, 255, 0.55));
}

.upgrade-card.is-legendary {
  border-color: rgba(255, 209, 102, 0.7);
  box-shadow:
    0 18px 42px rgba(255, 184, 77, 0.18),
    inset 0 0 0 1px rgba(255, 209, 102, 0.18);
}

.upgrade-card.is-legendary::before {
  filter: drop-shadow(0 0 16px rgba(255, 209, 102, 0.6));
}

.upgrade-card.is-mythic {
  border-color: rgba(255, 91, 107, 0.78);
  background: linear-gradient(165deg, rgba(48, 12, 18, 0.94), rgba(20, 6, 8, 0.96));
  box-shadow:
    0 18px 42px rgba(255, 91, 107, 0.2),
    inset 0 0 0 1px rgba(255, 91, 107, 0.24);
}

.upgrade-card.is-mythic::before {
  filter: drop-shadow(0 0 18px rgba(255, 91, 107, 0.7));
}

.upgrade-name,
.upgrade-category,
.upgrade-effect,
.upgrade-price {
  display: block;
  min-width: 0;
  overflow: hidden;
}

.upgrade-name {
  font-size: clamp(13px, 2.4vw, 16px);
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.upgrade-art {
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid rgba(124, 232, 255, 0.16);
  border-radius: var(--radius-sm);
  background: rgba(2, 12, 18, 0.46);
}

.upgrade-art img {
  width: min(86px, 82%);
  max-height: 86px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}

.upgrade-category {
  color: var(--cyan);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

/* Level row + pip dots — leveled-upgrade indicator (Vampire-Survivors pattern) */
.upgrade-level {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: rgba(255, 209, 102, 0.92);
  text-transform: uppercase;
}

.upgrade-pips {
  display: inline-flex;
  gap: 3px;
}

.upgrade-pip {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.upgrade-pip.is-filled {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 6px rgba(255, 209, 102, 0.7);
}

.upgrade-pip.is-next {
  background: rgba(255, 209, 102, 0.35);
  border-color: var(--gold);
  animation: pipNextPulse 1.4s ease-in-out infinite;
}

@keyframes pipNextPulse {
  0%, 100% { box-shadow: 0 0 4px rgba(255, 209, 102, 0.4); }
  50% { box-shadow: 0 0 10px rgba(255, 209, 102, 0.8); }
}

.upgrade-effect {
  align-self: center;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 8, 12, 0.42);
  color: rgba(241, 250, 255, 0.86);
  font-size: clamp(11px, 2.1vw, 13px);
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.upgrade-price {
  align-self: end;
  justify-self: center;
  width: min(110px, 100%);
  padding: 7px 8px 8px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(70, 48, 17, 0.92), rgba(28, 18, 8, 0.96));
  color: var(--gold);
  font-size: clamp(20px, 4.6vw, 28px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  border: 1px solid rgba(255, 184, 77, 0.32);
  box-shadow: inset 0 0 12px rgba(255, 184, 77, 0.1);
}

.shop-card .upgrade-art img {
  width: min(64px, 82%);
  max-height: 64px;
}

.shop-card .upgrade-price {
  width: min(86px, 100%);
  font-size: clamp(17px, 3.6vw, 24px);
}

.upgrade-card.shop-card {
  grid-template-rows: 22px 64px 14px 16px minmax(36px, auto) 36px;
  min-height: 218px;
  padding: 9px 8px;
  gap: 5px;
}

.upgrade-card.shop-card::before {
  inset: 26px 0 auto 0;
  width: 88px;
  height: 88px;
  opacity: 0.24;
}

.level-cards.is-expanded .upgrade-card {
  grid-template-rows: 20px 70px 14px 16px minmax(36px, auto) 36px;
  min-height: 234px;
  padding: 10px 7px;
  gap: 5px;
}

.level-cards.is-expanded .upgrade-card::before {
  inset: 22px 0 auto 0;
  width: 86px;
  height: 86px;
}

.level-cards.is-expanded .upgrade-art img {
  width: min(64px, 82%);
  max-height: 64px;
}

.level-cards.is-expanded .upgrade-price {
  font-size: clamp(17px, 3.6vw, 24px);
}

@keyframes vfxPulse {
  0%,
  100% {
    opacity: 0.22;
    transform: scale(0.92) rotate(0deg);
  }
  50% {
    opacity: 0.42;
    transform: scale(1.08) rotate(6deg);
  }
}

/* ───────────── Shop ───────────── */
.shop-panel {
  top: 76px;
  bottom: 78px;
  display: grid;
  pointer-events: auto;
}

.shop-panel .panel-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(124, 232, 255, 0.42);
  background: var(--bg-surface-strong);
  box-shadow: var(--shadow-strong), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
  animation: panelIn 280ms cubic-bezier(0.22, 0.85, 0.32, 1);
  min-height: 0;
}

.shop-panel[hidden] {
  display: none;
}

.shop-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.shop-title {
  font-size: clamp(18px, 3.7vw, 26px);
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(120deg, var(--cyan-soft), var(--cyan), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.05;
}

.shop-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.shop-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 184, 77, 0.42);
  background: rgba(13, 22, 24, 0.88);
  color: #fff4d0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease;
}

.shop-icon-btn:hover {
  background: rgba(28, 38, 42, 0.95);
}

.shop-actions {
  display: grid;
}

.shop-actions button {
  position: relative;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 184, 77, 0.55);
  background: linear-gradient(180deg, rgba(70, 48, 17, 0.92), rgba(25, 18, 8, 0.96));
  color: #fff4d0;
  padding-left: 42px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  overflow: hidden;
}

.shop-actions button::before {
  content: "";
  position: absolute;
  left: 12px;
  width: 28px;
  height: 28px;
  background: url("../assets/generated/polish/final/rarity-reroll-prism.webp?v=20260503-polish-runtime1") center / contain no-repeat;
  opacity: 0.78;
  filter: drop-shadow(0 0 10px rgba(217, 122, 255, 0.45));
}

.shop-actions button:disabled::before {
  opacity: 0.32;
}

.shop-actions button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255, 184, 77, 0.16);
}

.shop-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ───────────── Overlays (Pause / Game Over / Victory) ───────────── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.85) 100%);
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  animation: overlayIn 220ms ease-out;
}

.overlay[hidden] {
  display: none;
}

@keyframes overlayIn {
  from {
    opacity: 0;
  }
}

.overlay-card {
  display: grid;
  gap: 14px;
  padding: 28px 26px 24px;
  width: min(420px, 100%);
  border-radius: var(--radius-lg);
  background: linear-gradient(170deg, rgba(8, 36, 50, 0.96), rgba(4, 16, 24, 0.98));
  border: 1px solid var(--line-strong);
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.7), inset 0 0 32px rgba(124, 232, 255, 0.08);
  text-align: center;
  animation: panelIn 320ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

.overlay-pause .overlay-card {
  border-color: rgba(124, 232, 255, 0.5);
}

/* ───────────── Title screen — editorial / cinematic poster ─────────────
 * No card container. Hero typography on cosmic backdrop, sci-fi metadata
 * row, framed engage button, and a thin foot strip with credits.
 */
.overlay-title {
  background:
    radial-gradient(circle at 50% 28%, rgba(0, 16, 28, 0.55) 0%, transparent 65%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.92));
  backdrop-filter: blur(4px) saturate(120%);
  -webkit-backdrop-filter: blur(4px) saturate(120%);
  padding: 0;
  align-items: stretch;
  justify-items: stretch;
  /* Without minmax(0, 1fr) the grid column auto-sizes to min-content of its
     item — and a non-wrapping word like "BRIGHT.SUN" forces that min-content
     wider than the stage on desktop, pushing the banner past the right edge.
     Pinning the column to fit the parent fixes that overflow. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

/* ═══════════════════════════════════════════════════════════════
   Title screen — magazine-cover hierarchy:
   1. BRIGHT.SUN (artist) at the top, electric violet
   2. PRESENTS divider
   3. Hero icon (the brand mark)
   4. EARTH DEFENSE (the work) with CN subtitle
   5. 开始游戏 button + progress bar (loads inline after click)
   6. DIGIREPUB STUDIO · 2026 attribution at the bottom
   ═══════════════════════════════════════════════════════════════ */
.title-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: max(28px, env(safe-area-inset-top)) 24px max(22px, env(safe-area-inset-bottom));
  text-align: center;
  font-family: "SF Pro Display", "Inter", "Helvetica Neue", system-ui, sans-serif;
  animation: titleStageIn 700ms cubic-bezier(0.22, 0.85, 0.32, 1);
}

@keyframes titleStageIn {
  from { opacity: 0; transform: translateY(6px); }
}

/* === BRIGHT.SUN banner — solid violet card, white type for maximum legibility
       (the previous dark-violet-on-violet read as "subtle"; this reads as
       "premium publisher card") === */
.title-banner {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  width: 100%;
  padding: 16px 24px 18px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(180deg, #b365ff 0%, #8a3fe6 60%, #6a25c2 100%);
  box-shadow:
    0 0 56px rgba(199, 125, 255, 0.55),
    0 0 18px rgba(199, 125, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  line-height: 1;
  animation: titleBlockIn 700ms 60ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

/* Diamond corner accents — pinned to the four corners as a marquee detail */
.title-banner-corner {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  background: #6a25c2;
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}
.title-banner-corner-tl { top: -6px; left: -6px; }
.title-banner-corner-tr { top: -6px; right: -6px; }
.title-banner-corner-bl { bottom: -6px; left: -6px; }
.title-banner-corner-br { bottom: -6px; right: -6px; }

/* All three banner lines: drop text-indent and use a left-padding equal
   to one letter-space so the visible glyphs sit centered. text-indent
   shifts only the first line of inline content and fights text-align:
   center; padding-left + the trailing letter-space cancel cleanly. */
.title-banner-eyebrow {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.46em;
  padding-left: 0.46em;
  text-align: center;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}

.title-banner-name {
  /* On a 430px iPhone Pro Max viewport, the previous 11.5vw → 49.5px font
     filled the banner edge-to-edge — "N" of SUN visibly clipping the right
     border. Tightened to 9.2vw cap 50px so there's always breathing room. */
  font-size: clamp(36px, 9.2vw, 50px);
  font-weight: 900;
  letter-spacing: 0.06em;
  padding-left: 0.06em;
  text-align: center;
  color: #ffffff;
  text-shadow:
    0 0 24px rgba(255, 255, 255, 0.5),
    0 1px 0 rgba(0, 0, 0, 0.18);
  margin-top: 4px;
}

.title-banner-tagline {
  margin-top: 6px;
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.36em;
  padding-left: 0.36em;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

/* === Hero icon — the brand mark, gently floating === */
.title-hero-art {
  margin: 0;
  width: clamp(132px, 36vw, 184px);
  height: clamp(132px, 36vw, 184px);
  filter: drop-shadow(0 22px 48px rgba(199, 125, 255, 0.32))
          drop-shadow(0 0 18px rgba(124, 232, 255, 0.18));
  animation: titleBlockIn 800ms 320ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.title-hero-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 28px;
  display: block;
  animation: titleHeroFloat 4.6s ease-in-out infinite;
}

@keyframes titleHeroFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* === Game title === */
.title-game {
  display: grid;
  gap: 8px;
  margin: 0;
  line-height: 1;
  animation: titleBlockIn 700ms 460ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.title-game-en {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #f1faff 0%, var(--cyan-soft) 50%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 32px rgba(124, 232, 255, 0.22);
}

.title-game-cn {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: rgba(241, 250, 255, 0.7);
}

/* === CTA cluster: button + progress bar (mutually exclusive) === */
.title-cta {
  display: grid;
  gap: 16px;
  justify-items: center;
  width: 100%;
  animation: titleBlockIn 700ms 600ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.title-engage {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 16px 38px;
  border: 1px solid rgba(124, 232, 255, 0.55);
  background: linear-gradient(180deg, rgba(8, 56, 78, 0.55) 0%, rgba(4, 26, 38, 0.78) 100%);
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms cubic-bezier(0.22, 0.85, 0.32, 1),
    border-color 160ms ease, box-shadow 160ms ease;
  box-shadow:
    inset 0 0 22px rgba(124, 232, 255, 0.16),
    0 0 38px rgba(124, 232, 255, 0.14);
  clip-path: polygon(
    14px 0%, 100% 0%, 100% calc(100% - 14px),
    calc(100% - 14px) 100%, 0% 100%, 0% 14px
  );
  -webkit-tap-highlight-color: transparent;
}

.title-engage:hover {
  transform: translateY(-2px);
  border-color: var(--cyan);
  box-shadow:
    inset 0 0 32px rgba(124, 232, 255, 0.28),
    0 0 64px rgba(124, 232, 255, 0.32);
}

.title-engage:active { transform: translateY(0) scale(0.98); }

.title-engage:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow:
    inset 0 0 28px rgba(255, 209, 102, 0.2),
    0 0 36px rgba(255, 209, 102, 0.34);
}

.title-engage.is-loading {
  display: none;
}

.title-engage-marker {
  font-size: 12px;
  color: var(--cyan);
  animation: engageMarker 1.4s ease-in-out infinite;
}

@keyframes engageMarker {
  0%, 100% { transform: translateX(0); opacity: 0.85; }
  50% { transform: translateX(3px); opacity: 1; }
}

.title-engage-en {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  background: linear-gradient(180deg, #ffffff 0%, var(--cyan-soft) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* === Loading progress bar === */
.title-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(280px, 80%);
}

.title-progress.is-visible {
  display: flex;
  animation: titleBlockIn 360ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.title-progress-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
}

.title-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #c77dff 0%, #7ce8ff 100%);
  box-shadow: 0 0 14px rgba(199, 125, 255, 0.6);
  border-radius: 999px;
  transition: width 220ms ease;
}

.title-progress-label {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.36em;
  text-indent: 0.36em;
  text-transform: uppercase;
  color: rgba(124, 232, 255, 0.78);
}

/* === Bottom studio attribution === */
.title-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: rgba(241, 250, 255, 0.42);
  animation: titleBlockIn 700ms 720ms cubic-bezier(0.22, 0.85, 0.32, 1) backwards;
}

.title-foot-year {
  color: rgba(241, 250, 255, 0.28);
}

@keyframes titleBlockIn {
  from { opacity: 0; transform: translateY(10px); }
}

/* Compact title for phone viewports (≤410 catches iPhone 14/15 Pro) */
@media (max-width: 410px) {
  .title-stage {
    padding: max(20px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom));
  }
  .title-banner { padding: 14px 18px 16px; }
  .title-banner-eyebrow { font-size: 9px; letter-spacing: 0.4em; }
  .title-banner-name { font-size: clamp(34px, 10.5vw, 48px); letter-spacing: 0.05em; }
  .title-banner-tagline { font-size: 9px; letter-spacing: 0.32em; }
  .title-brand-tagline { font-size: 10px; letter-spacing: 0.36em; }
  .title-divider { font-size: 8px; letter-spacing: 0.4em; gap: 10px; width: min(220px, 70%); }
  .title-hero-art { width: clamp(120px, 34vw, 160px); height: clamp(120px, 34vw, 160px); }
  .title-game-en { font-size: clamp(26px, 8.5vw, 38px); }
  .title-game-cn { font-size: 10px; letter-spacing: 0.42em; }
  .title-engage { padding: 14px 30px; gap: 12px; }
  .title-engage-en { font-size: 16px; letter-spacing: 0.28em; }
  .title-progress { width: min(240px, 84%); }
  .title-foot { font-size: 9px; letter-spacing: 0.28em; }
}

.overlay-gameover .overlay-card {
  border-color: rgba(255, 91, 107, 0.55);
  box-shadow: 0 28px 72px rgba(255, 91, 107, 0.16), inset 0 0 32px rgba(255, 91, 107, 0.1);
}

.overlay-victory .overlay-card {
  border-color: rgba(255, 209, 102, 0.65);
  box-shadow: 0 28px 72px rgba(255, 184, 77, 0.18), inset 0 0 32px rgba(255, 184, 77, 0.1);
}

.overlay-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--text-muted);
}

.overlay-gameover .overlay-eyebrow {
  color: rgba(255, 91, 107, 0.86);
}

.overlay-victory .overlay-eyebrow {
  color: rgba(255, 209, 102, 0.92);
}

.overlay-title {
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  background: linear-gradient(120deg, var(--cyan-soft), var(--cyan), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-gameover .overlay-title {
  background: linear-gradient(120deg, #ffb1bd, var(--crimson) 60%, #ff9c5b);
  -webkit-background-clip: text;
  background-clip: text;
}

.overlay-victory .overlay-title {
  background: linear-gradient(120deg, #fff4c1, var(--gold) 60%, var(--cyan-soft));
  -webkit-background-clip: text;
  background-clip: text;
}

.overlay-sub {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 600;
}

.overlay-stats {
  margin-top: 4px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
}

.overlay-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 8, 12, 0.46);
  border: 1px solid rgba(124, 232, 255, 0.18);
  font-size: 13px;
}

.overlay-stat .stat-key {
  color: var(--text-muted);
  font-weight: 700;
}

.overlay-stat .stat-val {
  color: var(--text);
  font-weight: 900;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.overlay-actions {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-grid;
  place-items: center;
  min-height: 46px;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(124, 232, 255, 0.4);
  background: linear-gradient(180deg, rgba(8, 60, 76, 0.95), rgba(4, 22, 30, 0.98));
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
  box-shadow: inset 0 0 14px rgba(124, 232, 255, 0.12);
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--cyan);
  box-shadow: 0 10px 28px rgba(124, 232, 255, 0.18), inset 0 0 18px rgba(124, 232, 255, 0.18);
}

.btn-primary {
  background: linear-gradient(180deg, rgba(36, 110, 130, 0.95), rgba(8, 32, 44, 0.98));
  border-color: var(--cyan);
}

.overlay-gameover .btn-primary {
  background: linear-gradient(180deg, rgba(120, 30, 40, 0.95), rgba(40, 8, 12, 0.98));
  border-color: rgba(255, 91, 107, 0.7);
}

.overlay-gameover .btn-primary:hover {
  border-color: var(--crimson);
  box-shadow: 0 10px 28px rgba(255, 91, 107, 0.22), inset 0 0 18px rgba(255, 91, 107, 0.18);
}

.overlay-victory .btn-primary {
  background: linear-gradient(180deg, rgba(110, 80, 24, 0.95), rgba(40, 26, 8, 0.98));
  border-color: rgba(255, 209, 102, 0.7);
}

/* ───────────── Bottom controls ───────────── */
.controls {
  position: absolute;
  z-index: 4;
  /* iOS home-indicator clearance + landscape side safe-areas */
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ─── Speed toggle button (bottom-left) ─── */
.speed-btn {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(124, 232, 255, 0.45);
  background: rgba(6, 22, 40, 0.82);
  color: var(--accent, #7ce8ff);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.5px;
  cursor: pointer;
  z-index: 5;
  transition: border-color 180ms ease, background 180ms ease, transform 120ms ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
  align-self: flex-start;
}
.speed-btn:active { transform: scale(0.92); }
.speed-btn.speed-fast {
  border-color: #ffcc44;
  color: #ffcc44;
  background: rgba(40, 28, 6, 0.85);
  box-shadow: 0 0 10px rgba(255, 200, 60, 0.25), 0 2px 12px rgba(0,0,0,0.5);
}

.hero-roster {
  display: flex;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
}

/* Standalone fallback — overridden by .hero-roster-slot .hero-roster-avatar */
.hero-roster-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.controls-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.ctrl-settings-wrap {
  position: relative;
}

.settings-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 130px;
  background: rgba(6, 22, 32, 0.96);
  border: 1px solid rgba(124, 232, 255, 0.32);
  border-radius: var(--radius-md);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.55);
  padding: 4px 0;
  z-index: 10;
}

.settings-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 100ms ease;
  -webkit-tap-highlight-color: transparent;
}

.settings-item:hover {
  background: rgba(124, 232, 255, 0.1);
}

.settings-item:active {
  background: rgba(124, 232, 255, 0.18);
}

.ctrl-btn-primary {
  min-width: 90px;
  border-color: rgba(124, 232, 255, 0.5);
  box-shadow: inset 0 0 20px rgba(124, 232, 255, 0.12), 0 6px 18px rgba(0, 0, 0, 0.42);
}

/* Bottom control bar (重开/商店/暂停/音效) sits at z-index 4 — below the
   title overlay (z 10). With the overlay's backdrop-filter blur, the
   four buttons leaked through as blurred squares behind "DIGIREPUB
   STUDIO · 2026", which looked like loose icons cluttering the title.
   Hide them while pre-gameplay overlays are up. */
.stage:has(#titlePanel:not([hidden])) .controls,
.stage:has(#prologueOverlay:not([hidden])) .controls,
.stage:has(#heroIntro:not([hidden])) .controls,
.stage:has(#bossReveal:not([hidden])) .controls {
  display: none;
}

/* Subtle bottom fade only — used to be a heavy mask that was very
   visible on darker scenes. Pull-down opacity keeps button legibility
   without painting a visible band across the playfield. */
.controls::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: -12px;
  right: -12px;
  top: -20px;
  bottom: -12px;
  background: linear-gradient(180deg, rgba(1, 7, 11, 0) 0%, rgba(1, 7, 11, 0.18) 60%, rgba(1, 7, 11, 0.32));
  pointer-events: none;
}

.ctrl-btn {
  display: grid;
  grid-template-rows: 20px 14px;
  align-items: center;
  justify-items: center;
  gap: 3px;
  /* Apple HIG minimum 44pt — pad to 52 for thumb comfort */
  min-height: 52px;
  padding: 8px 6px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(124, 232, 255, 0.32);
  background: linear-gradient(180deg, rgba(6, 36, 46, 0.92), rgba(4, 14, 20, 0.96));
  color: var(--text);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
  box-shadow: inset 0 0 16px rgba(124, 232, 255, 0.08), 0 6px 18px rgba(0, 0, 0, 0.42);
  /* iOS: kill tap-highlight halo */
  -webkit-tap-highlight-color: transparent;
  /* Don't let long-press pop up the selection menu over a button */
  -webkit-touch-callout: none;
}

.ctrl-btn:hover {
  border-color: var(--cyan);
  transform: translateY(-1px);
  box-shadow: inset 0 0 18px rgba(124, 232, 255, 0.14), 0 10px 26px rgba(124, 232, 255, 0.12);
}

.ctrl-btn:active {
  transform: translateY(0);
}

.ctrl-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ctrl-icon {
  font-size: 16px;
  line-height: 1;
  color: var(--cyan);
}

.ctrl-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: rgba(241, 250, 255, 0.8);
}

/* ───────────── Mobile tweaks (iPhone-first) ─────────────
 * Tier 1 (≤460): general phone — iPhone Pro Max etc.
 * Tier 2 (≤390): standard iPhone — 14 / 15
 * Tier 3 (≤360): compact — iPhone SE / 13 mini / older
 */
@media (max-width: 460px) {
  .hud-bar {
    padding: 4px 6px;
    gap: 3px;
  }

  .hud-stat {
    padding: 3px 6px;
    font-size: 11px;
    gap: 3px;
  }

  .hud-stat.hud-theme {
    font-size: 10px;
  }

  .hud-icon {
    width: 12px;
    height: 12px;
    font-size: 10px;
  }

  .hud-state {
    font-size: 10px;
    margin-top: 12px;
  }

  .level-panel {
    top: 100px;
    bottom: 96px;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
  }

  .level-cards {
    gap: 9px;
  }

  .level-cards.is-expanded {
    grid-template-columns: repeat(auto-fit, minmax(106px, 1fr));
    gap: 7px;
  }

  .upgrade-card {
    grid-template-rows: 20px 80px 16px minmax(42px, auto) 38px;
    min-height: 248px;
    padding: 12px 10px;
    gap: 6px;
  }

  .upgrade-card::before {
    inset: 24px 0 auto 0;
    width: 116px;
    height: 116px;
  }

  .upgrade-card.shop-card {
    grid-template-rows: 18px 56px 14px minmax(36px, auto) 32px;
    min-height: 168px;
    padding: 7px 6px;
  }

  .level-cards.is-expanded .upgrade-card {
    grid-template-rows: 18px 56px 14px minmax(36px, auto) 32px;
    min-height: 178px;
    padding: 7px 6px;
  }

  .boss-panel {
    top: 70px;
    width: min(86%, 320px);
    padding: 9px 12px 10px;
  }

  .shop-panel {
    top: 70px;
    bottom: 92px;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
  }

  .shop-panel .panel-shell {
    padding: 11px;
  }

  .ctrl-btn {
    /* keep 48 for tap comfort even on small phones */
    min-height: 48px;
    padding: 7px 4px;
    grid-template-rows: 18px 12px;
    gap: 2px;
  }

  .ctrl-icon {
    font-size: 15px;
  }

  .ctrl-label {
    font-size: 10px;
  }

  .overlay-card {
    padding: 22px 20px 20px;
  }

  .overlay-stats {
    gap: 6px 10px;
  }

  .overlay-stat {
    padding: 7px 10px;
    font-size: 12px;
  }

  .mini-boss-tag {
    font-size: 10px;
    padding: 3px 8px;
  }
}

@media (max-width: 410px) {
  .stage {
    border-radius: 12px;
  }

  .hud-top {
    top: max(8px, env(safe-area-inset-top));
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    gap: 3px;
  }

  .hud-bar {
    padding: 3px 5px;
    gap: 3px;
  }

  .hud-stat {
    font-size: 10px;
    padding: 2px 5px;
  }

  .hud-icon {
    width: 11px;
    height: 11px;
    font-size: 9px;
  }

  .upgrade-card {
    min-height: 230px;
    grid-template-rows: 18px 70px 14px minmax(38px, auto) 34px;
    padding: 10px 8px;
  }

  .upgrade-card::before {
    inset: 20px 0 auto 0;
    width: 104px;
    height: 104px;
  }

  .upgrade-name {
    font-size: 13px;
  }

  .upgrade-effect {
    padding: 6px 8px;
    font-size: 11px;
  }

  .upgrade-price {
    font-size: 22px;
    padding: 5px 8px 6px;
  }

  .controls {
    gap: 5px;
  }

  .controls-bar {
    gap: 6px;
  }

  .ctrl-btn {
    min-height: 46px;
    padding: 6px 3px;
  }

  .hero-roster-slot {
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 360px) {
  /* iPhone SE 1st-gen ≈ 320pt; older devices */
  .hud-bar {
    flex-wrap: wrap;
  }

  .hud-state {
    display: none;
  }

  .level-panel {
    top: 96px;
    bottom: 86px;
  }

  .level-cards {
    gap: 7px;
  }

  .upgrade-card {
    min-height: 212px;
    grid-template-rows: 16px 62px 14px minmax(34px, auto) 30px;
    padding: 8px 6px;
    gap: 5px;
  }

  .upgrade-card::before {
    inset: 18px 0 auto 0;
    width: 92px;
    height: 92px;
  }

  .upgrade-name {
    font-size: 12px;
  }

  .upgrade-effect {
    -webkit-line-clamp: 2;
    font-size: 10px;
  }

  .upgrade-price {
    font-size: 19px;
  }

  .ctrl-btn {
    min-height: 44px;
    grid-template-rows: 16px 11px;
  }

  .ctrl-icon {
    font-size: 13px;
  }

  .ctrl-label {
    font-size: 9px;
  }
}

/* iOS Safari fine-tuning (Touch + WebKit-only properties) */
@supports (-webkit-touch-callout: none) {
  .ctrl-btn,
  .btn,
  .upgrade-card,
  .shop-icon-btn,
  .shop-actions button {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
  /* Lock canvas from rubber-band scroll on iOS */
  canvas {
    overscroll-behavior: contain;
  }
}

/* Landscape phones — keep stage centered, don't crop */
@media (orientation: landscape) and (max-height: 500px) {
  .shell {
    padding: 6px;
  }
  .stage {
    width: min(100vw, calc(100dvh * 9 / 16));
    border-radius: 4px;
  }
}

/* Desktop wide screens — add ambient halo around the centered stage */
@media (min-width: 1024px) {
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background:
      radial-gradient(ellipse 600px 400px at 18% 50%, rgba(124, 232, 255, 0.06), transparent 60%),
      radial-gradient(ellipse 600px 400px at 82% 50%, rgba(217, 122, 255, 0.05), transparent 60%);
  }

  .stage {
    box-shadow:
      0 0 0 1px rgba(124, 232, 255, 0.22),
      0 32px 80px rgba(0, 0, 0, 0.78),
      0 0 120px rgba(124, 232, 255, 0.08),
      0 0 240px rgba(217, 122, 255, 0.05),
      inset 0 0 120px rgba(124, 232, 255, 0.04);
    border-radius: 12px;
  }
}

@media (min-width: 1440px) {
  .stage {
    box-shadow:
      0 0 0 1px rgba(124, 232, 255, 0.28),
      0 40px 100px rgba(0, 0, 0, 0.82),
      0 0 160px rgba(124, 232, 255, 0.10),
      0 0 320px rgba(217, 122, 255, 0.07),
      inset 0 0 120px rgba(124, 232, 255, 0.05);
  }
}
