/* ============ THANH TRẠNG THÁI + BẢNG NHÂN VẬT + THÔNG BÁO ============ */

/* ---------------- thanh kinh nghiệm cố định ở đáy ---------------- */

/**
 * z-index 50 để nằm TRÊN cả màn chiến đấu (z 30) — người chơi phải xem được
 * thanh kinh nghiệm ở mọi lúc, kể cả đang đánh nhau. Màn chiến đấu chừa sẵn
 * padding dưới để không bị thanh này che mất thanh kỹ năng.
 */
#statusBar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 7px 12px;
  background: rgba(11, 15, 24, .96);
  border-top: 1px solid #263047;
  backdrop-filter: blur(8px);
  z-index: 50;
}
#statusBar.hidden { display: none; }

.sb-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  text-align: left;
}
.sb-main:hover { background: #131b2c; border-color: #2b3651; }

.sb-name { color: #e6e9ef; font-weight: 600; font-size: 13px; white-space: nowrap; }
.sb-name em { font-style: normal; color: #8b95ab; font-weight: 400; font-size: 12px; }

.sb-exp {
  position: relative;
  flex: 1;
  min-width: 90px;
  max-width: 420px;
  height: 17px;
  background: #0a0e17;
  border: 1px solid #2b3651;
  border-radius: 9px;
  overflow: hidden;
}
.sb-exp > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #7c5cff, #b18cff);
  transition: width .4s ease;
}
.sb-exp > span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 600;
  color: #e6e9ef;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
}

.sb-gold { color: #ffd166; font-weight: 700; font-size: 13px; white-space: nowrap; }

/* ---------------- nút chức năng trên thanh ---------------- */

.sb-actions { display: flex; gap: 6px; }

.sb-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: #141c2e;
  border: 1px solid #2b3651;
  border-radius: 9px;
  color: #cfe0ff;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.sb-btn:hover { border-color: #4c7dff; background: #17223b; }
.sb-btn-label { font-size: 12px; }
.sb-btn.danger { color: #ff9aa8; border-color: #4a2b38; background: #1f1418; }
.sb-btn.danger:hover { border-color: #ff6b6b; background: #2c1a1f; }

/* Chấm báo còn điểm kỹ năng chưa tiêu */
.sb-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #46c46b;
  color: #08120b;
  font-size: 10px;
  font-weight: 700;
  animation: pulse 1.6s ease-in-out infinite;
}
.sb-badge.hidden { display: none; }
@keyframes pulse { 50% { opacity: .5; } }

@media (max-width: 620px) {
  .sb-btn-label { display: none; }
  .sb-name em { display: none; }
}

/* ---------------- bảng nhân vật ---------------- */

#panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(6, 8, 13, .72);
}
#panel.hidden { display: none; }

.p-box {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: #121826;
  border: 1px solid #2b3651;
  border-radius: 14px;
  overflow: hidden;
}

.p-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid #263047;
}
.p-head h2 { font-size: 16px; color: #cfe0ff; }
.p-head button {
  width: 28px; height: 28px;
  background: transparent;
  border: 1px solid #2b3651;
  border-radius: 6px;
  color: #8b95ab;
  cursor: pointer;
}
.p-head button:hover { border-color: #ff6b6b; color: #ff9aa8; }

.p-body {
  display: grid;
  grid-template-columns: 250px 1fr 1fr;
  gap: 16px;
  padding: 16px 18px 20px;
  overflow-y: auto;
}

.p-col h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: #6b7791;
  margin-bottom: 9px;
}
.p-col h3.mt { margin-top: 18px; }
.dim { color: #6b7791; font-weight: 400; text-transform: none; letter-spacing: 0; }

/* ---------------- ô trang bị ---------------- */

.p-slots { display: flex; flex-direction: column; gap: 5px; }

.slot {
  display: flex;
  align-items: center;
  gap: 9px;
  /* Cao cố định: một ô trang bị lỡ chứa hai phần tử (kéo thả dở dang, icon
     chưa kịp dọn) cũng không được phép kéo giãn cả hàng ra */
  height: 48px;
  padding: 6px 8px;
  background: #0f1420;
  border: 1px solid #232c42;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.slot:hover { border-color: #4c7dff; background: #131b2c; }
.slot.empty { opacity: .55; cursor: default; }
.slot.empty:hover { border-color: #232c42; background: #0f1420; }

.slot-icon {
  width: 26px; height: 26px;
  flex: 0 0 26px;
  border-radius: 5px;
  background: #1a2233;
  border: 1px solid #2b3651;
}
.slot-info { min-width: 0; }
.slot-label { font-size: 9px; color: #6b7791; text-transform: uppercase; letter-spacing: .4px; }
.slot-item {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- chỉ số ---------------- */

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid #1c2436;
  font-size: 12px;
}
.stat-row:last-child { border-bottom: 0; }
.stat-label { color: #a9b4c9; }
.stat-val { color: #e6e9ef; font-weight: 600; }
.stat-bonus { color: #7ee89a; font-size: 11px; margin-left: 5px; }

.stat-add {
  width: 21px; height: 21px;
  margin-left: 8px;
  background: #1d3324;
  border: 1px solid #2f5340;
  border-radius: 5px;
  color: #93e0b0;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.stat-add:hover { background: #27462f; }
.stat-add:disabled { opacity: .25; cursor: default; }

/* ---------------- túi đồ ---------------- */

.p-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
}

.cell {
  aspect-ratio: 1;
  border-radius: 7px;
  background: #0f1420;
  border: 1px solid #232c42;
  cursor: pointer;
  position: relative;
  transition: transform .1s, border-color .1s;
}
.cell:hover { transform: translateY(-2px); }
.cell.filled::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 4px;
  background: currentColor;
  opacity: .85;
}
.cell.lv {
  font-size: 8px;
  color: #6b7791;
}

/* ---------------- tooltip món đồ ---------------- */

.tip {
  position: fixed;
  z-index: 50;
  width: 230px;
  padding: 11px 13px;
  background: #0d121d;
  border: 1px solid #2b3651;
  border-radius: 9px;
  font-size: 11px;
  line-height: 1.6;
  pointer-events: none;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
.tip.hidden { display: none; }
.tip h4 { font-size: 12px; margin-bottom: 1px; }
.tip .tip-sub { color: #6b7791; margin-bottom: 7px; }
.tip .tip-stat { color: #7ee89a; }
.tip .tip-passive { color: #d3b8f0; margin-top: 5px; }
.tip .tip-hint { color: #6b7791; margin-top: 8px; font-style: italic; }

/* ---------------- thông báo phần thưởng ---------------- */

/**
 * Nằm NGAY TRÊN thanh kinh nghiệm, không phải sát đáy màn hình.
 *
 * Sát đáy thì thông báo chui xuống dưới hai nút Balo / Kỹ năng (thanh đó
 * z-index 50, cao hơn) và không đọc được chữ nào. `--sb-h` do game.js đo bằng
 * getBoundingClientRect rồi ghi vào, nên màn hẹp làm thanh xuống dòng cao gấp
 * đôi thì chỗ chừa cũng tự cao theo.
 */
#toasts {
  position: fixed;
  right: 14px;
  bottom: calc(var(--sb-h, 48px) + 12px);
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 55;
  pointer-events: none;
}

.toast {
  min-width: 200px;
  padding: 9px 13px;
  background: rgba(15, 20, 32, .94);
  border: 1px solid #2b3651;
  border-left-width: 3px;
  border-radius: 8px;
  font-size: 12px;
  color: #cfe0ff;
  animation: toastIn .3s ease, toastOut .4s ease 3.6s forwards;
}
.toast .t-title { font-weight: 600; }
.toast .t-sub { color: #8b95ab; font-size: 11px; }
.toast.levelup { border-left-color: #ffd166; }
.toast.item { border-left-color: #5b9cff; }
.toast.warn { border-left-color: #ff9f43; }

@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

@media (max-width: 780px) {
  .p-body { grid-template-columns: 1fr; }
  #statusBar { width: calc(100vw - 24px); flex-wrap: wrap; justify-content: center; }
  .sb-exp { width: 100%; }
}

/* ---------- bị động đang có hiệu lực ---------- */

.passive-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #1c2436;
  font-size: 12px;
}
.passive-row:last-child { border-bottom: 0; }

/* Ba dòng xếp dọc: tên · hiệu quả · nguồn. Hiệu quả nằm giữa vì đó là thứ
   người chơi mở bảng này ra để đọc — trước đây nó bị giấu trong tooltip. */
.passive-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.passive-name { color: #d3b8f0; font-weight: 600; }
.passive-effect { font-size: 11px; color: #7ee89a; line-height: 1.45; }
.passive-from { font-size: 10px; color: #6b7791; }
.passive-val { color: #7ee89a; font-weight: 600; white-space: nowrap; align-self: center; }
.passive-empty { font-size: 12px; color: #6b7791; line-height: 1.6; }

/* ============ HUY HIỆU ĐỘ TRỄ (góc phải trên) ============ */

#navbar {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 36;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;   /* thuần hiển thị, không chắn thao tác phía dưới */
}
#navbar.hidden { display: none; }

#pingBadge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: rgba(13, 18, 29, .88);
  border: 1px solid #263047;
  border-radius: 9px;
  font-size: 12px;
  color: #cfe0ff;
  backdrop-filter: blur(6px);
}

.zone-badge {
  padding-right: 8px;
  border-right: 1px solid #263047;
  color: #8b95ab;
  font-size: 11px;
  max-width: 220px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- đồng hồ Thủ Lĩnh ---------- */

#bossBar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  background: rgba(13, 18, 29, .88);
  border: 1px solid #3a3020;
  border-radius: 9px;
  font-size: 12px;
  color: #a9b4c9;
  backdrop-filter: blur(6px);
}
#bossBar.hidden { display: none; }
.boss-ico { color: #6b7791; }

/* Đang có Thủ Lĩnh ngoài bản đồ — đổi màu và nhấp nháy để không ai bỏ lỡ */
#bossBar.up {
  border-color: #7a5a1e;
  background: rgba(38, 28, 10, .9);
  color: #ffd166;
  animation: bossPulse 1.8s ease-in-out infinite;
}
#bossBar.up .boss-ico { color: #ffd166; }

@keyframes bossPulse {
  50% { box-shadow: 0 0 14px rgba(255, 209, 102, .35); }
}
.ping-unit { color: #6b7791; font-size: 10px; margin-left: 2px; }

.ping-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #46c46b;
  box-shadow: 0 0 6px rgba(70, 196, 107, .8);
}
/* Đổi màu theo độ trễ để nhìn phát biết ngay, không phải đọc số */
.ping-dot.warn { background: #ffb703; box-shadow: 0 0 6px rgba(255, 183, 3, .8); }
.ping-dot.bad { background: #ff6b6b; box-shadow: 0 0 6px rgba(255, 107, 107, .8); }

/* ---------- chọn nhiều món để xoá ---------- */

.p-pick-btn {
  float: right;
  padding: 2px 9px;
  background: #1c1622;
  border: 1px solid #3a3050;
  border-radius: 6px;
  color: #9aa5ba;
  font-size: 11px;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.p-pick-btn:hover { border-color: #a97bff; color: #d3b8f0; }
.p-pick-btn.on { background: #3a1f28; border-color: #a34455; color: #ff9aa8; }

.p-pickbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 9px;
  padding: 9px;
  background: #14111c;
  border: 1px solid #2f2540;
  border-radius: 8px;
}
.p-pickbar.hidden { display: none; }

.p-pick-filters { display: flex; flex-wrap: wrap; gap: 5px; }

.p-pick-f {
  padding: 3px 9px;
  background: transparent;
  border: 1px solid #3a3050;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
  transition: background .12s;
}
.p-pick-f:hover { background: #221b2e; }
.p-pick-f.all { color: #9aa5ba; border-color: #3a3050; }

/* Cột túi đồ hẹp nhất trong ba cột, nên cho xuống dòng thay vì bóp chữ
   "Đã chọn 16" thành hai dòng */
.p-pick-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.p-pick-count { flex: 1 0 auto; font-size: 11px; color: #8b95ab; white-space: nowrap; }

.p-pick-clear,
.p-pick-del {
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid #3a3050;
  background: #1c1622;
  color: #9aa5ba;
  transition: border-color .12s, background .12s, color .12s;
}
.p-pick-clear:hover { border-color: #6b7791; color: #c9d1e0; }

.p-pick-del { border-color: #a34455; color: #ff9aa8; }
.p-pick-del:hover:not(:disabled) { background: #3a1f28; }
.p-pick-del:disabled { opacity: .35; cursor: not-allowed; }

/* Ô đang được tick — viền dày và dấu ✓ ở góc, phân biệt được cả khi
   màu hạng đồ vốn đã sáng */
.p-grid .cell.pickable { cursor: pointer; }
.p-grid .cell.picked {
  outline: 2px solid #ff9aa8;
  outline-offset: -2px;
  opacity: .55;
}
.p-grid .cell.picked::after {
  content: '✓';
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #ff9aa8;
}

/* ---------- tooltip Tippy ---------- */
/* Chỉ đổi màu; phần lật và trượt tránh mép để Tippy lo. */

.tippy-box[data-theme~='frozen'] {
  background: #12101a;
  border: 1px solid #3a3050;
  border-radius: 9px;
  color: #c9d1e0;
  font-size: 12px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .55);
}
.tippy-box[data-theme~='frozen'] .tippy-content { padding: 9px 11px; }
.tippy-box[data-theme~='frozen'][data-placement^='top'] > .tippy-arrow::before { border-top-color: #3a3050; }
.tippy-box[data-theme~='frozen'][data-placement^='bottom'] > .tippy-arrow::before { border-bottom-color: #3a3050; }
.tippy-box[data-theme~='frozen'][data-placement^='left'] > .tippy-arrow::before { border-left-color: #3a3050; }
.tippy-box[data-theme~='frozen'][data-placement^='right'] > .tippy-arrow::before { border-right-color: #3a3050; }

.tippy-box[data-theme~='frozen'] h4 { margin: 0 0 3px; font-size: 13px; }
.tippy-box[data-theme~='frozen'] .tip-sub { margin-bottom: 6px; color: #6b7791; font-size: 11px; }
.tippy-box[data-theme~='frozen'] .tip-stat { color: #8fd4a0; }
.tippy-box[data-theme~='frozen'] .tip-passive { margin-top: 4px; color: #c9b3e0; }
.tippy-box[data-theme~='frozen'] .tip-hint {
  margin-top: 7px; padding-top: 6px;
  border-top: 1px solid #2f2540;
  color: #6b7791; font-size: 11px;
}

/* ---------- kéo thả ---------- */

/**
 * `place-items: stretch` chứ KHÔNG phải `center`.
 *
 * Căn giữa làm ô lưới co theo nội dung, nên phần tử con đặt `height: 100%` không
 * có gì xác định để tính phần trăm — và icon bên trong nó cũng vậy, rơi về kích
 * thước SVG mặc định rồi tràn ra ngoài hàng. Cho con kéo căng ra đúng 34px thì
 * mọi phần trăm bên trong đều có gốc để bám. Việc căn giữa để `.slot-icon` lo.
 */
.slot-drop {
  display: grid;
  place-items: stretch;
  border-radius: 8px;
  transition: background .12s, box-shadow .12s;
}
/* Mọi thứ trong ô thả nằm CHỒNG lên nhau ở cùng một ô lưới. Để mặc định thì
   grid xếp mỗi phần tử một hàng, và một khoảnh khắc có hai phần tử (lúc thả đồ
   xuống, trước khi vẽ lại) là ô méo hẳn đi */
.slot-drop > * { grid-area: 1 / 1; }

/* Ô trống vẽ mờ để phân biệt với ô đang có đồ */
.slot-ghost { opacity: .32; }

/* Chỗ món sẽ rơi xuống */
.p-drop-ghost { opacity: .3; }
/* Món vừa được nhấc lên */
.p-drag-chosen { box-shadow: 0 0 0 2px #a97bff; }
/* Bản sao bay theo con trỏ */
.p-drag-move { opacity: .9; transform: scale(1.08); }
/* Ô trang bị đang nhận đồ — sáng lên để biết thả vào đâu */
.slot-drop:has(.p-drop-ghost) { background: rgba(169, 123, 255, .18); box-shadow: inset 0 0 0 2px #a97bff; }

/* Ô có icon thì bỏ khối màu đặc cũ — nó vẽ đè lên hình */
.cell.filled.ico::after { display: none; }
.cell.filled.ico {
  display: grid;
  place-items: center;
  background: #131b2c;
}
.cell.filled.ico .gi { width: 68%; height: 68%; }

/* Vùng thả của ô trang bị phải đủ to để nhắm trúng khi kéo bằng chuột */
.slot-drop { width: 34px; height: 34px; flex: 0 0 34px; }

/**
 * Kích thước tính bằng PIXEL, không phải phần trăm.
 *
 * `height: 100%` ở đây từng tạo ra vòng luẩn quẩn: ô chứa co theo nội dung, nên
 * phần trăm không có gốc để tính, nên icon rơi về kích thước SVG mặc định
 * (300×150), nên ô chứa phình lên theo. Kết quả là icon của MỌI ô trang bị
 * trống cao 114px, thò xuống đè lên hàng dưới — chỉ ô cuối cùng là lộ ra vì
 * dưới nó không còn hàng nào che.
 */
.slot-drop .slot-icon {
  width: 34px; height: 34px;
  flex: none;
  margin: 0;
}
.slot-drop .slot-icon .gi { width: 26px; height: 26px; }

/* ---------------------------------------------------- rửa điểm --------- */
/* Giá hiện thẳng trên nút. Bắt người chơi bấm rồi mới biết mình không đủ vàng
   là cách chắc chắn nhất để họ ngại bấm lần sau. */
.respec-btn {
  margin-top: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #5a3a4a;
  background: #241923;
  color: #e8b3ab;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.respec-btn:hover:not(:disabled) { background: #33212e; border-color: #7a4d61; }
.respec-btn:disabled { opacity: .45; cursor: default; }
.respec-btn b { color: #ffd166; }
.respec-gold { width: 13px; height: 13px; color: #ffd166; }
.mst-respec .respec-btn { margin-top: 0; width: auto; flex: 0 0 auto; }
