:root {
  --tg-header: 48px;
  --hud-side-padding: 12px;
}

/* ===== Base ===== */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', Inter, system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: #0f1216;
  color: #111;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
}

/* ===== HUD (top panel) =====
   Слева: баланс + доход
   Справа: индикаторы энергии и уровня
*/
.hud-panel {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 80px);
  max-width: 480px;
  background: #000;
  border-radius: 16px;
  padding: 12px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  z-index: 1000;
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* выезжающая строка */
.liquid-earned {
  position: fixed;
  top: calc(120px + 60px); /* сразу под HUD (20px отступ + высота HUD ~60px) */
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  width: calc(100% - 80px);
  max-width: 480px;
  background: #000;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding: 10px;
  border-radius: 16px;
  opacity: 0;
  transition: transform 0.5s ease, opacity 0.5s ease;
  pointer-events: none;
  z-index: 999;
}

.liquid-earned.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hud-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.money-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.money-currency {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}

.money-value {
  font-size: 18px;
  line-height: 1;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.money-caption {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,.7);
}

.income-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.income-icon {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}

.income-text {
  font-size: 16px;
  line-height: 1;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Правая часть HUD */
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== Circular gauges ===== */
.gauge {
  position: relative;
  width: 56px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gauge svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.gauge-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 6;
}

.gauge-fg {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset .3s ease, stroke .3s ease;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gauge-center img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.gauge-center span {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}

/* ===== Scene and screens ===== */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  overflow: visible; /* ⚡ glow не режется */
  background: url('backgrounds/apartment.webp') top center / cover no-repeat;
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--tg-header));
  z-index: 0;
}

.scene.is-hidden { display: none; }

.screen {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(56px + env(safe-area-inset-top, 0px) + var(--tg-header));
  bottom: 140px;
  padding: 12px;
  background: rgba(246, 247, 251, 0.85);
  backdrop-filter: blur(6px);
  display: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}

.screen.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

/* ===== Cat ===== */
.cat {
  position: absolute;
  bottom: 23vh;
  z-index: 1;
  max-height: 78vh;
  max-width: 92vw;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform .1s ease;
}

/* ===== Map and business panel ===== */
#screen-business #map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
.business-panel {
  position: relative;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(255, 255, 255, 0.94);
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
  display: none;
  width: 280px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.business-panel.active {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.business-panel h3 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 900;
  color: #0f1221;
}

.business-panel button {
  margin-top: 8px;
  background: #6b7cff;
  color: #fff;
  padding: 8px 12px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 900;
}

.biz-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 20px;
  font-weight: bold;
  color: #333; /* тёмный крестик, чтобы не терялся */
  cursor: pointer;
  line-height: 1;
}

.biz-close:hover {
  color: #ff5252;
}

/* Подсветка статуса */
.biz-status {
  margin-top: 8px;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-block;
}

.biz-status.free {
  background: rgba(0,200,83,0.15);
  color: #00c853;
}

.biz-status.owned {
  background: rgba(33,150,243,0.15);
  color: #2196f3;
}

.biz-status.taken {
  background: rgba(244,67,54,0.15);
  color: #f44336;
}

/* ===== FAB menu ===== */
.fab-container {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 3000; /* выше HUD и панелей */
}

.fab-main {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 0);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #000;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px rgba(0,0,0,0.45), inset 0 2px 0 rgba(255,255,255,0.06);
  cursor: pointer;
  transition: transform .18s ease;
}

.fab-main:active {
  transform: translate(-50%, 1px) scale(0.98);
}

.fab-main img {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}

.fab-item {
  position: absolute;
  left: 50%;
  bottom: 36px;
  transform: translate(-50%, 0) scale(0.6);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #000;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .25s ease;
  will-change: transform, opacity;
}

.fab-item img {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}

.fab-container.open .fab-item {
  opacity: 1;
  pointer-events: auto;
}

/* ===== Misc ===== */
#map { z-index: 1; }
.business-panel { z-index: 10; }

.leaflet-control-attribution a[href*="carto.com"],
.leaflet-control-attribution img {
  display: none !important;
}

/* ===== Fullscreen business map ===== */
#screen-business {
  position: absolute;
  inset: 0;            /* растягиваем на весь экран */
  padding: 0;          /* убираем внутренние отступы */
  background: #000;    /* фон под картой (можно прозрачный) */
  backdrop-filter: none;
  overflow: hidden;
  z-index: 5;          /* ниже HUD, но выше сцены */
}

#screen-business.active {
  display: block;
  opacity: 1;
  transform: none;
}

#screen-business #map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Центрированная бизнес‑панель поверх карты */
.business-panel {
  position: absolute;
  left: 50%;
  bottom: 100px;              /* ⚡ поднимаем выше FAB (72px + отступы) */
  transform: translateX(-50%) translateY(20px);
  background: rgba(255, 255, 255, 0.94);
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
  display: none;
  width: 90%;                 /* ⚡ адаптивная ширина */
  max-width: 360px;           /* ограничение по ширине */
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-height: 50%;            /* не выше половины экрана */
  overflow-y: auto;           /* скролл если контента много */
}

.business-panel.active {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Filter button & panel ===== */
.filter-toggle {
  position: absolute;
  bottom: 100px;   /* чуть выше FAB, можно подогнать */
  left: 12px;
  z-index: 1200;
  background: #000;
  border: none;
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.filter-toggle img {
  width: 24px;
  height: 24px;
  filter: invert(1);
}

.filter-panel {
  position: absolute;
  left: 50%;
  top: 180px; /* ⚡ ниже HUD, чтобы не перекрывал */
  transform: translateX(-50%) translateY(-20px);
  background: rgba(255,255,255,0.95);
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
  width: 90%;
  max-width: 320px;
  z-index: 1300;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.filter-panel.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.filter-panel h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 900;
  color: #0f1221;
}
.filter-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #333;
}
.filter-panel input,
.filter-panel select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #ccc;
  margin-top: 4px;
}
.filter-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 20px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
}

/* ===== Магазин (Shop) ===== */
.screen-shop-full {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, #10131a 0%, #0a0b0e 80%);
  padding-top: 180px; /* ⚡ реальный отступ под HUD */
  display: none;
  overflow: visible;   /* ⚡ glow не режется */
  z-index: 20;
  color: #fff;
  font-family: "Poppins", "Inter", sans-serif;
}

.screen-shop-full:not([hidden]) {
  display: block;
  opacity: 1;
  transform: none;
}

.screen-title {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin: 20px 0;
  color: #f5f5f7;
  text-shadow: 0 0 8px rgba(255,255,255,0.25);
  position: relative;
  z-index: 1100; /* ⚡ выше HUD */
}

.shop-cards {
  display: flex;
  gap: 24px;
  padding: 20px 40px; /* ⚡ добавили поля слева/справа */
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  z-index: 50;
}

/* скрываем скроллбары */
.shop-cards::-webkit-scrollbar,
.shop-tabs::-webkit-scrollbar { display: none; }
.shop-cards, .shop-tabs {
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.shop-card {
  flex: 0 0 auto;
  width: 260px;
  aspect-ratio: 2/3;
  border-radius: 20px;
  position: relative;
  overflow: visible; /* ⚡ убрали hidden */
  background: linear-gradient(145deg, rgba(25,25,35,0.8), rgba(10,10,20,0.8));
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 0 20px rgba(0,0,0,0.4);
  transition: transform 0.4s ease, box-shadow 0.4s ease;
  cursor: pointer;
}

.shop-card.active {
  transform: translateY(-10px) scale(1.05);
  box-shadow: 0 0 30px rgba(80,200,255,0.4);
}

.shop-card-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 80%, rgba(80,200,255,0.2), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.shop-card.active .shop-card-glow { opacity: 1; }

.shop-card-content {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 2;
}

.shop-card-content h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.shop-card-content p {
  font-size: 0.9rem;
  opacity: 0.8;
}

.shop-card-illustration {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  height: 70%;
  z-index: 1;
  pointer-events: none;
  filter: drop-shadow(0 0 20px rgba(255,255,255,0.25));
  transition: transform .3s ease;
  max-width: 100%;
  max-height: 100%;
  clip-path: inset(0 round 20px); /* ⚡ повторяем радиус */
}
.shop-card.active .shop-card-illustration {
  transform: translateX(-50%) translateY(-8px) scale(1.05);
}

/* ===== Вкладки и товары ===== */
.shop-items {
  margin-top: 20px;
  padding: 0 20px;
  display: none;
  background: none;
  border: none;
  overflow: visible;
}
.shop-items.active { display: block; }

.shop-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 40px; /* ⚡ добавили поля слева/справа */
  overflow-x: auto;
  overflow-y: visible;
}

.shop-tabs .tab {
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(20,20,30,0.6);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.3s ease;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.shop-tabs .tab.active {
  background: linear-gradient(145deg, rgba(25,25,35,0.9), rgba(10,10,20,0.9));
  box-shadow: 0 0 25px rgba(80,200,255,0.5);
  transform: translateY(-2px) scale(1.05);
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.shop-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(80,200,255,0.3);
}
.shop-item img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}
.shop-item h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.shop-item span {
  font-size: 0.85rem;
  opacity: 0.8;
}

/* ===== Модалки магазина ===== */
.market-modal {
  display: none;              /* скрыта по умолчанию */
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 5000;
  align-items: center;
  justify-content: center;
}

.market-modal.active {
  display: flex;              /* показываем при active */
}

.market-modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  color: #000;
  font-family: "Poppins", "Inter", sans-serif;
}

.market-modal-card h3 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.2rem;
  font-weight: 600;
}

.market-modal-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.market-modal-card input,
.market-modal-card select {
  width: 100%;
  padding: 6px 8px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
}

.market-modal-card .modal-actions {
  text-align: right;
  margin-top: 16px;
}

.market-modal-card button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: #007bff;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}
.market-modal-card button:hover {
  background: #0056b3;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}
