* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body, html {
  width: 100%;
  height: 100%;
  height: 100dvh; /* Modern mobile viewport height */
  overflow: hidden;
  position: fixed; /* Prevent mobile rubber-banding */
  background-color: #1a2129;
  touch-action: none; /* Block browser gestures, pull-to-refresh & pinch */
  overscroll-behavior: none;
}

#game-container {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  touch-action: none;
}

/* --- HUD Top Bar --- */
#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: none;
  gap: 8px;
}

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

.hud-pill {
  background: rgba(18, 25, 33, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 30px;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}

.gold-icon {
  font-size: 1.25rem;
  filter: drop-shadow(0 2px 4px rgba(255, 215, 0, 0.5));
}

#money-value {
  color: #ffd700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}

.cart-icon {
  font-size: 1.2rem;
}

.cart-progress-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 75px;
}

.cart-text-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #b0bec5;
}

.cart-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  overflow: hidden;
}

#cart-fill-bar {
  width: 0%;
  height: 100%;
  background: #00e5ff;
  border-radius: 4px;
  transition: width 0.2s ease-out, background-color 0.2s;
}

/* Action Buttons */
.btn-pill {
  background: linear-gradient(135deg, #00c853, #64dd17);
  border: none;
  color: #fff;
  font-weight: 800;
  padding: 8px 16px;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 200, 83, 0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn-pill:active {
  transform: scale(0.92);
}

.btn-icon-only {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(18, 25, 33, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
}

/* --- Controls Tutorial / Bottom Hint --- */
#bottom-hint {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 15, 20, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 16px;
  border-radius: 20px;
  color: #cfd8dc;
  font-size: 0.85rem;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* --- Floating Toast ($+12) --- */
#floating-toast {
  position: absolute;
  top: 75px;
  left: 24px;
  font-size: 1.4rem;
  font-weight: 900;
  color: #76ff03;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: translateY(0);
  pointer-events: none;
  z-index: 20;
}

#floating-toast.active {
  animation: floatUpFade 0.9s ease-out forwards;
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-20px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1);
  }
}

/* --- Whip Hit Screen Flash & Alert --- */
#whip-flash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  box-shadow: inset 0 0 100px 30px rgba(255, 23, 68, 0.85);
  pointer-events: none;
  z-index: 400;
  opacity: 0;
  transition: opacity 0.08s ease-out;
}

#whip-flash-overlay.flash {
  opacity: 1;
}

#whip-hit-text {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: rgba(213, 0, 0, 0.9);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 900;
  padding: 10px 22px;
  border-radius: 30px;
  border: 2px solid #ffd700;
  box-shadow: 0 10px 30px rgba(213, 0, 0, 0.6);
  z-index: 450;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.15s;
  white-space: nowrap;
}

#whip-hit-text.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

/* --- Big Announcement Banner --- */
#announcement-banner {
  position: absolute;
  top: 80px;
  left: 50%;
  width: 90%;
  max-width: 480px;
  text-align: center;
  transform: translateX(-50%) translateY(-20px);
  background: linear-gradient(135deg, rgba(255, 111, 0, 0.95), rgba(255, 171, 0, 0.95));
  color: #ffffff;
  font-weight: 900;
  font-size: 1rem;
  padding: 10px 20px;
  border-radius: 30px;
  box-shadow: 0 10px 30px rgba(255, 111, 0, 0.4);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

#announcement-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Boss Li 3D Floating Speech Bubble --- */
#boss-speech-bubble {
  position: absolute;
  top: -999px;
  left: -999px;
  transform: translate(-50%, -100%) translateY(-18px);
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid #ffd700;
  border-radius: 16px;
  padding: 8px 14px;
  max-width: 240px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6), 0 0 15px rgba(255, 215, 0, 0.3);
  z-index: 150;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.1s ease-out;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.boss-avatar-badge {
  font-size: 0.72rem;
  font-weight: 800;
  color: #ffd700;
  background: rgba(255, 215, 0, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
  align-self: flex-start;
  letter-spacing: 0.3px;
}

#boss-speech-text {
  font-size: 0.88rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.speech-tail {
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 9px solid #ffd700;
}

/* --- Player Floating Nametag (高工) --- */
#player-nametag {
  position: absolute;
  top: -999px;
  left: -999px;
  transform: translate(-50%, -100%) translateY(-14px);
  background: rgba(18, 25, 33, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 229, 255, 0.5);
  border-radius: 20px;
  padding: 3px 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 229, 255, 0.3);
  z-index: 140;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.nametag-icon {
  font-size: 0.95rem;
}

.nametag-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: #00e5ff;
  letter-spacing: 0.5px;
}

.buff-badge {
  font-size: 0.68rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ffd600, #ff6d00);
  color: #212121;
  padding: 1px 6px;
  border-radius: 8px;
  display: none;
  animation: pulseBuff 0.8s infinite alternate;
}

.buff-badge.active {
  display: inline-block;
}

@keyframes pulseBuff {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.08); }
}

/* --- Dynamic Virtual Touch Joystick --- */
#joystick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  margin-left: -60px;
  margin-top: -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(0, 229, 255, 0.4);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.25);
  pointer-events: none;
  z-index: 100;
  display: none;
}

#joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  margin-top: -26px;
  border-radius: 50%;
  background: radial-gradient(circle, #00e5ff 0%, #0091ea 100%);
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.9);
}

/* --- Upgrade Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  background: #1e2730;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  color: #fff;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffd600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-btn {
  background: none;
  border: none;
  color: #90a4ae;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 4px;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}

.upgrade-card {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 14px;
  gap: 12px;
  transition: background 0.15s;
}

.upgrade-card.affordable {
  border-color: rgba(0, 229, 255, 0.4);
}

.card-icon {
  font-size: 1.8rem;
}

.card-info {
  flex: 1;
}

.card-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #eceff1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-title .lvl {
  font-size: 0.7rem;
  background: #37474f;
  padding: 2px 6px;
  border-radius: 8px;
  color: #00e5ff;
}

.card-desc {
  font-size: 0.75rem;
  color: #90a4ae;
  margin-top: 2px;
}

.buy-btn {
  background: linear-gradient(135deg, #ffd600, #ffab00);
  color: #212121;
  font-weight: 800;
  font-size: 0.9rem;
  border: none;
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 214, 0, 0.3);
  transition: transform 0.1s;
  min-width: 75px;
}

.buy-btn:active {
  transform: scale(0.92);
}

.buy-btn.disabled {
  background: #37474f;
  color: #78909c;
  box-shadow: none;
  cursor: not-allowed;
}

/* --- Mobile Responsive Media Queries --- */
@media (max-width: 600px) {
  #hud {
    gap: 6px;
  }

  .hud-pill {
    padding: 6px 10px;
    font-size: 0.9rem;
    gap: 6px;
  }

  .gold-icon, .cart-icon {
    font-size: 1.1rem;
  }

  #money-value {
    font-size: 1.05rem;
  }

  .cart-progress-container {
    min-width: 55px;
  }

  .cart-text-row {
    font-size: 0.7rem;
  }

  .btn-pill {
    padding: 7px 12px;
    font-size: 0.85rem;
  }

  .btn-icon-only {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  #bottom-hint {
    font-size: 0.78rem;
    padding: 5px 12px;
  }

  .modal-card {
    max-height: 85vh;
    padding: 16px;
  }
}
