:root {
  --bg: #0b101b;
  --surface: #131c2e;
  --surface-2: #1b2740;
  --border: #2a3a5c;
  --text: #eef2ff;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --accent: #f97316;
  --success: #22c55e;
  --danger: #ef4444;
  --gold: #eab308;
  --epic: #a855f7;
  --legendary: #f59e0b;
  --elite: #ec4899;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #17233c, #070b13 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }

.app-shell {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Auth */
.auth-hero {
  text-align: center;
  padding: 36px 20px 16px;
}
.brand-logo { width: 76px; height: 76px; margin-bottom: 10px; }
.auth-hero h1 { margin: 0; font-size: 1.65rem; letter-spacing: 0.3px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }
.auth-card { margin: 16px; }

/* Cards & Inputs */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.highlight-card {
  background: linear-gradient(145deg, #162238, #11192b);
  border-color: #38bdf855;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.05rem; }

.stack-md { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.inline-field { flex: 1; min-width: 170px; }
.field input, .field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
}

/* Buttons */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  color: #08101c;
  background: #cbd5e1;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #05131f; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.btn.full { width: 100%; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
}

.tabs-inline { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs-inline.scrollable { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; margin-bottom: 10px; }
.pill-btn {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn.active { background: var(--primary); color: #05131f; border-color: var(--primary); }

.divider {
  display: flex; align-items: center; text-align: center;
  color: var(--muted); font-size: 0.8rem; margin: 12px 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; border-bottom: 1px solid var(--border);
}
.divider span { padding: 0 10px; }

/* Top Bar */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(19, 28, 46, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.player-id-block { display: flex; flex-direction: column; gap: 2px; min-width: 85px; }
.player-id-block strong { font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.currency-strip { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.75rem;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: fit-content;
}
.badge.rank { color: var(--gold); border-color: #eab30855; }

/* Main & Bottom Nav */
.main-content {
  flex: 1;
  padding: 12px 12px 84px;
  overflow-y: auto;
}
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  max-width: 478px;
  background: rgba(19, 28, 46, 0.98);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 4px 0;
}
.nav-btn span { font-size: 0.7rem; font-weight: 600; }
.nav-btn.active { color: var(--primary); }

/* Stats & Grids */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
}
.stat-box span { display: block; color: var(--muted); font-size: 0.72rem; }

.team-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.unit-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.unit-card.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.unit-title { font-weight: 700; font-size: 0.88rem; }
.unit-meta { font-size: 0.75rem; color: var(--muted); }
.rarity-Common { color: #cbd5e1; }
.rarity-Rare { color: #38bdf8; }
.rarity-Epic { color: var(--epic); }
.rarity-Legendary { color: var(--legendary); }
.rarity-Elite { color: var(--elite); }

.collection-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

/* Summon */
.summon-actions { display: flex; flex-direction: column; gap: 10px; }
.summon-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px; }
.summon-btn small { font-weight: 400; opacity: 0.85; font-size: 0.76rem; }
.summon-reveal {
  margin-top: 14px;
  padding: 16px;
  border-radius: 12px;
  border: 2px solid var(--primary);
  background: #0e172a;
  text-align: center;
  animation: popIn 0.25s ease;
}
@keyframes popIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Progress & Results */
.progress-wrap { margin-top: 12px; }
.progress-label { font-size: 0.82rem; color: var(--primary); margin-bottom: 6px; }
.progress-bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width 0.2s linear; }

.result-box {
  margin-top: 10px;
  background: #0d1424;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.muted { color: var(--muted); font-size: 0.85rem; margin: 4px 0; }
.error-text { color: var(--danger); font-size: 0.85rem; margin: 6px 0 0; }

.toast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--primary);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* Visual Battle Arena & Unit Cards */
.unit-card.border-Rare { border-color: #38bdf866; }
.unit-card.border-Epic { border-color: #a855f788; }
.unit-card.border-Legendary { border-color: #f59e0b99; box-shadow: inset 0 0 12px rgba(245, 158, 11, 0.12); }
.unit-card.border-Elite { border-color: #ec4899aa; box-shadow: inset 0 0 14px rgba(236, 72, 153, 0.16); }

.battle-arena {
  margin-top: 12px;
  background: linear-gradient(180deg, #0d1526, #131d33);
  border: 1px solid #38bdf855;
  border-radius: 12px;
  padding: 10px;
}
.arena-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 0.88rem;
}
.arena-sides {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}
.arena-col { display: flex; flex-direction: column; gap: 6px; }
.arena-vs { font-weight: 900; color: var(--accent); font-size: 0.9rem; }
.fighter-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.76rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.fighter-chip.hit {
  transform: scale(0.95);
  border-color: var(--danger);
  background: #3b121c;
}
.hp-bar {
  height: 5px;
  background: #090e18;
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.2s ease;
}
.arena-feed {
  margin-top: 8px;
  font-size: 0.78rem;
  color: #cbd5e1;
  background: #090e18;
  border-radius: 8px;
  padding: 6px 8px;
  min-height: 28px;
}
