:root {
  --bg: #13111c;
  --panel: #1e1a2b;
  --panel-dark: #161322;
  --border: #3a3250;
  --accent: #f59e0b;
  --gem: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --purple: #a855f7;
  --text: #f8fafc;
  --muted: #94a3b8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none;
  overflow-x: hidden;
}

.game-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* HUD BAR */
.hud-bar {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.hud-left, .hud-right {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.logo-pill {
  font-weight: 900; letter-spacing: 0.06em; font-size: 15px;
  background: #2b2340; border: 2px solid #524378; padding: 5px 11px; border-radius: 8px;
  color: #fde047;
}
.stat-pill {
  background: var(--panel-dark);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 5px;
}
.stat-gem {
  border-color: rgba(56,189,248,0.5);
  cursor: pointer;
}
.stat-gem:hover { background: #182638; }
.plus-btn {
  background: var(--gem); color: #0b1120; font-weight: 900;
  width: 18px; height: 18px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; margin-left: 2px;
}
.stat-boss { color: #fca5a5; border-color: rgba(239,68,68,0.4); }

.hud-btn {
  background: #28223a; color: var(--text);
  border: 2px solid #453b63; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: transform 0.08s, background 0.12s;
}
.hud-btn:hover { background: #362e4f; }
.hud-btn:active { transform: translateY(1px); }
.hud-btn-donate {
  background: linear-gradient(135deg, #d97706, #b45309);
  border-color: #fbbf24; color: #fff;
  box-shadow: 0 0 14px rgba(245,158,11,0.35);
}
.hud-btn-donate:hover { background: linear-gradient(135deg, #f59e0b, #d97706); }
.vip-tag {
  background: #fef08a; color: #713f12; font-size: 10px;
  padding: 1px 5px; border-radius: 4px; margin-left: 4px; font-weight: 900;
}

/* MAIN GRID */
.main-grid {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 14px;
  align-items: start;
}

/* SLOT MACHINE */
.slot-column {
  background: #2c2438;
  border: 3px solid #52456b;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.slot-column.skin-demon {
  background: #2b151c; border-color: #dc2626;
  box-shadow: 0 0 28px rgba(220,38,38,0.35);
}
.slot-column.skin-gold {
  background: #2d2514; border-color: #facc15;
  box-shadow: 0 0 28px rgba(250,204,21,0.3);
}
.slot-column.skin-cyber {
  background: #101b2e; border-color: #22d3ee;
  box-shadow: 0 0 28px rgba(34,211,238,0.35);
}

.machine-crown {
  background: rgba(0,0,0,0.35);
  border-bottom: 2px solid rgba(255,255,255,0.08);
  padding: 10px 14px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.skull-icon { font-size: 22px; }
.machine-title { font-weight: 900; font-size: 14px; letter-spacing: 0.08em; color: #e2e8f0; }

.machine-body {
  padding: 12px 14px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.cost-bar {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: #cbd5e1;
  background: rgba(0,0,0,0.28); padding: 6px 10px; border-radius: 8px;
}
.free-spins-badge { color: #86efac; font-size: 12px; }

.reels-wrapper {
  display: grid;
  grid-template-columns: 1fr 28px;
  gap: 8px;
  align-items: center;
}
.reels-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #14101d;
  border: 3px solid #483d60;
  border-radius: 10px;
  padding: 8px;
}
.reel-cell {
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 42%, #f4ebd8, #d9c7a3);
  border: 3px solid #6b563c;
  box-shadow: inset 0 3px 6px rgba(0,0,0,0.28), inset 0 -2px 0 rgba(255,255,255,0.45);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s, box-shadow 0.15s;
}
.reel-img {
  image-rendering: pixelated;
  width: 68px; height: 68px;
  object-fit: contain;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,0.35));
}
.roster-avatar {
  width: 28px; height: 28px;
  image-rendering: pixelated;
  object-fit: contain;
}
.codex-sprite {
  width: 58px; height: 58px;
  image-rendering: pixelated;
  object-fit: contain;
  background: rgba(0,0,0,0.35);
  border: 1.5px solid #41375c;
  border-radius: 10px;
  padding: 4px;
}
.merchant-banner-wrap {
  width: 100%;
  height: 155px;
  overflow: hidden;
  border-bottom: 2px solid var(--border);
  background: #0d0a14;
}
.merchant-banner {
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}
.reel-cell.spinning {
  filter: blur(1px);
  transform: scale(0.95);
}
.reel-cell.win-normal {
  border-color: #22c55e;
  box-shadow: 0 0 14px rgba(34,197,94,0.85);
  background: #dcfce7;
}
.reel-cell.win-rare {
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(56,189,248,0.9);
  background: #e0f2fe;
}
.reel-cell.win-legendary {
  border-color: #facc15;
  box-shadow: 0 0 20px rgba(250,204,21,0.95);
  background: #fef9c3;
}

.lever-track {
  height: 150px;
  background: #14101d;
  border: 2px solid #483d60;
  border-radius: 14px;
  position: relative;
  cursor: pointer;
}
.lever-shaft {
  width: 6px; height: 64px; background: #94a3b8;
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  border-radius: 3px; transition: top 0.16s ease;
}
.lever-knob {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f87171, #b91c1c);
  border: 2px solid #fecaca;
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  transition: top 0.16s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.lever-track.pulled .lever-knob { top: 106px; }
.lever-track.pulled .lever-shaft { top: 52px; }

.spin-actions { display: flex; flex-direction: column; gap: 7px; }
.btn-spin {
  width: 100%; padding: 12px; border-radius: 10px;
  background: linear-gradient(180deg, #22c55e, #15803d);
  border: 2px solid #86efac; color: #fff;
  font-size: 15px; font-weight: 900; letter-spacing: 0.03em;
  cursor: pointer; box-shadow: 0 4px 0 #14532d;
}
.btn-spin:hover { filter: brightness(1.08); }
.btn-spin:active { transform: translateY(2px); box-shadow: 0 2px 0 #14532d; }
.btn-spin:disabled { opacity: 0.55; cursor: not-allowed; }

.spin-subrow { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.btn-gold-spin {
  padding: 9px 10px; border-radius: 9px;
  background: linear-gradient(180deg, #0284c7, #0369a1);
  border: 2px solid #7dd3fc; color: #fff;
  font-size: 12.5px; font-weight: 800; cursor: pointer;
}
.btn-gold-spin:hover { filter: brightness(1.1); }
.btn-autospin {
  padding: 9px 12px; border-radius: 9px;
  background: #27213a; border: 2px solid #4c406e; color: #cbd5e1;
  font-size: 12.5px; font-weight: 800; cursor: pointer;
}
.btn-autospin.active { background: #4c1d95; border-color: #c084fc; color: #fff; }

.relics-section {
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 8px 10px;
}
.relics-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; font-weight: 800; color: var(--muted); margin-bottom: 7px;
}
.mini-link {
  background: none; border: none; color: #fbbf24; font-size: 11.5px; font-weight: 700; cursor: pointer;
}
.relics-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
}
.relic-slot {
  aspect-ratio: 1; border-radius: 8px;
  background: #14101d; border: 2px dashed #3b3252;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 20px; position: relative; cursor: pointer;
}
.relic-slot.filled {
  border-style: solid; border-color: #a855f7; background: #231936;
}
.relic-slot.ready {
  border-color: #facc15; box-shadow: 0 0 10px rgba(250,204,21,0.5);
}
.relic-slot .relic-tag {
  font-size: 9px; color: #cbd5e1; font-weight: 700; margin-top: 2px;
}

.daily-chest-btn {
  width: 100%; padding: 9px; border-radius: 9px;
  background: rgba(245,158,11,0.14); border: 1px solid rgba(245,158,11,0.5);
  color: #fde68a; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.daily-chest-btn:disabled { opacity: 0.45; cursor: default; }

/* ARENA */
.arena-column {
  display: flex; flex-direction: column; gap: 10px;
}
.arena-frame {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
}
.world-banner {
  background: #161322;
  padding: 8px 14px;
  border-bottom: 2px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 800; color: #e2e8f0;
}
.wave-badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: rgba(99,102,241,0.2); color: #a5b4fc;
}
.wave-badge.combat { background: rgba(239,68,68,0.22); color: #fca5a5; }

.boss-bar-wrap {
  position: absolute; top: 48px; left: 50%; transform: translateX(-50%);
  width: 68%; z-index: 5; text-align: center;
}
.boss-name {
  font-size: 13px; font-weight: 900; color: #fecaca;
  text-shadow: 0 2px 6px #000; margin-bottom: 4px;
}
.boss-bar-bg {
  height: 14px; background: #0f172a; border: 2px solid #ef4444;
  border-radius: 7px; overflow: hidden;
}
.boss-bar-fill {
  height: 100%; background: linear-gradient(90deg, #dc2626, #f97316);
  transition: width 0.12s;
}

.summon-banner {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,0.92); border: 2px solid #facc15;
  color: #fef08a; padding: 7px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 800; z-index: 6; pointer-events: none;
  box-shadow: 0 8px 22px rgba(0,0,0,0.6);
}

#arenaCanvas {
  display: block; width: 100%; height: auto;
  image-rendering: pixelated;
  background: #1b2432;
}

.arena-footer {
  background: #161322;
  border-top: 2px solid var(--border);
  padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.skills-bar { display: flex; gap: 7px; flex-wrap: wrap; }
.skill-btn {
  padding: 8px 11px; border-radius: 8px;
  background: #252038; border: 2px solid #473c66; color: #e2e8f0;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.skill-btn:hover { background: #332c4d; }
.skill-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-next-wave {
  padding: 10px 20px; border-radius: 10px;
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  border: 2px solid #fca5a5; color: #fff;
  font-size: 14px; font-weight: 900; cursor: pointer;
  box-shadow: 0 3px 0 #7f1d1d;
}
.btn-next-wave:hover { filter: brightness(1.08); }
.btn-next-wave:disabled { opacity: 0.5; cursor: not-allowed; }

.roster-bar {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  min-height: 58px;
}
.roster-empty { color: var(--muted); font-size: 13px; }
.roster-chip {
  background: #151220; border: 1.5px solid #41375c;
  border-radius: 8px; padding: 5px 10px;
  font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
}
.roster-chip.rare { border-color: #38bdf8; }
.roster-chip.legendary { border-color: #facc15; background: #262010; }
.roster-chip .sell-x {
  color: #f87171; cursor: pointer; font-weight: 900; margin-left: 4px;
}

/* MODALS */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,6,12,0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100; backdrop-filter: blur(4px);
}
.modal-box {
  background: #1b1728; border: 2px solid #4d406e;
  border-radius: 16px; width: 100%; max-width: 640px;
  max-height: 88vh; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.7);
}
.modal-wide { max-width: 820px; }
.modal-head {
  padding: 16px 20px; background: #141020; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-close {
  background: #2b243f; border: 1px solid #4a3f68; color: #fff;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}

.gateway-strip {
  padding: 10px 20px; background: #191529; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap;
}
.gateway-strip select {
  background: #0f0d18; color: #fff; border: 1px solid #4a3f68;
  border-radius: 7px; padding: 5px 10px; font-size: 12.5px;
}
.tx-counter { margin-left: auto; color: #86efac; font-weight: 700; }

.modal-tabs {
  display: flex; gap: 6px; padding: 12px 20px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.tab-btn {
  padding: 8px 14px; background: transparent; border: none;
  border-bottom: 3px solid transparent; color: var(--muted);
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.tab-btn.active { color: #fde047; border-bottom-color: #f59e0b; }

.modal-content {
  padding: 18px 20px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px;
}
.offer-card {
  background: #141020; border: 2px solid #393052; border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  position: relative;
}
.offer-card.popular { border-color: #f59e0b; background: #211a14; }
.offer-badge {
  position: absolute; top: -10px; right: 12px;
  background: #f59e0b; color: #1c1917; font-size: 10px; font-weight: 900;
  padding: 2px 8px; border-radius: 999px;
}
.offer-title { font-size: 15px; font-weight: 800; color: #fff; }
.offer-desc { font-size: 12.5px; color: #cbd5e1; line-height: 1.45; }
.offer-price-row { display: flex; align-items: baseline; gap: 8px; }
.offer-price { font-size: 19px; font-weight: 900; color: #fde047; }
.offer-old { font-size: 13px; color: #64748b; text-decoration: line-through; }
.btn-buy {
  width: 100%; padding: 9px; border-radius: 8px;
  background: linear-gradient(180deg, #f59e0b, #d97706);
  border: 1px solid #fde68a; color: #1c1917; font-weight: 900; font-size: 13px; cursor: pointer;
}
.btn-buy:disabled { opacity: 0.45; cursor: default; }
.btn-buy-gem {
  background: linear-gradient(180deg, #38bdf8, #0284c7); color: #fff; border-color: #bae6fd;
}

.shop-footer {
  padding: 12px 20px; border-top: 1px solid var(--border); background: #141020; text-align: right;
}
.btn-reroll {
  padding: 8px 16px; border-radius: 8px; background: #31274a;
  border: 1px solid #63538c; color: #fff; font-weight: 700; cursor: pointer;
}

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: #171326; border: 2px solid #f59e0b; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.18s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .main-grid { grid-template-columns: 1fr; }
}
