/* ============================================================================
 *  main.css — GIAO DIỆN PHONG CÁCH TIÊN HIỆP MỘC MẠC
 * ----------------------------------------------------------------------------
 *  Bảng màu: giấy dó ngả vàng, gỗ mun, mực nho, điểm xuyết kim tuyến & ngọc bích.
 *  Toàn bộ layout dùng đơn vị co giãn để chạy tốt từ điện thoại tới màn 4K.
 * ==========================================================================*/

:root {
  --ink:        #1c1610;
  --ink-soft:   #3a2e22;
  --parchment:  #e7dabb;
  --parchment-2:#d6c49f;
  --wood:       #392b1e;
  --wood-dark:  #241a12;
  --gold:       #c9a45c;
  --jade:       #7aa887;
  --blood:      #a3453b;
  --qi:         #6ba3c4;
  --shadow:     0 8px 28px rgba(0, 0, 0, 0.55);
  /* Font tiếng Việt. Palatino / Book Antiqua trước đây thiếu nhiều chữ có dấu
   * nên máy phải ghép dấu rời, chữ "ệ" "ỡ" "ẩ" bị lệch và mờ. Hai họ dưới đây
   * có sẵn toàn bộ ký tự tiếng Việt, dự phòng cũng chỉ chọn font đủ dấu:
   * Segoe UI / Roboto / Noto Sans / Tahoma. */
  --font-serif: "Noto Serif", "Times New Roman", Georgia, "Segoe UI", serif;
  --font-ui:    Roboto, "Segoe UI", "Noto Sans", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0b09;
  color: var(--parchment);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

.hidden { display: none !important; }

/* ============================================================================
 *  KHUNG VẼ GAME — chìa khoá của độ sắc nét pixel art
 * ==========================================================================*/
#game-canvas {
  position: absolute;
  top: 0; left: 0;
  display: block;
  background: #12100d;

  /* Giữ từng pixel vuông vắn khi phóng to trên màn Retina / 4K */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;

  touch-action: none;            /* tắt cuộn/zoom mặc định của trình duyệt */
}

/* ============================================================================
 *  MÀN HÌNH CHỜ
 * ==========================================================================*/
#loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 45%, #1e2620 0%, #0d0b09 75%);
  z-index: 500;
}
#loading h1 {
  font-family: var(--font-serif);
  font-size: clamp(24px, 5vw, 44px);
  letter-spacing: 0.16em;
  color: var(--parchment);
  margin: 0 0 12px;
  text-shadow: 0 2px 0 #000;
}
#loading p { color: var(--jade); letter-spacing: 0.1em; margin: 0; }
.load-box { text-align: center; }

/* ============================================================================
 *  HUD
 * ==========================================================================*/
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 100; }

.panel {
  background: linear-gradient(180deg, rgba(35, 26, 18, 0.92), rgba(20, 15, 10, 0.94));
  border: 1px solid rgba(201, 164, 92, 0.45);
  border-radius: 4px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  padding: 8px 10px;
}

/* Nhấp nháy nhẹ khi nội dung panel vừa cập nhật (vd: quest tracker) */
.panel.pulse { animation: panel-pulse 0.5s ease-out; }
@keyframes panel-pulse {
  0%   { box-shadow: var(--shadow), 0 0 0 1px var(--gold), 0 0 10px 2px var(--gold); }
  100% { box-shadow: var(--shadow), inset 0 0 0 1px rgba(0, 0, 0, 0.5); }
}

/* Bảng nhân vật + chỉ số dồn về góc trái trên, giống bố cục MMORPG mobile */
#hud-left {
  position: absolute; top: 12px; left: 12px;
  /* Nới từ 208px: chữ to hơn nên "Cảnh giới: Luyện Khí Tầng 13" — chuỗi dài
   * nhất có thể hiện ra — mới đủ chỗ trên một dòng, không bị gãy đôi đè lên
   * thanh máu. Màn hình nhỏ vẫn giữ 180px ở media query cuối file. */
  width: 274px;
  pointer-events: auto;
  cursor: pointer;                 /* bấm vào là mở Càn Khôn Đãy */
  touch-action: manipulation;
  transition: filter 0.15s ease, border-color 0.15s ease;
}
#hud-left:hover,
#hud-left:focus-visible {
  filter: brightness(1.12);
  border-color: var(--gold);
}
#hud-left:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
#hud-left:active { filter: brightness(0.95); }
.hud-id { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }

/* Hàng nút chức năng ngay dưới bảng nhân vật */
#hud-btns {
  position: absolute; top: 158px; left: 12px;
  pointer-events: auto;
}

/* Cột giấy tờ — dưới hàng nút chức năng, tự dồn khi mở tờ phá quan */
#hud-journal {
  position: absolute; top: 204px; left: 12px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  pointer-events: none;
}
#breakthrough-widget, #quest-tracker { pointer-events: auto; }
#quest-tracker { position: static; max-width: 230px; }

/* Nút cuộn giấy luôn hiện để người chơi biết nơi xem điều kiện phá quan. */
#btn-breakthrough {
  display: flex; align-items: center; gap: 8px;
  min-height: 38px; max-width: min(292px, calc(100vw - 24px));
  padding: 6px 9px;
  color: var(--parchment); background: rgba(48, 35, 23, 0.94);
  border: 1px solid rgba(201, 164, 92, 0.75); border-radius: 3px;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.45);
  font-family: var(--font-serif); font-size: 13px; letter-spacing: 0.035em;
  cursor: pointer; touch-action: manipulation;
}
#btn-breakthrough:hover, #btn-breakthrough:focus-visible { filter: brightness(1.13); }
#btn-breakthrough:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#btn-breakthrough.ready { border-color: #a8d7a9; box-shadow: 0 0 0 1px rgba(168, 215, 169, 0.24), 0 5px 16px rgba(0, 0, 0, 0.45); }
#breakthrough-button-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#breakthrough-badge {
  flex: none; margin-left: auto; padding: 2px 5px;
  color: #ead28e; background: #241a12; border: 1px solid rgba(201, 164, 92, 0.4);
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.04em;
}
#breakthrough-badge.ready { color: #d9f0d6; border-color: rgba(122, 168, 135, 0.75); }
.scroll-icon {
  position: relative; flex: none; width: 19px; height: 23px;
  background: #dfcd9f; border: 1px solid #7e6030; box-shadow: inset 2px 0 #f2e5bf;
}
.scroll-icon::before, .scroll-icon::after {
  content: ''; position: absolute; left: -3px; width: 23px; height: 4px;
  background: #b99555; border: 1px solid #6f5028; border-radius: 3px;
}
.scroll-icon::before { top: -2px; }
.scroll-icon::after { bottom: -2px; }
.scroll-icon i, .scroll-icon i::before, .scroll-icon i::after {
  position: absolute; content: ''; left: 4px; width: 9px; height: 1px; background: #735b35;
}
.scroll-icon i { top: 7px; }
.scroll-icon i::before { top: 4px; left: 0; }
.scroll-icon i::after { top: 8px; left: 0; width: 6px; }

/* Tờ giấy sáng, giống một trang ghi chép thật thay vì một hộp thoại chặn game. */
.breakthrough-sheet {
  width: min(292px, calc(100vw - 24px)); margin-top: 7px; padding: 13px 14px 12px;
  color: #342819;
  background:
    linear-gradient(90deg, rgba(111, 79, 35, 0.13), transparent 12%, transparent 88%, rgba(111, 79, 35, 0.13)),
    #e5d3a8;
  border: 2px solid #9b7841; border-radius: 2px;
  box-shadow: inset 0 0 0 1px #f2e5bf, 0 9px 24px rgba(0, 0, 0, 0.5);
}
.breakthrough-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sheet-kicker { display: block; color: #8b5f2b; font-size: 9px; font-weight: 700; letter-spacing: 0.18em; }
.breakthrough-head h2 {
  margin: 2px 0 0; color: #251a10;
  font-family: var(--font-serif); font-size: 17px; line-height: 1.15; letter-spacing: 0.025em;
}
#breakthrough-close {
  flex: none; width: 28px; height: 28px; padding: 0;
  color: #5d4225; background: transparent; border: 1px solid rgba(94, 66, 35, 0.45);
  font-size: 22px; line-height: 24px; cursor: pointer;
}
#breakthrough-close:hover, #breakthrough-close:focus-visible { color: #281b0f; border-color: #5d4225; }
.breakthrough-route {
  margin: 9px 0 10px; padding: 6px 7px;
  color: #62401f; background: rgba(255, 247, 218, 0.48);
  border-block: 1px solid rgba(111, 80, 40, 0.28);
  font-size: 11px; font-weight: 700; text-align: center;
}
.breakthrough-requirement { margin: 9px 0; }
.requirement-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; }
.requirement-top span { min-width: 0; }
.requirement-top b { flex: none; color: #75451e; font-size: 12px; font-variant-numeric: tabular-nums; }
.breakthrough-requirement.done .requirement-top { color: #355b35; }
.breakthrough-progress {
  height: 9px; margin-top: 4px; overflow: hidden;
  background: #b7a47a; border: 1px solid #765b32; box-shadow: inset 0 1px 2px rgba(49, 34, 15, 0.35);
}
.breakthrough-progress i {
  display: block; height: 100%; min-width: 0;
  background: linear-gradient(90deg, #9a6332, #d09b4e);
}
.breakthrough-requirement.done .breakthrough-progress i { background: linear-gradient(90deg, #416d43, #79a76f); }
.breakthrough-status {
  margin-top: 11px; padding: 7px 8px;
  color: #7a2f25; background: rgba(136, 52, 39, 0.08); border: 1px solid rgba(122, 47, 37, 0.35);
  font-size: 11px; font-weight: 800; letter-spacing: 0.05em; text-align: center;
}
.breakthrough-status.ready { color: #315c35; background: rgba(59, 104, 61, 0.09); border-color: rgba(49, 92, 53, 0.4); }
.breakthrough-status.blocked { text-align: left; line-height: 1.45; font-weight: 600; letter-spacing: 0; }
.breakthrough-place { margin-top: 7px; color: #654c2d; font-size: 11px; line-height: 1.4; text-align: center; }

/* Bảng mục tiêu đang giao chiến — góc phải, ngay dưới minimap */
/* Bảng mục tiêu — giữa mép trên, chuẩn bố cục MMORPG: tên + cảnh giới + máu */
#hud-target {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  width: 176px;
}
.t-head {
  display: flex; align-items: baseline; justify-content: center; gap: 6px;
  margin-bottom: 4px;
}
#target-name {
  font-family: var(--font-serif);
  font-size: 13px; color: var(--parchment);
}
#target-level {
  font-family: var(--font-serif);
  font-size: 12px; color: var(--gold);
  letter-spacing: 0.04em;
}

.face-frame {
  width: 48px; height: 48px;
  border: 1px solid var(--gold);
  background: #1b2119;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.7);
  flex: none;
}
#hud-face { display: block; width: 48px; height: 48px; image-rendering: pixelated; }

.hud-info { flex: 1; min-width: 0; }
#hud-name {
  font-family: var(--font-serif);
  font-size: 15px; color: var(--parchment);
  letter-spacing: 0.05em;
}
#hud-realm {
  font-size: 12px; color: var(--jade); margin-bottom: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.bar {
  position: relative;
  height: 12px; margin-top: 3px;
  background: #140f0a;
  border: 1px solid rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.bar.thin { height: 6px; }
.bar .fill {
  position: absolute; inset: 0 auto 0 0;
  display: block; width: 100%;
  transition: width 0.25s ease;
}
.fill.hp { background: linear-gradient(180deg, #c25a4d, #7d2f27); }
.fill.mp { background: linear-gradient(180deg, #6fa8c8, #35617d); }
.fill.sp { background: linear-gradient(180deg, #a06ac0, #593573); }
.fill.bp { background: linear-gradient(180deg, #e08327, #9a430d); }
.fill.xp { background: linear-gradient(180deg, #d3b46a, #8a6f34); }
.bar > span {
  position: absolute; inset: 0;
  /* 8px thì dấu tiếng Việt dính hết vào thân chữ, phải nới ra 10px */
  font-size: 10px; line-height: 12px; text-align: center;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 1px #000;
  letter-spacing: 0.08em;
}
.bar.thin span { display: none; }

.resource-bar { overflow: visible; }
.resource-bar .fill { overflow: hidden; }
.resource-bar .bar-label {
  left: 20px; right: 64px;
  font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.resource-bar .bar-value {
  position: absolute; z-index: 2; top: 0; right: 4px;
  font-size: 9px; line-height: 12px; color: #fff1d2;
  font-weight: 700; text-shadow: 0 1px 1px #000;
}
.resource-bar .resource-icon {
  z-index: 2; width: 18px; right: auto;
  display: grid; place-items: center;
  color: #fff; font-size: 10px; line-height: 12px;
  background: rgba(15, 10, 8, 0.58);
  border-right: 1px solid rgba(255, 255, 255, 0.18);
  text-shadow: 0 1px 1px #000;
}
.resource-bar .hp-icon { color: #ffd1cd; }
.resource-bar .mp-icon { color: #cceeff; }
.resource-bar .sp-icon { color: #ead5ff; }
.resource-bar .bp-icon { color: #ffe0b0; }
.resource-bar.locked .bar-label,
.resource-bar.locked .bar-value { color: rgba(255, 255, 255, 0.5); }

#hud-right {
  position: absolute; top: 12px; right: 12px;
  text-align: center; pointer-events: auto;
  width: 120px;
}
#minimap {
  display: block; margin: 4px 0;
  width: 100px; height: 75px;
  image-rendering: pixelated;
  border: 1px solid rgba(201, 164, 92, 0.45);
  background: #141b13;
}
#hud-map { font-family: var(--font-serif); font-size: 14px; letter-spacing: 0.08em; }
.dim { font-size: 11px; color: rgba(231, 218, 187, 0.5); }

.hud-btns button {
  margin-top: 6px; margin-left: 4px;
  width: 34px; height: 30px;
  background: rgba(60, 45, 30, 0.9);
  border: 1px solid var(--gold);
  color: var(--parchment);
  font-size: 15px; cursor: pointer;
  border-radius: 3px;
}
.hud-btns button:hover { background: rgba(90, 68, 42, 0.95); }
.hud-btns button.active { border-color: var(--jade); background: rgba(58, 122, 74, 0.4); }

#hud-hint {
  position: absolute; left: 50%; bottom: 92px;
  transform: translateX(-50%);
  background: rgba(20, 15, 10, 0.9);
  border: 1px solid rgba(201, 164, 92, 0.5);
  padding: 6px 14px;
  font-size: 12px; color: var(--parchment);
  border-radius: 3px;
  white-space: nowrap;
}

#hud-keys {
  position: absolute; left: 50%; bottom: 10px;
  transform: translateX(-50%);
  font-size: 11px; padding: 5px 12px;
  white-space: nowrap; overflow: hidden; max-width: max(360px, calc(100vw - 560px));
}
#hud-keys b { color: var(--gold); font-weight: 600; }

/* ============================================================================
 *  ĐIỀU KHIỂN CẢM ỨNG
 * ==========================================================================*/
#touch-ui { position: absolute; inset: 0; pointer-events: none; z-index: 120; }

#dpad {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 150px; height: 132px;
  pointer-events: auto; touch-action: none;
  filter: drop-shadow(0 5px 5px rgba(13, 8, 5, 0.6));
}
.dpad-btn, .dpad-run {
  position: absolute; width: 48px; height: 44px; padding: 0;
  color: rgba(255, 239, 196, 0.9);
  background: linear-gradient(180deg, rgba(83, 62, 37, 0.84), rgba(34, 25, 17, 0.9));
  border: 1px solid rgba(221, 183, 105, 0.75);
  box-shadow: inset 0 0 0 1px rgba(15, 9, 5, 0.7), inset 0 3px 5px rgba(255, 231, 171, 0.1);
  font-family: var(--font-ui); font-size: 20px; cursor: pointer;
  touch-action: none; user-select: none;
  transition: transform 70ms ease, filter 100ms ease;
}
.dpad-btn.up    { left: 51px; top: 0; }
.dpad-btn.left  { left: 0; top: 44px; }
.dpad-btn.right { right: 0; top: 44px; }
.dpad-btn.down  { left: 51px; bottom: 0; }
.dpad-run {
  left: 51px; top: 44px; color: #dfc98e; font-size: 10px; letter-spacing: 0.08em;
  background: radial-gradient(circle, rgba(83, 66, 41, 0.94), rgba(29, 21, 14, 0.96));
}
.dpad-btn.pressed { transform: scale(0.88); filter: brightness(1.35); }
.dpad-run.active { color: #d6f0c8; border-color: #8fc88e; filter: brightness(1.25); }

/* Cụm phải dưới chia làm hai tầng rõ rệt, theo lối các MMORPG mobile Việt:
 *   - TẦNG CHIẾN ĐẤU: nút Công Thường tròn to ôm góc, ba chiêu tròn nhỏ hơn
 *     xếp trên một vòng cung bán kính 104px quanh nó. Ngón cái đặt ở góc thì
 *     chiêu gần nhất (Lôi Kích) chỉ cần gập đốt là tới, xa dần là chiêu ít
 *     dùng hơn (Pháp Thuật, rồi Tọa Thiền).
 *   - TẦNG TIỆN ÍCH: hàng nút vuông tách hẳn lên trên, cách vòng cung một
 *     khoảng trống. Trước đây Túi và Đổi nằm chen giữa các chiêu nên vừa dễ
 *     bấm nhầm lúc đánh nhau, vừa kéo cụm rộng tới 236px, lấn vào phím hướng
 *     trên máy màn hình hẹp.
 * Nút chiêu để tròn, nút tiện ích để vuông bo góc — nhìn hình là biết loại. */
#touch-buttons {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 188px; height: 228px;
  pointer-events: auto;
}
.tbtn {
  position: absolute; width: 56px; height: 56px; padding: 0;
  border-radius: 8px; border: 2px solid #b49a66;
  background:
    radial-gradient(circle at 38% 30%, rgba(117, 94, 57, 0.86), rgba(30, 22, 15, 0.96) 70%);
  color: #f2ecdc;
  font-family: var(--font-ui); font-size: 12px;
  box-shadow: 0 5px 10px rgba(12, 7, 4, 0.66), inset 0 0 0 1px rgba(0, 0, 0, 0.75);
  cursor: pointer;
  touch-action: none; user-select: none;
  transition: transform 70ms ease, filter 100ms ease, border-color 140ms ease;
}
.tbtn .skill-key {
  position: absolute; left: 3px; top: 2px; z-index: 2;
  color: #d6c08b; font: 700 8px/1 var(--font-ui); letter-spacing: 0;
}
.tbtn .skill-glyph {
  position: absolute; inset: 3px 3px 13px;
  display: grid; place-items: center;
  color: #f5e5b5; font-family: Georgia, serif; font-size: 25px; line-height: 1;
  text-shadow: 0 2px 2px #000;
}
.tbtn .skill-name {
  position: absolute; left: 2px; right: 2px; bottom: 2px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: #efe2c2; font-size: 8px; line-height: 10px; letter-spacing: 0;
  text-shadow: 0 1px 1px #000;
}
/* Chiêu thức: tròn hẳn, chữ và ký hiệu thu vào trong đường tròn */
.tbtn.skill { border-radius: 50%; }
.tbtn.skill .skill-key { left: 7px; top: 5px; }
.tbtn.skill .skill-glyph { inset: 5px 5px 15px; font-size: 23px; }
.tbtn.skill .skill-name { bottom: 5px; }

.tbtn.attack-touch {
  right: 0; bottom: 0; width: 86px; height: 86px; z-index: 3;
  border-radius: 50%; border-color: #e0bf70;
  background: radial-gradient(circle at 38% 30%, #76663e, #322319 68%, #17100c);
}
.attack-touch .attack-slash {
  position: absolute; left: 25px; top: 13px; width: 12px; height: 48px;
  transform: rotate(42deg); border-radius: 100% 0;
  background: linear-gradient(90deg, transparent, #fff2bc 48%, #ad7537 52%, transparent);
  filter: drop-shadow(0 0 3px #f0c36f);
}
.attack-touch .skill-name { bottom: 8px; font-size: 10px; color: #fff0bd; }
.attack-touch .skill-key { left: 8px; top: 8px; }

/* Vòng cung chiêu thức — toạ độ lấy từ tâm nút Công Thường (43,43), bán kính
 * 104px, ba mốc cách nhau 45° nên hai nút cạnh nhau luôn hở ít nhất 14px. */
.thunder-touch  { right: 119px; bottom: 24px;  z-index: 4; }
.spell-touch    { right: 82px;  bottom: 95px;  z-index: 4; }
.meditate-touch { right: 6px;   bottom: 119px; z-index: 4; }

/* Hàng tiện ích, cách vòng cung 7px để không chạm phải lúc bấm chiêu */
.tbtn.utility   { width: 42px; height: 42px; bottom: 182px; }
.interact-touch { right: 0; }
.target-touch   { right: 48px; }
.fly-touch      { right: 96px; }
.bag-touch      { right: 144px; }
.tbtn.utility .skill-key { display: none; }
.tbtn.utility .skill-glyph { inset: 2px 2px 11px; font-size: 17px; }
.tbtn.utility .skill-name { font-size: 8px; }

/* Vòng hồi chiêu quét ngược kim đồng hồ như mọi game mobile: phần tối là
 * thời gian còn phải chờ, sáng dần lên là sắp bấm được. Trước đây cả nút bị
 * phủ một lớp đục nên nhìn không ra còn bao lâu, chỉ thấy con số. */
.skill-cooldown {
  position: absolute; inset: -2px; z-index: 5; border-radius: inherit;
  display: grid; place-items: center;
  color: #eaf6ff;
  background: conic-gradient(rgba(6, 10, 14, 0.76) calc(var(--cd, 0) * 360deg),
                             rgba(6, 10, 14, 0.14) 0);
  font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px #000;
}
/* Tu Vi viên mãn — thanh vàng nhấp nháy nhắc đi phá quan */
#row-xp.full .fill.xp { background: linear-gradient(90deg, #c9a45c, #ffe9a8); }
#row-xp.full span { color: #ffe9a8; animation: xp-pulse 1.6s ease-in-out infinite; }
@keyframes xp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* Nút "Đổi" mang sắc vàng của mũi tên chọn mục tiêu */
#btn-target { border-color: #f7c822; color: #ffeaa0; }

/* Nút chiêu Lôi Chưởng — sắc lam của tia sét, mờ đi trong lúc chờ hồi */
#btn-thunder {
  border-color: #5bd6e8; color: #eafcff;
  background: radial-gradient(circle at 35% 30%, rgba(46, 143, 176, 0.85), rgba(18, 44, 58, 0.92));
}
#btn-thunder.cooling {
  border-color: #4c5a60; color: #9fb2b8;
  background: radial-gradient(circle at 35% 30%, rgba(50, 62, 68, 0.85), rgba(20, 26, 30, 0.92));
}

/* Nút pháp thuật bí tịch — nằm ngay trên nút Công Thường, ẩn cho tới khi
 * Tàng Kinh Lão Nhân trao quyển đầu tiên. Viền và nền đổi theo hệ của chiêu
 * đang gắn, nên nhìn màu nút là biết mình đang cầm quyển nào. */
/* Chưa học quyển nào thì ô vẫn nằm đó nhưng để mờ, bấm vào là mở Kỹ Năng Lục.
 * Ẩn hẳn nút sẽ thủng một mắt trong vòng cung, và người chơi không có manh mối
 * nào để biết ô ấy tồn tại. */
#btn-spell.locked {
  border-color: #6c6252; border-style: dashed; color: #b7ac95;
  background: radial-gradient(circle at 35% 30%, rgba(62, 56, 44, 0.7), rgba(24, 21, 16, 0.85));
  box-shadow: 0 4px 8px rgba(12, 7, 4, 0.5), inset 0 0 0 1px rgba(0, 0, 0, 0.6);
}
#btn-spell.locked .skill-glyph { opacity: 0.7; }
#btn-spell.spell-hoa_cau {
  border-color: #ff9a3c; color: #ffe7c2;
  background: radial-gradient(circle at 35% 30%, rgba(176, 63, 30, 0.88), rgba(58, 20, 12, 0.94));
}
#btn-spell.spell-phong_nhan {
  border-color: #9ff0c8; color: #e6fff2;
  background: radial-gradient(circle at 35% 30%, rgba(46, 130, 98, 0.86), rgba(16, 44, 33, 0.94));
}
#btn-spell.spell-bang_thau {
  border-color: #a9e4ff; color: #eafaff;
  background: radial-gradient(circle at 35% 30%, rgba(44, 116, 164, 0.86), rgba(15, 38, 56, 0.94));
}
#btn-spell.spell-dia_thich {
  border-color: #d9c08a; color: #f7ecd2;
  background: radial-gradient(circle at 35% 30%, rgba(122, 88, 52, 0.88), rgba(44, 30, 18, 0.94));
}
#btn-spell.cooling {
  border-color: #5a5850; color: #b3aea2;
  background: radial-gradient(circle at 35% 30%, rgba(58, 56, 50, 0.85), rgba(24, 23, 20, 0.92));
}
/* Bảng thử bí tịch chỉ do skills.js mở ở localhost?skilltest=1. Giữ gọn trên
 * đầu màn hình để không che vùng chiến đấu và dùng được cả chuột lẫn phím. */
#skill-test-panel {
  position: absolute; z-index: 150; top: 8px; left: 50%;
  width: min(760px, calc(100% - 190px)); transform: translateX(-50%);
  padding: 7px 9px 6px;
  color: #eadfbe; background: rgba(20, 17, 12, 0.94);
  border: 1px solid #8b7240; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
  font-family: var(--font-ui); text-align: center;
}
.skill-test-title {
  margin-bottom: 5px; color: #f0d27a;
  font-size: 10px; font-weight: 700; letter-spacing: 0.16em;
}
.skill-test-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.skill-test-buttons button {
  padding: 5px 8px; color: #e9dfc6; background: #33291d;
  border: 1px solid #655237; cursor: pointer; font: inherit; font-size: 11px;
}
.skill-test-buttons button:hover { filter: brightness(1.22); }
.skill-test-buttons button.active {
  color: #21170e; background: #f0d27a; border-color: #fff0ac;
}
.skill-test-buttons button.active.cooling {
  color: #d8c9a4; background: #29241c; border-color: #8b7240;
  box-shadow: inset 0 -2px 0 rgba(240, 210, 122, 0.18);
}
.skill-test-buttons [data-passive-label] {
  display: inline-block; min-width: 58px; font-variant-numeric: tabular-nums;
}
.skill-test-buttons kbd {
  display: inline-grid; min-width: 17px; min-height: 17px; place-items: center;
  color: inherit; background: rgba(0, 0, 0, 0.18); border: 1px solid currentColor;
}
#skill-test-panel small {
  display: block; margin-top: 5px; color: #b9aa88; font-size: 10px;
}

.tbtn.pressed { transform: scale(0.9); filter: brightness(1.3); }
.tbtn.active { border-color: var(--jade); filter: brightness(1.3); }

/* ============================================================================
 *  LỚP PHỦ DÙNG CHUNG (hộp thoại, menu, tạo nhân vật)
 * ==========================================================================*/
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(8, 7, 5, 0.72);
  backdrop-filter: blur(2px);
  z-index: 200;
  overflow: auto;
}

.scroll-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: 94vh;
  overflow: auto;
  padding: 22px 26px 26px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 252, 240, 0.5), rgba(255, 252, 240, 0) 30%),
    linear-gradient(180deg, var(--parchment) 0%, var(--parchment-2) 100%);
  border: 2px solid var(--wood);
  border-radius: 3px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(201, 164, 92, 0.6);
}
.scroll-panel.narrow { width: min(460px, 100%); text-align: center; }

/* Hai thanh trục gỗ hai bên như cuộn thư tịch */
.scroll-panel::before,
.scroll-panel::after {
  content: '';
  position: absolute; top: 0; bottom: 0; width: 7px;
  background: linear-gradient(90deg, var(--wood-dark), var(--wood) 45%, var(--wood-dark));
}
.scroll-panel::before { left: 0; }
.scroll-panel::after  { right: 0; }

/* ----------------------------------------------------------------------
 *  TRANG BỊ & CÀN KHÔN ĐÃY — paper-doll + lưới 30 ô kiểu MMORPG mobile
 * -------------------------------------------------------------------- */
.equipment-bag-panel { width: min(880px, 100%); }
.bag-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 0 5px 10px; border-bottom: 1px solid rgba(75, 49, 25, 0.28);
}
.bag-head h2 { margin-bottom: 0; }
.bag-count {
  flex: none; margin-top: 5px; padding: 5px 8px;
  color: #f3e6c6; background: #4b3724; border: 1px solid #8f6b38;
  font-size: 10px; font-variant-numeric: tabular-nums; letter-spacing: 0.06em;
}
.bag-shell {
  display: grid; grid-template-columns: minmax(280px, 0.82fr) minmax(360px, 1.18fr);
  gap: 18px; margin: 14px 0 10px;
}
.equipment-pane, .inventory-pane { min-width: 0; }
.equipment-pane h3, .inventory-pane h3 { font-size: 15px; letter-spacing: 0.09em; }
.inventory-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.inventory-head span { color: #7d6748; font-size: 10px; }
.equipment-board {
  position: relative; height: 244px; margin-top: 8px; overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(93, 125, 88, 0.28), transparent 45%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.02) 0 1px, transparent 1px 4px),
    #2d241b;
  border: 2px solid #6f5432;
  box-shadow: inset 0 0 0 1px #15100b, inset 0 0 24px rgba(0, 0, 0, 0.55);
}
#equipment-avatar {
  position: absolute; z-index: 1; left: 50%; top: 50%;
  width: 64px; height: 96px; transform: translate(-50%, -50%);
  image-rendering: pixelated;
  filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.65));
}
.equip-slot {
  position: absolute; z-index: 2; width: 58px; height: 58px; padding: 0;
  color: #a99064; background: linear-gradient(180deg, #3e3021, #201811);
  border: 2px solid #705632; border-radius: 3px;
  box-shadow: inset 0 0 0 1px #17100b, 0 3px 7px rgba(0, 0, 0, 0.45);
  cursor: pointer; transition: filter 140ms ease, transform 80ms ease;
}
.equip-slot:hover { filter: brightness(1.25); }
.equip-slot:active { transform: translateY(1px); }
.equip-slot:focus-visible { outline: 2px solid #d5b56d; outline-offset: 2px; }
.equip-slot canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.equip-slot small {
  position: absolute; left: -2px; right: -2px; bottom: -15px;
  color: #d9c69e; font-size: 8px; line-height: 10px; white-space: nowrap;
  text-shadow: 0 1px 1px #000;
}
.equip-slot .slot-mark { color: #8e7955; font-size: 8px; font-weight: 800; letter-spacing: 0.04em; }
.equip-vu_khi { left: 16px; top: 48px; }
.equip-mu { left: 50%; top: 12px; transform: translateX(-50%); }
.equip-mu:active, .equip-giay:active { transform: translateX(-50%) translateY(1px); }
.equip-ao { right: 16px; top: 48px; }
.equip-giay { left: 50%; bottom: 22px; transform: translateX(-50%); }
.equip-phap_boi { left: 16px; bottom: 34px; }
.equip-nhan { right: 16px; bottom: 34px; }
.equip-slot.grade-fine, .bag-slot.grade-fine { border-color: #79a477; }
.equip-slot.grade-spirit, .bag-slot.grade-spirit { border-color: #5bb4bd; }
.equip-slot.grade-earth, .bag-slot.grade-earth { border-color: #8b65b5; }
.equipment-summary {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 8px;
}
.equipment-summary span {
  padding: 4px 2px; text-align: center; color: #5d482f;
  background: rgba(73, 52, 29, 0.08); border: 1px solid rgba(73, 52, 29, 0.22);
  font-size: 9px; font-variant-numeric: tabular-nums;
}
.equipment-summary i { display: block; font-style: normal; color: #826843; }
.equipment-summary b { display: block; margin-top: 1px; color: #3d6546; }
.bag-list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 8px 0;
}
.bag-slot {
  position: relative;
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  color: inherit;
  font: inherit;
  background: linear-gradient(180deg, rgba(57, 43, 30, 0.12), rgba(57, 43, 30, 0.24));
  border: 1px solid var(--wood);
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.bag-slot.empty { cursor: default; opacity: 0.45; }
.bag-slot:hover    { border-color: var(--gold); }
.bag-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.bag-slot.selected { border-color: var(--jade); box-shadow: inset 0 0 0 1px var(--jade); }
.bag-slot canvas   { width: 70%; height: 70%; image-rendering: pixelated; }
.bag-qty {
  position: absolute; right: 2px; bottom: 1px;
  font-size: 10px; font-weight: 700; line-height: 1.3;
  color: var(--parchment);
  background: rgba(28, 22, 16, 0.85);
  padding: 0 3px; border-radius: 2px;
}
.bag-detail {
  position: relative; min-height: 78px; text-align: left;
  border: 1px solid rgba(57, 43, 30, 0.35);
  background: rgba(255, 248, 226, 0.32);
  padding: 10px 150px 10px 12px; margin-bottom: 12px;
}
.bag-detail b  { font-family: var(--font-serif); font-size: 15px; color: var(--ink); }
.bag-detail i  { font-style: normal; font-size: 12px; color: var(--ink-soft); margin-left: 6px; }
.bag-detail em {
  display: block; font-style: normal; font-size: 11px;
  color: var(--blood); letter-spacing: 0.05em; margin: 2px 0 6px;
}
.bag-detail p  { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.item-bonuses { margin-bottom: 5px; color: #3d6546; font-size: 11px; font-weight: 700; }
.equip-action {
  position: absolute; right: 10px; top: 50%; width: 126px; min-height: 38px;
  transform: translateY(-50%); cursor: pointer;
  color: #f5e8c9; background: linear-gradient(180deg, #5d7b56, #38513c);
  border: 1px solid #29432f; border-radius: 2px;
  font-family: var(--font-serif); font-size: 12px; letter-spacing: 0.06em;
}
.equip-action:hover { filter: brightness(1.12); }
.equip-action:active { transform: translateY(calc(-50% + 1px)); }
.equipment-bag-panel > .btn-main { width: min(260px, 100%); margin: 0 auto; }

/* ----------------------------------------------------------------------
 *  KỸ NĂNG LỤC — danh sách chiêu đã lĩnh ngộ + hộp mô tả
 * -------------------------------------------------------------------- */
/* Kỹ Năng Lục mở được từ trong menu Tạm Dừng, nên phải nằm TRÊN menu; hộp mô tả
 * lại nằm trên Kỹ Năng Lục. Cả hai đứng trước #menu trong index.html nên thứ tự
 * DOM không đủ, phải nói rõ tầng. */
#skillbook { z-index: 210; }
#skill-pop { z-index: 220; }
.skillbook-panel { width: min(560px, 100%); }
.skill-list { margin: 12px 0 14px; text-align: left; }
.skill-group {
  margin: 14px 2px 6px; padding-bottom: 4px;
  color: var(--blood); font-size: 12px; letter-spacing: 0.16em;
  border-bottom: 1px solid rgba(75, 49, 25, 0.28);
}
.skill-group:first-child { margin-top: 0; }
.skill-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; margin: 5px 0; padding: 8px 10px;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  background: rgba(255, 248, 226, 0.34);
  border: 1px solid rgba(75, 49, 25, 0.32); border-radius: 3px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.skill-row:hover { border-color: var(--gold); background: rgba(255, 248, 226, 0.62); }
.skill-row:active { transform: translateY(1px); }
.skill-row:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.skill-row.equipped { border-color: var(--jade); box-shadow: inset 0 0 0 1px var(--jade); }
/* Đã học nhưng chưa đủ điều kiện: vẫn đọc rõ, chỉ nhạt đi và ngả vàng cảnh báo */
.skill-row.unready { background: rgba(216, 178, 106, 0.16); }
.skill-row.locked { opacity: 0.55; }
.skill-row-icon {
  flex: none; width: 38px; height: 38px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 38% 30%, #4a3a26, #1d160f 72%);
  border: 1px solid #705632; border-radius: 3px;
  font-family: Georgia, serif; font-size: 21px; line-height: 1;
  text-shadow: 0 0 6px currentColor;
}
.skill-row.locked .skill-row-icon { filter: grayscale(0.85); }
.skill-row-main { flex: 1 1 auto; min-width: 0; }
.skill-row-main b {
  display: block; font-family: var(--font-serif); font-size: 15px; color: var(--ink);
}
.skill-row-main em {
  margin-left: 7px; font-style: normal; font-size: 10px; letter-spacing: 0.08em;
  color: var(--ink-soft);
}
/* Cắt gọn còn hai dòng: dài hơn thì danh sách hoá bức tường chữ, ngắn hơn thì
 * câu mô tả đứt giữa chừng nhìn như lỗi. Bản đầy đủ nằm trong hộp mô tả. */
.skill-row-main small {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  margin-top: 2px; overflow: hidden;
  color: var(--ink-soft); font-size: 11px; line-height: 1.4;
}
.skill-row.unready .skill-row-main small { color: #8a5a22; }
.skill-row-side {
  flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
}
.skill-row-side kbd {
  display: inline-grid; min-width: 20px; min-height: 18px; place-items: center;
  padding: 0 4px;
  color: #f3e6c6; background: #4b3724; border: 1px solid #8f6b38; border-radius: 2px;
  font: 700 10px/1 var(--font-ui);
}
.skill-row-side i {
  font-style: normal; font-size: 10px; letter-spacing: 0.05em; color: var(--ink-soft);
}
.skill-row.equipped .skill-row-side i { color: #3d6546; font-weight: 700; }

/* Hộp mô tả nổi lên trên danh sách. Bộ chọn phải ghi kèm .scroll-panel mới đủ
 * đặc hiệu để thắng .scroll-panel.narrow { text-align: center } — căn giữa thì
 * bảng thông số đọc như thơ chứ không ra bảng. */
.scroll-panel.skill-pop-panel { text-align: left; }
.skill-pop-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.skill-pop-glyph {
  flex: none; width: 52px; height: 52px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 38% 30%, #4a3a26, #1d160f 72%);
  border: 2px solid #705632; border-radius: 4px;
  font-family: Georgia, serif; font-size: 28px; line-height: 1;
  text-shadow: 0 0 8px currentColor;
}
.skill-pop-head h2 { margin-bottom: 2px; font-size: 20px; }
.skill-pop-tags { margin: 0; color: var(--blood); font-size: 11px; letter-spacing: 0.06em; }
.skill-pop-desc { margin: 0 0 10px; }
.skill-stats {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
  margin: 0 0 10px; padding: 9px 11px;
  background: rgba(57, 43, 30, 0.1); border: 1px solid rgba(75, 49, 25, 0.28);
}
.skill-stats dt { color: #826843; font-size: 11px; letter-spacing: 0.05em; }
.skill-stats dd {
  margin: 0; color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums;
}
.skill-pop-warn {
  margin: 0 0 8px; padding: 7px 9px;
  color: #8a5a22; background: rgba(216, 178, 106, 0.2);
  border-left: 3px solid #c9a45c; font-size: 12px; line-height: 1.5;
}
.skill-pop-note { margin: 0 0 12px; color: var(--ink-soft); font-size: 11px; line-height: 1.5; }

/* ----------------------------------------------------------------------
 *  TRỌNG THƯƠNG — bảng chọn đường ra khi Khí Huyết cạn
 *
 *  Cố ý KHÔNG mượn .scroll-panel giấy vàng như mọi cửa sổ khác: cảnh gục
 *  phải khác hẳn tông — tối và đỏ — để người chơi nhận ra mình vừa ngã ngay
 *  trước cả khi kịp đọc chữ. Nền phủ cũng ngả đỏ và rút bớt màu của thế giới
 *  phía sau, hợp với thân xác đã xám ngoét đang nằm dưới đó.
 * -------------------------------------------------------------------- */
#downed {
  z-index: 260;
  background:
    radial-gradient(ellipse at center, rgba(74, 8, 8, 0.42), rgba(6, 4, 3, 0.9) 72%);
  backdrop-filter: blur(2px) saturate(0.35);
}
.downed-panel {
  width: min(400px, 100%);
  padding: 20px 22px 18px;
  text-align: center;
  color: #e8dcc8;
  background: linear-gradient(180deg, rgba(38, 20, 18, 0.97), rgba(19, 12, 11, 0.98));
  border: 2px solid #7d2b2b;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(0, 0, 0, 0.6),
              inset 0 1px 0 rgba(224, 120, 120, 0.18);
}
.downed-mark {
  margin-bottom: 2px;
  color: #c0392b; font-size: 32px; line-height: 1;
  text-shadow: 0 0 18px rgba(192, 57, 43, 0.75);
}
#downed-title {
  margin: 0 0 10px;
  font-family: var(--font-serif); font-size: 25px; letter-spacing: 0.22em;
  color: #e8695e;
  text-shadow: 0 2px 0 #000, 0 0 22px rgba(192, 57, 43, 0.45);
}
.downed-tale {
  margin: 0 0 12px;
  color: #b09a80; font-size: 12.5px; line-height: 1.6; text-align: left;
}
.downed-timer {
  margin: 0 0 14px; padding: 6px 4px;
  color: #9a8a72; font-size: 12px; letter-spacing: 0.04em;
  border-top: 1px solid rgba(125, 43, 43, 0.5);
  border-bottom: 1px solid rgba(125, 43, 43, 0.5);
}
.downed-timer b {
  color: #f0b26a; font-variant-numeric: tabular-nums; font-size: 14px;
}

/* Ba lối ra dùng chung một khuôn nút: tên đậm ở trên, cái giá phải trả ghi
 * ngay dưới. Người chơi đang hoảng thì không ai đọc chú thích ở chỗ khác. */
.downed-btn {
  display: block; width: 100%; margin: 7px 0; padding: 9px 12px;
  text-align: left; cursor: pointer;
  color: #e9dcc4;
  background: linear-gradient(180deg, rgba(72, 40, 33, 0.95), rgba(41, 24, 20, 0.96));
  border: 1px solid #8a4a38; border-radius: 3px;
  transition: filter 0.15s ease, transform 0.08s ease, border-color 0.15s ease;
}
.downed-btn b {
  display: block;
  font-family: var(--font-serif); font-size: 15px; letter-spacing: 0.08em;
}
.downed-btn small {
  display: block; margin-top: 2px;
  color: #a08b72; font-size: 10.5px; line-height: 1.45;
}
.downed-btn:hover { filter: brightness(1.18); border-color: #c9a45c; }
.downed-btn:active { transform: translateY(1px); }
.downed-btn:focus-visible { outline: 2px solid #c9a45c; outline-offset: 2px; }

/* Lối về làng là lối an toàn, nên nó là nút xanh nổi nhất */
.downed-btn.primary {
  color: #f2ead6;
  background: linear-gradient(180deg, #4b6b52, #2c4535);
  border-color: #6d9070;
}
.downed-btn.primary small { color: #bcd3bd; }
/* Nằm xem không phải một lựa chọn "làm gì đó", nên để chìm hẳn xuống */
.downed-btn.ghost {
  background: rgba(0, 0, 0, 0.28); border-color: #5d4a40; color: #b6a48d;
}
.downed-btn.ghost small { color: #86735f; }

/* Huy hiệu lúc đang nằm xem: nhỏ, đỏ, nhấp nháy chậm ở mép trên màn hình để
 * không đè lên cảnh vật mà vẫn nhắc rằng ván này chưa xong. */
#downed-badge {
  position: absolute; z-index: 250;
  left: 50%; top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 6px 14px;
  color: #ffd7cf;
  background: linear-gradient(180deg, rgba(122, 30, 30, 0.95), rgba(58, 14, 14, 0.96));
  border: 1px solid #c0392b; border-radius: 3px;
  font-family: var(--font-serif); font-size: 12px; letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  animation: downed-pulse 1.9s ease-in-out infinite;
}
#downed-badge.hidden { display: none; }
#downed-badge:hover { filter: brightness(1.2); }
@keyframes downed-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.62; } }

.scroll-panel h1, .scroll-panel h2, .scroll-panel h3 {
  font-family: var(--font-serif);
  color: var(--ink);
  margin: 0;
}
.scroll-panel h2 { font-size: 22px; letter-spacing: 0.1em; margin-bottom: 10px; }
.scroll-panel p  { color: var(--ink-soft); line-height: 1.65; font-size: 14px; }

#dialog-text { white-space: pre-line; text-align: left; margin: 6px 4px 18px; }

/* Nút bấm chuẩn */
.btn-main, .btn-sub, .btn-enter {
  font-family: var(--font-serif);
  cursor: pointer;
  border-radius: 2px;
  transition: filter 0.15s ease, transform 0.08s ease;
}
.btn-main {
  display: block; width: 100%;
  margin: 6px 0;
  padding: 11px 18px;
  font-size: 15px; letter-spacing: 0.12em;
  color: var(--parchment);
  background: linear-gradient(180deg, #4b6b52, #2f4735);
  border: 1px solid var(--wood);
}
.btn-sub {
  display: block; width: 100%;
  margin: 6px 0; padding: 9px 16px;
  font-size: 13px; letter-spacing: 0.08em;
  color: var(--ink);
  background: linear-gradient(180deg, #dccfae, #c6b48e);
  border: 1px solid var(--wood);
}
.btn-main:hover, .btn-sub:hover { filter: brightness(1.1); }
.btn-main:active, .btn-sub:active { transform: translateY(1px); }

/* Danh sách lựa chọn trong hộp thoại (gieo hạt, chăm luống thuốc…) */
.dlg-choices { margin: 4px 0 10px; }
.dlg-choices .btn-choice {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  width: 100%; margin: 5px 0; padding: 8px 12px;
  font-family: var(--font-serif); font-size: 14px; letter-spacing: 0.06em;
  text-align: left; cursor: pointer;
  color: var(--parchment);
  background: linear-gradient(180deg, #46604b, #2c3f31);
  border: 1px solid var(--wood); border-radius: 2px;
  transition: filter 0.15s ease, transform 0.08s ease;
}
.dlg-choices .btn-choice:hover { filter: brightness(1.15); }
.dlg-choices .btn-choice:active { transform: translateY(1px); }
.dlg-choices .btn-choice[disabled] { opacity: 0.45; cursor: not-allowed; }
.dlg-choices .btn-choice canvas {
  width: 22px; height: 22px; flex: none; image-rendering: pixelated;
}
/* Tên đan phương giữ nguyên một dòng, dòng chú thích nguyên liệu xuống hàng
 * dưới và tự ngắt dòng — công thức nhiều vị vẫn không phá khung hộp thoại. */
.dlg-choices .btn-choice > span:not(.c-note) { flex: 1 1 auto; min-width: 0; }
.dlg-choices .btn-choice .c-note {
  flex: 1 1 100%; margin-left: 30px;
  font-size: 12px; opacity: 0.75; white-space: normal; line-height: 1.35;
}

/* ============================================================================
 *  MÀN TẠO NHÂN VẬT
 * ==========================================================================*/
.creator-head { text-align: center; margin-bottom: 14px; }
.creator-head h1 {
  font-size: clamp(22px, 4vw, 32px);
  letter-spacing: 0.22em;
}
.creator-head .sub {
  margin: 4px 0 0;
  font-size: 12px; letter-spacing: 0.1em;
  color: #6c5a41;
}

.creator-body {
  display: flex; gap: 22px; align-items: flex-start;
}

/* --- Cột xem trước --- */
.preview-wrap { flex: none; width: 216px; text-align: center; }
.preview-stage {
  background:
    radial-gradient(ellipse at 50% 82%, #4a5c40 0%, #26301f 55%, #171c14 100%);
  border: 2px solid var(--wood);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.7);
  padding: 10px 0 4px;
}
#preview {
  display: block; margin: 0 auto;
  width: 128px; height: 192px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#preview-dirs { display: flex; justify-content: center; gap: 5px; margin-top: 8px; }
#preview-dirs button {
  width: 34px; height: 28px;
  background: #cfbd97; color: var(--ink);
  border: 1px solid var(--wood);
  cursor: pointer; font-size: 12px;
}
#preview-dirs button.active { background: var(--jade); color: #fff; }

.realm-tag {
  margin-top: 10px; font-size: 12px;
  color: #5d4c36; letter-spacing: 0.06em;
}
.realm-tag b { color: var(--blood); }

.desc {
  margin-top: 8px !important;
  font-size: 11.5px !important;
  line-height: 1.6 !important;
  color: #6c5a41 !important;
  min-height: 56px;
  text-align: left;
}

/* --- Cột tuỳ chọn --- */
.options { flex: 1; min-width: 0; }
.options section { margin-bottom: 13px; }
.options h3 {
  font-size: 13px; letter-spacing: 0.14em;
  color: #6c5a41;
  border-bottom: 1px solid rgba(58, 46, 34, 0.3);
  padding-bottom: 3px; margin-bottom: 7px;
}

.row { display: flex; flex-wrap: wrap; gap: 6px; }

.opt-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 11px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--ink);
  background: linear-gradient(180deg, #ded1b1, #c9b791);
  border: 1px solid #8c7a5c;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.opt-btn:hover { background: linear-gradient(180deg, #ece0c3, #d7c6a1); }
.opt-btn.active {
  background: linear-gradient(180deg, #5f8a6b, #3d5c46);
  border-color: var(--wood);
  color: #f4efe1;
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.opt-btn .chip {
  width: 14px; height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  flex: none;
}

.name-row { display: flex; gap: 8px; }
#opt-name {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  font-family: var(--font-ui); font-size: 14px;
  color: var(--ink);
  background: #f2ead4;
  border: 1px solid #8c7a5c;
  border-radius: 2px;
  outline: none;
}
#opt-name:focus { border-color: var(--jade); box-shadow: 0 0 0 2px rgba(122, 168, 135, 0.3); }
#opt-name.invalid { border-color: var(--blood); background: #f6e2df; }
.name-row .btn-sub { width: auto; margin: 0; white-space: nowrap; }

#name-hint {
  display: block; margin-top: 5px;
  font-size: 12px; color: #6f8a72;
}
#name-hint.warn { color: var(--blood); }

.btn-enter {
  display: block; width: 100%;
  margin-top: 18px; padding: 15px;
  font-size: 18px; letter-spacing: 0.3em;
  color: #f7f1e0;
  background: linear-gradient(180deg, #5a7f63, #33502f 60%, #24391f);
  border: 2px solid var(--wood);
  box-shadow: 0 0 0 1px var(--gold) inset, 0 4px 0 rgba(0, 0, 0, 0.25);
}
.btn-enter:hover:not(:disabled) { filter: brightness(1.15); }
.btn-enter:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 1px var(--gold) inset; }
.btn-enter:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }

/* ============================================================================
 *  LỚP CHUYỂN CẢNH
 * ==========================================================================*/
#fade {
  position: absolute; inset: 0;
  background: #000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.42s ease;
  z-index: 400;
}
#fade.on { opacity: 1; pointer-events: auto; }

/* ============================================================================
 *  ĐÁP ỨNG MÀN HÌNH NHỎ
 * ==========================================================================*/
@media (max-width: 760px) {
  #skill-test-panel {
    top: 4px; width: calc(100% - 8px); padding: 5px;
  }
  .skill-test-buttons { gap: 3px; }
  .skill-test-buttons button { flex: 1; padding: 5px 2px; font-size: 9px; }
  #skill-test-panel small { font-size: 8px; }
  .creator-body { flex-direction: column; align-items: center; }
  .preview-wrap { width: 100%; max-width: 320px; }
  .desc { text-align: center; min-height: 0; }
  .scroll-panel { padding: 16px 18px 20px; }
  #hud-keys { display: none; }
  #hud-left { width: 180px; transform: scale(0.92); transform-origin: top left; }
  #hud-btns { top: 158px; left: 8px; }
  #hud-journal { top: 204px; left: 8px; }
  #btn-breakthrough, .breakthrough-sheet { width: min(264px, calc(100vw - 16px)); }
  #hud-right { transform: scale(0.92); transform-origin: top right; }
  .equipment-bag-panel { padding: 16px 18px 20px; }
  .bag-shell { grid-template-columns: 1fr; }
  .equipment-board { height: 230px; }
  .bag-list { grid-template-columns: repeat(5, 1fr); }
  .bag-detail { padding-right: 10px; padding-bottom: 56px; }
  .equip-action { top: auto; right: 10px; bottom: 9px; transform: none; }
  .equip-action:active { transform: translateY(1px); }
  .skillbook-panel { padding: 16px 18px 20px; }
  .skill-row-main small { font-size: 10px; -webkit-line-clamp: 3; }
}

@media (max-width: 420px) {
  #dpad { transform: scale(0.84); transform-origin: left bottom; }
  #touch-buttons { transform: scale(0.82); transform-origin: right bottom; }
  .bag-head { align-items: flex-start; }
  .bag-head h2 { font-size: 17px; letter-spacing: 0.04em; }
  .bag-count { font-size: 8px; }
  .equipment-summary { grid-template-columns: repeat(5, 1fr); }
  #hud-hint { max-width: 92vw; white-space: normal; text-align: center; }
  #hud-hint { bottom: 150px; font-size: 11px; }
}

/* Màn hình ngang thấp (điện thoại xoay ngang) */
@media (max-height: 480px) {
  /* Cụm nút phải dưới cao 228px — trên máy xoay ngang phải thu lại, không thì
   * hàng tiện ích trèo lên quá nửa màn hình. */
  #touch-buttons { transform: scale(0.78); transform-origin: right bottom; }
  #dpad { transform: scale(0.86); transform-origin: left bottom; }
  .scroll-panel { max-height: 96vh; padding: 12px 16px 16px; }
  .creator-head h1 { font-size: 20px; }
  .btn-enter { padding: 11px; font-size: 15px; margin-top: 12px; }
}

/* ============================================================================
 *  CỬA VÀO — ĐĂNG NHẬP / ĐĂNG KÝ
 *  Nằm trên cả màn hình chờ (z-index 600 > 500) vì phải hỏi danh tính trước
 *  khi biết nạp nhân vật nào.
 * ==========================================================================*/
#auth-gate {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, #212a23 0%, #0b0a08 78%);
  z-index: 600;
}
#auth-gate.hidden { display: none; }
#auth-gate.busy { pointer-events: none; opacity: 0.75; }

.auth-box {
  width: min(360px, 100%);
  background: linear-gradient(180deg, rgba(38, 29, 20, 0.96), rgba(21, 16, 11, 0.97));
  border: 1px solid rgba(201, 164, 92, 0.45);
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  padding: 22px 20px 18px;
  text-align: center;
}

#auth-title {
  font-family: var(--font-serif);
  font-size: 28px; letter-spacing: 0.18em;
  color: var(--parchment);
  margin: 0 0 6px;
  text-shadow: 0 2px 0 #000;
}
.auth-sub {
  color: var(--jade);
  font-size: 12px; line-height: 1.5;
  margin: 0 0 18px;
}

.auth-field { display: block; text-align: left; margin-bottom: 12px; }
.auth-field span {
  display: block;
  color: var(--parchment-2);
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 5px;
}
.auth-field input {
  width: 100%; box-sizing: border-box;
  padding: 10px 11px;
  font-family: var(--font-ui); font-size: 15px;
  color: var(--parchment);
  background: rgba(12, 9, 7, 0.85);
  border: 1px solid rgba(201, 164, 92, 0.35);
  border-radius: 3px;
  outline: none;
}
.auth-field input:focus { border-color: var(--gold); }

/* Ô thông báo giữ chỗ sẵn một dòng, để nút bấm không nhảy lên nhảy xuống mỗi
 * lần hiện lỗi rồi ẩn đi. */
.auth-msg {
  min-height: 17px;
  margin: 2px 0 10px;
  font-size: 12px; line-height: 1.4;
  color: var(--jade);
}
.auth-msg.warn { color: #e0a06a; }

.auth-btn {
  width: 100%;
  padding: 11px;
  font-family: var(--font-serif); font-size: 16px; letter-spacing: 0.14em;
  color: var(--ink);
  background: linear-gradient(180deg, #d9bd7f, #b08c47);
  border: 1px solid #7c5f2c;
  border-radius: 3px;
  cursor: pointer;
}
.auth-btn:hover { filter: brightness(1.08); }
.auth-btn:disabled { filter: grayscale(0.6); cursor: default; }

.auth-link {
  display: block; width: 100%;
  margin-top: 10px; padding: 4px;
  background: none; border: none;
  color: var(--qi); font-family: var(--font-ui); font-size: 12px;
  cursor: pointer;
}
.auth-link:hover { text-decoration: underline; }
.auth-link.dim { color: #8a7b63; font-size: 11px; margin-top: 4px; }

/* Số người chơi đang ở cùng bản đồ, nép dưới tên bản đồ ở HUD */
#hud-online {
  color: var(--qi);
  font-size: 11px; letter-spacing: 0.06em;
  margin-top: 2px;
}
#hud-online.hidden { display: none; }
