:root {
  --bg-dark: #0b0f19;
  --bg-card: rgba(22, 28, 45, 0.75);
  --bg-card-hover: rgba(30, 39, 64, 0.85);
  --border-color: rgba(255, 255, 255, 0.1);
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-gold: #f59e0b;
  --accent-gem: #ec4899;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --font-heading: 'Space Grotesk', sans-serif;
  --font-body: 'Outfit', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: radial-gradient(circle at top, #1e1b4b 0%, #0b0f19 70%);
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-ring {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.user-text {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.user-sub {
  font-size: 11px;
  color: var(--text-sub);
}

.currencies {
  display: flex;
  gap: 8px;
}

.currency-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 20px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--border-color);
}

.gold-badge {
  color: var(--accent-gold);
}

.gem-badge {
  color: var(--accent-gem);
}

/* Wave Banner */
.wave-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.wave-progress-container {
  flex: 1;
}

.wave-title {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent-cyan);
  margin-bottom: 3px;
}

.wave-bar-bg {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.wave-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  transition: width 0.3s ease;
  border-radius: 4px;
}

.speed-badge {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Main Content Body */
.content-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  height: 100%;
  width: 100%;
  overflow-y: auto;
  padding: 12px;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* Panel 1: Battle View */
#panel-battle {
  padding: 0;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
  background: #000;
}

#canvas-container {
  width: 100%;
  height: 100%;
}

.boss-alert-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(239, 68, 68, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse-bg 1s infinite alternate;
  z-index: 5;
}

.boss-alert-box {
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--accent-red);
  padding: 16px 24px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

.boss-alert-box h2 {
  font-family: var(--font-heading);
  color: var(--accent-red);
  font-size: 20px;
}

/* Game Over / Victory Modal */
.game-over-overlay, .modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.modal-card {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-card h2 {
  font-family: var(--font-heading);
  color: var(--accent-gold);
  margin-bottom: 8px;
}

.reward-preview {
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  border-radius: 12px;
  margin: 16px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gem-val {
  font-weight: 700;
  color: var(--accent-gem);
}

/* In-Round Upgrades Grid */
.upgrades-panel {
  flex: 1;
  background: rgba(11, 15, 25, 0.85);
  padding: 12px;
  overflow-y: auto;
}

.panel-header-title {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-sub);
  margin-bottom: 8px;
}

.upgrades-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.coin-svg {
  vertical-align: middle;
  display: inline-block;
}

.upg-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.upg-card:active {
  transform: scale(0.97);
  background: var(--bg-card-hover);
}

.upg-card.unaffordable {
  opacity: 0.45;
  filter: grayscale(0.5);
}

.upg-cost {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
}

.upg-icon {
  font-size: 22px;
}

.upg-details {
  flex: 1;
}

.upg-name {
  font-size: 12px;
  font-weight: 600;
}

.lvl-badge {
  font-size: 10px;
  color: var(--accent-cyan);
}

.upg-effect {
  font-size: 11px;
  color: var(--text-sub);
}

.upg-cost {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-gold);
}

/* Generic Section Titles */
.section-title {
  margin-bottom: 16px;
}

.section-title h2 {
  font-family: var(--font-heading);
  font-size: 20px;
}

.section-title p {
  font-size: 12px;
  color: var(--text-sub);
}

/* Talents & Shop Lists */
.talents-list, .shop-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.talent-item, .shop-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.item-icon {
  font-size: 28px;
}

.item-info {
  flex: 1;
}

.item-title {
  font-weight: 700;
  font-size: 14px;
}

.item-desc {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 2px;
}

/* Referrals Card */
.ref-card-main {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(6, 182, 212, 0.15));
  border: 1px solid var(--accent-cyan);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
}

.ref-banner-icon {
  font-size: 36px;
  margin-bottom: 4px;
}

.ref-input-box {
  display: flex;
  gap: 6px;
  margin: 12px 0;
}

.ref-input-box input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 12px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  padding: 0 12px;
  color: white;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  color: white;
  font-family: var(--font-heading);
  font-weight: 700;
  border: none;
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.3);
}

.ref-stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.stat-val {
  display: block;
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-cyan);
}

.stat-lbl {
  font-size: 11px;
  color: var(--text-sub);
}

.sub-list-title {
  font-size: 13px;
  margin-bottom: 8px;
}

.ref-tree-list, .leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leader-row {
  display: flex;
  align-items: center;
  padding: 10px;
  background: var(--bg-card);
  border-radius: 10px;
  gap: 10px;
}

.leader-rank {
  font-family: var(--font-heading);
  font-weight: 700;
  width: 24px;
  color: var(--accent-gold);
}

.leader-name {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
}

.leader-wave {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--accent-cyan);
}

/* Offline Modal Specifics */
.offline-card {
  border-color: var(--accent-gold);
}

.offline-icon {
  font-size: 40px;
}

.offline-rewards {
  background: rgba(245, 158, 11, 0.1);
  border: 1px dashed var(--accent-gold);
  padding: 12px;
  border-radius: 12px;
  margin: 12px 0 20px 0;
}

.off-reward-item {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  margin: 4px 0;
}

/* Bottom Navigation Bar */
.app-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(11, 15, 25, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  padding: 6px 0;
  z-index: 10;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-icon {
  font-size: 20px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
}

.nav-btn.active {
  color: var(--accent-cyan);
}

.hidden {
  display: none !important;
}

@keyframes pulse-bg {
  0% { background: rgba(239, 68, 68, 0.15); }
  100% { background: rgba(239, 68, 68, 0.35); }
}
