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

:root {
  --bg: #17122b;
  --panel: #221a3a;
  --panel2: #2b2148;
  --border: #453468;
  --gold: #ffcf4d;
  --text: #e8e2f8;
  --dim: #9a8fc0;
  --hp: #57d97a;
  --accent: #8f6bff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  user-select: none;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 2px solid var(--border);
}

#logo { height: 44px; }

#stats { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.icon { width: 22px; height: 22px; }

#resetBtn {
  background: #5a2440; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
#resetBtn:hover { background: #7a3055; }

main {
  display: grid;
  grid-template-columns: 290px 1fr 250px;
  gap: 12px;
  padding: 12px;
  max-width: 1400px;
  margin: 0 auto;
}

aside {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 640px;
  overflow-y: auto;
}
aside h2 { font-size: 14px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- поле боя ---------- */
#battlefield {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 560px;
  background: #000;
}

#bg {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.85);
}

#topControls {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px;
  z-index: 10;
}
#topControls button {
  background: rgba(20, 14, 40, 0.9);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
#topControls button:hover { filter: brightness(1.3); }
#topControls button.stop {
  background: rgba(150, 35, 35, 0.95);
  border-color: #ff6b6b;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 10px rgba(255, 90, 90, 0.5);
}

#enemies {
  position: absolute;
  left: 0; right: 0; bottom: 40px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  padding: 0 20px;
}

.enemy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}
.enemy:hover { transform: scale(1.07); }
.enemy img {
  width: 96px; height: 96px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.6));
}
.enemy.dead { opacity: 0.15; pointer-events: none; transform: translateY(14px) rotate(8deg); }
.enemy.hit img { filter: drop-shadow(0 0 12px #ff5555) brightness(1.6); }
.enemyName { font-size: 12px; color: var(--text); text-shadow: 0 1px 3px #000; }

.hpbar {
  width: 90px; height: 10px;
  background: #111; border: 1px solid #000;
  border-radius: 5px; overflow: hidden;
}
.hpbar.small { height: 8px; width: 100%; }
.hpbar div {
  height: 100%;
  background: linear-gradient(#7cf29c, var(--hp));
  transition: width 0.15s;
}

#fxLayer { position: absolute; inset: 0; pointer-events: none; }
.dmgText {
  position: absolute;
  font-weight: 800; font-size: 18px;
  color: #ffe9a8;
  text-shadow: 0 2px 4px #000;
  animation: rise 0.9s ease-out forwards;
}
.dmgText.crit { color: #ff6a4d; font-size: 24px; }
@keyframes rise {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-46px); opacity: 0; }
}

.goldText {
  position: absolute;
  font-weight: 800; font-size: 18px;
  color: var(--gold);
  text-shadow: 0 2px 4px #000;
  animation: rise 1s ease-out forwards;
  pointer-events: none;
}

.loot {
  position: absolute;
  z-index: 12;
  pointer-events: auto;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  animation: lootpop 0.3s ease-out;
  transition: transform 0.1s;
}
.loot:hover { transform: scale(1.12); }
.loot img { width: 48px; height: 48px; filter: drop-shadow(0 0 8px var(--gold)); }
.lootName {
  font-size: 11px; color: var(--gold); text-shadow: 0 1px 3px #000;
  background: rgba(20,14,40,0.85); border: 1px solid var(--gold);
  border-radius: 6px; padding: 1px 6px;
}
.loot.fading { animation: lootfade 1s ease-out forwards; }
@keyframes lootpop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes lootfade { to { opacity: 0; transform: translateY(-12px); } }

#banner {
  position: absolute;
  top: 56px; left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 14, 40, 0.9);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 8px 18px;
  border-radius: 10px;
  font-weight: 700;
  z-index: 11;
}

/* ---------- карточки героев ---------- */
.heroCard {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  margin-bottom: 8px;
}
.heroCard.active { border-color: var(--accent); box-shadow: 0 0 10px rgba(143,107,255,0.4); }
.heroCard.locked { cursor: default; opacity: 0.85; }
.heroCard.down { border-color: #7a2030; }
.heroCard.down .heroArt { filter: grayscale(1) brightness(0.5); }

.heroPortrait { position: relative; flex-shrink: 0; }
.heroArt { width: 56px; height: 56px; border-radius: 8px; display: block; }
.heroArt.dim { filter: grayscale(1) brightness(0.55); }
.cdSweep {
  position: absolute; inset: 0; border-radius: 8px; pointer-events: none;
  background: transparent;
}
.heroCard.ready .cdSweep { box-shadow: 0 0 0 1px rgba(143,107,255,0.35) inset; }
.upgBtn {
  position: absolute; right: -6px; bottom: -6px;
  width: 24px; height: 24px;
  background: var(--accent); color: #fff;
  border: 2px solid var(--panel); border-radius: 50%;
  font-size: 12px; line-height: 1;
  cursor: pointer;
}
.upgBtn:hover { filter: brightness(1.3); }
.upgBadge {
  position: absolute; right: -6px; top: -6px;
  width: 20px; height: 20px;
  background: var(--gold); color: #1a1206;
  border: 2px solid var(--panel); border-radius: 50%;
  font-size: 12px; line-height: 18px; text-align: center;
  pointer-events: none;
}

.heroMeta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.heroTitle { font-size: 12px; color: var(--dim); }
.heroSub { font-size: 12px; color: var(--dim); }
.heroHpText { color: var(--text); }

.buyBtn {
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  padding: 6px 10px; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.buyBtn:hover { filter: brightness(1.2); }
.buyBtn:disabled, .trackBuy:disabled, .shopBuy:disabled { background: #3a3355; color: #77708f; cursor: not-allowed; }

/* ---------- локации ---------- */
.locItem {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.locItem.current { border-color: var(--gold); }
.locItem.locked { opacity: 0.45; cursor: not-allowed; }
.locThumb { width: 64px; height: 36px; border-radius: 6px; object-fit: cover; }

/* ---------- торговец ---------- */
#npcs {
  position: absolute;
  left: 0; right: 0; bottom: 40px;
  display: flex;
  justify-content: center;
  gap: 40px;
  z-index: 8;
}
.npc {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.12s;
}
.npc:hover { transform: scale(1.08); }
.npc img {
  width: 110px; height: 110px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.6));
}
.npcName {
  font-size: 13px; font-weight: 700; color: var(--gold);
  background: rgba(20,14,40,0.85);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 3px 10px;
  text-shadow: 0 1px 3px #000;
}

.shopItem {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.shopItem.equipped { border-color: var(--hp); }
.shopBuy {
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  padding: 6px 10px; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.shopBuy:hover { filter: brightness(1.2); }

/* ---------- модалки магазинов ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modalPanel {
  position: relative;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  width: min(520px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
}
.modalClose {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; color: var(--dim);
  font-size: 18px; cursor: pointer;
}
.modalHead2 { display: flex; gap: 12px; margin-bottom: 14px; align-items: center; }
.modalHead2 img { width: 64px; height: 64px; border-radius: 10px; }
.modalTitle { font-size: 18px; font-weight: 700; color: var(--gold); }
.modalSub { font-size: 12px; color: var(--dim); }
#merchantHeroTabs { display: flex; gap: 8px; margin-bottom: 10px; }
#merchantHeroTabs .tab {
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
}
#merchantHeroTabs .tab.active { border-color: var(--accent); }
#merchantHeroTabs .tab img { width: 48px; height: 48px; border-radius: 6px; display: block; }

/* ---------- логин и лидерборд ---------- */
.loginRow { margin-bottom: 10px; }
.loginRow input {
  width: 100%; padding: 8px 10px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px;
}
.loginBtns { display: flex; gap: 10px; }
.loginBtns button {
  flex: 1; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; padding: 8px 10px;
  font-size: 14px; cursor: pointer;
}
.loginBtns button:hover { filter: brightness(1.2); }
.loginMsg { margin-top: 10px; font-size: 13px; color: var(--gold); min-height: 18px; }
#logoutBtn {
  background: #3a3355; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
#logoutBtn:hover { background: #4a4368; }
.lbRow {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 6px;
}
.lbRow .lbPos { width: 28px; font-weight: 700; color: var(--gold); }
.lbRow .lbName { flex: 1; }
.lbRow .lbGold { color: var(--gold); }
.lbRow .lbKills { color: var(--text-dim); }

/* ---------- модалка ---------- */
#upgradeModal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
#upgradeModal.hidden, .hidden { display: none !important; }

#upgradePanel {
  position: relative;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  width: min(520px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
}
#closeModal {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; color: var(--dim);
  font-size: 18px; cursor: pointer;
}
#modalHead { display: flex; gap: 12px; margin-bottom: 14px; }
#modalHeroArt { width: 72px; height: 72px; border-radius: 10px; }
#modalHeroName { font-size: 18px; font-weight: 700; }
#modalHeroDesc { font-size: 13px; color: var(--dim); }

.track {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.trackInfo { flex: 1; }
.trackLvl { font-size: 12px; color: var(--gold); }
.trackDesc { font-size: 12px; color: var(--dim); }

.trackBuy {
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  padding: 6px 10px; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.trackBuy:hover { filter: brightness(1.2); }

@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; }
  aside { max-height: none; }
  #battlefield { order: -1; }
}
