/* 直式 9:16；支援 320／360／390／430 px */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1b1410; color: #f5ead6; font-family: system-ui, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; font-size: 14px; }
#app { position: relative; max-width: 430px; min-width: 320px; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; background: #2a1f18; overflow: hidden; }
#testbar { background: #b03a2e; color: #fff; text-align: center; font-size: 12px; padding: 2px 0; font-weight: bold; }
#top { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 4px; align-items: center; padding: 4px 6px; background: #3a2a1e; font-size: 12px; }
#top .cur { display: flex; align-items: center; gap: 3px; justify-content: flex-end; }
#top .cur img { width: 18px; height: 18px; }
#battle { position: relative; height: min(55dvh, calc(min(100vw, 430px) * 1.1)); overflow: hidden; user-select: none; touch-action: manipulation; cursor: pointer; flex: none; }
#bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.unit { position: absolute; bottom: 14%; width: 38%; text-align: center; transition: transform .08s; }
.unit img { width: 100%; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 4px 4px #0008); }
#hero { left: 4%; } #enemy { right: 4%; }
#enemy.entering { transform: translateX(30%); opacity: .5; }
/* 敵人朝向：--face 由 ui.js 依 art-facing.js 設定（1＝不翻、-1＝翻轉）；名將／隊長的放大與翻轉合併，不互相覆寫 */
/* v0.6 視覺比例：--es（縮放）、--eox／--eoy（以敵人腳底與身體中線為原點）、--edy（腳底對齊主將地平線）由 ui.js 依 art-metrics.js 設定；
   小兵＝主將視覺身高 0.92（隊長 0.95）、名將 1.12。朝向 --face 與比例合併在同一條 transform，名將／隊長不再另有放大規則 */
#enemyImg { transform-origin: calc(var(--eox, .5) * 100%) calc(var(--eoy, .92) * 100%); transform: translateY(calc(var(--edy, 0) * 100%)) scaleX(var(--face, 1)) scale(var(--es, 1)); }
.unit .bar { height: 6px; background: #0008; border-radius: 3px; margin: 0 8%; position: relative; overflow: hidden; }
.unit .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: #4cd964; }
#enemy .bar i { background: #e74c3c; }
.unit .bar b { position: absolute; left: 0; top: 0; bottom: 0; background: #5dade2aa; }
.unit .name { font-size: 12px; text-shadow: 0 1px 2px #000; min-height: 16px; }
#bossTimer { position: absolute; top: 6px; left: 8%; right: 8%; height: 14px; background: #0009; border-radius: 7px; overflow: hidden; }
#bossTimer i { position: absolute; left: 0; top: 0; bottom: 0; background: #f39c12; }
#bossTimer span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 14px; }
#floaters { position: absolute; inset: 0; pointer-events: none; }
.fl { position: absolute; font-weight: bold; text-shadow: 0 1px 2px #000, 0 0 2px #000; animation: up .9s ease-out forwards; white-space: nowrap; }
.fl.crit { color: #ffcc33; font-size: 22px; } .fl.tap { color: #9be7ff; font-size: 13px; } .fl.normal { color: #fff; font-size: 15px; }
@keyframes up { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-50px); opacity: 0; } }
#phaseMsg { position: absolute; top: 28%; width: 100%; text-align: center; font-size: 18px; font-weight: bold; text-shadow: 0 2px 4px #000; pointer-events: none; }
#guide { position: absolute; left: 6px; right: 6px; top: 26px; background: #000c; border: 1px solid #f39c12; border-radius: 8px; padding: 6px 8px; font-size: 12px; }
#guide button { float: right; }
#skillBar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 4px; padding: 4px; justify-content: center; background: linear-gradient(transparent, #0009); }
#skillBar button { position: relative; width: 44px; height: 44px; padding: 0; border-radius: 8px; border: 1px solid #a67c52; background: #3a2a1e; overflow: hidden; }
#skillBar button img { width: 100%; height: 100%; }
#skillBar button span { position: absolute; right: 2px; bottom: 0; font-size: 10px; color: #fff; text-shadow: 0 0 2px #000; }
#skillBar button em { position: absolute; left: 0; right: 0; bottom: 0; background: #000a; font-style: normal; font-size: 11px; color: #fff; }
#skillBar button.locked { opacity: .35; } #skillBar button.auto { box-shadow: 0 0 0 2px #27ae60 inset; }
#tabs { display: grid; grid-template-columns: repeat(7, 1fr); background: #3a2a1e; flex: none; }
#tabs button { background: none; border: 0; color: #d9c7a8; padding: 4px 0; font-size: 12px; display: flex; flex-direction: column; align-items: center; min-height: 44px; }
#tabs button img { width: 22px; height: 22px; }
#tabs button.on { color: #ffcc33; background: #4a3626; }
#panel { flex: 1; overflow-y: auto; padding: 6px 8px 16px; }
#panel h3 { margin: 6px 0; font-size: 15px; color: #ffcc33; }
.row { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid #ffffff14; }
.row .grow { flex: 1; min-width: 0; }
.row small { color: #b8a78d; display: block; }
button, .btn { background: #8e5a2e; color: #fff; border: 0; border-radius: 6px; padding: 6px 8px; font-size: 12px; min-height: 32px; cursor: pointer; }
button:disabled { background: #555; color: #999; cursor: not-allowed; }
button.sec { background: #4a3626; } button.warn { background: #b03a2e; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.item { position: relative; aspect-ratio: 1; border-radius: 6px; border: 2px solid; background: #00000040; padding: 2px; cursor: pointer; }
.item img { width: 100%; height: 100%; }
.item span { position: absolute; right: 2px; bottom: 0; font-size: 10px; text-shadow: 0 0 2px #000; }
.r0 { border-color: #bbb; } .r1 { border-color: #4caf50; } .r2 { border-color: #3498db; } .r3 { border-color: #9b59b6; } .r4 { border-color: #e67e22; } .r5 { border-color: #e74c3c; box-shadow: 0 0 6px #e74c3c; }
.card { display: inline-block; width: 31%; margin: 1%; vertical-align: top; text-align: center; font-size: 11px; }
.card .frame { position: relative; aspect-ratio: 3/4; border-radius: 6px; border: 3px solid; overflow: hidden; background: linear-gradient(#5a4030, #2a1f18); }
.card .frame img { width: 100%; height: 72%; object-fit: contain; }
.card .frame.gray img { filter: grayscale(1) brightness(.3); }
.card .plate { position: absolute; bottom: 0; left: 0; right: 0; background: #000b; padding: 2px; }
.card .badge { position: absolute; left: 3px; top: 3px; background: #000a; border-radius: 50%; width: 20px; height: 20px; line-height: 20px; }
#modal { position: absolute; inset: 0; background: #000b; display: flex; align-items: center; justify-content: center; z-index: 20; }
#modal .box { background: #3a2a1e; border: 1px solid #a67c52; border-radius: 10px; padding: 12px; width: 92%; max-height: 86%; overflow-y: auto; }
#modal .box h3 { margin-top: 0; color: #ffcc33; }
#toast { position: absolute; left: 50%; bottom: 80px; transform: translateX(-50%); background: #000d; padding: 6px 12px; border-radius: 16px; font-size: 12px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 30; max-width: 90%; }
#toast.show { opacity: 1; }
.notice { background: #b03a2e33; border: 1px solid #b03a2e; border-radius: 6px; padding: 6px; font-size: 12px; margin: 6px 0; }
.plan { border: 1px solid #a67c52; border-radius: 8px; padding: 6px; text-align: center; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tag { display: inline-block; background: #e67e22; color: #fff; border-radius: 4px; padding: 0 4px; font-size: 10px; }
table.mini { width: 100%; border-collapse: collapse; font-size: 11px; } table.mini td, table.mini th { border-bottom: 1px solid #ffffff14; padding: 3px; text-align: left; }
@media (max-width: 340px) { #tabs button span { display: none; } #top { font-size: 11px; } body { font-size: 13px; } }

.fl.miss { color: #9ad; font-style: italic; }
#splash { position: absolute; inset: 0; z-index: 40; background: #120c08; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
#splash #splashImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#splash p { position: relative; margin-bottom: 18%; background: #000a; padding: 6px 14px; border-radius: 16px; font-size: 13px; }
#modal .box.gacha { background: linear-gradient(#000a, #000c), url(./assets/bg/bg_gacha.png) center / cover; }
.ico { width: 22px; height: 22px; vertical-align: middle; margin-right: 4px; object-fit: contain; } .ico.big { width: 40px; height: 40px; }

/* ---- v0.5 視覺細審：背景壓暗、前景描邊、短螢幕版面 ---- */
#shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(to bottom, rgba(0,0,0,.45) 0%, rgba(0,0,0,.30) 22%, rgba(0,0,0,.34) 55%, rgba(0,0,0,.60) 100%); }
.unit img { filter: drop-shadow(0 0 1.5px #000) drop-shadow(0 0 1.5px #000) drop-shadow(0 6px 6px #000b); }
.unit .bar { box-shadow: 0 0 0 1px #000c; }
.unit .name { display: inline-block; padding: 0 6px; border-radius: 8px; background: rgba(0,0,0,.65); text-shadow: 0 1px 2px #000; }
.fl { -webkit-text-stroke: .6px #000; }
#phaseMsg { -webkit-text-stroke: .6px #000; }
#fx { position: absolute; width: 46%; aspect-ratio: 1; right: 2%; bottom: 18%; pointer-events: none; mix-blend-mode: screen; opacity: .9; }
#panel button { min-height: 34px; }
#panel .row { gap: 4px; }
.card .frame img.cardframe { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.card .frame.has-art { border-color: transparent; }
/* 短螢幕（如 320×568、360×640）：戰場縮小，讓下方分頁內容至少約 40% 高度可用 */
@media (max-height: 700px) {
  #battle { height: min(46dvh, calc(min(100vw, 430px) * 1.0)); }
  #guide { top: 22px; padding: 4px 6px; font-size: 11px; line-height: 1.35; }
  #skillBar button { width: 40px; height: 40px; }
  #tabs button { min-height: 42px; }
}
#splash img.logo { position: absolute; inset: auto; top: 4%; left: 50%; transform: translateX(-50%); width: 46%; height: auto; object-fit: contain; z-index: 1; }
img.star { width: 12px; height: 12px; vertical-align: -1px; } img.cardback { float: right; width: 48px; margin-left: 6px; border-radius: 4px; }
#tabs .tabglyph { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 6px; background: #6b4a2e; color: #ffd98a; font-size: 13px; }
.card small { font-size: 10px; display: inline-block; line-height: 1.3; } #panel small { font-size: max(10px, .82em); }
.item img.empty { filter: grayscale(1) brightness(.6); opacity: .7; }
/* v0.5：卡片元件尺寸（避免被 .card .frame img 規則放大） */
.card .frame .plate img.star, .card .frame img.star { width: 11px; height: 11px; aspect-ratio: auto; object-fit: contain; vertical-align: -1px; filter: none; }
.card .frame img.cardframe { z-index: 2; }
.card .frame .plate, .card .frame .badge { z-index: 3; }
.card .frame .plate[style] { background-color: transparent; color: #fff; text-shadow: 0 1px 2px #000; padding: 4px 8% 6px; }
.card .frame .badge[style] { width: 22px; height: 22px; line-height: 22px; background-color: transparent; color: #fff; text-shadow: 0 1px 2px #000; }
#modal .box h3[style] { padding: 6px 18px; color: #fff; text-shadow: 0 1px 3px #000; background-size: 100% 100% !important; display: inline-block; }

/* ---- v0.6 P0／P1：戰鬥演出圖層與版面重構 ---- */
/* 戰場：寬 × 0.85（矮螢幕另以 46dvh 為上限），背景改對準地平線與地面，不再偏天空 */
#battle { height: min(calc(min(100vw, 430px) * 0.85), 55dvh); }
#bg { object-position: center 78%; }
#top { grid-template-columns: 1fr 1fr; }
/* 角色放大：寬 56%（原 38%）、往中央靠、腳站在技能列上緣 */
.unit { width: 56%; bottom: 44px; transition: none; }
#hero { left: -6%; } #enemy { right: -1%; }
.unit .bar { margin: 0 22%; }
#enemy .name { position: relative; z-index: 1; }
.sprite { position: relative; transform-origin: 50% 92%; will-change: transform; }
.sprite img { display: block; }
.sprite img.prev { position: absolute; inset: 0; opacity: 0; pointer-events: none; }

/* 兩張特效 Canvas：後層在角色之下（殘影）、前層在角色之上（軌跡、火花） */
#fxBack, #fxFront { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* 上方資訊帶：關卡、擊殺（原在戰場外上方列），名將戰時計時條接在下方 */
#hud { position: absolute; left: 6px; right: 6px; top: 5px; display: flex; gap: 6px; align-items: center; pointer-events: none; font-size: 12px; }
#hud > div { background: rgba(0,0,0,.62); border-radius: 10px; padding: 2px 9px; text-shadow: 0 1px 2px #000; white-space: nowrap; }
#stageLabel { font-weight: bold; color: #ffe2a0; }
#bossTimer { top: 30px; }
#fx { width: 40%; right: 8%; bottom: 26%; }
#guide { top: 30px; }
#phaseMsg { top: 22%; }
@media (max-height: 700px) {
  #battle { height: min(calc(min(100vw, 430px) * 0.85), 46dvh); }
  .unit { bottom: 38px; }
  #guide { top: 28px; }
}
@media (min-width: 375px) and (min-height: 701px) { .unit { width: 61%; } #hero { left: -8%; } #enemy { right: -2%; } }

/* ---- v0.6 檢查點 2：敵人外框、連擊數、傷害字 ---- */
#enemy.entering { transform: none; opacity: 1; } /* 登場改由 anim.js 演出 */
#enemySprite { transform-origin: 50% 92%; }
#battle { will-change: transform; }
/* 連擊數：資訊帶右側；10／30／50／100 變色，跨段時彈一下 */
#combo { margin-left: auto; font-weight: bold; font-size: 14px; color: #fff; }
#combo.t1 { color: #ffb347; } #combo.t2 { color: #ff5a3c; } #combo.t3 { color: #d07bff; } #combo.t4 { color: #ffd34d; text-shadow: 0 0 6px #ff9a2a, 0 1px 2px #000; }
#combo.pop { animation: comboPop .26s ease-out; }
@keyframes comboPop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
/* 傷害字：由 1.6 倍彈回原大小，再以拋物線往左／右上方飛出（--dx 由程式隨機給） */
.fl { animation: flyHit .9s cubic-bezier(.2,.7,.3,1) forwards; -webkit-text-stroke: .8px #000; paint-order: stroke fill; }
.fl.normal { font-size: 16px; }
.fl.crit { font-size: 24px; color: #ffd34d; animation-duration: 1.1s; text-shadow: 0 0 6px #ff8a2a, 0 1px 2px #000; }
@keyframes flyHit {
  0% { transform: translate(0, 0) scale(1.6); opacity: 1; }
  15% { transform: translate(calc(var(--dx, 0px) * .2), -14px) scale(1); opacity: 1; }
  60% { transform: translate(calc(var(--dx, 0px) * .7), -46px) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx, 0px), -34px) scale(.9); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .fl, .fl.crit { animation: up .9s ease-out forwards; } #combo.pop { animation: none; } }

/* ---- v0.6 比例校正＋檢查點 3 ---- */
/* 敵人名牌與血條：不佔版面，貼在「縮放後的頭頂」上方 10px（--headY 由 ui.js 計算），任何比例都不會被頭頂蓋住 */
#enemy .name { position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--headY, 40px) - 38px); white-space: nowrap; z-index: 1; min-height: 0; }
#enemy .bar { position: absolute; left: 22%; right: 22%; margin: 0; top: calc(var(--headY, 40px) - 16px); z-index: 1; }
/* 名將戰：倒數條移到資訊帶（取代關卡／擊殺），名將名字寫在倒數條內；敵人名牌隱藏，只留頭頂上的血條 */
#battle.bossfight #stageLabel, #battle.bossfight #killLabel, #battle.bossfight #enemy .name { display: none; }
#battle.bossfight #bossTimer { top: 5px; left: 6px; right: 96px; height: 20px; border-radius: 10px; }
#battle.bossfight #bossTimer span { line-height: 20px; font-size: 11px; }
/* (a) 絕技橫幅、(d) 名將來襲橫幅 */
#skillBanner, #bossBanner { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); pointer-events: none; opacity: 0; text-align: center; white-space: nowrap; z-index: 3; }
#skillBanner { padding: 6px 34px 8px; background: url(./assets/ui/ui_card_ribbon.png) center / 100% 100% no-repeat; }
#skillBanner small, #bossBanner small { display: block; font-size: 11px; letter-spacing: 4px; color: #ffe8b0; text-shadow: 0 1px 2px #000; }
#skillBanner b { font-size: 24px; letter-spacing: 6px; color: #fff; -webkit-text-stroke: 1px #6a2a00; paint-order: stroke fill; text-shadow: 0 0 8px var(--sk, #ffd34d), 0 2px 2px #000; }
#skillBanner.show { animation: bannerIn .95s ease-out forwards; }
#bossBanner { top: 30%; padding: 8px 26px; background: linear-gradient(90deg, transparent, rgba(120,0,0,.88) 18%, rgba(120,0,0,.88) 82%, transparent); border-top: 2px solid #ffcf6a; border-bottom: 2px solid #ffcf6a; }
#bossBanner small { font-size: 22px; letter-spacing: 10px; color: #fff3c4; font-weight: bold; -webkit-text-stroke: .8px #400; paint-order: stroke fill; }
#bossBanner b { font-size: 13px; color: #ffd9a0; letter-spacing: 3px; }
#bossBanner.show { animation: bannerIn 1.5s ease-out forwards; }
@keyframes bannerIn { 0% { opacity: 0; transform: translateX(-50%) scale(1.6); } 12% { opacity: 1; transform: translateX(-50%) scale(1); } 80% { opacity: 1; transform: translateX(-50%) scale(1); } 100% { opacity: 0; transform: translateX(-50%) scale(.96) translateY(-8px); } }
/* (c) 金幣、裝備飛入層 */
#flyLayer { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#flyLayer img { position: absolute; left: 0; top: 0; width: 18px; height: 18px; will-change: transform; }
#flyLayer img.gear { width: 30px; height: 30px; border-radius: 6px; background: rgba(0,0,0,.4); }
.bump { animation: bump .3s ease-out; }
@keyframes bump { 0% { transform: scale(1.35); filter: brightness(1.6); } 100% { transform: scale(1); } }
#tabs button.gearGlow { animation: gearGlow 1s ease-out; }
@keyframes gearGlow { 0% { box-shadow: inset 0 0 0 2px var(--rc, #ffd34d), 0 0 14px var(--rc, #ffd34d); } 100% { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { #skillBanner.show, #bossBanner.show { animation-name: bannerFade; } }
@keyframes bannerFade { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
