/* ── Тёмное фэнтези: базовая тема, каркас, общие элементы ───────────────── */
:root {
  --bg: #08070a;
  --bg-2: #0e0c11;
  --panel: #14111a;
  --panel-2: #1a1620;
  --line: #2b2333;
  --line-soft: #221c2a;
  --text: #cabfb0;
  --text-dim: #8a8070;
  --text-faint: #5f5850;
  --gold: #c9a13f;
  --gold-dim: #8a6f2a;
  --blood: #8f2b26;
  --blood-bright: #c0342c;
  --green: #4aa84a;
  --blue: #4d8dff;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.65);
  --font-title: Georgia, "Times New Roman", serif;
  --font-body: "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, #191320 0%, transparent 70%),
    linear-gradient(180deg, #0a080c 0%, #060508 100%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  overflow-y: auto;
}

body::before {
  /* лёгкая зернистость поверх всего */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.035;
  background-image: repeating-linear-gradient(0deg, #fff 0 1px, transparent 1px 3px);
}

#app {
  max-width: 1560px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

/* ── Шапка ──────────────────────────────────────────────────────────────── */
#topbar {
  position: relative;
  z-index: 630; /* выше меню баланса, чтобы кнопки шапки всегда кликались */
  background: linear-gradient(180deg, #0b0910 70%, transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { color: var(--blood-bright); font-size: 20px; }
.brand-name {
  font-family: var(--font-title);
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(201, 161, 63, 0.25);
}
.brand-sub { color: var(--text-faint); font-size: 11px; letter-spacing: 3px; text-transform: uppercase; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.fps { color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; }
#header-actions { display: flex; gap: 6px; }

/* ── Раскладка ──────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(520px, 1fr) 330px;
  gap: 14px;
  align-items: start;
}

.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

@media (max-width: 1240px) {
  .layout { grid-template-columns: 240px 1fr; }
  .col-right { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .col-right > .panel { flex: 1 1 320px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .col-right { flex-direction: column; }
}

/* ── Панели ─────────────────────────────────────────────────────────────── */
.panel {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 40%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 12px 14px 14px;
  box-shadow: var(--shadow);
}
.panel::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  pointer-events: none;
}

.panel-title {
  margin: 0 0 10px;
  font-family: var(--font-title);
  font-size: 13px;
  font-weight: normal;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold-dim);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 7px;
}
.panel-hint { font-family: var(--font-body); font-size: 10px; letter-spacing: 0; color: var(--text-faint); text-transform: none; }

.panel-subtitle {
  margin: 12px 0 6px;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ── Сцена ──────────────────────────────────────────────────────────────── */
.scene-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #000;
  box-shadow: var(--shadow), inset 0 0 60px rgba(0, 0, 0, 0.9);
  overflow: hidden;
}
.scene-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 2px, transparent 2px 4px);
  opacity: 0.4;
}
#scene {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Полоски ────────────────────────────────────────────────────────────── */
.bar-row { margin: 6px 0; }
.bar {
  position: relative;
  height: 16px;
  background: #0b0910;
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.bar.thin { height: 12px; }
.bar-fill {
  height: 100%;
  transition: width 0.18s linear;
  background: linear-gradient(180deg, #6b1f1c, #3d0f0d);
}
.bar-fill.hp { background: linear-gradient(180deg, #a83a33, #5d1a16); }
.bar-fill.xp { background: linear-gradient(180deg, #3d6ea8, #1c3455); }
.bar-fill.stage { background: linear-gradient(180deg, #8a6f2a, #4a3a12); }
.bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #e6dbc8;
  text-shadow: 0 1px 2px #000;
  letter-spacing: 0.5px;
}

/* ── Кнопки ─────────────────────────────────────────────────────────────── */
.btn, .chip {
  font-family: var(--font-body);
  color: var(--text);
  background: linear-gradient(180deg, var(--panel-2), #100d14);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip { padding: 5px 9px; font-size: 11px; }
.btn:hover, .chip:hover { border-color: var(--gold-dim); color: #efe5d2; }
.btn:disabled, .chip:disabled { opacity: 0.45; cursor: not-allowed; }
.chip.active { border-color: var(--gold-dim); color: var(--gold); }
.chip.danger { color: #a8635c; border-color: #3a1f1c; }
.chip.danger:hover {
  border-color: var(--blood-bright);
  color: #f0a89c;
  background: linear-gradient(180deg, #2a1210, #160a09);
}

.btn-merge {
  border-color: var(--gold-dim);
  color: var(--gold);
}
.btn-merge:hover { background: linear-gradient(180deg, #241d15, #14100c); }
.btn-merge.pulse { animation: mergeReady 2s ease-in-out infinite; }
@keyframes mergeReady {
  0%, 100% { box-shadow: 0 0 0 rgba(201, 161, 63, 0); }
  50% { box-shadow: 0 0 14px rgba(201, 161, 63, 0.45); }
}

.btn-boss {
  width: 100%;
  margin: 8px 0 4px;
  padding: 10px;
  font-family: var(--font-title);
  letter-spacing: 2px;
  border-color: #4a1f1c;
  color: #a86a60;
}
.btn-boss.ready {
  border-color: var(--blood-bright);
  color: #f0c8a0;
  background: linear-gradient(180deg, #2a1210, #160a09);
  animation: bossPulse 1.8s ease-in-out infinite;
}
@keyframes bossPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(192, 52, 44, 0); }
  50% { box-shadow: 0 0 18px rgba(192, 52, 44, 0.45); }
}
.hidden { display: none !important; }

/* ── Модалки ────────────────────────────────────────────────────────────── */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 3, 6, 0.86);
  backdrop-filter: blur(2px);
  padding: 20px;
  overflow: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  max-width: 940px;
  width: 100%;
  border-radius: 3px;
}
.modal.small { max-width: 420px; text-align: center; }
.modal-title {
  font-family: var(--font-title);
  font-weight: normal;
  letter-spacing: 3px;
  color: var(--gold);
  margin: 0 0 8px;
  text-align: center;
}
.modal-sub { color: var(--text-dim); text-align: center; margin: 0 0 20px; font-size: 12px; line-height: 1.6; }
.modal-note { color: #c08a60; font-size: 11px; margin: 12px 0 16px; }

.class-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.class-card {
  text-align: left;
  background: linear-gradient(180deg, #191320, #0f0c14);
  border: 1px solid var(--line);
  padding: 16px;
  cursor: pointer;
  color: var(--text);
  border-radius: 3px;
  transition: border-color 0.15s, transform 0.15s;
}
.class-card:hover { border-color: var(--gold-dim); transform: translateY(-2px); }
.class-title { font-family: var(--font-title); font-size: 20px; color: var(--gold); letter-spacing: 2px; }
.class-tagline { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.class-stats { display: flex; gap: 12px; margin: 10px 0; font-family: var(--font-mono); font-size: 12px; }
.class-desc { font-size: 11.5px; line-height: 1.6; color: var(--text-dim); margin: 0 0 10px; }
.class-growth { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); }

.offline-rows { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 18px; }
.offline-row {
  display: flex; justify-content: space-between;
  border-bottom: 1px dashed var(--line-soft);
  padding: 5px 2px;
  font-size: 12px;
}
.offline-row b { color: var(--gold); font-family: var(--font-mono); }

/* ── Тосты ──────────────────────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(16, 12, 20, 0.95);
  border: 1px solid var(--line);
  border-left: 2px solid var(--gold-dim);
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 0.4s, transform 0.4s;
}
.toast.out { opacity: 0; transform: translateY(8px); }

/* ── Страница 404 ────────────────────────────────────────────────────────── */
.page-404 {
  max-width: 560px;
  margin: 40px auto;
  text-align: center;
}
.page-404 .panel-title { justify-content: center; }
.page-404 p {
  color: var(--text-dim);
  line-height: 1.7;
  margin: 14px 0 22px;
}
.page-404 .btn {
  display: inline-block;
  text-decoration: none;
}
