/*
  header.css — Стили для header-панели.
  Компактный хедер: персонаж, ресурсы, инструменты, кнопки панелей.
*/

/* === Header === */
#game-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 6px 14px;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border-bottom: 2px solid #0f3460;
  min-height: 62px;
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
  user-select: none;
  position: relative;
}

/* ============================
   ЛЕВЫЙ БЛОК (персонаж + инструменты + панели)
   ============================ */
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 1;
  min-width: 0;
  flex-wrap: wrap;
  z-index: 3;
}

/* Квесты (звезда) сразу после карточки игрока */
.header-panel-btns-quests {
  gap: 10px;
}

/* Четыре панели по центру окна браузера (вьюпорта) */
.header-center-nav {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(14px, 3vw, 32px);
  z-index: 2;
  pointer-events: none;
}

.header-center-nav > * {
  pointer-events: auto;
}

.header-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.header-nav-label {
  font-size: 10px;
  font-weight: 700;
  color: rgba(200, 216, 248, 0.82);
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-bottom: 3px;
}

/* Справа: сводка ресурсов и кнопка возврата из полноэкранного embed */
.header-right-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-divider {
  width: 1px;
  height: 40px;
  background: rgba(255,255,255,0.08);
  flex-shrink: 0;
}

/* === Блок персонажа === */
.header-player {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4488ff, #2255cc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  border: 2px solid #6aa8ff;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(68, 136, 255, 0.3);
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-weight: bold;
  font-size: 13px;
  color: #c8d8f8;
}

.player-level-badge {
  font-size: 10px;
  font-weight: bold;
  color: #FFD700;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.25);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.3;
}

/* === Бары HP / XP === */
.player-bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bar-label {
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  width: 14px;
  text-align: right;
  flex-shrink: 0;
}

.hp-label { color: #e57373; }
.xp-label { color: #8BC34A; }

.bar-value {
  font-size: 9px;
  color: #888;
  min-width: 40px;
  text-align: left;
  flex-shrink: 0;
}

.hp-bar, .xp-bar {
  width: 100px;
  height: 6px;
  background: #1a1a2a;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}

.hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #e53935, #ef5350);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 100%;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4CAF50, #8BC34A);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ============================
   РЕСУРСЫ (правая часть)
   ============================ */
.header-resources {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 6px;
  flex-shrink: 1;
  min-width: 0;
  max-width: min(520px, 52vw);
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.06);
  cursor: default;
  transition: background 0.15s;
}

.resource-item:hover {
  background: rgba(255,255,255,0.08);
}

.resource-icon {
  font-size: 14px;
}

.resource-value {
  font-size: 13px;
  font-weight: bold;
  color: #90EE90;
  min-width: 16px;
  text-align: center;
}

.header-resources-scroll {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(320px, 52vh);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 6px 4px 2px;
  max-width: min(340px, 42vw);
  background: rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  scrollbar-width: thin;
}

.header-res-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.header-res-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.header-res-ic .ui-svg-icon {
  display: flex;
  align-items: center;
}

.header-res-ic .ui-svg-icon svg {
  width: 16px;
  height: 16px;
}

.header-res-n {
  font-size: 12px;
  font-weight: bold;
  color: #a5d6a7;
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Растягиваем центр хедера, если справа нет блока ресурсов */
.header-spacer {
  flex: 1;
  min-width: 8px;
}

/* Сводка справа в хедере: дерево / камень / золото */
.header-right-totals {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px 8px;
  flex-shrink: 0;
  max-width: min(340px, 38vw);
}

.header-total-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #e8f5e9;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.header-total-pill .ui-svg-icon svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.95;
}

.header-total-pill .header-total-num {
  color: #fff9c4;
}

/* ============================
   ВЫБОР ИНСТРУМЕНТА (плавающая панель)
   ============================ */
/* HUD сырья: слева; top задаёт JS = верх canvas + отступ под HUD дня/ночи */
.resource-hud {
  position: absolute;
  z-index: 11;
  pointer-events: none;
  width: min(52vw, 280px);
  min-width: 140px;
  padding: 0;
}

.resource-hud--stack {
  left: 6px;
  right: auto;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.resource-hud--stack .resource-hud-legend {
  text-align: left;
}

/* Один скролл: сначала блок дерева (все породы), затем блок камня — без наложения двух max-height */
.resource-hud-scroll {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  width: 100%;
  max-height: min(calc(100vh - 180px), 68vh);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px 4px 4px 0;
  pointer-events: auto;
}

.resource-hud-block {
  flex: 0 0 auto;
  width: 100%;
  min-height: 0;
}

.resource-hud-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
}

.resource-hud-legend {
  display: block;
  font-size: 9px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 3px;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9), 0 1px 2px rgba(0, 0, 0, 0.95);
}

/* legacy: если где-то остался класс chips */
.resource-hud-chips {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
}

.resource-hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #e8f5e9;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.95), 0 1px 3px rgba(0, 0, 0, 1);
  line-height: 1.25;
}

.resource-hud-row .ui-svg-icon svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.85));
}

.resource-hud-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.resource-hud-empty {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.45);
  font-style: italic;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
}

.tool-selector-float {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: auto;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(10, 10, 30, 0.78);
  padding: 5px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(8px);
  z-index: 8;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  user-select: none;
}

/* Визуальный разрыв между группами: инструменты | постройки | зелья (без фона, ~половина кнопки) */
.tool-group-spacer {
  width: 20px;
  height: 40px;
  flex-shrink: 0;
  pointer-events: none;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  font-size: 22px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}

.tool-btn .ui-svg-icon svg {
  width: 24px;
  height: 24px;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.14);
  transform: translateY(-1px);
}

.tool-btn.active {
  border-color: #4FC3F7;
  background: rgba(79, 195, 247, 0.2);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.3), inset 0 0 8px rgba(79, 195, 247, 0.1);
}

.tool-btn.tool-potion-tile {
  border-radius: 50%;
}

.tool-btn.tool-potion-heal {
  border-color: rgba(129, 199, 132, 0.35);
}

.tool-btn.tool-potion-heal:not(.is-empty) {
  background: rgba(76, 175, 80, 0.18);
  border-color: rgba(129, 199, 132, 0.55);
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.25);
}

.tool-btn.tool-potion-speed {
  border-color: rgba(79, 195, 247, 0.35);
}

.tool-btn.tool-potion-speed:not(.is-empty) {
  background: rgba(79, 195, 247, 0.14);
  border-color: rgba(129, 212, 250, 0.55);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.22);
}

.tool-btn.tool-potion-defense {
  border-color: rgba(186, 104, 200, 0.35);
}

.tool-btn.tool-potion-defense:not(.is-empty) {
  background: rgba(186, 104, 200, 0.12);
  border-color: rgba(206, 147, 216, 0.5);
  box-shadow: 0 0 10px rgba(186, 104, 200, 0.2);
}

.tool-btn.tool-potion-tile.is-empty {
  opacity: 0.42;
  filter: grayscale(0.55);
  cursor: pointer;
}

.tool-btn.tool-potion-tile:not(.is-empty):hover {
  transform: translateY(-1px);
}

.tool-btn.tool-trap {
  border-radius: 8px;
  border-color: rgba(255, 193, 7, 0.35);
}

.tool-btn.tool-trap:not(.is-empty) {
  background: rgba(255, 193, 7, 0.12);
  border-color: rgba(255, 213, 79, 0.5);
}

.tool-btn.tool-trap.is-empty {
  opacity: 0.38;
  filter: grayscale(0.5);
  pointer-events: none;
  cursor: default;
}

.tool-btn-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: #222;
  color: #fff;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 6px;
  border: 1px solid #555;
  line-height: 1;
  pointer-events: none;
}

.tool-btn.tool-hotkeys-btn {
  width: 34px;
  height: 34px;
  font-size: 15px;
  margin-left: 2px;
  border-color: rgba(255, 255, 255, 0.14);
  color: #b0bec5;
}

.tool-btn.tool-hotkeys-btn:hover {
  color: #fff;
  border-color: rgba(144, 202, 249, 0.45);
  background: rgba(100, 150, 255, 0.12);
}

/* Панель «все бинды» */
.hotkeys-panel {
  position: fixed;
  inset: 0;
  z-index: 56;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.hotkeys-panel[hidden] {
  display: none !important;
}

.hotkeys-panel-inner {
  width: 100%;
  max-width: 420px;
  max-height: min(80vh, 520px);
  overflow: auto;
  background: rgba(18, 18, 35, 0.98);
  border: 1px solid rgba(100, 150, 255, 0.25);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.hotkeys-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.hotkeys-title {
  font-size: 16px;
  font-weight: 700;
  color: #e3f2fd;
}

.hotkeys-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #bbb;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.hotkeys-close:hover {
  background: rgba(244, 67, 54, 0.25);
  color: #fff;
}

.hotkeys-lead {
  margin: 0;
  padding: 10px 14px 0;
  font-size: 12px;
  color: #90a4ae;
  line-height: 1.4;
}

.hotkeys-table-wrap {
  padding: 12px 14px 16px;
}

.hotkeys-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  color: #cfd8dc;
}

.hotkeys-table th,
.hotkeys-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hotkeys-table th {
  color: #81d4fa;
  font-weight: 600;
  width: 38%;
}

.hotkeys-table tr:last-child td {
  border-bottom: none;
}

.hotkeys-footnote {
  margin: 12px 0 0;
  font-size: 11px;
  color: #78909c;
  line-height: 1.45;
}

.hotkeys-kbd {
  display: inline-block;
  padding: 2px 7px;
  margin: 0 2px 0 0;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #fff9c4;
}

/* === Кнопки панелей === */
.header-panel-btns {
  display: flex;
  align-items: center;
}

/* Иконка прокачки: зелёная стрелка вверх (не эмодзи — стабильный цвет) */
.icon-upgrade-growth {
  color: #66BB6A;
  font-size: 33px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 8px rgba(102, 187, 106, 0.4);
}

.icon-upgrade-growth--title {
  display: inline-flex;
  font-size: 17px;
  margin-right: 4px;
  vertical-align: middle;
  text-shadow: none;
}

.panel-toggle-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #bbb;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.panel-toggle-btn.panel-toggle-btn-lg {
  width: 42px;
  height: 42px;
  font-size: 30px;
  border-radius: 8px;
}

.panel-toggle-btn:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
  transform: translateY(-1px);
}

.panel-toggle-btn.active {
  background: rgba(100, 150, 255, 0.2);
  border-color: rgba(100, 150, 255, 0.4);
  color: #8ab4f8;
  box-shadow: 0 0 6px rgba(100, 150, 255, 0.15);
}

/* ============================
   DEBUG-BAR (скрытая панель)
   ============================ */
.debug-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  background: rgba(255, 200, 50, 0.06);
  border-bottom: 1px solid rgba(255, 200, 50, 0.15);
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.debug-bar.hidden {
  display: none;
}

.debug-title {
  font-size: 9px;
  font-weight: bold;
  color: rgba(255, 200, 50, 0.5);
  letter-spacing: 1px;
  margin-right: 4px;
}

.debug-bar input {
  width: 48px;
  padding: 3px 5px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255, 200, 50, 0.2);
  border-radius: 4px;
  color: #FFD54F;
  font-size: 10px;
  text-align: center;
  outline: none;
}

.debug-bar input::placeholder {
  color: rgba(255, 213, 79, 0.35);
}

.debug-bar input:focus {
  border-color: rgba(255, 200, 50, 0.5);
}

.debug-bar button {
  padding: 2px 8px;
  background: rgba(255, 200, 50, 0.1);
  border: 1px solid rgba(255, 200, 50, 0.2);
  border-radius: 4px;
  color: #FFD54F;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.debug-bar button:hover {
  background: rgba(255, 200, 50, 0.25);
}

/* ============ Планшет / узкое окно (восстановленное из максимизации и т.п.) ============ */
@media (max-width: 1100px) {
  #game-header {
    flex-wrap: wrap;
    align-items: flex-start;
    row-gap: 8px;
    padding: 6px 10px;
  }

  .header-spacer {
    display: none;
  }

  .header-center-nav {
    position: static;
    left: auto;
    top: auto;
    transform: none;
    order: 5;
    flex: 1 1 100%;
    width: 100%;
    align-items: flex-end;
    justify-content: center;
    margin-top: 2px;
    padding-bottom: 2px;
    gap: clamp(10px, 2.5vw, 22px);
  }

  .header-right-cluster {
    flex: 1 1 100%;
    order: 10;
    justify-content: flex-start;
    margin-left: 0;
  }

  .header-right-totals {
    max-width: none;
  }

  .header-left {
    flex: 1 1 auto;
    min-width: 0;
    order: 1;
  }

  .hp-bar,
  .xp-bar {
    width: min(92px, 28vw);
  }

  .resource-hud {
    width: min(48vw, 240px);
  }

  .resource-hud-scroll {
    max-height: min(calc(100vh - 200px), 55vh);
  }

  .tool-btn {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }

  .tool-group-spacer {
    width: 10px;
    height: 36px;
  }

  .tool-selector-float {
    padding: 4px 5px;
    gap: 3px;
  }
}

@media (max-height: 720px) {
  #game-header {
    min-height: 48px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .header-nav-label {
    font-size: 9px;
    max-width: 64px;
  }

  .player-avatar {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .resource-hud-scroll {
    max-height: min(calc(100vh - 160px), 50vh);
  }
}

/* ============ Телефон: меньше перекрытий над картой, тап по земле ============ */
@media (max-width: 600px) {
  #game-header {
    padding: 4px 6px;
    row-gap: 4px;
    min-height: 0;
  }

  .header-nav-label {
    display: none;
  }

  .header-center-nav {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-top: 0;
    padding-bottom: 2px;
  }

  .header-center-nav::-webkit-scrollbar {
    display: none;
  }

  .header-nav-item {
    flex-shrink: 0;
  }

  .header-player {
    gap: 6px;
  }

  .player-name {
    font-size: 11px;
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hp-bar,
  .xp-bar {
    width: min(72px, 22vw);
    height: 5px;
  }

  .bar-value {
    font-size: 8px;
    min-width: 34px;
  }

  .header-total-pill {
    font-size: 9px;
    padding: 2px 6px;
  }

  .resource-hud.resource-hud--stack {
    left: 4px;
    max-width: min(36vw, 132px);
    width: auto;
  }

  .resource-hud-scroll {
    max-height: min(20vh, 140px);
    padding: 2px 2px 2px 0;
  }

  /* Панель инструментов снизу — не перекрывает центр карты (top задаётся из JS) */
  .tool-selector-float {
    left: 50% !important;
    top: auto !important;
    bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
    transform: translateX(-50%);
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100% - 10px);
    gap: 3px;
    padding: 4px 5px;
  }

  .tool-btn {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .tool-group-spacer {
    width: 6px;
    height: 34px;
  }
}
