/* Khung game cố định 540x960 (tỉ lệ 9:16), JS co giãn vừa cửa sổ, nền đen xung quanh. */
@font-face {
  font-family: "Baloo2";
  src: url("assets/fonts/Baloo2.ttf") format("truetype");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --ink: #1b2f57;
  --muted: #55688d;
  --gold: #ffd35a;
  --red: #e5534b;
  --green: #3fae6a;
  --navy: #0f2147;
  --font: "Baloo2", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  touch-action: manipulation;
}

button, input { font-family: var(--font); }

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 540px;
  height: 960px;
  transform: translate(-50%, -50%) scale(var(--s, 1));
  transform-origin: center center;
  overflow: hidden;
  background: #0a1838 url("assets/final/bg_pattern.jpg") center / cover no-repeat;
}

.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: 14px 16px; z-index: 1; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- Kiểu chữ chung: viền xanh đậm + bóng, cùng ngôn ngữ với nút ---------- */
.game-text {
  color: #fff;
  font-weight: 800;
  -webkit-text-stroke: 4px var(--navy);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--navy);
}

.logo-wrap { display: flex; flex-direction: column; align-items: center; margin-top: 30px; }
.logo-wrap.small { margin-top: 6px; }
/* logo PNG đã đổi nền đen thành trong suốt, giữ nguyên ánh sáng viền */
.logo-img {
  width: 520px;
  max-width: 100%;
  height: auto;
  animation: logoFloat 3.4s ease-in-out infinite;
}
.logo-wrap.small .logo-img { width: 520px; }
.logo {
  margin: -10px auto 0;
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 2px;
  color: var(--gold);
  -webkit-text-stroke: 8px #5a2a00;
  paint-order: stroke fill;
  text-shadow: 0 7px 0 #5a2a00, 0 14px 18px rgba(0,0,0,.45);
  text-align: center;
  animation: logoFloat 3s ease-in-out infinite;
}
.logo.small { margin-top: -6px; font-size: 44px; }
.contact {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  text-align: center;
  color: #cfe0ff;
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  text-shadow: 0 2px 0 var(--navy);
  z-index: 3;
}
.contact:active { color: var(--gold); }
@keyframes logoFloat { 50% { transform: translateY(-6px); } }

.chip {
  display: flex;
  align-items: center;
  height: 44px;
  border: 0 solid transparent;
  border-width: 0 24px;
  border-image: url("assets/final/plate.png") 0 330 fill / 0 24px stretch;
  color: #fff;
  padding: 0 4px 3px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 2px 0 var(--navy);
}
.top-row { display: flex; justify-content: space-between; align-items: center; }
.lang-btn {
  min-width: 64px;
  height: 52px;
  padding: 0 14px 4px;
  border: 4px solid #3c74c4;
  border-radius: 16px;
  background: linear-gradient(#2c68b4, #164a8a);
  box-shadow: 0 4px 0 #0f2147;
  color: #fff;
  font: 800 24px/1 var(--font);
  -webkit-text-stroke: 4px var(--navy);
  paint-order: stroke fill;
  cursor: pointer;
}
.lang-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #0f2147; }
.lang-btn.auth-lang { position: absolute; top: 16px; right: 16px; z-index: 5; }
.top-actions { align-items: center; }
.top-actions { display: flex; gap: 8px; }
.round-btn { width: 64px; height: 64px; padding: 0; border: 0; background: none; cursor: pointer; transition: transform .08s; }
.round-btn img { width: 100%; height: 100%; object-fit: contain; }
.round-btn.small { width: 56px; height: 56px; }
.round-btn:active { transform: scale(.9); }

/* Nút chữ nhật dùng border-image để góc đá không bị méo */
.wbtn {
  display: block;
  width: 100%;
  min-height: 92px;
  margin: 8px 0;
  padding: 0 10px;
  border: 30px solid transparent;
  border-image: url("assets/final/btn_orange.png") 80 fill / 30px stretch;
  background: transparent;
  font: 800 30px/1 var(--font);
  color: #fff;
  -webkit-text-stroke: 5px var(--navy);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--navy);
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.wbtn:active { transform: scale(.96); filter: brightness(.9); }
.wbtn.orange { border-image-source: url("assets/final/btn_orange.png"); }
.wbtn.blue   { border-image-source: url("assets/final/btn_blue.png"); }
.wbtn.green  { border-image-source: url("assets/final/btn_green.png"); }
.wbtn.grey   { border-image-source: url("assets/final/btn_grey.png"); }
.wbtn.small  { min-height: 80px; font-size: 26px; }

.link { background: none; border: 0; color: var(--muted); font-size: 18px; font-weight: 600; text-decoration: underline; cursor: pointer; }

/* ---------- Popup: khung đá viền xanh giống nút ---------- */
.panel {
  position: relative;
  border: 44px solid transparent;
  border-image: url("assets/final/panel.png") 140 fill / 44px stretch;
  padding: 0 4px;
  color: var(--ink);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .45));
}
.panel .big, .panel p, .panel h3 { margin: 0; }
.center { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.big { font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.muted { color: var(--muted); font-size: 20px; font-weight: 600; margin: 2px 0; line-height: 1.2; }
.err { color: var(--red); font-size: 18px; font-weight: 600; min-height: 22px; margin: 0; text-align: center; }
.row-btns { display: flex; gap: 8px; }
.row-btns .wbtn { flex: 1; }

/* Ribbon tiêu đề gắn trên mép popup */
.ribbon {
  position: relative;
  width: 400px;
  height: 120px;
  margin: -118px auto 6px;
  background: url("assets/final/ribbon.png") center / 100% 100% no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 6px #7a3000;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 #7a3000;
  padding: 0 70px 6px;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.35));
}
.ribbon span { display: block; text-align: center; }

input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  border: 4px solid #3c74c4;
  box-shadow: inset 0 3px 0 rgba(0,0,0,.12);
  font-size: 24px;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
  user-select: text;
}
input::placeholder { color: #8fa3c8; font-weight: 600; }
.code-input { text-align: center; letter-spacing: 5px; text-transform: uppercase; }

.menu { margin-top: auto; padding-bottom: 44px; }
/* Màn đăng nhập: cụm nút nằm giữa màn hình, ngay dưới logo */
#screen-auth .menu { margin-top: 36px; padding-bottom: 0; }
.auth-form {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 390px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.auth-form h3 { text-align: center; font-size: 32px; font-weight: 800; }
.code-box {
  align-self: center;
  margin-top: 8px;
  background: rgba(8, 20, 48, .72);
  border: 3px solid #4a7fc7;
  color: #fff;
  border-radius: 18px;
  padding: 2px 22px 4px;
  font-size: 22px;
  font-weight: 700;
}
.code-box b { color: var(--gold); letter-spacing: 3px; }

.parade { display: flex; justify-content: center; align-items: flex-end; gap: 0; height: 142px; margin-top: 4px; }
.pdragon { display: flex; flex-direction: column; align-items: center; width: 100px; cursor: pointer; }
.pname {
  margin-top: -4px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 5px var(--navy);
  paint-order: stroke fill;
  text-shadow: 0 2px 0 var(--navy);
}

/* ---------- Sprite quái (sprite sheet 5 frame: đứng, đi, đi, đánh, chết) ---------- */
.spr {
  width: var(--size, 90px);
  height: var(--size, 90px);
  background-repeat: no-repeat;
  background-size: 500% 100%;
  background-position: 0% 0;
  filter: drop-shadow(0 5px 3px rgba(0,0,0,.35));
}
.spr.idle { animation: idleBob 2.2s ease-in-out infinite; animation-delay: var(--d, 0s); }
.spr.walk { animation: walkFrames .5s steps(1, end) infinite; }
.spr.atk  { background-position: 75% 0; }
.spr.die  { background-position: 100% 0; }

@keyframes idleBob { 50% { transform: translateY(-4px) scale(1.02, .98); } }
@keyframes walkFrames {
  0%   { background-position: 25% 0; }
  50%  { background-position: 50% 0; }
  100% { background-position: 25% 0; }
}

/* ---------- Trận đấu ---------- */
.game-hud { height: 64px; display: flex; justify-content: space-between; align-items: center; padding: 0 2px; }
/* Đồng hồ hình chữ nhật, cùng khung đá viền xanh với nút */
.timer {
  min-width: 108px;
  height: 44px; /* cao bằng khung tên người chơi */
  border: 13px solid transparent;
  border-image: url("assets/final/btn_orange.png") 80 fill / 13px stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px 3px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 5px #7a3000;
  paint-order: stroke fill;
  text-shadow: 0 2px 0 #7a3000;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.4));
}
.timer.low { border-image-source: url("assets/final/btn_grey.png"); animation: pulse .5s infinite alternate; color: #ffe0dc; -webkit-text-stroke-color: #a01610; text-shadow: 0 3px 0 #a01610; }
@keyframes pulse { to { transform: scale(1.1); } }

/* Một khung chung cho sân đấu và bàn chơi, không có đường ngăn ở giữa.
   Sân cỏ mờ dần vào nền xanh của bàn chơi bằng dải chuyển màu ở đáy sân. */
.play-frame {
  border: 20px solid transparent;
  border-image: url("assets/final/frame_board.png") 290 / 20px stretch;
  background: #1c4a88 padding-box; /* khớp màu cuối dải chuyển của sân và màu đầu của bàn */
  box-shadow: inset 0 0 22px rgba(0, 0, 0, .45);
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .45));
  margin-top: 2px;
}
.battle {
  position: relative;
  height: 340px;
  overflow: hidden;
  background: #0f2147;
}
.battle::after { /* dải chuyển màu: đáy sân hoà vào nền bàn chơi, nằm dưới quái và nhà */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100px;
  background: linear-gradient(rgba(28, 74, 136, 0), rgba(28, 74, 136, .7) 50%, #1c4a88);
  pointer-events: none;
  z-index: 1;
}
/* Sân đấu: ảnh nền gốc có sẵn 2 toà lâu đài hai bên, chính là nhà chính. Ảnh canh đáy, phần trời phía trên
   được nối bằng màu trời để không có đường cắt. */
.battle-bg {
  position: absolute;
  inset: 0;
  background: #0069da url("assets/ui/bg_battle_ref.png") 50% 100% / 100% auto no-repeat;
}
.battle-bg::before { /* nối màu trời với mép trên của ảnh */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 150px;
  background: linear-gradient(#0069da 52%, rgba(0, 105, 218, 0));
}
.battle.shake { animation: screenShake .25s; }
@keyframes screenShake { 25% { transform: translate(-4px, 2px); } 75% { transform: translate(4px, -2px); } }

.hp-row { position: absolute; top: 4px; left: 6px; right: 6px; display: flex; justify-content: space-between; gap: 10px; z-index: 5; }
.hp { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 700; color: #fff; text-shadow: 0 2px 0 var(--navy); }
.hp-name { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp b { min-width: 34px; text-align: right; font-size: 18px; }
.hbar {
  flex: 1;
  height: 26px;
  border: 0 solid transparent;
  border-width: 0 12px;
  border-image: url("assets/final/hpbar.png") 0 190 fill / 0 12px stretch;
  padding: 6px 0;
}
.hbar > div { height: 100%; border-radius: 4px; background: linear-gradient(#7ee79c, #2f9d57); transition: width .3s; }
.hp.enemy .hbar > div { background: linear-gradient(#ff8f89, #c9362e); }

/* Nhà chính: 2 toà lâu đài vẽ sẵn trong ảnh nền. Phần tử này chỉ là vùng va chạm vô hình để chạy hiệu ứng trúng đòn. */
.house {
  position: absolute;
  bottom: 94px;
  width: 70px;
  height: 130px;
  border-radius: 14px 14px 4px 4px;
  z-index: 1;
}
.house.left { left: 18px; }
.house.right { right: 18px; }
.house::after { content: ""; position: absolute; inset: -8px; border-radius: 18px; opacity: 0; background: radial-gradient(ellipse at 50% 55%, rgba(255, 238, 150, .95), rgba(255, 170, 40, .45) 55%, transparent 75%); }
.house.hit::after { animation: houseFlash .3s ease-out; }
.house.hurt::before { content: ""; position: absolute; inset: 6px 4px 0; border-radius: 10px; background: radial-gradient(ellipse at 50% 70%, rgba(40, 14, 0, .55), transparent 72%); }
@keyframes houseFlash { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }

.lane { position: absolute; inset: 0; z-index: 2; }

.unit { position: absolute; transform: translate(-50%, -100%); transition: left .1s linear, top .35s linear; }
.unit .body { position: relative; transition: opacity .6s; }
.unit.enemy .spr { transform: scaleX(-1); }
.unit.enemy .spr.idle { animation-name: idleBobFlip; }
@keyframes idleBobFlip { 50% { transform: scaleX(-1) translateY(-4px); } }
.unit.lvl1 { --size: 61px; }
.unit.lvl2 { --size: 69px; }
.unit.lvl3 { --size: 77px; }
.unit.lvl4 { --size: 85px; }
.unit.lvl5 { --size: 112px; }
.unit .hpbar {
  position: absolute;
  left: 18%;
  right: 18%;
  top: -2px;
  height: 9px;
  border-radius: 5px;
  background: #0b1530;
  border: 2px solid #3c74c4;
  overflow: hidden;
  z-index: 3;
}
.unit .hpbar > div { height: 100%; background: #46d36f; transition: width .15s; }
.unit.enemy .hpbar > div { background: #f05a50; }
.unit.lunge .body { animation: lungeR .32s ease-out; }
.unit.enemy.lunge .body { animation: lungeL .32s ease-out; }
@keyframes lungeR { 40% { transform: translateX(22px) scale(1.08); } }
@keyframes lungeL { 40% { transform: translateX(-22px) scale(1.08); } }
.unit.hurt .spr { filter: drop-shadow(0 5px 3px rgba(0,0,0,.35)) brightness(1.9) saturate(.6); }
/* trạng thái skill */
.unit.slowed .spr { filter: drop-shadow(0 5px 3px rgba(0,0,0,.35)) hue-rotate(155deg) saturate(1.5) brightness(1.15); }
.unit.slowed .body::after {
  content: "";
  position: absolute;
  left: 15%;
  right: 15%;
  bottom: 0;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(150, 225, 255, .85), rgba(150, 225, 255, 0) 70%);
}
.poison-fx {
  position: absolute;
  left: 50%;
  top: -34px;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  background: url("assets/final/fx_poison.png") center / contain no-repeat;
  animation: poisonFloat 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 4;
}
.poison-fx.p2 { width: 52px; height: 52px; margin-left: -26px; top: -46px; }
.poison-fx.hidden { display: none; }
@keyframes poisonFloat { 50% { transform: translateY(-6px) scale(1.12); } }
/* rồng to từ ngọc rồng: hào quang vàng */
.unit.boss .spr { filter: drop-shadow(0 0 10px #ffd35a) drop-shadow(0 5px 3px rgba(0,0,0,.35)); }
.unit.boss .body::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -4px;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 214, 90, .9), rgba(255, 214, 90, 0) 72%);
  animation: auraPulse 1.2s ease-in-out infinite;
}
@keyframes auraPulse { 50% { transform: scaleX(1.18); opacity: .7; } }
.unit.pop .body { animation: popIn .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes popIn { from { transform: scale(0) translateY(-40px); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.unit.dead { z-index: 0 !important; }
.unit.dead .body { opacity: 0; }

.dmg {
  position: absolute;
  font-size: 30px;
  font-weight: 800;
  color: #fff;
  -webkit-text-stroke: 5px #b3201a;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 rgba(0,0,0,.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.fx-img { position: absolute; width: 90px; transform: translate(-50%, -50%); pointer-events: none; }

/* ---------- Bàn chơi ---------- */
.board-area {
  display: flex;
  justify-content: center;
  position: relative;
  background: linear-gradient(#1c4a88, #11305f);
}
.board {
  position: relative;
  width: 468px;
  height: 468px;
  touch-action: none;
  overflow: hidden;
}
.item {
  position: absolute;
  width: 78px;
  height: 78px;
  transition: top .38s cubic-bezier(.45, .05, .55, 1.15), left .24s ease-out;
  cursor: pointer;
  z-index: 2;
}
.item .tile { position: absolute; inset: 0; background: url("assets/final/tile.png") center / 100% 100% no-repeat; }
.item .spr { position: absolute; left: 5px; right: 5px; bottom: 5px; width: auto; height: 68px; background-position: 0% 0; }
.item .mag { position: absolute; inset: 4px; background: url("assets/final/orb.png") center / contain no-repeat; animation: magSpin 1.6s ease-in-out infinite; filter: drop-shadow(0 0 8px #ffd35a); }
@keyframes magSpin { 50% { transform: scale(1.15) rotate(8deg); } }
.item.sel { filter: brightness(1.25); transform: scale(1.1); z-index: 5; }
.item.bad { animation: badShake .3s; }
@keyframes badShake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.item.pop { animation: itemPop .3s ease-in forwards; z-index: 6; }
@keyframes itemPop { 30% { transform: scale(1.3); filter: brightness(1.8); } 100% { transform: scale(.1); opacity: 0; } }
.item.gone { opacity: 0; transition: opacity .15s; }

.combo {
  position: absolute;
  left: 50%;
  top: 520px;
  transform: translateX(-50%);
  font-size: 56px;
  font-weight: 800;
  white-space: nowrap;
  color: var(--gold);
  -webkit-text-stroke: 9px #5a2a00;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #5a2a00;
  pointer-events: none;
  opacity: 0;
  z-index: 8;
}
.combo.show { animation: comboPop .8s ease-out; }
@keyframes comboPop {
  0% { opacity: 0; transform: translateX(-50%) scale(.3); }
  25% { opacity: 1; transform: translateX(-50%) scale(1.25); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-50px) scale(1); }
}

/* ---------- Kết quả ---------- */
/* Màn kết quả: cột flex theo chiều cao khung. Popup thống kê co giãn vừa phần còn lại và cuộn nếu thiếu chỗ. */
#screen-result { align-items: stretch; padding: 0 16px 18px; }
.result-hero {
  position: relative;
  flex: 0 0 auto;
  height: 232px;
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* tia sáng quay phía sau tiêu đề */
.rays {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 760px;
  height: 760px;
  margin: -380px 0 0 -380px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 226, 120, .55) 0deg 9deg, rgba(255, 226, 120, 0) 9deg 22deg);
  -webkit-mask-image: radial-gradient(circle, #000 12%, transparent 66%);
  mask-image: radial-gradient(circle, #000 12%, transparent 66%);
  opacity: 0;
  pointer-events: none;
}
#screen-result.win .rays { opacity: 1; animation: raysSpin 14s linear infinite; }
@keyframes raysSpin { to { transform: rotate(360deg); } }

.result-banner {
  position: relative;
  width: 470px;
  height: 160px;
  margin-bottom: 26px;
  background: url("assets/final/ribbon.png") center / 100% 100% no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 90px 10px;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,.45));
  overflow: hidden;
}
.result-banner::after { /* vệt sáng lướt qua */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 70px;
  left: -120px;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.65), transparent);
  transform: skewX(-18deg);
}
.result-title {
  font-size: 58px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 9px #7a3000;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 #7a3000;
}
.result-sub {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 0;
  text-align: center;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  text-shadow: 0 2px 0 var(--navy), 0 0 8px rgba(0,0,0,.6);
}

#screen-result.win .result-hero { animation: heroDrop .8s cubic-bezier(.2, 1.5, .4, 1) both, floatY 3.2s ease-in-out .8s infinite; }
#screen-result.win .result-banner::after { animation: shine 2.8s ease-in-out 1s infinite; }
#screen-result.win .result-title { animation: titleGlow 1.6s ease-in-out 1s infinite; }
#screen-result.lose .result-hero { animation: heroSink .9s ease-out both, sway 4s ease-in-out .9s infinite; }
#screen-result.draw .result-hero { animation: heroDrop .7s ease-out both, floatY 4s ease-in-out .7s infinite; }
#screen-result.lose .result-banner { filter: grayscale(.85) brightness(.85) drop-shadow(0 10px 12px rgba(0,0,0,.45)); }
#screen-result.lose::after { content: ""; position: absolute; inset: 0; background: rgba(8, 14, 32, .4); pointer-events: none; z-index: 2; }

.stats-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0 0 10px;
}
#screen-result .stats-wrap { animation: panelRise .8s cubic-bezier(.2, 1.3, .4, 1) .35s both, floatY 3.6s ease-in-out 1.2s infinite; }
#screen-result.lose .stats-wrap { animation: panelRise .8s ease-out .5s both, sway 5s ease-in-out 1.3s infinite; }

@keyframes heroDrop { from { transform: translateY(-180px) scale(.5); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes heroSink { from { transform: translateY(-120px) rotate(-4deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes panelRise { from { transform: translateY(260px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes floatY { 50% { transform: translateY(-6px); } }
@keyframes sway { 50% { transform: translateY(3px) rotate(.8deg); } }
@keyframes shine { 0% { left: -120px; } 45%, 100% { left: 560px; } }
@keyframes titleGlow { 50% { transform: scale(1.06); filter: brightness(1.25) drop-shadow(0 0 10px #fff3a8); } }

/* Nội dung thống kê cuộn được khi màn hình thấp */
.stats-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 4px;
  scrollbar-width: thin;
  scrollbar-color: #3c74c4 transparent;
  user-select: none;
  -webkit-overflow-scrolling: touch;
}
.stats { width: 100%; border-collapse: collapse; font-size: 20px; font-weight: 600; }
.stats th, .stats td { padding: 1px 6px; border-bottom: 2px solid #d9c9a3; text-align: center; line-height: 1.25; }
.stats th { color: var(--muted); font-weight: 800; position: sticky; top: 0; background: #fbf1da; z-index: 1; }
.stats td:first-child, .stats th:first-child { text-align: left; }
/* Chỉ số hơn: xanh dương sáng và đậm. Chỉ số kém hơn hoặc bằng: đen và mảnh. */
.stats td { color: #111a2c; font-weight: 400; }
.stats td.hi { color: #0a7cff; font-weight: 800; text-shadow: 0 0 10px rgba(10, 124, 255, .25); }
.stats td:first-child { font-weight: 500; color: #111a2c; }

.result-menu { flex: 0 0 auto; z-index: 3; }
.result-menu .wbtn { margin: 0; }
.fx-over { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.confetti { position: absolute; top: -50px; font-size: 34px; animation: confFall 2.8s linear forwards; }
@keyframes confFall { to { transform: translateY(1050px) rotate(600deg); } }
.spark-star {
  position: absolute;
  font-size: 26px;
  animation: twinkle 1.4s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { transform: scale(.4) rotate(0); opacity: 0; } 50% { transform: scale(1.1) rotate(40deg); opacity: 1; } }

/* ---------- Overlay, toast, spinner ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 30, .68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
.overlay > .panel { width: 100%; animation: popupIn .35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes popupIn { from { transform: scale(.7) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.spinner {
  width: 64px;
  height: 64px;
  margin: 4px auto;
  border-radius: 50%;
  border: 8px solid #cfdcf3;
  border-top-color: #f08a1c;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  max-width: 470px;
  background: rgba(8, 20, 48, .92);
  border: 3px solid #4a7fc7;
  color: #fff;
  padding: 6px 22px 8px;
  border-radius: 18px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  z-index: 30;
  text-align: center;
}

/* ---------- Popup hướng dẫn ---------- */
.guide-panel { display: flex; flex-direction: column; gap: 8px; }
.guide-body {
  max-height: 560px;
  overflow-y: auto;
  padding: 0 6px 0 2px;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: #3c74c4 transparent;
  user-select: none;
  -webkit-overflow-scrolling: touch;
}
.guide-h {
  margin: 10px 0 6px;
  padding: 2px 12px 4px;
  border-radius: 12px;
  background: linear-gradient(#2c68b4, #164a8a);
  border: 3px solid #3c74c4;
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 2px 0 var(--navy);
}
.guide-h:first-child { margin-top: 0; }
.guide-card, .guide-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 2px solid #e2d3ad;
}
.guide-info { flex: 1; min-width: 0; }
.guide-name { font-size: 24px; font-weight: 800; color: #0a5fd0; line-height: 1.1; }
.guide-p { margin: 0; font-size: 18px; font-weight: 500; line-height: 1.25; color: #111a2c; }
.guide-skill { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.25; color: #111a2c; }
.guide-stat { margin: 2px 0 0; font-size: 17px; font-weight: 500; color: #4a5b7c; }
.guide-stat.strong { font-weight: 800; color: #0a7cff; }
.guide-note { margin: 6px 0 0; font-size: 16px; font-weight: 600; color: #7a5a1a; line-height: 1.25; }
.guide-badge {
  flex: 0 0 auto;
  min-width: 74px;
  text-align: center;
  padding: 1px 8px 3px;
  border-radius: 12px;
  background: linear-gradient(#ffb23a, #e8820c);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  text-shadow: 0 2px 0 #7a3000;
}
.guide-num {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  line-height: 32px;
  text-align: center;
  border-radius: 50%;
  background: linear-gradient(#2c68b4, #164a8a);
  border: 3px solid #3c74c4;
  color: #fff;
  font-weight: 800;
  font-size: 20px;
}
.mini-shape { flex: 0 0 auto; display: grid; gap: 3px; width: 100px; justify-content: center; align-content: center; }
.mini-shape i { width: 18px; height: 18px; border-radius: 5px; background: #cdd8ea; }
.mini-shape i.on { background: linear-gradient(#52b6ff, #1c7fe0); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.mini-shape.orb i.on { background: linear-gradient(#ffe27a, #f0a010); }
.guide-card .spr { flex: 0 0 auto; width: 64px; height: 64px; }
