:root {
  --bg-dark: #0b0e17;
  --panel-bg: #151a28;
  --panel-border: #273047;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.4);
  --elixir: #d946ef;
  --gold: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --text: #f1f5f9;
  --muted: #94a3b8;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top, #1a2238 0%, var(--bg-dark) 70%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.screen {
  display: none;
  width: 100%;
}

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

/* MENU SCREEN */
#menu-screen {
  max-width: 1050px;
  padding: 20px;
  gap: 20px;
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 2.4rem;
}

.logo h1 {
  font-size: 1.6rem;
  letter-spacing: 1.5px;
  background: linear-gradient(90deg, #60a5fa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--muted);
}

.menu-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--accent-glow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: #273047;
  color: white;
  border: 1px solid #3b4766;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-icon {
  background: #1e2538;
  border: 1px solid var(--panel-border);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon.small {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
}

.menu-content {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
}

@media (max-width: 820px) {
  .menu-content {
    grid-template-columns: 1fr;
  }
}

.deck-panel, .collection-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-header h2 {
  font-size: 1.1rem;
}

.avg-elixir {
  font-size: 0.9rem;
  color: #e879f9;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.deck-card {
  background: #1e2538;
  border: 2px solid #2e3954;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, border-color 0.12s;
}

.deck-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.deck-card.in-deck {
  border-color: var(--success);
  background: #162a2c;
}

.deck-card.selected-swap {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

.card-cost-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--elixir);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0b0e17;
}

.card-elem-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.75rem;
}

.card-emoji {
  font-size: 1.9rem;
  margin: 6px 0 4px;
}

.card-name {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-type {
  font-size: 0.65rem;
  color: var(--muted);
}

.synergy-bar {
  margin-top: 14px;
  padding: 10px 12px;
  background: #101420;
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* BATTLE SCREEN */
#battle-screen {
  max-width: 500px;
  margin: 0 auto;
  height: 100vh;
  max-height: 920px;
  padding: 8px;
}

.battle-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 8px;
}

.top-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 12px;
}

.player-tag {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-tag .name {
  font-size: 0.82rem;
  font-weight: 700;
}

.player-tag .crowns {
  font-size: 0.8rem;
  color: var(--gold);
}

.match-timer-box {
  text-align: center;
}

#match-timer {
  font-size: 1.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.event-badge {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: #273047;
  color: #93c5fd;
  margin-top: 2px;
}

.arena-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: #111827;
}

#game-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: crosshair;
  display: block;
}

.resonance-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  pointer-events: none;
  animation: popIn 0.25s ease;
}

@keyframes popIn {
  from { opacity: 0; transform: translate(-50%, -10px) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.bottom-hud {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.elixir-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.elixir-bar-bg {
  flex: 1;
  height: 22px;
  background: #0f1320;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  border: 1px solid #2e3954;
}

.elixir-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #a21caf, #ec4899);
  transition: width 0.08s linear;
}

.elixir-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.btn-ultimate {
  background: linear-gradient(135deg, #f59e0b, #dc2626);
  border: none;
  color: white;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-ultimate:disabled {
  background: #1e2538;
  color: var(--muted);
  cursor: not-allowed;
}

.hand-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hand-cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.hand-card {
  background: #1e2538;
  border: 2px solid #334155;
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, border-color 0.1s;
}

.hand-card.selected {
  border-color: var(--gold);
  transform: translateY(-6px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.hand-card.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.next-card-box {
  width: 52px;
  text-align: center;
  background: #101420;
  border-radius: 8px;
  padding: 4px;
  border: 1px solid #273047;
}

.next-label {
  font-size: 0.62rem;
  color: var(--muted);
  display: block;
}

.next-card-mini {
  font-size: 1.3rem;
  margin-top: 2px;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.hidden {
  display: none !important;
}

.modal-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}

.result-icon {
  font-size: 3.5rem;
  margin-bottom: 10px;
}

.result-stats {
  margin: 18px 0;
  background: #101420;
  border-radius: 12px;
  padding: 12px;
  font-size: 0.88rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
