/* =============================================================
   TowerD: Тёмное Славянство — Основные стили
   ============================================================= */

/* Google Fonts */
@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Ruslan+Display&display=swap");

/* Local Fonts */
#game-title, #debug-ui-wrapper, #core-panel-top, #core-panel-bot {
  display: none;
}
@font-face {
  font-family: 'Cyrillic Old';
  src: url('../assets/ui/CyrillicOld.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* === Reset & Base === */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Палитра */
  --bg-dark: #0a0a0f;
  --bg-panel: #111118;
  --bg-card: #1a1a24;
  --border: #2a2a3a;
  --text: #e8dcc8;
  --text-dim: #8a8070;
  --gold: #d4a017;
  --gold-glow: #ffd700;
  --red: #8b0000;
  --red-bright: #ff3333;
  --green: #2d5a1e;
  --blue: #1a237e;
  --spirit-blue: #4fc3f7;

  /* Размеры */
  --canvas-w: 1664px;
  --canvas-h: 998px;

  /* Шрифты */
  --font: "Outfit", "Segoe UI", sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

/* === Контейнер игры === */
#game-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center center;
  display: flex;
  flex-direction: column;
  /* Ширина теперь задается динамически в main.js */
}

/* === Canvas === */
#game-canvas {
  display: block;
  width: calc(100% + 30px);
  margin-left: -15px;
  margin-right: -15px;
  margin-top: -15px;
  margin-bottom: -4px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  cursor: crosshair;
  image-rendering: auto;
  box-shadow:
    0 0 40px rgba(212, 160, 23, 0.08),
    0 4px 20px rgba(0, 0, 0, 0.6);
}

/* === Game Toolbar (под канвасом) === */
#game-toolbar {
  display: none;
  flex-shrink: 0;
  width: 100%;
  /* Toolbar styling overrides will now be handled inside core-panel-bot */
  position: relative;
  box-sizing: border-box;
  overflow: visible;
}

#game-toolbar.visible {
  display: flex;
}

/* === Core UI Panels (Fullscreen Overlays) === */
.core-panel-top,
.core-panel-bot {
  position: absolute;
  left: 0;
  width: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw / var(--game-scale, 1));
  z-index: 100;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  pointer-events: none; /* Let clicks pass through empty space */
}
.core-panel-top *, .core-panel-bot * {
  pointer-events: auto; /* Enable clicks on internal elements */
}


.core-panel-top {
  position: absolute;
  display: flex;
  align-items: center;
  z-index: 100;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw / var(--game-scale, 1));
  height: 59px;
  top: calc( calc(var(--game-h, 998px) / 2) - calc(var(--screen-center-y, 0px) / var(--game-scale, 1)) );
  flex-direction: row;
  justify-content: space-between;
  padding: 0 32px;
  background-image: url('../assets/ui/ui_elements/core_panel_top.png');
  background-repeat: repeat-x;
  background-position: center top;
  background-size: auto 59px;
}

/* Нативный 9slice для прогресс бара */
.cp-progress-9slice {
  position: absolute;
  inset: 0;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px #000);
  border-style: solid;
  border-width: 12px;
  border-image: url('../assets/ui/ui_elements/bar_gold_bg.png') 12 12 12 12 fill;
}

.core-panel-bot {
  position: absolute;
  display: flex;
  align-items: flex-end;
  padding-bottom: 13px;
  z-index: 100;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw / var(--game-scale, 1));
  height: 112px;
  bottom: calc( calc(var(--game-h, 998px) / 2) - calc(var(--screen-bottom-dist, 0px) / var(--game-scale, 1)) );
  flex-direction: row;
  justify-content: space-between;
  padding-left: 32px;
  padding-right: 32px;
  /* Подложка применяется динамически в JS через stretchSpriteCenter (9-slice) */
}

/* Top Panel Parts */
.cp-top-left {
  display: flex; align-items: center; justify-content: flex-start;
  flex: 1; padding-top: 8px;
}
.cp-top-center {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  flex: 2; padding-top: 0px; margin-top: -4px;
}
.cp-top-right {
  display: flex; align-items: center; justify-content: flex-end; gap: 19px;
  flex: 1; opacity: 1; margin-bottom: 30px;
}

/* Top Panel Progress & Timer */
.cp-title-text {
  font-family: 'Ruslan Display', serif;
  font-size: 14px; color: #ffeb3b; 
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  margin-bottom: 3px; letter-spacing: 1px;
}
.cp-progress-row {
  display: flex; align-items: center; gap: 6px;
}
.cp-progress-wrap {
  width: 384px; height: 26px;
  background: url('../assets/ui/ui_elements/progress_gold_bg.png') center/100% 100% no-repeat;
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.cp-progress-bar {
  position: absolute; top: 5px; left: 5px; height: calc(100% - 10px);
  max-width: calc(100% - 10px);
  background: url('../assets/ui/ui_elements/progress_green.png') left center/auto 100% repeat-x;
  border-radius: 4px;
  transition: width 0.3s;
  z-index: 1;
}
.cp-progress-text {
  position: relative; z-index: 2; font-family: var(--font); font-weight: 700;
  font-size: 12px; color: #fff; text-shadow: 0 2px 2px rgba(0,0,0,0.8);
}
.cp-timer-wrap {
  min-width: 72px; height: 27px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font); font-weight: 700; font-size: 14px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8); padding: 0 13px;
}
.cp-pause-btn {
  width: 54px; height: 54px;
  background: url('../assets/ui/ui_elements/btn_round_pause.png') center/100% 100% no-repeat;
  border: none; cursor: pointer; transition: transform 0.15s;
  margin-bottom: 20px; outline: none; box-shadow: none; border-radius: 50%;
}
.cp-pause-btn:hover { transform: scale(1.05); }
.cp-pause-btn:active { transform: scale(0.95); }

/* Top Panel Resources */
.cp-resource {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font); font-weight: 700; font-size: 19px;
}
.cp-res-heart { color: #ef5350; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.cp-res-gold { color: #ffd740; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.cp-res-skull { color: #c8b888; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }

/* Floating debug wrapper */
#debug-ui-wrapper {
  position: absolute; top: 180px; left: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 99;
}

.toolbar-left, .toolbar-right, .toolbar-center {
  display: none; /* These will be recreated structurally in core-panel-bot */
}

/* Toolbar divider (Celtic ornament) */
.toolbar-divider {
  align-self: stretch;
  width: 80px;
  height: auto;
  object-fit: fill;
  flex-shrink: 0;
  margin: -12px -10px;
  pointer-events: none;
  z-index: 5;
}

/* --- HUD Info (жизни, золото, волна) --- */
#hud-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  font-size: 14px;
  font-weight: 600;
  padding: 0 8px;
  white-space: nowrap;
}

.hud-lives {
  color: #ef5350;
}

.hud-gold {
  color: var(--gold);
}

/* Wave button bar — centered on the top */
#hud-wave-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
}

.hud-next-wave-btn {
  background: url('../assets/ui/ui_wives_bg.png') center/100% 100% no-repeat;
  border: none;
  border-radius: 0;
  color: #e3c9a4;
  padding: 0;
  width: 336px;
  height: 45px;
  box-sizing: border-box;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Cyrillic Old', serif;
  cursor: pointer;
  letter-spacing: 1.5px;
  -webkit-text-stroke: 1.5px #150000;
  paint-order: stroke fill;
  text-shadow: none;
  box-shadow: none;
  animation: none;
  transition: none;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  position: relative;
}

.wave-text {
  flex: 1;
  text-align: center;
  padding: 0 10px 0 20px;
}

.wave-play-icon {
  position: absolute;
  right: -52px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #e3c9a4;
  -webkit-text-stroke: 0;
}

.hud-wave-timer {
  display: inline-block;
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
  font-size: 13px;
  font-weight: 800;
  color: #ffeb3b;
  min-width: 20px;
  text-align: center;
}

.hud-next-wave-btn:hover {
  filter: none;
  transform: none;
  box-shadow: none;
}

.hud-next-wave-btn:active {
  transform: none;
  filter: none;
  box-shadow: none;
}

.hud-next-wave-btn--active {
  background: url('../assets/ui/ui_wives_bg.png') center/100% 100% no-repeat;
  color: #e3c9a4;
  animation: none;
}

.hud-next-wave-btn--active:hover {
  filter: none;
  box-shadow: none;
}

/* === Wave Bonus Popup === */
.wave-bonus-popup {
  position: fixed;
  top: 60px;
  right: 30px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s, transform 0.6s;
}

.wave-bonus-popup--show {
  opacity: 1;
  transform: translateY(0);
  animation: wbp-float 2.5s ease-out forwards;
}

.wbp-gold {
  font-size: 28px;
  font-weight: 900;
  color: #ffd740;
  text-shadow: 0 0 12px rgba(255, 215, 64, 0.6), 0 2px 4px rgba(0, 0, 0, 0.7);
  letter-spacing: 1px;
}

.wbp-mult {
  font-size: 18px;
  font-weight: 700;
  color: #69f0ae;
  text-shadow: 0 0 8px rgba(105, 240, 174, 0.5), 0 1px 3px rgba(0, 0, 0, 0.6);
}

@keyframes wbp-float {
  0% {
    opacity: 1;
    transform: translateY(0);
  }

  70% {
    opacity: 1;
    transform: translateY(-20px);
  }

  100% {
    opacity: 0;
    transform: translateY(-40px);
  }
}

/* === HUD оверлей (будет добавлен) === */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 10;
}

#perf-hud {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 1200;
  width: 132px;
  padding: 8px 10px;
  display: none;
  pointer-events: none;
  color: #edf7ea;
  font-family: "Outfit", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  background: rgba(7, 12, 10, 0.58);
  border: 1px solid rgba(136, 205, 122, 0.34);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(6px);
}

#perf-hud.perf-hud--visible {
  display: block;
}

.perf-hud__main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  min-height: 28px;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.perf-hud__main span,
.perf-hud__grid span {
  color: rgba(237, 247, 234, 0.58);
  font-size: 10px;
  font-weight: 700;
}

.perf-hud__main strong {
  color: #8bdc72;
  font-size: 26px;
  line-height: 1;
}

.perf-hud__grid {
  display: grid;
  grid-template-columns: 42px 1fr;
  row-gap: 3px;
  align-items: baseline;
}

.perf-hud__grid b {
  min-width: 46px;
  color: #f4f7ef;
  font-size: 12px;
  line-height: 1.2;
  text-align: right;
}

#perf-hud.perf-hud--warn {
  border-color: rgba(244, 199, 84, 0.52);
}

#perf-hud.perf-hud--warn .perf-hud__main strong {
  color: #f4c754;
}

#perf-hud.perf-hud--bad {
  border-color: rgba(255, 96, 86, 0.64);
}

#perf-hud.perf-hud--bad .perf-hud__main strong {
  color: #ff6056;
}

/* === Заголовок === */
#game-title {
  position: absolute;
  top: -40px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: 4px;
  text-transform: uppercase;
}

/* === Tooltip === */
.tooltip {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s ease;
  max-width: 250px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.tooltip.visible {
  opacity: 1;
}

/* === Кнопки общие === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  background: linear-gradient(180deg, rgba(30, 30, 42, 0.95), rgba(18, 18, 28, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(4px);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow:
    0 0 12px rgba(212, 160, 23, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.97) translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.btn-gold {
  background: linear-gradient(135deg, #3a2a0a, #2a1a00);
  border-color: var(--gold);
  color: var(--gold);
}

.btn-gold:hover {
  background: linear-gradient(135deg, #4a3a1a, #3a2a0a);
  box-shadow: 0 0 20px rgba(212, 160, 23, 0.3);
}

/* ═══════════════════════════════════════════
   GAME HUD — In-game UI elements
   ═══════════════════════════════════════════ */

/* --- Exit Button --- */
#exit-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 50;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, rgba(40, 15, 15, 0.9), rgba(25, 8, 8, 0.95));
  border: 1px solid rgba(180, 40, 40, 0.4);
  border-radius: 6px;
  color: #ef5350;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.25s ease;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 100, 100, 0.06);
}

#exit-btn:hover {
  background: linear-gradient(180deg, rgba(55, 18, 18, 0.95), rgba(35, 10, 10, 0.98));
  border-color: #c62828;
  color: #ff6659;
  box-shadow:
    0 0 16px rgba(198, 40, 40, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 100, 100, 0.1);
  transform: translateY(-1px);
}

#exit-btn:active {
  transform: scale(0.96);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}



/* --- Tower Panel (toolbar center) --- */
#tower-panel {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  transform: translateY(18px);
}

/* --- Tower Buttons --- */
.tower-btn {
  padding: 0 !important;
  font-size: 14px !important;
  line-height: 1;
  width: 115px;
  height: 166px;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  /* 9-slice item background will be set dynamically in JS */
  background: transparent;
  border: none !important;
  border-radius: 0 !important;
  color: var(--text) !important;
  text-align: center;
  position: relative;
  overflow: visible;
  box-shadow: none !important;
  backdrop-filter: none !important;
  margin-bottom: 13px;
}

.tower-btn .tower-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
}

.tower-btn img.tower-icon {
  width: 80px !important;
  height: 80px !important;
}

.tower-btn:hover {
  filter: brightness(1.15) drop-shadow(0 0 8px rgba(255, 220, 120, 0.6));
}

@keyframes magicalAcidGreenGlow {
  0% {
    filter: brightness(1.1) drop-shadow(0 0 2px rgba(200, 255, 200, 1)) drop-shadow(0 0 6px rgba(57, 255, 20, 0.9)) drop-shadow(0 0 12px rgba(57, 255, 20, 0.6));
  }
  50% {
    filter: brightness(1.25) drop-shadow(0 0 3px rgba(220, 255, 220, 1)) drop-shadow(0 0 8px rgba(100, 255, 50, 1)) drop-shadow(0 0 18px rgba(57, 255, 20, 0.8));
  }
  100% {
    filter: brightness(1.1) drop-shadow(0 0 2px rgba(200, 255, 200, 1)) drop-shadow(0 0 6px rgba(57, 255, 20, 0.9)) drop-shadow(0 0 12px rgba(57, 255, 20, 0.6));
  }
}

.tower-btn.selected {
  animation: magicalAcidGreenGlow 2.5s infinite ease-in-out;
  box-shadow: none !important;
}

.tower-btn .tower-cost {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #fff;
  font-weight: 900;
  font-family: 'Outfit', sans-serif;
  /* background will be set dynamically */
  padding: 0;
  width: 90px;
  height: 24px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  -webkit-text-stroke: 0;
  text-shadow: 0 1px 2px #000;
  paint-order: stroke fill;
  z-index: 2;
  box-sizing: border-box;
  pointer-events: none;
}

.tower-cost-icon {
  font-size: 13px;
  flex-shrink: 0;
  pointer-events: none;
}

/* --- Tower Info Panel — Dark Tooltip --- */
#tower-info {
  position: absolute;
  width: 308px;
  z-index: 70;
  background: rgba(10, 10, 25, 0.80);
  border: 2px solid rgba(255, 215, 0, 0.25);
  border-radius: 14px;
  padding: 14px 20px;
  color: #bbb;
  pointer-events: auto;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.6), 0 0 21px rgba(255, 215, 0, 0.08);
  backdrop-filter: blur(8px);
  transition: left 0.15s ease, top 0.15s ease;
  text-align: left;
}

#tower-info .ti-body {
  display: block;
}

#tower-info #ti-close {
  position: absolute;
  top: -11px;
  right: -11px;
  width: 31px;
  height: 31px;
  background: url('../assets/ui/ui_elements/btn_close.png') center/contain no-repeat;
  cursor: pointer;
  z-index: 10;
  transition: transform 0.1s, filter 0.1s;
}

#tower-info #ti-close:hover {
  transform: scale(1.1);
  filter: brightness(1.15);
}

#tower-info #ti-close:active {
  transform: scale(0.95);
  filter: brightness(0.9);
}

/* Actions container */
#tower-info #ti-actions {
  margin-top: 11px;
  border-top: 2px solid rgba(255, 255, 255, 0.08);
  padding-top: 11px;
}

/* Upgrade button — green wood plank */
.ti-upgrade-btn {
  width: 100%;
  height: 34px;
  background: transparent;
  border: none !important;
  color: #fff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  font-family: inherit;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  letter-spacing: 1px;
  text-align: center;
  transition: filter 0.15s, transform 0.15s;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  padding: 0 !important;
}

.ti-upgrade-btn:hover {
  filter: brightness(1.15);
  transform: scale(1.03);
}

.ti-upgrade-btn:active {
  filter: brightness(0.9);
  transform: scale(0.97);
}

/* Sell button — wood plank, smaller */
.ti-sell-btn {
  width: 100%;
  height: 34px;
  background: transparent;
  border: none !important;
  color: #fff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  font-family: inherit;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  letter-spacing: 1px;
  text-align: center;
  transition: filter 0.15s, transform 0.15s;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  padding: 0 !important;
}

.ti-sell-btn:hover {
  opacity: 1;
  filter: brightness(1.1);
}

.ti-sell-btn:active {
  filter: brightness(0.85);
  transform: scale(0.97);
}

/* --- Troop Panel (toolbar left) --- */
#troop-panel {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* --- Upgrade Button --- */
#upgrade-btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  background: linear-gradient(180deg, rgba(25, 50, 15, 0.9), rgba(15, 35, 8, 0.95));
  border: 1px solid rgba(76, 175, 80, 0.4);
  border-radius: 6px;
  color: #66bb6a;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.25s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#upgrade-btn:hover {
  background: linear-gradient(180deg, rgba(35, 65, 20, 0.95), rgba(20, 45, 10, 0.98));
  border-color: #4caf50;
  box-shadow: 0 0 12px rgba(76, 175, 80, 0.2), 0 4px 10px rgba(0, 0, 0, 0.5);
  transform: translateY(-1px);
}

#upgrade-btn:disabled,
#upgrade-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* === Анимации === */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

@keyframes glow {

  0%,
  100% {
    box-shadow: 0 0 5px rgba(212, 160, 23, 0.3);
  }

  50% {
    box-shadow: 0 0 20px rgba(212, 160, 23, 0.6);
  }
}

/* =============================================================
   Start Screen / Main Menu
   ============================================================= */

#start-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  /* Slavic village background */
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 40%, rgba(0, 0, 0, 0.4) 100%),
    url('../assets/ui/menu_bg.png') center/cover no-repeat;
  background-color: #0a0a0f;
  opacity: 0;
  transition: opacity 0.5s ease;
  border-radius: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

#start-screen.start-screen--visible {
  opacity: 1;
}

#start-screen.start-screen--hiding {
  opacity: 0;
  pointer-events: none;
}

/* Particles */
.ss-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ss-particle {
  position: absolute;
  background: var(--gold);
  border-radius: 50%;
  animation: ssFloat linear infinite;
}

@keyframes ssFloat {
  0% {
    transform: translateY(0) scale(1);
    opacity: 0.3;
  }

  50% {
    transform: translateY(-60px) scale(1.5);
    opacity: 0.6;
  }

  100% {
    transform: translateY(-120px) scale(0.5);
    opacity: 0;
  }
}

/* Content */
.ss-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 1250px;
  padding: 10px 0 20px;
  animation: fadeIn 0.8s ease;
}

.ss-logo {
  text-align: center;
  animation: fadeIn 0.4s ease both;
}

.ss-logo-img {
  max-width: 280px;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 20px rgba(212, 160, 23, 0.5));
  animation: ssLogoGlow 3s ease-in-out infinite;
  margin-bottom: 8px;
}

.ss-logo-icon {
  font-size: 56px;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 20px rgba(212, 160, 23, 0.5));
  animation: ssLogoGlow 3s ease-in-out infinite;
}

@keyframes ssLogoGlow {

  0%,
  100% {
    filter: drop-shadow(0 0 15px rgba(212, 160, 23, 0.3));
  }

  50% {
    filter: drop-shadow(0 0 30px rgba(212, 160, 23, 0.7));
  }
}

.ss-title {
  font-size: 52px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 6px;
  text-transform: uppercase;
  text-shadow: 0 2px 20px rgba(212, 160, 23, 0.4);
  margin: 0;
  line-height: 1;
}

.ss-subtitle {
  font-size: 18px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 8px;
  text-transform: uppercase;
  margin-top: 6px;
}

.ss-tagline {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 3px;
  margin-top: 12px;
}

/* Menu buttons */
.ss-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 280px;
  animation: slideUp 0.6s ease 0.4s both;
}

/* Menu buttons — Wood plank style (image-based) */
.ss-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 24px;
  /* 9-slice parchment scroll image */
  background: transparent;
  border: 20px solid transparent;
  border-image-source: url('../assets/ui/btn_wood.png?v=5');
  border-image-slice: 55 90 fill;
  border-image-width: 20px 32px;
  border-image-repeat: stretch;
  color: #3a2010;
  font-family: 'Ruslan Display', var(--font);
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
  transition: filter 0.2s ease, transform 0.2s ease;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

.ss-btn:hover {
  filter: brightness(1.15) drop-shadow(0 3px 8px rgba(0, 0, 0, 0.4));
  transform: scale(1.04);
}

.ss-btn:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

.ss-btn-icon {
  display: none;
}

.ss-btn--play {
  border: 20px solid transparent;
  border-image-source: url('../assets/ui/btn_green.png?v=4');
  border-image-slice: 60 80 fill;
  border-image-width: 20px 28px;
  border-image-repeat: stretch;
  color: #d4cfc0;
  font-weight: 400;
  font-size: 19px;
  padding: 8px 24px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  animation: btnGlow 3s ease-in-out infinite;
}

@keyframes btnGlow {

  0%,
  100% {
    filter: drop-shadow(0 0 6px rgba(80, 180, 50, 0.3));
  }

  50% {
    filter: drop-shadow(0 0 16px rgba(80, 180, 50, 0.6));
  }
}

.ss-btn--play:hover {
  filter: brightness(1.2) drop-shadow(0 3px 10px rgba(76, 175, 80, 0.3));
  transform: scale(1.06);
}

.ss-btn--back {
  margin-top: 10px;
  font-size: 17px;
  padding: 10px 36px;
  width: fit-content;
  align-self: center;
}

.ss-btn--pvp {
  animation: pvpGlow 3s ease-in-out infinite;
}

@keyframes pvpGlow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(220, 50, 50, 0.3)); }
  50% { filter: drop-shadow(0 0 16px rgba(220, 50, 50, 0.6)); }
}

.ss-btn--pvp:hover {
  filter: brightness(1.2) drop-shadow(0 3px 10px rgba(220, 50, 50, 0.4));
  transform: scale(1.06);
}

@keyframes pvp-spin {
  to { transform: rotate(360deg); }
}

@keyframes heroSpin {
  to { transform: rotate(360deg); }
}

/* Arsenal tab badge */
.ars-tab-badge {
  display: none;
  position: absolute;
  right: -6px;
  top: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: linear-gradient(135deg, #c62828, #e65100);
  color: #ffd700;
  font-size: 11px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  padding: 0 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  box-shadow: 0 0 6px rgba(198,40,40,0.7), 0 1px 4px rgba(0,0,0,0.5);
  border: 1.5px solid #ffd70088;
  z-index: 5;
}
.ars-tab-badge:empty {
  display: none !important;
}

/* Settings & Levels panels */
.ss-panel {
  width: 440px;
  max-width: 95vw;
  animation: slideUp 0.3s ease both;
}

/* Level selection panel — stretches to fill parent */
#ss-levels-panel.ss-panel {
  align-self: stretch;
  width: auto;
  max-width: none;
  padding: 0 20px;
}

/* PvP panels — wider for card layout */
#ss-pvp-search.ss-panel,
#ss-pvp-countdown.ss-panel {
  width: auto;
  max-width: 90vw;
}

/* PvP search popup / countdown — fix card sizing */
#cl-pane-pvp .ss-char,
#ss-pvp-search .ss-char,
#ss-pvp-countdown .ss-char {
  width: 200px;
  height: 260px;
  min-width: 200px;
  padding: 0;
  background: none;
  cursor: default;
}
#cl-pane-pvp .ss-char:hover,
#ss-pvp-search .ss-char:hover,
#ss-pvp-countdown .ss-char:hover {
  transform: none;
  filter: none;
}

.ss-panel-title {
  font-family: 'Cyrillic Old', var(--font);
  font-size: 32px;
  font-weight: 400;
  color: #a0a0a0;
  margin-bottom: 16px;
  text-align: center;
  letter-spacing: 3px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Level selection grid — 3 columns with fixed width */
.ss-levels-grid {
  display: grid;
  grid-template-columns: repeat(3, 384px);
  gap: 16px;
  padding: 16px 0;
  justify-content: center;
}

.hide-scrollbar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.hide-scrollbar::-webkit-scrollbar {
  display: none;
}

#arsenal-content {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#arsenal-content::-webkit-scrollbar {
  display: none;
}

/* Level card — vertical layout: preview on top, info below */
.ss-level-card {
  display: flex;
  flex-direction: column;
  background: transparent;
  border: none;
  padding: 24px 24px 24px 34px;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
  text-align: left;
  color: #f5e6c8;
  font-family: var(--font);
  position: relative;
  width: 384px;
  height: 260px;
  box-sizing: border-box;
}



/* Level card background preview */
.ss-level-bg {
  position: absolute;
  inset: 10px 8px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
}

.ss-level-card:hover {
  transform: scale(1.04);
  filter: brightness(1.15) drop-shadow(0 4px 14px rgba(212, 160, 23, 0.35));
}

.ss-level-card:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

/* Map preview — top section */
.ss-level-preview {
  width: 100%;
  height: 110px;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.ss-level-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.ss-level-preview canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: saturate(1.1) contrast(1.05);
}

/* Card content — bottom 1/3 */
.ss-level-content {
  box-sizing: border-box;
  padding: 8px 34px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.95) 100%);
  position: absolute;
  bottom: 12px;
  left: 15px;
  right: 15px;
  height: 48%;
  z-index: 3;
}

.ss-level-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.ss-level-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ss-level-name {
  font-family: 'Ruslan Display', serif;
  font-size: 16px;
  font-weight: 400;
  color: #f5e6c8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.ss-level-diff {
  color: #d4a017;
  font-size: 18px;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(212, 160, 23, 0.5);
}

.ss-level-desc {
  font-size: 12px;
  color: rgba(245, 230, 200, 0.7);
  line-height: 1.3;
  font-style: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.ss-level-meta {
  display: flex;
  gap: 10px;
  font-size: 14px;
  color: rgba(245, 230, 200, 0.8);
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(139, 111, 71, 0.2);
}

.ss-level-meta span {
  white-space: nowrap;
  font-weight: 700;
}

.ss-level-meta .meta-lives {
  color: #ef5350;
}

.ss-level-meta .meta-gold {
  color: #ffd700;
}

.ss-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 19px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  margin-bottom: 10px;
  font-size: 17px;
  font-weight: 700;
}

.ss-radio-group {
  display: flex;
  gap: 14px;
}

.ss-radio {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.2s;
}

.ss-radio:has(input:checked) {
  color: var(--gold);
}

.ss-radio input {
  accent-color: var(--gold);
}

/* Custom Image Checkboxes */
.ss-custom-cb {
  position: relative;
  width: 36px;
  height: 36px;
  transition: transform 0.1s, filter 0.15s;
  filter: drop-shadow(0 0 0 transparent);
  flex-shrink: 0;
}
.ss-radio:hover .ss-custom-cb {
  transform: scale(1.05);
  filter: drop-shadow(0 4px 12px rgba(143, 230, 116, 0.6));
}
.ss-cb-bg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.ss-cb-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
  width: 100%;
  height: 100%;
}
.ss-radio input:checked ~ .ss-custom-cb .ss-cb-mark {
  display: block;
}

/* Controls grid */
.ss-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 10px;
}

.ss-key-group {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  padding: 14px;
}

.ss-key-group h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.ss-key-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.ss-key-row kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
}

.ss-key-row span:last-child {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 13px;
}

/* Footer */
.ss-footer {
  font-size: 11px;
  color: rgba(138, 128, 112, 0.5);
  letter-spacing: 2px;
  animation: slideUp 0.6s ease 0.6s both;
}

/* ─── Панель валют ─── */
.ss-currency-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 6px 10px;
  animation: slideUp 0.4s ease 0.2s both;
  margin-bottom: 8px;
}

.ss-currency {
  font-size: 14px;
  color: #c8b99a;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 15, 25, 0.85);
  border: 1px solid rgba(130, 100, 60, 0.4);
  border-radius: 8px;
  padding: 8px 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.ss-currency:hover {
  background: rgba(25, 25, 35, 0.95);
  box-shadow: 0 6px 14px rgba(0,0,0,0.6);
}

.ss-currency b {
  color: #f5e6c8;
  font-size: 16px;
  min-width: 28px;
  text-align: right;
}

.ss-user-info {
  font-size: 12px;
  color: #888;
  margin-left: 12px;
}

/* ─── Замок и Герой ─── */
.ss-characters {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
  animation: slideUp 0.5s ease 0.3s both;
}

.ss-char-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.ss-char-label {
  color: var(--gold, #d4a017);
  font-family: 'Ruslan Display', serif;
  font-size: 15px;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow:
    0 2px 0 rgba(120, 70, 0, 0.9),
    0 4px 0 rgba(80, 40, 0, 0.7),
    0 6px 12px rgba(0, 0, 0, 0.8);
  margin-top: 6px;
  text-align: center;
}

.ss-char {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 20px;
  background: url('../assets/ui/main_menu_bg.png') center / 100% 100% no-repeat;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 190px;
}

.ss-char:hover {
  transform: translateY(-2px) scale(1.05);
  filter: drop-shadow(0 0 12px rgba(212, 160, 23, 0.5));
}

.ss-char-img {
  width: 220px;
  height: 240px;
  object-fit: cover;
  margin-bottom: 0;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.6));
  transition: transform 0.2s;
  border-radius: 4px;
}



.ss-char-icon {
  font-size: 36px;
  margin-bottom: 4px;
}

.ss-char-name {
  font-family: 'CyrillicOld', serif;
  color: #f5e6c8;
  font-size: 22px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.ss-char-level {
  font-family: 'CyrillicOld', serif;
  color: #d4a017;
  font-size: 20px;
  font-weight: bold;
  margin-top: 4px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.ss-char--dead {
  opacity: 0.5;
  border-color: #f44336;
}

.ss-char--dead .ss-char-icon {
  filter: grayscale(80%);
}

.ss-hero-timer {
  color: #f44336;
  font-size: 11px;
  font-weight: bold;
  margin-top: 4px;
  animation: pulse 1s ease infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* ─── Авторизация ─── */
.ss-auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  animation: slideUp 0.4s ease 0.3s both;
}

.ss-auth-input {
  width: 220px;
  padding: 8px 12px;
  background: rgba(15, 15, 30, 0.8);
  border: 1px solid rgba(100, 80, 50, 0.5);
  border-radius: 6px;
  color: #f5e6c8;
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.ss-auth-input:focus {
  border-color: #d4a017;
}

.ss-auth-input::placeholder {
  color: #666;
}

.ss-auth-btns {
  display: flex;
  gap: 8px;
}

.ss-btn--small {
  padding: 6px 16px !important;
  font-size: 12px !important;
  min-width: auto !important;
}

.ss-auth-error {
  color: #f44336;
  font-size: 11px;
  min-height: 16px;
}

/* =============================================================
   Upgrade Screen (Castle / Hero)
   ============================================================= */

#upgrade-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

#upgrade-screen.upgrade-screen--visible {
  opacity: 1;
}

#upgrade-screen.upgrade-screen--hiding {
  opacity: 0;
}

.upg-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.upg-panel {
  position: relative;
  width: 420px;
  max-height: 80vh;
  background: linear-gradient(180deg, #1a1520 0%, #0d0b12 100%);
  border: 1px solid rgba(160, 120, 50, 0.5);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.upg-header {
  text-align: center;
  margin-bottom: 12px;
}

.upg-title {
  font-family: 'CyrillicOld', serif;
  color: #f5e6c8;
  font-size: 20px;
  margin: 0 0 4px;
}

.upg-subtitle {
  color: #888;
  font-size: 13px;
}

.upg-bonuses {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.upg-bonus-tag {
  background: rgba(40, 35, 50, 0.8);
  border: 1px solid rgba(100, 80, 50, 0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: #4fc3f7;
}

.upg-next {
  background: rgba(20, 18, 30, 0.9);
  border: 1px solid rgba(212, 160, 23, 0.4);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  margin-bottom: 12px;
}

.upg-next-header {
  color: #888;
  font-size: 11px;
  margin-bottom: 6px;
}

.upg-next-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.upg-next-icon {
  font-size: 24px;
}

.upg-next-name {
  color: #f5e6c8;
  font-size: 15px;
  font-family: 'CyrillicOld', serif;
}

.upg-next-cost {
  color: #d4a017;
  font-size: 13px;
  margin-bottom: 10px;
}

.upg-btn {
  display: block;
  width: 100%;
  padding: 10px;
  background: linear-gradient(180deg, #2a6a2a 0%, #1a4a1a 100%);
  border: 2px solid #4caf50;
  border-radius: 6px;
  color: #fff;
  font-family: 'CyrillicOld', serif;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.upg-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #3a8a3a 0%, #2a6a2a 100%);
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
}

.upg-btn--disabled,
.upg-btn:disabled {
  background: rgba(40, 40, 50, 0.8);
  border-color: #555;
  color: #888;
  cursor: not-allowed;
}

.upg-max {
  text-align: center;
  color: #ffd700;
  font-size: 16px;
  padding: 16px;
  font-family: 'CyrillicOld', serif;
}

.upg-list {
  flex: 1;
  overflow-y: auto;
  max-height: 300px;
  margin-bottom: 12px;
}

.upg-list::-webkit-scrollbar {
  width: 5px;
}

.upg-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.upg-list::-webkit-scrollbar-thumb {
  background: rgba(160, 120, 50, 0.4);
  border-radius: 3px;
}

.upg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  border-bottom: 1px solid rgba(50, 45, 55, 0.5);
}

.upg-row--done {
  color: #666;
}

.upg-row--done .upg-row-name {
  text-decoration: line-through;
}

.upg-row--current {
  color: #f5e6c8;
  background: rgba(212, 160, 23, 0.1);
  border-radius: 4px;
}

.upg-row--locked {
  color: #555;
}

.upg-row-lvl {
  min-width: 40px;
}

.upg-row-icon {
  font-size: 14px;
  min-width: 20px;
  text-align: center;
}

.upg-row-name {
  flex: 1;
}

.upg-row-cost {
  min-width: 60px;
  text-align: right;
  color: #888;
}

.upg-close {
  display: block;
  width: 100%;
  padding: 8px;
  background: rgba(40, 35, 50, 0.8);
  border: 1px solid rgba(100, 80, 50, 0.4);
  border-radius: 6px;
  color: #c8b99a;
  font-family: 'CyrillicOld', serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.upg-close:hover {
  border-color: #d4a017;
  color: #f5e6c8;
}

/* =============================================================
   Node Screens (Reward, Shop, Rest, Event, Forge)
   ============================================================= */

#node-screen {
  position: absolute;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 4px;
}

#node-screen.ns--visible {
  opacity: 1;
}

.ns-panel {
  background: rgba(17, 17, 24, 0.95);
  border: 1px solid rgba(212, 160, 23, 0.3);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  backdrop-filter: blur(12px);
  animation: slideUp 0.4s ease;
}

.ns-panel--wide {
  max-width: 560px;
}

.ns-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 12px;
  letter-spacing: 2px;
}

.ns-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.ns-reward-gold {
  font-size: 28px;
  font-weight: 700;
  color: var(--gold-glow);
  margin-bottom: 16px;
  text-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.ns-gold {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 16px;
}

.ns-gold strong {
  color: var(--gold);
  font-size: 18px;
}

/* Cards grid */
.ns-cards {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.ns-card {
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ns-card:hover {
  transform: translateY(-6px);
}

.ns-card-border {
  border: 2px solid #555;
  border-radius: 8px;
  padding: 12px 10px;
  background: rgba(26, 26, 36, 0.9);
  width: 110px;
  text-align: center;
}

.ns-card-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

.ns-card-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.ns-card-cost {
  font-size: 12px;
  color: var(--spirit-blue);
  margin-bottom: 4px;
}

.ns-card-desc {
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* Shop */
.ns-shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.ns-shop-item {
  position: relative;
  cursor: pointer;
  transition: transform 0.2s;
}

.ns-shop-item:hover:not(.ns-shop-item--disabled) {
  transform: scale(1.03);
}

.ns-shop-item--disabled {
  opacity: 0.4;
  pointer-events: none;
}

.ns-price {
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
  margin-top: 6px;
  text-align: center;
}

.ns-sold {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  color: #4caf50;
  font-weight: 700;
  font-size: 14px;
  border-radius: 8px;
}

.ns-shop-actions {
  margin-bottom: 12px;
}

/* Rest */
.ns-rest-info {
  margin: 20px 0;
}

.ns-rest-hp {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 6px;
}

.ns-rest-heal {
  font-size: 28px;
  font-weight: 700;
  color: #4caf50;
  text-shadow: 0 0 12px rgba(76, 175, 80, 0.4);
}

/* Event */
.ns-event-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 20px;
}

.ns-event-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.ns-event-btn {
  text-align: left;
}

.ns-event-result {
  font-size: 14px;
  color: var(--gold);
  padding: 12px;
  background: rgba(212, 160, 23, 0.08);
  border: 1px solid rgba(212, 160, 23, 0.2);
  border-radius: 6px;
  margin-bottom: 12px;
}

/* Forge */
.ns-forge-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.ns-forge-card {
  padding: 8px 14px;
  background: rgba(26, 26, 36, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  transition: all 0.2s;
  position: relative;
}

.ns-forge-card:hover {
  border-color: #f44336;
  color: #f44336;
}

.ns-forge-card-name {
  font-weight: 600;
}

.ns-forge-card-cost {
  font-size: 10px;
  color: var(--spirit-blue);
}

/* Buttons */
.ns-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  background: rgba(26, 26, 36, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.ns-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}

.ns-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.ns-btn--gold {
  background: linear-gradient(135deg, rgba(42, 26, 0, 0.9), rgba(26, 16, 0, 0.9));
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

.ns-btn--skip {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

/* =============================================================
   Bestiary Screen
   ============================================================= */

#bestiary-screen {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(76, 175, 80, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(139, 0, 0, 0.08) 0%, transparent 50%),
    rgba(6, 6, 12, 0.82);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.4s ease;
  border-radius: 4px;
  overflow: hidden;
}

#bestiary-screen.bestiary--visible {
  opacity: 1;
}

#bestiary-screen.bestiary--hiding {
  opacity: 0;
  pointer-events: none;
}

.bestiary-panel {
  width: 95%;
  max-width: 1100px;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.5s ease;
}

.bestiary-header {
  text-align: center;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.bestiary-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 2px 15px rgba(212, 160, 23, 0.3);
  margin-bottom: 14px;
}

.bestiary-tabs {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: -15px;
  position: relative;
  z-index: 10;
}

.bestiary-tabs--user {
  margin-top: -38px;
}

.bestiary-tab {
  height: 46px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 38px; /* 12px padding + 26px border from before */
  background: transparent no-repeat center center;
  background-size: 100% 100%;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: filter 0.2s ease, color 0.2s ease;
  letter-spacing: 1px;
}

.bestiary-tab--user {
  height: 69px;
  padding: 0 55px; /* 16px padding + 39px border from before */
  font-size: 20px;
}

.bestiary-tab:hover {
  color: var(--text);
  filter: brightness(1.2);
}

.bestiary-tab--active {
  color: #fff;
  font-weight: 600;
  filter: none;
}

.bestiary-tab-count {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  font-size: 11px;
  margin-left: 4px;
  padding: 0 5px;
}

.bestiary-tab--user .bestiary-tab-count {
  min-width: 22px;
  height: 22px;
  line-height: 22px;
  border-radius: 11px;
  font-size: 13px;
  margin-left: 6px;
  padding: 0 6px;
}

.bestiary-tab--active .bestiary-tab-count {
  background: rgba(212, 160, 23, 0.3);
}

.bestiary-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0 0 8px 8px;
  background: rgba(17, 17, 24, 0.5);
}

/* Scrollbar */
.bestiary-content::-webkit-scrollbar {
  width: 6px;
}

.bestiary-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.bestiary-content::-webkit-scrollbar-thumb {
  background: rgba(212, 160, 23, 0.4);
  border-radius: 3px;
}

.bestiary-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

/* === Card === */
.bestiary-card {
  display: flex;
  background: rgba(26, 26, 36, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.bestiary-card:hover {
  border-color: rgba(212, 160, 23, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(212, 160, 23, 0.06);
  transform: translateY(-2px);
}

.bestiary-card-sprite {
  position: relative;
  width: 128px;
  min-height: 128px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.bestiary-sprite-canvas {
  display: block;
}

.bestiary-boss-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 8px;
  background: linear-gradient(135deg, #ff6f00, #e65100);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
}

.bestiary-card-info {
  flex: 1;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bestiary-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bestiary-card-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.bestiary-type-tag {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.bestiary-card-lore {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
  font-style: italic;
  margin: 2px 0;
}

.bestiary-card-desc {
  font-size: 12px;
  color: var(--spirit-blue);
  margin: 0;
}

/* === Stats === */
.bestiary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 4px;
}

.bestiary-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  position: relative;
  min-width: 140px;
}

.bestiary-stat-icon {
  font-size: 13px;
  width: 18px;
  text-align: center;
}

.bestiary-stat-label {
  color: var(--text-dim);
  min-width: 60px;
}

.bestiary-stat-value {
  color: var(--text);
  font-weight: 600;
  margin-left: auto;
}

.bestiary-stat-bar {
  position: absolute;
  bottom: -2px;
  left: 22px;
  height: 2px;
  border-radius: 1px;
  opacity: 0.5;
}

/* === Hero section === */
.bestiary-hero-section {
  display: flex;
  gap: 32px;
  padding: 24px;
  align-items: flex-start;
}

.bestiary-hero-portrait {
  flex-shrink: 0;
  width: 200px;
  height: 200px;
  background: rgba(26, 26, 36, 0.9);
  border: 2px solid rgba(212, 160, 23, 0.3);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px rgba(212, 160, 23, 0.1);
}

.bestiary-hero-canvas {
  width: 200px !important;
  height: 200px !important;
}

.bestiary-hero-info {
  flex: 1;
}

.bestiary-hero-name {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  margin: 0 0 4px;
}

.bestiary-hero-title {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0 0 12px;
}

.bestiary-hero-lore {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  margin: 0 0 20px;
}

.bestiary-hero-abilities h3 {
  font-size: 14px;
  color: var(--gold);
  margin: 0 0 10px;
  letter-spacing: 1px;
}

.bestiary-hero-ability {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(26, 26, 36, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
}

.bestiary-ability-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(42, 26, 0, 0.8);
  border: 1px solid var(--gold);
  border-radius: 4px;
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

/* === Footer === */
.bestiary-footer {
  display: flex;
  justify-content: center;
  margin-top: 14px;
  flex-shrink: 0;
}

/* === Lightbox === */
.bestiary-lightbox {
  position: absolute;
  inset: 0;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bestiary-lightbox--open {
  pointer-events: all;
  opacity: 1;
}

.bestiary-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
}

.bestiary-lightbox-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: slideUp 0.3s ease;
  max-width: min(92vw, 1040px);
}

.bestiary-lightbox-main {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 22px;
  max-width: 100%;
}

.bestiary-lightbox-text {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  max-width: 520px;
  min-width: 260px;
  padding: 6px 4px;
  color: #d7cdb8;
}

.bestiary-lightbox-media {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#bestiary-lightbox-canvas,
#bestiary-lightbox-img {
  display: block;
  width: 400px;
  height: 400px;
  border: 2px solid rgba(212, 160, 23, 0.4);
  border-radius: 12px;
  background: rgba(17, 17, 24, 0.9);
  box-shadow: 0 0 60px rgba(212, 160, 23, 0.15), 0 20px 60px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
}

#bestiary-lightbox-img {
  object-fit: cover;
}

.bestiary-lightbox-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(212, 160, 23, 0.3);
  margin-bottom: 12px;
}

.bestiary-lightbox-lore {
  font-size: 14px;
  line-height: 1.65;
  color: #cfc5b0;
  font-style: italic;
  white-space: pre-wrap;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 6px;
}

.bestiary-lightbox-lore::-webkit-scrollbar {
  width: 6px;
}

.bestiary-lightbox-lore::-webkit-scrollbar-thumb {
  background: rgba(212, 160, 23, 0.25);
  border-radius: 3px;
}

.bestiary-lightbox-hint {
  font-size: 11px;
  color: rgba(138, 128, 112, 0.5);
  letter-spacing: 1px;
}

@media (max-width: 900px) {
  .bestiary-lightbox-main {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }
  .bestiary-lightbox-text {
    max-width: 92vw;
    min-width: 0;
    align-items: center;
    text-align: center;
  }
  .bestiary-lightbox-lore {
    text-align: left;
  }
}

/* === Tower Levels Table === */
.bestiary-levels {
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 8px;
}

.bestiary-levels-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.bestiary-levels-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.bestiary-levels-table thead th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 10px;
  text-align: center;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  letter-spacing: 0.5px;
}

.bestiary-levels-table tbody td {
  text-align: center;
  padding: 3px 6px;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.bestiary-levels-table tbody tr:hover {
  background: rgba(212, 160, 23, 0.06);
}

.bestiary-levels-table tbody tr.bestiary-lvl-first td {
  color: var(--gold);
  font-weight: 600;
}

.bestiary-levels-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

/* Sprite zoom cursor */
.bestiary-card-sprite:hover,
.bestiary-hero-portrait:hover {
  border-color: rgba(212, 160, 23, 0.4);
  box-shadow: 0 0 12px rgba(212, 160, 23, 0.1);
}

/* === Resistances === */
.bestiary-resistances {
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 6px;
}

.bestiary-res-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-bottom: 5px;
}

.bestiary-res-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.bestiary-res-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.bestiary-res-pill:hover {
  transform: translateY(-1px);
}

.bestiary-res-label {
  font-weight: 500;
}

.bestiary-res-val {
  font-weight: 700;
}

/* Сопротивление (зелёный) */
.bestiary-res--resist {
  background: rgba(76, 175, 80, 0.12);
  border-color: rgba(76, 175, 80, 0.25);
  color: #81c784;
}

/* Уязвимость (красный) */
.bestiary-res--weak {
  background: rgba(244, 67, 54, 0.12);
  border-color: rgba(244, 67, 54, 0.25);
  color: #ef9a9a;
}

/* Нейтральный (серый) */
.bestiary-res--neutral {
  background: rgba(158, 158, 158, 0.08);
  border-color: rgba(158, 158, 158, 0.15);
  color: #757575;
}

/* Spell tooltip animation */
@keyframes spellTipIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes towerTipInLeft {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
