* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #10160f;
  color: #f3e6c4;
  font-family: "Segoe UI", Tahoma, sans-serif;
  overflow: hidden;
}
#view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background: #1a2414;
}
/* ===== Video mở đầu ===== */
#intro {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  transition: opacity 1s ease;
}
#intro video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  transition: transform 1.2s cubic-bezier(0.3, 0.6, 0.2, 1), filter 1.2s ease;
}
/* Chuyển cảnh:
   - .match (video chạy hết): khung hình cuối video trùng với khung hình game (map.js đặt camera khớp) -> chỉ mờ chồng 0.7s.
   - không .match (bấm Bỏ qua giữa chừng): video mờ dần, phóng nhẹ và nhoè. */
#intro.out { opacity: 0; pointer-events: none; }
#intro.out video { transform: scale(1.08); filter: blur(6px) brightness(1.15); }
#intro.match { transition: opacity 0.7s ease-in-out; }
#intro.match.out video { transform: none; filter: none; }
#intro.gone { display: none; }
/* Nút bấm để phát có tiếng (khi trình duyệt chặn tự phát có tiếng) */
#intro-play {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 46px 16px !important;
  border: 2px solid #e6c36a !important;
  background: rgba(14, 8, 2, 0.82) !important;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.6), 0 0 34px rgba(255, 170, 40, 0.55);
  animation: playPulse 1.6s ease-in-out infinite;
}
#intro-play[hidden] { display: none; }
#intro-play .ip-text { font: 800 22px Segoe UI, sans-serif; letter-spacing: 0.12em; color: #fff3c4; text-transform: uppercase; }
/* 2 thanh kiếm bắt chéo: mở ra / khép lại như cây kéo, khép lại thì loé tia lửa ở chỗ giao nhau */
#intro-play .ip-swords { width: 96px; height: 96px; margin: -6px 0 -4px; overflow: visible; filter: drop-shadow(0 0 8px rgba(255, 170, 40, 0.65)); }
/* (chuyển động mở/khép của kiếm + tia lửa nằm trong SVG ở index.html: animateTransform) */
#intro-play:hover .ip-swords { filter: drop-shadow(0 0 12px rgba(255, 190, 60, 0.95)); }
@keyframes playPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.6), 0 0 24px rgba(255, 170, 40, 0.45); }
  50% { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.6), 0 0 44px rgba(255, 170, 40, 0.85); }
}
/* Trong lúc video: giao diện game ẩn sẵn ở vị trí lệch; hết video thì lần lượt trượt vào (độ trễ so le). */
#hud, #ui-bar, #joy, #mute {
  transition: opacity 0.55s ease, transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#ui-bar { transition-delay: 0.12s; }
#joy { transition-delay: 0.22s; }
#mute { transition-delay: 0.3s; }
body.intro-on #hud { opacity: 0; transform: translateX(40px); }
body.intro-on #ui-bar { opacity: 0; transform: translate(-50%, 100%); }
body.intro-on #joy { opacity: 0; transform: translateX(-40px); }
body.intro-on #mute { opacity: 0; transform: translateY(-24px); }
body.intro-on #test { opacity: 0; animation: none; }
#intro button {
  position: absolute;
  z-index: 2;
  padding: 7px 14px;
  border: 1px solid rgba(230, 195, 106, 0.7);
  background: rgba(16, 12, 8, 0.7);
  color: #ffe7a8;
  font: 700 14px Segoe UI, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
}
#intro button:hover { background: rgba(40, 28, 12, 0.9); }
#intro-skip { right: 16px; bottom: 22px; opacity: 0.85; }
/* Nhãn "Chạm để bật tiếng" khi trình duyệt chỉ cho tự phát không tiếng */
#intro-sound { left: 16px; top: 16px; animation: soundPulse 1.2s ease-in-out infinite; }
#intro-sound[hidden] { display: none; }
@keyframes soundPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 200, 80, 0.0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 200, 80, 0.35); }
}
#intro-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, 0.08); }
#intro-bar i { display: block; height: 100%; width: 0; background: #e6c36a; transition: width 0.3s linear; }
#intro.out #intro-bar, #intro.out button { opacity: 0; transition: opacity 0.3s; }
#intro-wait {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  padding: 6px 20px 7px;
  color: #ffe7a8;
  font: 700 15px Segoe UI, sans-serif;
  letter-spacing: 0.1em;
  background: rgba(10, 6, 2, 0.75);
  border: 1px solid rgba(230, 195, 106, 0.6);
  display: none;
}
#intro.waiting #intro-wait { display: block; }
#intro.waiting #intro-skip { display: none; }
@media (max-width: 720px), (max-height: 520px) {
  #intro button { padding: 5px 10px; font-size: 12px; }
  #intro-play .ip-swords { width: 68px; height: 68px; }
  #intro-play .ip-text { font-size: 16px; }
  #intro-skip { right: 10px; bottom: 14px; }
  #intro-sound { left: 10px; top: 10px; }
}
#veil {
  position: fixed;
  inset: 0;
  z-index: 14;
  pointer-events: none;
  background: #10160f;
  opacity: 1;
  transition: opacity 0.85s ease;
}
#veil.lift { opacity: 0; }
#veil.gone { display: none; }
#fog {
  display: block;
  width: 100%;
  height: 100%;
}
#test {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 16;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 16px 32px 14px;
  border: 1px solid rgba(230, 195, 106, 0.55);
  background: rgba(16, 12, 8, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transform: translate(-50%, -50%);
  animation: titleIn 1s cubic-bezier(0.16, 0.8, 0.24, 1) both;
}
#test.dock {
  top: auto;
  bottom: 148px;
  transform: translateX(-50%);
  animation: dockIn 0.55s ease both;
}
.gate-kicker {
  color: #e6c36a;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.42em;
  text-transform: uppercase;
}
.gate-words {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.03em;
  color: #ffe7a8;
  text-shadow: 0 2px 0 #1c1408, 0 0 2px #1c1408;
}
#test.dock .gate-words { font-size: 30px; }
#test.live .gate-kicker { display: none; }
#test.live .gate-words { font-size: 26px; letter-spacing: 0.12em; }
.gate-line {
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #e6c36a, transparent);
  animation: lineGrow 0.9s 0.25s ease forwards;
}
@keyframes titleIn {
  0% { opacity: 0; transform: translate(-50%, -36%) scale(0.92); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes dockIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  100% { opacity: 1; transform: translateX(-50%); }
}
@keyframes titleShine {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}
@keyframes lineGrow { to { width: min(460px, 70vw); } }
#test:hover { background: rgba(16, 12, 8, 0.78); }
body.hold #joy,
body.hold #pad,
body.hold #minimap,
body.hold #view,
body.locked #test,
body.locked #joy,
body.locked #pad,
body.locked #minimap,
body.locked #view { pointer-events: none; }
#mute {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(230, 195, 106, 0.7);
  background: rgba(16, 12, 8, 0.82);
  color: #ffe7a8;
  font: 700 14px Segoe UI, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
}
#mute svg { width: 18px; height: 18px; fill: none; stroke: #ffe7a8; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#mute.off { color: #b7aa90; }
#mute.off .wave { display: none; }
#mute:hover { background: rgba(36, 26, 14, 0.92); }
/* ===== Thẻ kết thúc (Tải game) ===== */
#install {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* trận đánh vẫn chạy phía sau: tối dần ra viền + nhoè nhẹ */
  background: radial-gradient(ellipse at center, rgba(10, 6, 2, 0.35) 0%, rgba(4, 2, 0, 0.82) 75%);
  backdrop-filter: blur(2px) saturate(0.85);
  -webkit-backdrop-filter: blur(2px) saturate(0.85);
  pointer-events: auto;
}
#install.on { display: flex; animation: endFade 0.6s ease both; }
#test.away { display: none; }
.end-card {
  position: relative;
  width: min(540px, 100%);
  padding: 30px 34px 26px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(40, 26, 10, 0.94) 0%, rgba(16, 10, 4, 0.96) 100%);
  border: 1px solid rgba(230, 195, 106, 0.75);
  box-shadow: 0 0 0 4px rgba(12, 8, 3, 0.85), 0 0 0 5px rgba(230, 195, 106, 0.35), 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 80px rgba(255, 150, 30, 0.18);
  animation: endCardIn 0.75s cubic-bezier(0.2, 0.9, 0.25, 1.15) both;
}
/* góc trang trí */
.end-card::before, .end-card::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid #e6c36a;
  pointer-events: none;
}
.end-card::before { left: 8px; top: 8px; border-right: 0; border-bottom: 0; }
.end-card::after { right: 8px; bottom: 8px; border-left: 0; border-top: 0; }
.end-card > * { animation: endItemIn 0.5s ease both; }
.end-emblem { width: 84px; height: 84px; display: block; margin: -4px auto 6px; filter: drop-shadow(0 0 10px rgba(255, 170, 40, 0.6)); animation-delay: 0.15s; }
.end-kicker { color: #e6c36a; font: 700 13px Segoe UI, sans-serif; letter-spacing: 0.45em; text-transform: uppercase; animation-delay: 0.25s; }
.end-title {
  margin: 6px 0 8px;
  font: 900 40px/1.05 Segoe UI, sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff6d0 0%, #ffd56a 45%, #c98a22 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #3a1a00) drop-shadow(0 0 14px rgba(255, 140, 0, 0.45));
  animation-delay: 0.32s;
}
.end-sub { margin: 0 0 22px; color: #e8dcc0; font: 500 15px/1.45 Segoe UI, sans-serif; animation-delay: 0.4s; }
#install #download {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 380px;
  padding: 16px 28px;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffe48a 0%, #f2b33a 48%, #c97a12 100%);
  color: #2a1400;
  font: 900 24px Segoe UI, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 240, 200, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), inset 0 -3px 0 rgba(120, 60, 0, 0.45), 0 6px 0 #6e3a06, 0 12px 26px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  animation: endItemIn 0.5s ease 0.5s both, ctaPulse 1.8s ease-in-out 1.2s infinite;
}
#install #download svg { width: 26px; height: 26px; flex: none; }
/* vệt sáng lướt qua nút */
#install #download::after {
  content: "";
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: -40%;
  width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  transform: skewX(-20deg);
  animation: ctaShine 2.6s ease-in-out 1s infinite;
}
#install #download:hover { filter: brightness(1.08); }
#install #download:active { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), inset 0 -3px 0 rgba(120, 60, 0, 0.45), 0 3px 0 #6e3a06, 0 8px 18px rgba(0, 0, 0, 0.5); }
#install #replay {
  display: block;
  margin: 16px auto 0;
  padding: 6px 14px;
  border: 0;
  background: none;
  color: #cdbf9e;
  font: 600 14px Segoe UI, sans-serif;
  letter-spacing: 0.08em;
  cursor: pointer;
  animation-delay: 0.6s;
}
#install #replay:hover { color: #ffe7a8; text-decoration: underline; }
@keyframes endFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes endCardIn { from { opacity: 0; transform: scale(0.86) translateY(16px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes endItemIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ctaShine { 0% { left: -40%; } 55%, 100% { left: 130%; } }
@keyframes ctaPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@media (max-width: 520px), (max-height: 520px) {
  .end-card { padding: 22px 18px 18px; }
  .end-emblem { width: 60px; height: 60px; }
  .end-kicker { font-size: 11px; letter-spacing: 0.32em; }
  .end-title { font-size: 32px; }
  .end-sub { font-size: 13px; margin-bottom: 16px; }
  #install #download { font-size: 19px; padding: 13px 20px; }
  #install #download svg { width: 22px; height: 22px; }
}
@media (max-height: 420px) {
  .end-emblem { display: none; }
  .end-title { font-size: 28px; margin: 4px 0 6px; }
}
#minimap {
  position: fixed;
  right: 16px;
  top: 16px;
  width: 200px;
  background: rgba(10, 12, 8, 0.88);
  border: 1px solid rgba(230, 195, 106, 0.55);
}
.mini-title {
  padding: 4px 8px 5px;
  text-align: center;
  border-bottom: 1px solid rgba(230, 195, 106, 0.35);
}
#mini-name {
  color: #f3e6c4;
  font-size: 13px;
  line-height: 1.2;
}
#mini-pos {
  margin-top: 1px;
  color: #e6c36a;
  font-size: 12px;
  letter-spacing: 0.02em;
}
#mini {
  display: block;
  width: 200px;
  height: 128px;
  cursor: pointer;
  image-rendering: pixelated;
}
#joy {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 1px solid rgba(230, 195, 106, 0.5);
  background: rgba(16, 14, 10, 0.55);
  touch-action: none;
}
#joy i {
  position: absolute;
  width: 48px;
  height: 48px;
  left: 50%;
  top: 50%;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background: rgba(230, 195, 106, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
#pad {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-areas: ". up ." "left down right";
  gap: 6px;
}
#pad button {
  width: 52px;
  height: 52px;
  border: 1px solid rgba(230, 195, 106, 0.5);
  background: rgba(16, 14, 10, 0.78);
  color: #f3e6c4;
  font-size: 18px;
}
#pad button[data-k="up"] { grid-area: up; }
#pad button[data-k="left"] { grid-area: left; }
#pad button[data-k="down"] { grid-area: down; }
#pad button[data-k="right"] { grid-area: right; }
#load {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  background: transparent;
}
.load-card { width: min(360px, calc(100% - 40px)); text-align: center; }
#load-bar {
  margin: 14px 0 8px;
  height: 6px;
  background: #2a261c;
}
#load-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: #e6c36a;
}
#load.hide { display: none; }
/* ===== Giao diện game giả lập (cắt từ ảnh gốc 2560x1440, xem cut_ui.py) =====
   --u       : 1px của ảnh gốc quy ra màn hình (co theo chiều cao, không vượt chiều ngang)
   --hud-top : HUD góc phải trên dời xuống bao nhiêu (màn dọc để chừa nút Tắt âm)
   --bar-h   : chiều cao thanh rồng dưới đáy
   --ctl-b   : khoảng cách đáy của cần điều khiển, phím mũi tên, nút chiêu */
:root {
  --u: min(calc(100vh / 1440), calc(100vw / 1800));
  --hud-top: 0px;
  --bar-h: calc(var(--u) * 166);
  --ctl-b: 16px;
}
.game-ui { pointer-events: none; user-select: none; -webkit-user-drag: none; }
#ui-bar {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: 0;
  width: min(calc(var(--u) * 1053), 100vw);
  transform: translateX(-50%);
}
/* ===== HUD góc phải trên: icon tách riêng (data/ui, xem cut_icons.py) xếp lại quanh minimap =====
     [ lưới 6 cột x 2 hàng icon menu ][ minimap ]
                                      [ 4 nút tròn: Kiếm Auto Chạy Lên ]
                                      [ 4 ô vật phẩm                   ]
   --s  : cỡ một ô icon     --g : khe giữa các ô
   Lưới dưới minimap rộng đúng bằng minimap; lưới menu cao đúng bằng minimap.
   --hud-w / --hud-h : kích thước cả HUD (dùng để các khung khác né HUD). */
:root {
  --s: clamp(24px, 6vh, 58px);
  --g: calc(var(--s) * 0.08);
  --mm-w: calc(var(--s) * 4 + var(--g) * 3);
  --mm-h: calc(var(--mm-w) * 0.64);
  --hud-w: calc(var(--s) * 10 + var(--g) * 10);
  --hud-h: calc(var(--mm-h) + var(--s) * 2 + var(--g) * 2);
}
#hud {
  position: fixed;
  z-index: 12;
  right: 8px;
  top: calc(var(--hud-top) + 8px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--g);
  pointer-events: none;
}
#hud .hud-top { display: flex; align-items: stretch; gap: calc(var(--g) * 2); }
#hud-menu {
  display: grid;
  grid-template-columns: repeat(6, var(--s));
  grid-template-rows: repeat(2, 1fr);
  column-gap: var(--g);
  align-items: center;
  justify-items: center;
}
#hud-menu img, #hud-act img { display: block; width: var(--s); height: auto; }
#hud-act {
  display: grid;
  grid-template-columns: repeat(4, var(--s));
  gap: var(--g);
  align-items: center;
  justify-items: center;
}
#hud-act img.slot { width: calc(var(--s) * 0.86); }
#hud #minimap {
  position: relative;
  right: auto;
  top: auto;
  width: var(--mm-w);
  pointer-events: auto;
}
#hud #mini { width: 100%; height: auto; }
#hud .mini-title {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(var(--s) * 0.04) calc(var(--s) * 0.1) calc(var(--s) * 0.12);
  border-bottom: 0;
  background: linear-gradient(180deg, rgba(10, 12, 8, 0.9) 0%, rgba(10, 12, 8, 0.65) 70%, rgba(10, 12, 8, 0) 100%);
  pointer-events: none;
}
#hud #mini-name { font-size: max(8px, calc(var(--s) * 0.24)); line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud #mini-pos { font-size: max(8px, calc(var(--s) * 0.22)); margin-top: 0; }
#pad, #joy { z-index: 13; bottom: var(--ctl-b); }

/* Nút chiêu của nhân vật chính */
#skills {
  position: fixed;
  right: 200px;
  bottom: 20px;
  z-index: 22;
  display: none;
  gap: 14px;
}
body.fight #skills { display: flex; }
body.locked #skills { display: none; }
/* Ô kỹ năng vuông như trong game; icon lấy từ cột SkillIcon trong Settings\Skills.txt */
#skills { padding-bottom: 30px; gap: 44px; }
#skills button {
  --cd: 0;
  position: relative;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 2px solid #e6c36a;
  background: #140e06;
  box-shadow: 0 0 0 2px rgba(16, 12, 8, 0.85), 0 0 16px rgba(255, 196, 80, 0.45);
  color: #ffe7a8;
  cursor: pointer;
  touch-action: manipulation;
}
#skills button:active { transform: scale(0.94); }
#skills .ico {
  position: absolute;
  inset: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
#skills button[data-sk="166"] .ico { background-image: url(data/icon_sk_357.png); }
#skills button[data-sk="168"] .ico { background-image: url(data/icon_sk_359.png); }
#skills .sk-name {
  position: absolute;
  left: 50%;
  top: calc(100% + 5px);
  transform: translateX(-50%);
  white-space: nowrap;
  font: 800 12px/1.15 Segoe UI, sans-serif;
  text-align: center;
  text-shadow: 0 1px 0 #000, 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
}
#skills kbd {
  position: absolute;
  top: 1px;
  left: 3px;
  z-index: 1;
  font: 800 11px Segoe UI, sans-serif;
  color: #fff3c4;
  text-shadow: 0 1px 0 #000, 0 0 2px #000;
  pointer-events: none;
}
#skills button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: conic-gradient(rgba(0, 0, 0, 0.66) calc(var(--cd) * 360deg), transparent 0);
  pointer-events: none;
}
/* 2 nút chiêu nằm sát bên trái cụm phím mũi tên (góc phải dưới). Nếu đè lên thanh rồng (JS đặt
   body.skills-raise) thì nâng lên trên thanh rồng; màn dọc thì đặt ngay trên cụm phím mũi tên. */
/* Cụm phím mũi tên ảo đã tắt (di chuyển bằng cần điều khiển trái hoặc bàn phím); nút chiêu nằm sát góc phải. */
#pad { display: none !important; }
#skills { right: 16px; bottom: var(--ctl-b); }
body.skills-raise #skills { bottom: calc(var(--bar-h) + 10px); }
#hint {
  position: fixed;
  left: 50%;
  bottom: 128px;
  z-index: 21;
  transform: translateX(-50%);
  padding: 6px 22px 7px;
  color: #ffe7a8;
  font: 800 18px Segoe UI, sans-serif;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 2px 0 #000;
  background: linear-gradient(90deg, rgba(12, 8, 4, 0) 0%, rgba(12, 8, 4, 0.82) 12%, rgba(12, 8, 4, 0.82) 88%, rgba(12, 8, 4, 0) 100%);
  border-top: 1px solid rgba(230, 195, 106, 0.7);
  border-bottom: 1px solid rgba(120, 78, 28, 0.85);
  pointer-events: none;
  display: none;
}
#hint.on { display: block; }
/* Banner thúc giục khi chủ tướng tới gần cổng */
#urge {
  position: fixed;
  left: 50%;
  top: 30%;
  z-index: 23;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}
/* Banner hiện và đứng yên (nhấp nháy) tới khi chủ tướng bấm chiêu, rồi mới tắt (.leave) */
#urge.show {
  visibility: visible;
  animation: urgeIn 0.9s cubic-bezier(0.2, 0.9, 0.25, 1) forwards;
}
#urge.show .u-main { animation: urgeGlow 1.1s ease-in-out 0.9s infinite; }
#urge.show.leave { animation: urgeOut 0.45s ease-in forwards; }
@keyframes urgeGlow {
  0%, 100% { text-shadow: 0 3px 0 #5a1600, 0 0 4px #000, 0 0 22px rgba(255, 70, 0, 0.95), 0 0 46px rgba(255, 160, 0, 0.6); transform: scale(1); }
  50% { text-shadow: 0 3px 0 #5a1600, 0 0 4px #000, 0 0 34px rgba(255, 70, 0, 1), 0 0 70px rgba(255, 200, 0, 0.9); transform: scale(1.04); }
}
@keyframes urgeOut {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}
/* Thanh máu Cổng Thành ở giữa phía trên màn hình */
#gatebar {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 22;
  /* Không lấn sang HUD góc phải (rộng 1000u tính từ mép phải). */
  width: min(520px, calc(100vw - var(--hud-w) * 2 - 56px));
  min-width: 240px;
  transform: translateX(-50%);
  pointer-events: none;
  display: none;
}
#gatebar.on { display: block; animation: gbIn 0.4s ease both; }
#gatebar.hit { animation: gbHit 0.32s ease; }
#gatebar .gb-name {
  text-align: center;
  color: #ffe7a8;
  font: 800 15px Segoe UI, sans-serif;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(255, 90, 0, 0.7);
  margin-bottom: 4px;
}
#gatebar .gb-track {
  position: relative;
  height: 18px;
  border: 2px solid #e6c36a;
  background: rgba(20, 8, 4, 0.88);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.7), 0 4px 14px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
#gatebar .gb-lag, #gatebar .gb-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
}
#gatebar .gb-lag { background: #fff2c0; transition: width 0.6s ease 0.25s; }
#gatebar .gb-fill { background: linear-gradient(180deg, #ff6a3a 0%, #d71a0a 55%, #8e0a04 100%); transition: width 0.12s linear; }
#gatebar .gb-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font: 800 12px Segoe UI, sans-serif;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 #000, 0 0 3px #000;
}
@keyframes gbIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes gbHit {
  0% { transform: translateX(-50%); }
  25% { transform: translateX(calc(-50% - 5px)) scale(1.03); }
  50% { transform: translateX(calc(-50% + 5px)) scale(1.03); }
  100% { transform: translateX(-50%); }
}
body.locked #gatebar { display: none; }
body.gatebar #kills { top: 80px; }
#urge .u-kick {
  display: inline-block;
  padding: 4px 18px 5px 26px;
  color: #ffe27a;
  font: 900 20px Segoe UI, sans-serif;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  background: rgba(14, 6, 2, 0.88);
  border: 1px solid rgba(255, 200, 90, 0.85);
  -webkit-text-stroke: 1px #000;
  text-shadow: 0 2px 0 #000, 0 0 3px #000, 0 0 12px rgba(255, 120, 0, 0.9);
}
#urge .u-main {
  margin: 4px 0 6px;
  padding: 6px 40px 8px;
  color: #fff3c4;
  font: 900 54px/1 Segoe UI, sans-serif;
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-shadow: 0 3px 0 #5a1600, 0 0 4px #000, 0 0 22px rgba(255, 70, 0, 0.95), 0 0 46px rgba(255, 160, 0, 0.6);
  background: linear-gradient(90deg, rgba(60, 8, 0, 0) 0%, rgba(60, 8, 0, 0.78) 14%, rgba(60, 8, 0, 0.78) 86%, rgba(60, 8, 0, 0) 100%);
  border-top: 2px solid rgba(255, 200, 90, 0.9);
  border-bottom: 2px solid rgba(255, 200, 90, 0.9);
}
#urge .u-sub {
  display: inline-block;
  padding: 5px 20px 6px;
  color: #fff3c4;
  font: 800 19px Segoe UI, sans-serif;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: rgba(14, 6, 2, 0.88);
  border: 1px solid rgba(255, 200, 90, 0.85);
  -webkit-text-stroke: 0.6px #000;
  text-shadow: 0 2px 0 #000, 0 0 3px #000, 0 0 3px #000;
}
@keyframes urgeIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.4); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(0.92); }
  55% { transform: translate(-50%, -50%) scale(1.04); }
  66% { transform: translate(calc(-50% - 6px), -50%) scale(1); }
  77% { transform: translate(calc(-50% + 6px), -50%) scale(1); }
  88%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
/* Nút chiêu phát sáng nhịp nhàng khi đang đứng gần cổng */
body.urge #skills button { animation: skillPulse 0.9s ease-in-out infinite; }
@keyframes skillPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(16, 12, 8, 0.85), 0 0 14px rgba(255, 196, 80, 0.5); border-color: #e6c36a; }
  50% { box-shadow: 0 0 0 2px rgba(16, 12, 8, 0.85), 0 0 30px 8px rgba(255, 110, 20, 0.95); border-color: #fff1b0; }
}
body.locked #urge { display: none; }
body.locked #hint { display: none; }
#hint { bottom: max(128px, calc(var(--bar-h) + 12px)); }
/* Thông báo hạ gục: căn giữa phần trống bên trái HUD để không đè lên cụm nút menu. */
body #kills { left: calc((100vw - var(--hud-w) - 8px) / 2); width: auto; }

/* ----- Điện thoại xoay ngang (màn thấp): thu nhỏ chữ, gợi ý lên phía trên, banner nhỏ lại ----- */
/* (Số đo phím mũi tên / nút chiêu ở đây phải khớp với layoutSkills() trong map.js.) */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --s: clamp(20px, 6vh, 26px); }
  #joy { width: 80px; height: 80px; }
  #joy i { width: 34px; height: 34px; margin-left: -17px; margin-top: -17px; }
  #pad { grid-template-columns: 36px 36px 36px; gap: 4px; }
  #pad button { width: 36px; height: 36px; font-size: 13px; }
  #skills { right: 12px; gap: 24px; padding-bottom: 22px; }
  #skills button { width: 44px; height: 44px; }
  #skills .sk-name { font-size: 9px; white-space: normal; width: 60px; }
  #skills kbd { font-size: 9px; }
  #hint { top: 60px; bottom: auto; font-size: 12px; padding: 3px 14px 4px; }
  body #kills, body.gatebar #kills { top: 92px; gap: 3px; }
  body #kills .kill { font-size: 10px; padding: 1px 10px 2px 5px; }
  body #kills .kt, body #kills .vt, body #kills .km { font-size: 9px; }
  #gatebar { top: 8px; }
  #gatebar .gb-name { font-size: 10px; margin-bottom: 1px; }
  #gatebar .gb-track { height: 12px; }
  #gatebar .gb-num { font-size: 10px; }
  /* Nhân vật đứng giữa màn: banner đặt ở khoảng trống phía dưới chân nhân vật, trên cụm điều khiển. */
  #urge { top: 72%; }
  #urge .u-main { font-size: 22px; padding: 3px 16px 4px; margin: 2px 0 3px; }
  #urge .u-kick { font-size: 10px; padding: 2px 8px 2px 12px; }
  #urge .u-sub { font-size: 10px; padding: 2px 8px 3px; }
  #test.dock { bottom: calc(var(--bar-h) + 60px); padding: 8px 18px 7px; }
  #test.dock .gate-words { font-size: 18px; }
  #mute { left: 8px; top: 8px; padding: 4px 8px; font-size: 11px; gap: 5px; }
  #mute svg { width: 14px; height: 14px; }
}

/* ----- Màn dọc: HUD co theo bề ngang và dời xuống dưới nút Tắt âm; điều khiển nằm trên thanh rồng ----- */
@media (orientation: portrait) {
  :root {
    --u: min(calc((100vw - 8px) / 1000), calc(100vh / 2200));
    --s: min(calc((100vw - 16px) / 10.8), 44px);
    --hud-top: 50px;
    --ctl-b: calc(var(--bar-h) + 10px);
    --below-hud: calc(var(--hud-top) + var(--hud-h) + 18px);
  }
  #joy { width: 104px; height: 104px; }
  #skills, body.skills-raise #skills { right: 16px; bottom: var(--ctl-b); gap: 26px; }
  #skills button { width: 60px; height: 60px; }
  #skills .sk-name { white-space: normal; width: 76px; font-size: 10px; }
  #gatebar { top: var(--below-hud); width: calc(100vw - 32px); min-width: 0; }
  #gatebar .gb-name { font-size: 12px; }
  body #kills { left: 50%; top: var(--below-hud); gap: 4px; }
  body.gatebar #kills { top: calc(var(--below-hud) + 56px); }
  body #kills .kill { font-size: 11px; padding: 2px 12px 3px 6px; }
  body #kills .kt, body #kills .vt, body #kills .km { font-size: 10px; }
  #hint { bottom: calc(var(--ctl-b) + 236px); font-size: 14px; }
  /* Banner luôn nằm dưới thanh máu cổng (đáy thanh máu ≈ below-hud + 48px). */
  #urge { top: max(64%, calc(var(--below-hud) + 120px)); }
  #urge .u-main { font-size: 32px; padding: 5px 20px 6px; }
  #urge .u-kick { font-size: 14px; padding: 3px 12px 4px 18px; }
  #urge .u-sub { font-size: 13px; padding: 4px 12px 5px; }
}


.kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #e6c36a;
}
#kills {
  position: fixed;
  left: 50%;
  top: 72px;
  width: min(860px, calc(100% - 24px));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#kills .kill {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: max-content;
  padding: 3px 16px 4px 8px;
  color: #fff6e4;
  font: bold 16px Segoe UI, sans-serif;
  white-space: nowrap;
  background: linear-gradient(90deg, rgba(12, 8, 4, 0) 0%, rgba(12, 8, 4, 0.82) 10%, rgba(12, 8, 4, 0.82) 90%, rgba(12, 8, 4, 0) 100%);
  border-top: 1px solid rgba(230, 195, 106, 0.7);
  border-bottom: 1px solid rgba(120, 78, 28, 0.85);
  animation: killFade 3.2s linear forwards;
}
#kills .ki {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: #e6c36a;
}
#kills .kt, #kills .vt {
  color: #f0d48a;
  font: 700 13px Segoe UI, sans-serif;
  letter-spacing: 0.02em;
}
#kills .kb { color: #7ecbff; }
#kills .kr { color: #ff5c5c; }
#kills .km {
  color: #fff6e4;
  font: 600 13px Segoe UI, sans-serif;
}
@keyframes killFade {
  0% { opacity: 0; }
  8% { opacity: 1; }
  78% { opacity: 1; }
  100% { opacity: 0; }
}
