/* Khung cố định 540x960 (9:16), JS co giãn bằng transform: scale cho vừa cửa sổ. Mọi kích thước tính bằng px theo khung này.
   Ảnh UI (assets/ui/*.webp) do AI sinh theo style Swordman, cắt bằng tools/process_assets.py. */
@font-face { font-family: Lilita; src: url(assets/fonts/LilitaOne-Regular.ttf); font-weight: 400 800; }
@font-face { font-family: Lilita, Baloo; src: url(assets/fonts/Baloo2.ttf); font-weight: 400 800; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { font-synthesis: none; margin: 0; height: 100%; background: #08050f; overflow: hidden; font-family: Lilita, Baloo, system-ui, sans-serif; color: #fff; }
#stage { position: absolute; left: 0; top: 0; width: 540px; height: 960px; transform-origin: 0 0; overflow: hidden; background: #1b1233; }
.screen { position: absolute; inset: 0; display: none; background: center / cover no-repeat; }
.screen.show { display: block; }

/* ---- nút bằng ảnh ---- */
.ibtn {
  display: block; margin: 12px auto 0; width: 330px; height: 92px; border: 0; background: center / 100% 100% no-repeat; cursor: pointer;
  font: 800 34px Lilita, Baloo, sans-serif; color: #fff; padding-bottom: 12px; text-shadow: 0 3px 0 rgba(0,0,0,.45);
}
.ibtn.orange { background-image: url(assets/ui/btn_orange.webp); }
.ibtn.blue { background-image: url(assets/ui/btn_blue.webp); height: 80px; font-size: 28px; width: 290px; }
.ibtn.big { height: 104px; font-size: 40px; width: 380px; }
.ibtn:active { transform: translateY(3px) scale(.98); filter: brightness(.92); }
.rbtn { width: 64px; height: 64px; border: 0; background: url(assets/ui/btn_round.webp) center / 100% 100% no-repeat; font: 800 17px Lilita, Baloo; color: #fff; text-shadow: 0 2px 0 #000; cursor: pointer; padding: 0; }
.rbtn.help { background-image: url(assets/ui/btn_help.webp); }
.rbtn.sm { position: absolute; right: 6px; top: 466px; width: 46px; height: 46px; font-size: 14px; z-index: 5; }
.xbtn { position: absolute; right: -6px; top: -12px; width: 64px; height: 64px; border: 0; background: url(assets/ui/btn_close.webp) center / 100% 100% no-repeat; cursor: pointer; }
.topbtns { position: absolute; right: 14px; top: 14px; display: flex; gap: 8px; z-index: 3; }

/* ---- 1. loading ---- */
#s-load { background-image: url(assets/ui/bg_loading.webp); z-index: 50; }
.load-logo { position: absolute; left: 50%; top: 26px; width: 400px; margin-left: -200px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.45)); }
.load-bottom { position: absolute; left: 0; right: 0; bottom: 56px; text-align: center; }
.bar { position: relative; width: 420px; height: 52px; margin: 0 auto; background: url(assets/ui/bar_frame.webp) center / 100% 100% no-repeat; }
.bar i { position: absolute; left: 22px; top: 15px; height: 22px; width: 0; max-width: 376px; border-radius: 11px; background: url(assets/ui/bar_fill.webp) left center / 376px 100% no-repeat; transition: width .15s; }
#load-text { margin: 10px 0 0; font: 800 24px Lilita, Baloo; text-shadow: 0 2px 0 #000, 0 0 10px #000; }
#load-text.tap { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ---- 2. sảnh ---- */
#s-home { background-image: url(assets/ui/bg_home.webp); }
.home-logo { position: absolute; left: 50%; top: 50px; width: 440px; margin-left: -220px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.4)); animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.home-heroes { position: absolute; left: 0; right: 0; top: 400px; display: flex; justify-content: center; }
.home-hero { position: relative; width: 100px; height: 150px; }
.home-hero .hs { transform: scale(1.85); transform-origin: 50% 100%; left: calc(50px - 84px * var(--cx, .33)); top: 66px; filter: drop-shadow(0 6px 4px rgba(0,0,0,.35)); }
.me-box { position: absolute; left: 50%; top: 575px; width: 300px; margin-left: -150px; padding: 8px 0 6px; text-align: center; background: rgba(40,22,10,.62); border: 3px solid #7a4a1c; border-radius: 18px; }
.me-box b { display: block; font-size: 26px; line-height: 28px; } .me-box small { opacity: .8; font-size: 16px; }
#b-play { position: absolute; left: 50%; top: 650px; margin: 0 0 0 -190px; }
.menu3 { position: absolute; left: 0; right: 0; top: 780px; display: flex; justify-content: center; gap: 6px; }
.menu3 .ibtn { width: 168px; height: 76px; font-size: 22px; margin: 0; padding: 0 0 8px; }
.msg { position: absolute; left: 0; right: 0; top: 880px; text-align: center; color: #ffd0d0; font-size: 20px; text-shadow: 0 2px 0 #000; }

/* ---- 3. trận ---- */
#s-battle { background-image: url(assets/ui/bg_battle.webp); }
.hud { position: absolute; left: 14px; width: 512px; height: 64px; }
.hud.foe { top: 4px; } .hud.me { top: 894px; }
.pname { display: block; font: 700 19px/22px Lilita, Baloo; padding-left: 26px; text-shadow: 0 2px 0 #000, 0 0 6px #000; }
.hp { position: relative; height: 40px; border: 0 solid transparent; border-width: 0 26px; border-image: url(assets/ui/bar_frame.webp) 0 64 fill / 0 26px stretch; }
.hpin { position: absolute; left: -2px; right: -2px; top: 11px; bottom: 11px; overflow: hidden; border-radius: 8px; }
.hp i { display: block; height: 100%; width: 100%; background: url(assets/ui/bar_fill.webp) left center / 100% 100% no-repeat; transition: width .45s ease; filter: hue-rotate(-30deg) saturate(1.2); }
.hud.me .hp i { filter: hue-rotate(72deg) saturate(1.1) brightness(1.05); }
.hp b { position: absolute; left: 0; right: 0; top: 0; bottom: 0; text-align: center; font: 800 17px/40px Lilita, Baloo; text-shadow: 0 2px 0 #000, 0 0 5px #000; }
.shout { position: absolute; right: 6px; top: -2px; max-width: 280px; padding: 2px 14px; border-radius: 16px; font: 800 18px/26px Lilita, Baloo; color: #fff3b0; background: rgba(0,0,0,.6); border: 2px solid #e08b2e; opacity: 0; transform: translateY(6px) scale(.9); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 6; }
.shout.show { opacity: 1; transform: none; } .shout.foe { color: #ffd0d0; border-color: #d24a4a; }
.hud.hurt .hp { animation: hurt .35s; } .hud.healed .hp { animation: healed .5s; }
@keyframes hurt { 30% { transform: translateX(-5px); } 60% { transform: translateX(5px); } }
@keyframes healed { 40% { filter: drop-shadow(0 0 10px #7dffb0) brightness(1.3); } }

.board {
  position: absolute; left: 14px; width: 512px; height: 384px; touch-action: none;
  background: rgba(34,18,8,.5); box-shadow: inset 0 0 26px rgba(0,0,0,.45);
}
#grid-foe { top: 72px; } #grid-me { top: 508px; }
.board.shake { animation: shake .4s; } .board.shake2 { animation: shake .55s; }
@keyframes shake { 20% { translate: -7px 3px; } 40% { translate: 7px -3px; } 60% { translate: -5px 2px; } 80% { translate: 4px -2px; } }
.cell { position: absolute; left: 0; top: 0; width: 64px; height: 64px; transition: transform .34s cubic-bezier(.34, 1.25, .5, 1), opacity .2s; }
.cell .t { position: absolute; inset: 1px; background: url(assets/ui/tile.webp) center / 100% 100% no-repeat; }
.cell.sel .t { background-image: url(assets/ui/tile_sel.webp); inset: -2px; }
.cell.dim { opacity: .4; }
.cell.hint .t { animation: hint .7s ease-in-out infinite alternate; }
@keyframes hint { to { filter: brightness(1.9) drop-shadow(0 0 8px #fff3a0); } }
.cell.shuffle { animation: shuf .5s ease; }
@keyframes shuf { 45% { scale: .15; rotate: 180deg; opacity: .2; } }

/* hero: atlas 4x2 khung 84px (hàng 1 idle lặp, hàng 2 ăn/cast chạy 1 lần). --cx = vị trí tâm thân hero trong khung */
.hs { position: absolute; width: 84px; height: 84px; left: calc(32px - 84px * var(--cx, .33)); top: -17px; pointer-events: none;
  background-repeat: no-repeat; background-size: 336px 168px; animation: idle .8s steps(4, jump-none) infinite; transition: transform .12s; }
.h0 { background-image: url(assets/heroes/hero0.webp); } .h1 { background-image: url(assets/heroes/hero1.webp); }
.h2 { background-image: url(assets/heroes/hero2.webp); } .h3 { background-image: url(assets/heroes/hero3.webp); } .h4 { background-image: url(assets/heroes/hero4.webp); }
@keyframes idle { from { background-position: 0 0; } to { background-position: -252px 0; } }
@keyframes eat { from { background-position: 0 -84px; } to { background-position: -252px -84px; } }
.cell.sel .hs { transform: scale(1.12); }
.cell.hint .hs { transform: scale(1.14); }
.cell.eat { z-index: 6; }
.cell.eat .hs { animation: eat .36s steps(4, jump-none) forwards; }
.cell.eat .t { opacity: .15; transition: opacity .2s; }
/* hồi máu đang hồi chiêu: hero Thánh bị mờ + đếm giây */
.cooling .cell[data-t="4"] { filter: grayscale(.85) brightness(.7); }
.cooling .cell[data-t="4"]::after { content: attr(data-cd); position: absolute; left: 0; right: 0; top: 14px; text-align: center; font: 800 30px Lilita, Baloo; color: #fff; text-shadow: 0 2px 0 #000, 0 0 8px #000; z-index: 7; }
#trail { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 3; }
#hint-line { fill: none; stroke: rgba(255,240,160,.6); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 2 14; animation: dash .8s linear infinite; filter: drop-shadow(0 0 5px #fff3a0); }
@keyframes dash { to { stroke-dashoffset: -32; } }
#trail-line { fill: none; stroke: rgba(255,255,255,.85); stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px #fff7c2); }

.mid { position: absolute; left: 0; right: 0; top: 456px; height: 52px; z-index: 4; }
.ring { position: absolute; left: 50%; top: -14px; width: 84px; height: 84px; margin-left: -42px; background: url(assets/ui/badge.webp) center / 100% 100% no-repeat; }
#timer { position: absolute; inset: 0; padding-top: 22px; text-align: center; font: 800 32px/38px Lilita, Baloo; text-shadow: 0 2px 0 #000; }
#timer.low { color: #ff6b6b; animation: tick 1s infinite; }
@keyframes tick { 50% { transform: scale(1.25); } }
#preview { position: absolute; right: 56px; top: 8px; height: 38px; padding: 0 14px; border-radius: 19px; font: 800 19px/38px Lilita, Baloo; background: rgba(0,0,0,.55); border: 2px solid #e08b2e; display: none; white-space: nowrap; }
#preview.show { display: block; } #preview.dmg { color: #ffd2d2; } #preview.heal { color: #c8ffd8; }
#toast { position: absolute; left: 56px; top: 8px; height: 38px; padding: 0 14px; border-radius: 19px; font: 800 19px/38px Lilita, Baloo; background: rgba(0,0,0,.55); border: 2px solid #7fd4ff; display: none; }
#toast.show { display: block; animation: blink 1s 2; }

#fxlayer { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.fxs { position: absolute; pointer-events: none; mix-blend-mode: screen; background-repeat: no-repeat; }
.fxflash { position: absolute; inset: 0; }
.fxnum { position: absolute; font: 800 46px Lilita, Baloo; text-shadow: 0 3px 0 #000, 0 0 12px rgba(0,0,0,.6); pointer-events: none; }
.fxnum.dmg { color: #ff6060; } .fxnum.heal { color: #7dffb0; }

/* ---- popup, thẻ ---- */
.popup { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(5,2,12,.72); z-index: 40; }
.popup.show { display: flex; }
.card { position: relative; text-align: center; background: center / 100% 100% no-repeat; }
.card.small { width: 440px; height: 330px; background-image: url(assets/ui/panel_big.webp); padding: 62px 60px 0; }
.card.tall { width: 440px; height: 600px; background-image: url(assets/ui/panel.webp); padding: 74px 58px 0; }
.card p { font-size: 22px; margin: 6px 0 10px; text-shadow: 0 2px 0 #000; }
.guide { text-align: left; } .guide h3 { text-align: center; font-size: 30px; margin: 0 0 6px; color: #ffd36b; text-shadow: 0 2px 0 #000; }
.guide h4 { text-align: center; margin: 8px 0 2px; font-size: 17px; opacity: .9; }
.guide ol { padding-left: 22px; margin: 0; font-size: 16.5px; line-height: 1.22; text-shadow: 0 1px 0 #000; } .guide li { margin-bottom: 5px; }
#guide-table { margin: 0 auto; border-collapse: collapse; font-size: 15px; } #guide-table td, #guide-table th { padding: 1px 10px; text-align: center; }
.spin { width: 54px; height: 54px; margin: 8px auto 6px; border: 7px solid rgba(255,255,255,.25); border-top-color: #ffd36b; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card.small .ibtn { width: 230px; height: 66px; font-size: 24px; margin-top: 4px; padding-bottom: 8px; }

/* ---- 4. kết quả ---- */
#s-result { background: rgba(5,2,12,.82); z-index: 30; }
.res-card { position: relative; margin: 64px auto 0; width: 450px; height: 790px; padding: 150px 60px 0; text-align: center; background: url(assets/ui/panel.webp) center / 100% 100% no-repeat; }
.res-banner { position: absolute; left: 50%; top: -16px; width: 400px; margin-left: -200px; }
.res-card h2 { position: absolute; left: 0; right: 0; top: 14px; margin: 0; font: 800 50px/70px Lilita, Baloo; text-shadow: 0 4px 0 rgba(0,0,0,.55); z-index: 2; }
.res-card h2.win { color: #fff3b0; } .res-card h2.lose { color: #ffe2e2; } .res-card h2.draw { color: #e8f2ff; }
.res-emblem { width: 130px; margin: 6px auto 0; display: block; }
.res-card p { margin: 4px 0 8px; font-size: 21px; text-shadow: 0 2px 0 #000; }
.res-hp { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 19px; margin-bottom: 6px; text-shadow: 0 2px 0 #000; }
.res-hp b { font-size: 32px; } .res-hp em { opacity: .7; font-style: normal; } .res-hp span { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
#res-stats { width: 100%; margin: 4px 0 6px; font-size: 18px; text-shadow: 0 1px 0 #000; } #res-stats td { padding: 2px 6px; } #res-stats td:nth-child(2) { opacity: .8; }
.res-card .ibtn { width: 290px; height: 80px; font-size: 28px; margin-top: 8px; padding-bottom: 8px; }
.res-card .ibtn.blue { height: 72px; }

/* ---- mời bạn, BXH ---- */
.card.tall.short { height: 500px; padding-top: 80px; }
.card h3 { margin: 0 0 6px; font-size: 30px; color: #ffd36b; text-shadow: 0 2px 0 #000; }
.bigcode { display: inline-block; font: 800 40px/44px Lilita, Baloo; letter-spacing: 6px; color: #fff3b0; text-shadow: 0 3px 0 #000; }
#inp-code { display: block; width: 250px; height: 56px; margin: 6px auto 4px; border-radius: 14px; border: 3px solid #e08b2e; background: rgba(20,10,4,.8); color: #fff; text-align: center; font: 800 30px Lilita, Baloo; letter-spacing: 6px; text-transform: uppercase; outline: none; user-select: text; }
.card.tall .ibtn { width: 270px; height: 76px; font-size: 26px; margin-top: 8px; padding-bottom: 8px; }
.msg2 { min-height: 24px; margin-top: 6px; font-size: 18px; color: #ffd0d0; text-shadow: 0 2px 0 #000; }
.lb { text-align: center; }
.lb h3 { margin-bottom: 4px; }
.lb h4 { margin: 10px 0 4px; font-size: 19px; color: #ffd36b; text-shadow: 0 2px 0 #000; }
.lbrow { display: flex; align-items: center; justify-content: space-between; margin: 3px 4px; padding: 4px 12px; border-radius: 12px; background: rgba(0,0,0,.35); font-size: 17px; text-shadow: 0 1px 0 #000; }
.lbrow b { font-size: 24px; color: #fff3b0; } .lbrow small { opacity: .75; font-size: 14px; display: block; line-height: 14px; }
.lbrow span { text-align: left; }

.topbtns { align-items: center; }
.ibtn.blue.pill { width: 76px; height: 50px; margin: 0; padding: 0 0 5px; font-size: 20px; }
.rbtn.off { filter: grayscale(1) brightness(.6); }
.rbtn.off::after { content: ''; position: absolute; }

/* nền tối bên trong khung panel để chữ dễ đọc (ruột panel của ảnh gen trong suốt) */
.card::before, .res-card::before { content: ''; position: absolute; background: rgba(26,13,6,.9); border-radius: 8px; z-index: 0; }
.card.tall::before { left: 52px; right: 52px; top: 68px; bottom: 54px; }
.card.small::before { left: 52px; right: 52px; top: 56px; bottom: 48px; }
.res-card::before { left: 52px; right: 52px; top: 120px; bottom: 56px; }
.card > *, .res-card > * { position: relative; z-index: 1; }
.card > .xbtn { position: absolute; }
.res-card > .res-banner, .res-card > h2 { position: absolute; }

/* ---- sảnh: Ranking lên thanh trên, 2 nút còn lại xếp dọc như Dragon Battle ---- */
.menu2 { position: absolute; left: 0; right: 0; top: 752px; display: flex; flex-direction: column; align-items: center; }
.menu2 .ibtn { width: 310px; height: 80px; margin: 0; font-size: 28px; padding-bottom: 10px; }
.ibtn.blue.pill.wide { width: 120px; }
.topbtns { gap: 8px; }
.msg { top: 912px; }

/* ---- font kiểu game: chữ đậm có viền nâu (stroke) ---- */
.ibtn, .pname, .card h3, #timer, .fxnum, .bigcode, .res-card h2, .lbrow b, .hp b, #load-text, .logo, .chip b, .gh b, .shout {
  -webkit-text-stroke: 3px #2b1608; paint-order: stroke fill; letter-spacing: .3px;
}
.hp b, .pname { -webkit-text-stroke-width: 2.4px; }
.fxnum { -webkit-text-stroke-width: 5px; }
.card, .res-card, .msg, .me-box { font-weight: 700; }

/* ---- popup hướng dẫn: thân cuộn được, không vỡ khung ---- */
.card.tall.guide { width: 480px; height: 720px; padding: 78px 62px 0; text-align: center; }
.card.tall.guide::before { left: 58px; right: 58px; top: 70px; bottom: 58px; }
.guide h3 { font-size: 34px; margin: 0 0 6px; }
.gbody { height: 540px; overflow-y: auto; text-align: left; padding: 4px 6px 10px 2px; scrollbar-width: thin; }
.gbody ol { padding-left: 24px; margin: 0 0 8px; font-size: 17px; line-height: 1.25; font-weight: 700; }
.gbody li { margin-bottom: 6px; text-shadow: 0 2px 0 #000; }
.guide h4 { margin: 10px 0 6px; font-size: 19px; text-align: center; color: #ffd36b; text-shadow: 0 2px 0 #000; }
.gheroes { display: flex; justify-content: space-between; margin: 4px 0 2px; }
.gh { width: 70px; text-align: center; font-size: 15px; line-height: 16px; text-shadow: 0 2px 0 #000; }
.gh b { display: block; font-size: 16px; -webkit-text-stroke-width: 2.5px; }
.gh small { display: block; opacity: .8; font-size: 13px; }
.ghs { position: relative; width: 70px; height: 74px; overflow: visible; }
.ghs .hs { transform: scale(.9); transform-origin: 50% 100%; left: calc(35px - 84px * var(--cx, .33)); top: -10px; }
.gchips { display: flex; justify-content: space-between; gap: 4px; }
.chip { flex: 1; text-align: center; padding: 4px 0 5px; border-radius: 12px; background: rgba(224,139,46,.25); border: 2px solid #e08b2e; }
.chip small { display: block; font-size: 14px; opacity: .85; line-height: 14px; } .chip b { font-size: 24px; line-height: 26px; color: #fff3b0; }
.card.tall.guide { padding-top: 70px; }
.guide h3 { font-size: 30px; margin: 0 0 2px; }
.gbody { height: 510px; }
.gbody ol { font-size: 16px; line-height: 1.2; margin-bottom: 4px; }
.gbody li { margin-bottom: 4px; }
.ghs { height: 66px; }
.guide h4 { margin: 4px 0 4px; font-size: 18px; }
.card.tall.guide::before { bottom: 84px; }
.ghs { height: 74px; }
.gh b { position: relative; z-index: 2; margin-top: 2px; }

/* 3 nút menu cùng cỡ, cách đều */
.menu2 { top: 648px; gap: 12px; }
.menu2 .ibtn, #b-play { position: static; width: 320px; height: 84px; margin: 0; font-size: 30px; padding: 0 0 10px; }
.menu2 .ibtn.blue { height: 84px; width: 320px; }
.msg { top: 930px; font-size: 17px; }
