* { box-sizing: border-box; user-select: none; }
body {
  margin: 0;
  padding: 0;
  background: #120d09;
  color: #2b1b0e;
  font-family: 'Georgia', 'Palatino Linotype', 'Book Antiqua', serif;
  overflow: hidden;
}
#wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #141920;
  overflow: hidden;
}
#canvas3d {
  display: block;
  width: 100%;
  height: 100%;
}
#overlay2d {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Пергаментный бейдж загрузки */
#loading-badge {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #f3e3c3 0%, #dfc492 100%);
  border: 2px solid #5c3a18;
  outline: 1px solid #c89d54;
  color: #3b220c;
  padding: 5px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  z-index: 20;
  pointer-events: none;
  box-shadow: inset 0 0 10px rgba(102, 65, 24, 0.35), 0 4px 14px rgba(0,0,0,0.65);
  transition: opacity 0.3s;
}

/* Базовая пергаментная панель MMORPG */
.panel {
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 248, 231, 0.45), transparent 65%),
    linear-gradient(165deg, #f4e4c4 0%, #e5cca0 55%, #d6b67e 100%);
  border: 2px solid #5a3816;
  outline: 1px solid #c99e52;
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 12px;
  color: #2c1a0b;
  pointer-events: auto;
  box-shadow:
    inset 0 0 16px rgba(107, 68, 25, 0.38),
    inset 0 1px 0 rgba(255, 247, 226, 0.7),
    0 6px 18px rgba(0, 0, 0, 0.65);
}

/* Левый верхний фрейм персонажа */
#hud-top-left {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.unit-frame {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
}
.portrait-crest {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a2c10, #1f1208);
  border: 2px solid #5a3816;
  outline: 2px solid #c89d54;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 23px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.8), 0 2px 6px rgba(0,0,0,0.45);
  flex-shrink: 0;
}
.unit-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.unit-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}
.silver-pill {
  color: #78350f;
  background: rgba(255, 248, 231, 0.65);
  border: 1px solid #b88c44;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}
.bar-wrap {
  position: relative;
  width: 188px;
  height: 15px;
  background: #2b1b0f;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #6b441e;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
}
.bar-fill {
  height: 100%;
  transition: width 0.12s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
}
.hp-fill {
  background: linear-gradient(90deg, #881313, #dc2626);
}
.weight-fill {
  background: linear-gradient(90deg, #92400e, #d97706);
}
.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #fffbeb;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  pointer-events: none;
}

.camp-panel {
  padding: 7px 11px;
}
.camp-title {
  font-size: 11px;
  font-weight: 800;
  color: #5c2808;
  margin-bottom: 5px;
}
.camp-btns {
  display: flex;
  gap: 6px;
}
.btn-camp {
  background: linear-gradient(180deg, #b45309 0%, #7c2d12 100%);
  color: #fef3c7;
  border: 1px solid #451a03;
  outline: 1px solid #d97706;
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
}
.btn-camp:hover {
  background: linear-gradient(180deg, #d97706 0%, #9a3412 100%);
}
.btn-camp:disabled {
  background: #8c7a62;
  color: #d6cbb9;
  outline-color: #6e5e49;
  cursor: default;
}

/* Правый верхний угол: Мини-карта + пергаментный баннер зоны */
#minimap-cluster {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}
#minimap-wrap {
  position: relative;
  width: 172px;
  height: 172px;
  background: #23160c;
  border: 4px solid #5c3a18;
  outline: 2px solid #c89d54;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: auto;
  box-shadow:
    inset 0 0 12px rgba(0,0,0,0.85),
    0 6px 20px rgba(0,0,0,0.75);
}
#minimap {
  width: 164px;
  height: 164px;
  display: block;
  cursor: pointer;
}
.compass-n {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  background: #4a2c10;
  color: #fde68a;
  border: 1px solid #c89d54;
  font-size: 9px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 3px;
  pointer-events: none;
}
#zone-banner {
  padding: 4px 12px;
  border-radius: 5px;
  background: linear-gradient(180deg, #f5e6c8 0%, #dfc38d 100%);
  border: 2px solid #5c3a18;
  outline: 1px solid #c99e52;
  font-size: 11px;
  font-weight: 800;
  color: #3b210d;
  text-align: center;
  max-width: 210px;
  box-shadow:
    inset 0 0 10px rgba(102, 65, 24, 0.32),
    0 4px 12px rgba(0, 0, 0, 0.65);
}

/* Нижний центр: компактный пергаментно-бронзовый хотбар MMORPG */
#hud-bottom {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  background: linear-gradient(180deg, rgba(58, 36, 18, 0.92) 0%, rgba(34, 20, 10, 0.95) 100%);
  border: 2px solid #4a2c10;
  outline: 1px solid #c89d54;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.8);
}
.hotbar-divider {
  width: 2px;
  height: 44px;
  background: linear-gradient(180deg, transparent, #c89d54, transparent);
  margin: 0 2px;
}
.slot {
  background: linear-gradient(180deg, #f2e1be 0%, #dcc08e 100%);
  border: 2px solid #5c3a18;
  outline: 1px solid #b88c44;
  border-radius: 6px;
  width: 64px;
  height: 60px;
  padding: 4px;
  text-align: center;
  cursor: pointer;
  color: #2c1a0b;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  box-shadow:
    inset 0 0 10px rgba(107, 68, 25, 0.3),
    0 2px 6px rgba(0,0,0,0.55);
  transition: transform 0.08s, border-color 0.12s;
}
.slot:hover {
  transform: translateY(-2px);
  border-color: #8c5820;
  background: linear-gradient(180deg, #faedd2 0%, #e5cb9b 100%);
}
.slot.active {
  border-color: #991b1b;
  outline: 2px solid #f59e0b;
  background: linear-gradient(180deg, #fdf3dc 0%, #ebd09a 100%);
  box-shadow:
    inset 0 0 12px rgba(180, 83, 9, 0.35),
    0 0 10px rgba(245, 158, 11, 0.55);
}
.slot .key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  color: #5c3a18;
  font-weight: 800;
  background: rgba(255, 248, 231, 0.75);
  padding: 0 3px;
  border-radius: 3px;
}
.slot .slot-ico {
  font-size: 20px;
  line-height: 1;
  margin-top: 10px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}
.slot .title {
  font-weight: 800;
  font-size: 10px;
  color: #2b1809;
  white-space: nowrap;
}

/* Модальное окно Инвентаря (Фолиант / Пергаментный сундук) */
#inv-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 740px;
  max-width: 95vw;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 250, 235, 0.55), transparent 70%),
    linear-gradient(160deg, #f5e7ca 0%, #e5cda0 55%, #d3b277 100%);
  border: 4px solid #4a2c10;
  outline: 2px solid #c89d54;
  border-radius: 10px;
  padding: 18px 20px;
  z-index: 30;
  display: none;
  color: #2b1a0c;
  box-shadow:
    inset 0 0 28px rgba(92, 54, 18, 0.45),
    0 22px 55px rgba(0, 0, 0, 0.85);
}
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #8c6230;
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.inv-header h3 {
  margin: 0;
  font-size: 18px;
  color: #3b1f0b;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.6);
}
.inv-close {
  background: linear-gradient(180deg, #8b261d 0%, #5c1610 100%);
  color: #fef3c7;
  border: 1px solid #3b0d09;
  outline: 1px solid #cfa055;
  border-radius: 5px;
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
}
.inv-close:hover {
  background: linear-gradient(180deg, #a83227 0%, #731c15 100%);
}

/* Двухколоночная разметка книги: min-width: 0 на обоих блоках предотвращает перекос сетки */
.inv-body {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.inv-right-col {
  min-width: 0;
  width: 100%;
}
.equip-box {
  background: linear-gradient(180deg, rgba(232, 208, 165, 0.9) 0%, rgba(214, 184, 132, 0.9) 100%);
  border: 2px solid #785024;
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  box-shadow: inset 0 0 12px rgba(92, 54, 18, 0.28);
}
.equip-slot {
  background: #f6ead1;
  border: 1px solid #8c6230;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  box-shadow: inset 0 1px 3px rgba(92, 54, 18, 0.2);
}

/* Идеально ровная сетка 5x4 с фиксированной шириной колонок minmax(0, 1fr) */
.bag-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: 84px;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.bag-cell {
  background: linear-gradient(180deg, #ebd7b2 0%, #d8bc8a 100%);
  border: 2px solid #855c2b;
  border-radius: 7px;
  height: 84px;
  min-width: 0;
  width: 100%;
  padding: 5px 4px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(74, 44, 16, 0.28), 0 1px 2px rgba(255,255,255,0.45);
  transition: transform 0.08s, border-color 0.12s, box-shadow 0.12s;
}
.bag-cell:hover {
  transform: translateY(-2px);
  border-color: #4a2c10;
  background: linear-gradient(180deg, #f8ebd0 0%, #e5cb9c 100%);
}
/* Цветовая кодировка тиров на пергаменте */
.bag-cell.t2 {
  border-color: #1d4ed8;
  background: linear-gradient(180deg, #e0ecff 0%, #c7dbf7 100%);
  box-shadow: inset 0 0 10px rgba(29, 78, 216, 0.22);
}
.bag-cell.t3 {
  border-color: #15803d;
  background: linear-gradient(180deg, #dcfce7 0%, #bbf7d0 100%);
  box-shadow: inset 0 0 10px rgba(21, 128, 61, 0.22);
}
.bag-cell.t4 {
  border-color: #7e22ce;
  background: linear-gradient(180deg, #f3e8ff 0%, #e2cbfc 100%);
  box-shadow: inset 0 0 10px rgba(126, 34, 206, 0.25);
}
.bag-cell .tier-tag {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  font-weight: 800;
  color: #4a2c10;
  background: rgba(255, 248, 231, 0.75);
  padding: 0 3px;
  border-radius: 3px;
}
.bag-cell .qty-tag {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 11px;
  font-weight: 800;
  color: #2b1809;
  background: rgba(255, 248, 231, 0.8);
  padding: 0 4px;
  border-radius: 3px;
}
.bag-cell .ico {
  font-size: 24px;
  line-height: 1;
  margin-top: 15px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.25));
}
.bag-cell .nm {
  width: 100%;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  color: #2b1809;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}
#inv-Selected-Info {
  margin-top: 10px;
  padding: 8px 12px;
  background: #f6ead1;
  border: 1px solid #8c6230;
  border-radius: 6px;
  font-size: 11px;
  color: #3b210d;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  box-shadow: inset 0 1px 3px rgba(92, 54, 18, 0.2);
}
