:root {
  --bg: #0a0a18;
  --card: #12122a;
  --card2: #1a1a35;
  --accent: #7c3aed;
  --accent2: #5b21b6;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #facc15;
  --ice: #38bdf8;
  --text: #e2e8f0;
  --sub: #94a3b8;
  --border: rgba(255,255,255,0.08);
  --radius: 14px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Screens ── */
.screen { display: none; flex-direction: column; min-height: 100vh; padding-bottom: 64px; }
.screen.active { display: flex; }

/* ── Loading ── */
#screen-loading {
  align-items: center; justify-content: center;
  gap: 16px; padding-bottom: 0;
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Header ── */
.page-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 10px;
  position: sticky; top: 0; z-index: 10;
}
.page-header h1 { font-size: 18px; font-weight: 700; }
.page-header .sub { color: var(--sub); font-size: 12px; margin-top: 2px; }

/* ── Menu screen ── */
#menu-stats {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-pill {
  background: var(--card2);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
}
.stat-pill .val { font-size: 18px; font-weight: 700; }
.stat-pill .lbl { font-size: 11px; color: var(--sub); }
.rank-badge {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.rank-badge .rank { font-size: 20px; font-weight: 800; }
.rank-badge .mult { font-size: 12px; color: rgba(255,255,255,0.75); }

#menu-events {
  padding: 10px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.event-chip {
  background: linear-gradient(90deg, rgba(124,58,237,0.25), rgba(124,58,237,0.05));
  border: 1px solid rgba(124,58,237,0.3);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.event-chip .emins { color: var(--sub); font-size: 11px; }

#menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}
.menu-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.menu-btn:active { background: var(--card2); transform: scale(0.97); }
.menu-btn .ico { font-size: 32px; display: block; margin-bottom: 8px; }
.menu-btn .lbl { font-size: 13px; font-weight: 600; }

/* ── Bottom Nav ── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; cursor: pointer;
  padding: 6px 12px; border-radius: 10px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex: 1;
}
.nav-item.active { background: rgba(124,58,237,0.2); }
.nav-item .nav-ico { font-size: 20px; }
.nav-item .nav-lbl { font-size: 10px; color: var(--sub); }
.nav-item.active .nav-lbl { color: var(--accent); }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 12px 14px; }

/* ── HP bar ── */
.hp-bar-wrap { position: relative; height: 10px; background: #1e1e3a; border-radius: 5px; overflow: hidden; }
.hp-bar-fill {
  height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, var(--red), var(--green));
  transition: width 0.5s ease;
}

/* ── Battle screen ── */
#screen-battle {
  background: var(--bg);
  padding-bottom: 0;
}
.battle-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.battle-header .turn { font-size: 13px; color: var(--sub); }
.battle-header .vs { font-weight: 800; color: var(--accent); font-size: 16px; }

.combatant-card {
  margin: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: box-shadow 0.3s;
}
.combatant-card.hit { animation: shake 0.3s; box-shadow: 0 0 20px rgba(239,68,68,0.4); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.combatant-card .c-name { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.combatant-card .c-unit { font-size: 12px; color: var(--sub); margin-bottom: 10px; }
.combatant-card .c-hp-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.combatant-card .c-hp-txt { font-size: 12px; color: var(--sub); white-space: nowrap; min-width: 60px; text-align: right; }
.combatant-card .c-dmg { font-size: 12px; color: var(--orange); margin-bottom: 8px; }
.combatant-card .c-items { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.item-chip {
  background: var(--card2);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  display: flex; gap: 3px; align-items: center;
}
.item-chip.broken { opacity: 0.4; text-decoration: line-through; }
.combatant-card .c-effects { display: flex; flex-wrap: wrap; gap: 4px; }
.effect-badge {
  padding: 2px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.effect-badge.fire { background: rgba(249,115,22,0.25); color: var(--orange); }
.effect-badge.freeze { background: rgba(56,189,248,0.25); color: var(--ice); }
.effect-badge.boost { background: rgba(250,204,21,0.25); color: var(--yellow); }
.effect-badge.boom { background: rgba(239,68,68,0.25); color: var(--red); }

.hp-loss-flash {
  font-size: 13px; font-weight: 700; color: var(--red);
  animation: fadeUp 0.6s ease forwards;
}
@keyframes fadeUp {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}

.battle-log {
  margin: 0 16px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-height: 120px; overflow-y: auto;
}
.battle-log .log-title { font-size: 11px; color: var(--sub); margin-bottom: 6px; }
.log-line { font-size: 12px; line-height: 1.6; }

.battle-actions { padding: 0 16px 16px; display: flex; gap: 10px; }

/* ── Result overlay ── */
#result-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 24px;
}
#result-overlay.show { display: flex; }
.result-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  width: 100%; max-width: 320px;
}
.result-icon { font-size: 64px; margin-bottom: 12px; }
.result-title { font-size: 24px; font-weight: 800; margin-bottom: 16px; }
.result-title.win { color: var(--yellow); }
.result-title.loss { color: var(--red); }
.result-title.draw { color: var(--blue); }
.result-rewards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.reward-row { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }

/* ── Summon screen ── */
.summon-list { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.summon-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.summon-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.summon-card .balance { font-size: 12px; color: var(--sub); margin-bottom: 12px; }
.summon-card .actions { display: flex; gap: 8px; }

/* ── Gacha animation ── */
#gacha-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 200; gap: 16px;
}
#gacha-overlay.show { display: flex; }
.gacha-card-anim {
  width: 200px; height: 280px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border-radius: 20px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  font-size: 20px; font-weight: 700;
  box-shadow: 0 0 60px rgba(124,58,237,0.6);
  animation: cardReveal 0.5s ease;
}
@keyframes cardReveal {
  from { transform: scale(0.5) rotateY(90deg); opacity: 0; }
  to { transform: scale(1) rotateY(0); opacity: 1; }
}
.gacha-rarity { font-size: 28px; }
.gacha-name { font-size: 16px; text-align: center; padding: 0 12px; }
.gacha-kind { font-size: 12px; color: rgba(255,255,255,0.7); }

.multi-gacha-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 8px; padding: 0 16px;
}
.mini-gacha-card {
  background: var(--card2);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  font-size: 11px;
  animation: cardReveal 0.3s ease;
}
.mini-gacha-card .mgr { font-size: 18px; }

/* ── Inventory screen ── */
.inv-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--card);
}
.inv-tab {
  flex: 1; padding: 12px;
  text-align: center; font-size: 13px; font-weight: 600;
  color: var(--sub); cursor: pointer;
  border-bottom: 2px solid transparent;
}
.inv-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.inv-content { display: none; flex-direction: column; gap: 10px; padding: 14px 16px; }
.inv-content.active { display: flex; }

.unit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.unit-card-header {
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.unit-card-header .uname { font-size: 15px; font-weight: 700; }
.unit-card-header .power { font-size: 12px; color: var(--sub); }
.unit-card-stats {
  padding: 0 14px 12px;
  display: flex; gap: 12px;
}
.unit-card-stats span { font-size: 12px; }
.unit-card-items { padding: 0 14px 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.unit-card-actions { padding: 0 14px 12px; display: flex; gap: 8px; }

.item-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.item-row .slot-ico { font-size: 20px; flex-shrink: 0; }
.item-row .iinfo { flex: 1; }
.item-row .iname { font-size: 13px; font-weight: 600; }
.item-row .istats { font-size: 11px; color: var(--sub); }
.item-row .iequipped { font-size: 11px; color: var(--green); }

/* ── Leaderboard ── */
.lb-list { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.lb-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.lb-row.me { border-color: var(--accent); }
.lb-rank { font-size: 18px; font-weight: 800; width: 28px; text-align: center; }
.lb-name { flex: 1; font-size: 14px; font-weight: 600; }
.lb-cups { font-size: 14px; font-weight: 700; color: var(--yellow); }
.lb-cat { font-size: 11px; color: var(--sub); }

/* ── Clan ── */
.clan-header-card {
  margin: 14px 16px;
  background: linear-gradient(135deg, var(--accent2), #1e1a4e);
  border-radius: var(--radius);
  padding: 20px;
}
.clan-header-card h2 { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.clan-header-card .cdesc { font-size: 13px; color: rgba(255,255,255,0.7); margin-bottom: 12px; }
.clan-members-list { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 16px; }
.clan-member {
  background: var(--card); border-radius: 8px; padding: 8px 12px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.clan-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.clan-section-title { padding: 4px 16px 8px; font-size: 13px; font-weight: 700; color: var(--sub); }
.no-clan-box { text-align: center; padding: 40px 20px; }
.no-clan-box .ico { font-size: 48px; margin-bottom: 12px; }
.no-clan-box p { color: var(--sub); font-size: 14px; margin-bottom: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none; cursor: pointer;
  font-size: 14px; font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.8; transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%);
  background: #1e1e3a; color: var(--text);
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
  z-index: 500;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ── Back button row ── */
.back-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 0;
  cursor: pointer; color: var(--accent); font-size: 14px; font-weight: 600;
}

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--sub); font-size: 14px;
}
.empty-state .ico { font-size: 40px; margin-bottom: 10px; }

/* ── About ── */
.about-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 12px 16px 4px;
}
.about-tab {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--sub); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.about-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.about-text {
  margin: 10px 16px 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}

/* ── PvP wait ── */
.pvp-wait { text-align: center; padding: 30px 20px; }

/* ── Equip overlay ── */
#equip-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 250;
}
#equip-overlay.show { display: flex; }
.equip-box {
  background: var(--card);
  border-top-left-radius: 20px; border-top-right-radius: 20px;
  border: 1px solid var(--border);
  padding: 18px 16px 24px;
  width: 100%; max-width: 520px;
  max-height: 85vh; overflow-y: auto;
}
.equip-title { font-size: 17px; font-weight: 800; margin-bottom: 14px; text-align: center; }
.equip-slots { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.eq-slot {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.eq-slot-head { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.eq-cur {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; font-weight: 600; margin-bottom: 8px;
}
.eq-empty { font-size: 12px; color: var(--sub); margin-bottom: 8px; }
.eq-st { font-size: 11px; color: var(--sub); font-weight: 400; }
.eq-opts { display: flex; flex-direction: column; gap: 6px; }
.eq-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}

/* ── Admin ── */
.adm-sec {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.adm-h { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.adm-in {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
  font-family: inherit;
}
.adm-in:focus { outline: none; border-color: var(--accent); }
