/* ============================================================================
   Muffin Knight (松饼骑士) — Fairy-Tale Storybook UI Stylesheet
   Zero external fonts/assets (100% offline-ready)
   ============================================================================ */

:root {
  --bg-deep: #0e0a1c;
  --bg-indigo: #1c1538;
  --bg-panel: rgba(25, 19, 48, 0.92);
  --bg-panel-solid: #21193f;
  --parchment-top: #fdf5df;
  --parchment-bot: #f2dfb7;
  --parchment-border: #b9853b;
  --gold-light: #ffe899;
  --gold-main: #f7be38;
  --gold-dark: #b36b11;
  --gold-shadow: #6b3b07;
  --royal-light: #7c67f0;
  --royal-main: #5842c8;
  --royal-dark: #37258c;
  --crimson: #e84855;
  --emerald: #38c172;
  --text-light: #fff9eb;
  --text-muted: #d6c8eb;
  --text-ink: #3b2313;
  --font-display: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--text-light);
  background:
    radial-gradient(circle at 20% 20%, rgba(120, 74, 210, 0.28), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(247, 179, 56, 0.16), transparent 50%),
    linear-gradient(160deg, #0b0816 0%, #17102e 55%, #120c24 100%);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

/* ============================================================================
   Responsive 16:9 Stage Frame (Zero scrollbars on desktop & tablet)
   ============================================================================ */
.app-viewport {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.stage-frame {
  position: relative;
  width: min(calc(100vw - 20px), calc((100vh - 20px) * 16 / 9), 1240px);
  width: min(calc(100vw - 20px), calc((100dvh - 20px) * 16 / 9), 1240px);
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #140f24;
  border: 3px solid rgba(247, 190, 56, 0.72);
  box-shadow:
    0 0 0 1px rgba(255, 232, 153, 0.25) inset,
    0 22px 60px rgba(0, 0, 0, 0.72),
    0 0 36px rgba(247, 190, 56, 0.16);
}

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

/* ============================================================================
   Buttons — Tactile 3D Storybook Arcade Style
   ============================================================================ */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  border-radius: 14px;
  padding: 10px 20px;
  font-family: var(--font-display);
  font-size: clamp(13px, 1.4vw, 16px);
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.1s ease;
  text-decoration: none;
  line-height: 1.15;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.btn-text strong {
  font-size: clamp(14px, 1.55vw, 18px);
  line-height: 1.1;
}

.btn-text small {
  font-size: clamp(9px, 0.85vw, 10px);
  font-weight: 700;
  letter-spacing: 0.09em;
  opacity: 0.82;
}

.btn-icon {
  font-size: clamp(16px, 1.8vw, 22px);
  line-height: 1;
}

.btn-primary {
  color: #421f04;
  background: linear-gradient(180deg, #ffe787 0%, #f9bd33 52%, #e39218 100%);
  border: 2px solid #fff3bf;
  box-shadow: 0 5px 0 #8d4b0a, 0 8px 18px rgba(0, 0, 0, 0.35);
}

.btn-primary:active:not(:disabled) {
  box-shadow: 0 2px 0 #8d4b0a, 0 4px 10px rgba(0, 0, 0, 0.35);
}

.btn-play {
  padding: 11px 28px;
  min-width: clamp(160px, 20vw, 215px);
}

.btn-royal {
  color: #fffaf0;
  background: linear-gradient(180deg, #8b74ff 0%, #6147d8 58%, #4730ab 100%);
  border: 2px solid #c6b8ff;
  box-shadow: 0 5px 0 #2a1a73, 0 8px 18px rgba(0, 0, 0, 0.35);
}

.btn-royal:active:not(:disabled) {
  box-shadow: 0 2px 0 #2a1a73;
}

.btn-parchment {
  color: var(--text-ink);
  background: linear-gradient(180deg, #fff8e6 0%, #f1d9a8 100%);
  border: 2px solid #fff4d1;
  box-shadow: 0 5px 0 #9f7031, 0 8px 18px rgba(0, 0, 0, 0.3);
}

.btn-parchment:active:not(:disabled) {
  box-shadow: 0 2px 0 #9f7031;
}

.btn-ghost {
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.icon-btn {
  width: clamp(32px, 3.2vw, 38px);
  height: clamp(32px, 3.2vw, 38px);
  border-radius: 11px;
  border: 2px solid rgba(255, 232, 163, 0.55);
  background: rgba(25, 18, 49, 0.78);
  color: #fff9eb;
  font-size: clamp(14px, 1.45vw, 18px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(54, 40, 102, 0.92);
  border-color: var(--gold-light);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.icon-btn.active-toggle {
  background: rgba(102, 76, 212, 0.9);
  border-color: var(--gold-main);
  box-shadow: 0 0 10px rgba(247, 190, 56, 0.4), 0 3px 0 rgba(0, 0, 0, 0.45);
}

.icon-btn-gold {
  background: linear-gradient(180deg, #ffe27a 0%, #e59b1e 100%);
  color: #462004;
  border-color: #fff4c2;
}

.upgrade-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ff4769;
  border: 2px solid #fff7e6;
  box-shadow: 0 0 8px rgba(255, 71, 105, 0.85);
  animation: pulseDot 1.3s infinite ease-in-out;
}

/* ============================================================================
   IN-GAME HUD
   ============================================================================ */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: clamp(6px, 1vw, 11px) clamp(10px, 1.4vw, 16px);
  background: linear-gradient(180deg, rgba(16, 11, 34, 0.78) 0%, rgba(16, 11, 34, 0.36) 72%, rgba(16, 11, 34, 0) 100%);
  pointer-events: none;
}

.hud-left,
.hud-center,
.hud-right {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 12px);
}

.hud-center {
  justify-content: center;
}

.hud-right {
  justify-content: flex-end;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.hud-hero-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(24, 18, 48, 0.78);
  border: 2px solid rgba(247, 190, 56, 0.65);
  border-radius: 999px;
  padding: 3px 12px 3px 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.hud-portrait-ring {
  width: clamp(32px, 3.6vw, 44px);
  height: clamp(32px, 3.6vw, 44px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #43327c, #1d1438);
  border: 2px solid var(--gold-light);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#hud-hero-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hud-hero-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hud-hero-name {
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 800;
  color: var(--gold-light);
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.hud-hero-weapon {
  font-size: clamp(9px, 0.9vw, 11px);
  color: #dfd4f8;
  white-space: nowrap;
  opacity: 0.9;
}

.hud-hearts {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(20, 14, 40, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.heart-icon {
  width: clamp(16px, 1.8vw, 22px);
  height: clamp(16px, 1.8vw, 22px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.heart-icon.empty {
  opacity: 0.28;
  filter: grayscale(0.8);
  transform: scale(0.88);
}

.hud-hearts.low-hp .heart-icon.filled {
  animation: heartPulse 0.72s infinite ease-in-out;
}

.muffin-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 16px 4px 11px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 232, 138, 0.98) 0%, rgba(235, 162, 34, 0.96) 100%);
  border: 2px solid #fff8db;
  color: #462004;
  box-shadow: 0 4px 0 #8d4b0a, 0 0 18px rgba(255, 206, 74, 0.45);
}

.muffin-badge.pop {
  animation: badgePop 0.36s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.muffin-icon {
  display: inline-flex;
  align-items: center;
}

.muffin-count {
  font-size: clamp(16px, 2vw, 23px);
  font-weight: 900;
  line-height: 1;
  min-width: 1.3ch;
  text-align: center;
}

.hud-score-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  background: rgba(24, 18, 48, 0.74);
  border: 1.5px solid rgba(255, 232, 153, 0.38);
  border-radius: 12px;
  padding: 4px 10px;
}

.hud-score-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.hud-score-label {
  font-size: clamp(9px, 0.9vw, 11px);
  color: var(--text-muted);
}

.hud-score-val {
  font-size: clamp(12px, 1.35vw, 16px);
  font-weight: 900;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.hud-combo {
  padding: 1px 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7c5c, #d9344c);
  color: #fff;
  font-size: clamp(9px, 0.9vw, 11px);
  font-weight: 900;
  box-shadow: 0 0 8px rgba(255, 92, 92, 0.55);
}

.hud-combo.pop {
  animation: badgePop 0.25s ease;
}

.hud-xp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-level {
  font-size: clamp(9px, 0.9vw, 11px);
  font-weight: 800;
  color: var(--gold-light);
}

.hud-xp-track {
  width: clamp(58px, 7vw, 86px);
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.hud-xp-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5ce1e6 0%, #a5ff90 50%, #ffe066 100%);
  transition: width 0.2s ease-out;
}

/* ============================================================================
   HERO TRANSFORM TOAST
   ============================================================================ */
.transform-toast {
  position: absolute;
  top: clamp(54px, 10.5%, 70px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(35, 23, 72, 0.94) 0%, rgba(69, 41, 133, 0.94) 100%);
  border: 2px solid var(--gold-light);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 20px rgba(247, 190, 56, 0.45);
  pointer-events: none;
  opacity: 0;
}

.transform-toast.show {
  animation: toastSlideIn 0.32s cubic-bezier(0.22, 1.35, 0.36, 1) forwards;
}

.transform-toast.fade-out {
  animation: toastFadeOut 0.28s ease forwards;
}

.toast-portrait-wrap {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle, #513b94, #221647);
  border: 2px solid #fff3bf;
  overflow: hidden;
  flex-shrink: 0;
}

#toast-hero-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.toast-eyebrow {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--gold-light);
}

.toast-main {
  font-size: clamp(13px, 1.4vw, 16px);
  font-weight: 900;
  color: #ffffff;
  white-space: nowrap;
}

.toast-muffin-pill {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--gold-main);
  color: #462004;
  font-size: 11px;
  font-weight: 900;
}

/* ============================================================================
   TOUCH / IPAD VIRTUAL CONTROLS
   ============================================================================ */
.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 22;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: clamp(10px, 2vw, 20px);
  pointer-events: none;
}

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 1.4vw, 14px);
  pointer-events: auto;
}

.touch-btn {
  width: clamp(50px, 6.4vw, 68px);
  height: clamp(50px, 6.4vw, 68px);
  border-radius: 50%;
  border: 2.5px solid rgba(255, 240, 190, 0.65);
  background: rgba(24, 18, 48, 0.48);
  color: rgba(255, 250, 235, 0.92);
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 900;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  touch-action: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.36);
  transition: transform 0.08s ease, background 0.1s ease, border-color 0.1s ease;
}

.touch-down {
  width: clamp(42px, 5vw, 54px);
  height: clamp(42px, 5vw, 54px);
  font-size: clamp(14px, 1.7vw, 18px);
  opacity: 0.85;
}

.touch-fire {
  background: rgba(224, 72, 92, 0.56);
  border-color: rgba(255, 206, 212, 0.78);
}

.touch-jump {
  background: rgba(245, 180, 44, 0.6);
  border-color: rgba(255, 246, 200, 0.85);
  color: #3f1c02;
}

.touch-btn-glyph {
  font-size: clamp(16px, 2vw, 22px);
  line-height: 1;
}

.touch-btn-label {
  font-size: clamp(9px, 0.95vw, 11px);
  font-weight: 800;
  line-height: 1;
}

.touch-btn.pressed {
  transform: scale(0.92);
  background: rgba(255, 222, 118, 0.88);
  border-color: #ffffff;
  color: #3a1a03;
}

/* ============================================================================
   OVERLAYS & MAIN MENU
   ============================================================================ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
}

.menu-overlay {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(10px, 1.8vw, 20px) clamp(14px, 2.4vw, 28px);
  background:
    radial-gradient(ellipse at 50% 34%, rgba(28, 19, 58, 0.42) 0%, rgba(12, 8, 28, 0.78) 100%);
}

.menu-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.menu-stats-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(24, 17, 48, 0.82);
  border: 1.5px solid rgba(255, 232, 153, 0.45);
  font-size: clamp(11px, 1.15vw, 13px);
  color: var(--text-light);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.stat-pill strong {
  color: var(--gold-light);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stat-pill-gold {
  border-color: rgba(255, 215, 92, 0.8);
  background: linear-gradient(180deg, rgba(84, 52, 14, 0.86), rgba(48, 28, 8, 0.9));
}

.stat-pill-muted {
  opacity: 0.9;
}

.menu-utility-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-hero-header {
  text-align: center;
  margin-top: -4px;
}

.title-crest {
  display: inline-flex;
  filter: drop-shadow(0 4px 10px rgba(247, 190, 56, 0.5));
  animation: floatGentle 3.2s infinite ease-in-out;
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(30px, 4.8vw, 56px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.05;
  background: linear-gradient(180deg, #fffbe6 0%, #ffe07d 45%, #f09c1f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #5b2b0a) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.6));
}

.game-subtitle {
  margin-top: 3px;
  font-size: clamp(10px, 1.1vw, 13px);
  font-weight: 800;
  letter-spacing: 0.24em;
  color: #f6e7c8;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.75);
}

/* Stage Selector Cards */
.stage-picker {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

.stage-picker-label {
  text-align: center;
  font-size: clamp(10px, 1vw, 12px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--gold-light);
  margin-bottom: 7px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 1.4vw, 14px);
}

.stage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  border-radius: 15px;
  overflow: hidden;
  border: 2.5px solid rgba(255, 236, 180, 0.35);
  background: rgba(24, 18, 48, 0.86);
  color: var(--text-light);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.42);
}

.stage-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 224, 128, 0.8);
}

.stage-card.selected {
  border-color: #ffe380;
  box-shadow: 0 0 0 2px rgba(255, 227, 128, 0.35), 0 0 22px rgba(247, 190, 56, 0.42), 0 10px 22px rgba(0, 0, 0, 0.5);
  transform: translateY(-2px);
}

.stage-preview {
  position: relative;
  height: clamp(36px, 5.2vw, 56px);
  overflow: hidden;
}

.stage-preview-platform {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 11px;
  border-top: 3px solid;
}

.stage-preview-pit {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 26%;
  height: 11px;
  border-radius: 4px 4px 0 0;
}

.stage-selected-tag {
  position: absolute;
  top: 5px;
  right: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--gold-main);
  color: #462004;
  font-size: 9px;
  font-weight: 900;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.stage-card.selected .stage-selected-tag {
  opacity: 1;
  transform: scale(1);
}

.stage-card-body {
  padding: clamp(7px, 1vw, 11px) clamp(9px, 1.2vw, 12px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.stage-card-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.stage-card-name {
  font-size: clamp(13px, 1.45vw, 16px);
  font-weight: 900;
  color: #fff9ea;
}

.stage-card-best {
  font-size: clamp(10px, 1vw, 12px);
  font-weight: 800;
  color: var(--gold-light);
  white-space: nowrap;
}

.stage-card-sub {
  font-size: clamp(9px, 0.9vw, 11px);
  color: #cbbce8;
  font-weight: 700;
}

.stage-card-desc {
  font-size: clamp(10px, 0.95vw, 11.5px);
  color: #e4ddf5;
  opacity: 0.86;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.menu-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(8px, 1.4vw, 14px);
}

/* ============================================================================
   MODALS — Storybook Parchment & Midnight-Indigo Cards
   ============================================================================ */
.modal-backdrop {
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2vw, 20px);
  background: rgba(9, 6, 22, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.18s ease;
}

.storybook-card {
  position: relative;
  background: linear-gradient(180deg, #2a2050 0%, #1b1436 100%);
  border: 3px solid var(--gold-main);
  border-radius: var(--radius-lg);
  box-shadow:
    0 0 0 1px rgba(255, 240, 186, 0.35) inset,
    0 20px 48px rgba(0, 0, 0, 0.65);
  padding: clamp(14px, 2vw, 22px);
  color: var(--text-light);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  animation: modalPop 0.24s cubic-bezier(0.22, 1.25, 0.36, 1);
}

.modal-sm {
  width: min(370px, 92%);
  text-align: center;
}

.modal-md {
  width: min(500px, 94%);
  text-align: center;
}

.modal-lg {
  width: min(840px, 96%);
  height: min(585px, 94%);
  padding: clamp(12px, 1.6vw, 18px);
}

.card-ribbon {
  display: inline-block;
  margin: 0 auto 6px;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(247, 190, 56, 0.2);
  border: 1px solid rgba(247, 190, 56, 0.6);
  color: var(--gold-light);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.modal-title {
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
}

.modal-title-en {
  font-size: clamp(9px, 0.9vw, 11px);
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #cabce8;
}

.modal-subtitle {
  margin-top: 4px;
  font-size: clamp(12px, 1.2vw, 14px);
  color: #e0d5f5;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid rgba(255, 232, 153, 0.22);
  flex-shrink: 0;
}

.modal-header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.close-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid rgba(255, 232, 153, 0.45);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

.close-btn:hover {
  background: rgba(232, 72, 85, 0.78);
  border-color: #ffd0d5;
}

.modal-stack-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-row-actions {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-footer-center {
  margin-top: 10px;
  text-align: center;
  flex-shrink: 0;
}

/* ============================================================================
   GAME OVER MODAL
   ============================================================================ */
.new-record-badge {
  display: inline-block;
  margin: 0 auto 6px;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff6b6b, #ffd93d, #ff6b6b);
  background-size: 200% auto;
  color: #461702;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 0 18px rgba(255, 217, 61, 0.65);
  animation: shimmer 2s linear infinite;
}

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

.go-stat-box {
  background: rgba(14, 10, 30, 0.62);
  border: 1.5px solid rgba(255, 232, 153, 0.25);
  border-radius: 12px;
  padding: 10px 6px;
}

.go-stat-featured {
  background: linear-gradient(180deg, rgba(247, 190, 56, 0.24), rgba(179, 107, 17, 0.22));
  border-color: rgba(255, 224, 118, 0.8);
}

.go-stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.go-stat-value {
  margin-top: 4px;
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.go-stat-featured .go-stat-value {
  color: var(--gold-light);
}

.go-gold-banner {
  margin-top: 12px;
  padding: 9px 14px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(132, 80, 14, 0.48), rgba(92, 54, 12, 0.68));
  border: 1.5px solid rgba(247, 190, 56, 0.55);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: clamp(12px, 1.2vw, 14px);
}

.go-gold-banner strong {
  color: var(--gold-light);
  font-size: 1.1em;
}

/* ============================================================================
   UPGRADES & HERO CODEX TABS
   ============================================================================ */
.tab-bar {
  display: flex;
  gap: 8px;
  margin: 8px 0;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 8px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255, 232, 153, 0.25);
  background: rgba(14, 10, 30, 0.55);
  color: #d6c8eb;
  font-family: var(--font-display);
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tab-btn small {
  font-weight: 700;
  opacity: 0.75;
  margin-left: 4px;
}

.tab-btn.active {
  background: linear-gradient(180deg, #fff6db 0%, #f0d7a2 100%);
  border-color: #fff9e8;
  color: var(--text-ink);
  box-shadow: 0 3px 0 #9f7031;
}

.tab-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.tab-panel::-webkit-scrollbar {
  width: 6px;
}

.tab-panel::-webkit-scrollbar-thumb {
  background: rgba(247, 190, 56, 0.45);
  border-radius: 999px;
}

/* Upgrades Grid */
.upgrades-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.upgrade-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(253, 245, 223, 0.96) 0%, rgba(240, 219, 175, 0.96) 100%);
  border: 2px solid var(--parchment-border);
  color: var(--text-ink);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.upgrade-card.purchased-flash {
  animation: badgePop 0.35s ease;
}

.upgrade-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.upgrade-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(180deg, #35256b, #201545);
  border: 2px solid var(--gold-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  flex-shrink: 0;
}

.upgrade-info {
  flex: 1;
  min-width: 0;
}

.upgrade-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.upgrade-name {
  font-size: clamp(14px, 1.4vw, 16px);
  font-weight: 900;
  color: #361c0a;
}

.upgrade-lvl-text {
  font-size: 11px;
  font-weight: 800;
  color: #7c4c1b;
}

.upgrade-desc {
  margin-top: 2px;
  font-size: clamp(11px, 1vw, 12.5px);
  color: #5c3c20;
  line-height: 1.35;
}

.upgrade-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.level-pips {
  display: flex;
  align-items: center;
  gap: 5px;
}

.level-pip {
  width: 22px;
  height: 9px;
  border-radius: 999px;
  background: rgba(91, 56, 22, 0.22);
  border: 1px solid rgba(91, 56, 22, 0.35);
}

.level-pip.filled {
  background: linear-gradient(90deg, #f59e0b, #ffd54f);
  border-color: #9e5308;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.55);
}

.upgrade-buy-btn {
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: 10px;
  white-space: nowrap;
}

.upgrade-max-tag {
  padding: 5px 12px;
  border-radius: 10px;
  background: rgba(56, 193, 114, 0.2);
  border: 1.5px solid #2b8a53;
  color: #176138;
  font-size: 12px;
  font-weight: 900;
}

/* Heroes Codex Grid */
.heroes-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.hero-codex-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 8px;
  border-radius: 13px;
  background: rgba(16, 11, 34, 0.72);
  border: 2px solid rgba(255, 232, 153, 0.3);
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.hero-codex-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold-light);
}

.hero-codex-portrait {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.18), rgba(14, 10, 32, 0.92));
  border: 2.5px solid var(--gold-main);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 5px;
}

.hero-codex-portrait canvas {
  width: 54px;
  height: 54px;
  display: block;
}

.hero-codex-name {
  font-size: 13px;
  font-weight: 900;
  color: #fff8e6;
}

.hero-codex-en {
  font-size: 9.5px;
  font-weight: 700;
  color: #bfaee3;
}

.hero-codex-weapon {
  margin-top: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  background: rgba(247, 190, 56, 0.18);
  border: 1px solid rgba(247, 190, 56, 0.55);
  color: var(--gold-light);
}

.hero-codex-desc {
  margin-top: 4px;
  font-size: 10.5px;
  color: #ddd4f3;
  line-height: 1.3;
}

/* ============================================================================
   CONTROLS HELP MODAL
   ============================================================================ */
.controls-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

.section-heading {
  font-size: 14px;
  font-weight: 900;
  color: var(--gold-light);
  margin-bottom: 8px;
}

.key-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.key-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(12, 8, 26, 0.62);
  border: 1px solid rgba(255, 232, 153, 0.2);
}

.key-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 11px;
  color: #cbbce8;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  background: linear-gradient(180deg, #fff9e8, #e6cf9d);
  color: #3a1f0b;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 900;
  border: 1px solid #fff;
  box-shadow: 0 2px 0 #8f6328;
}

.key-desc {
  font-size: 12px;
  color: #f3ecff;
  text-align: right;
}

.tip-box {
  padding: 9px 11px;
  border-radius: 11px;
  margin-bottom: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  background: rgba(12, 8, 26, 0.62);
  border-left: 4px solid var(--gold-main);
}

.tip-box > strong {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-light);
  font-size: 12.5px;
}

.tip-box p strong {
  color: #fff3bf;
  font-weight: 900;
}

.tip-pit {
  border-left-color: #ff6243;
  background: rgba(88, 22, 18, 0.42);
}

.tip-pit > strong {
  color: #ffad87;
}

.tip-touch {
  border-left-color: #62d4ff;
}

.tip-touch > strong {
  color: #9de6ff;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */
@keyframes floatGentle {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
}

@keyframes badgePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(255, 70, 90, 0.5)); }
  50% { transform: scale(1.24); filter: drop-shadow(0 0 8px rgba(255, 70, 90, 0.95)); }
}

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

@keyframes toastSlideIn {
  0% { opacity: 0; transform: translate(-50%, -14px) scale(0.9); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@keyframes toastFadeOut {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(0.95); }
}

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

@keyframes modalPop {
  0% { opacity: 0; transform: scale(0.92) translateY(8px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes shimmer {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* ============================================================================
   RESPONSIVE TWEAKS FOR COMPACT TABLETS / SMALL SCREENS
   ============================================================================ */
@media (max-width: 780px) {
  .app-viewport {
    padding: 4px;
  }

  .stage-frame {
    width: min(calc(100vw - 8px), calc((100dvh - 8px) * 16 / 9));
    border-radius: 12px;
    border-width: 2px;
  }

  .hud-hero-weapon,
  .stage-card-desc {
    display: none;
  }

  .heroes-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .upgrades-grid,
  .controls-body {
    grid-template-columns: 1fr;
  }

  .gameover-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
