/* === 基底 === */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Microsoft JhengHei', 'PingFang TC', sans-serif;
  color: #f5f0e6;
  background: #1a1a24;
  overflow: hidden;
  user-select: none;
}
/* 預設不強制 pixelated，個別 chibi 圖另外指定 */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 20%, #2a1838 0%, #14101e 60%, #08060d 100%);
}

/* 玩家滾輪縮放：套在各畫面區段（JS 設 transform: scale(z)）。
   注意：縮放套在 #app 會被瀏覽器忽略，必須套在子層 section。 */
#select-screen, #battle-screen, #reward-screen {
  transform-origin: center center;
  transition: transform 0.12s ease-out;
}

/* 縮放提示小角標 */
#zoom-indicator {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  border: 1px solid rgba(255,216,106,0.4);
  color: #ffd86a;
  font-size: 12px;
  letter-spacing: 2px;
  padding: 5px 16px;
  border-radius: 16px;
  z-index: 9500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#zoom-indicator.show { opacity: 1; }

/* === 角色選擇畫面 === */
#select-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
}
#select-screen h1 {
  font-size: 52px;
  letter-spacing: 8px;
  color: #ffd86a;
  text-shadow: 0 0 20px rgba(255,216,106,0.5);
}
#select-screen .sub {
  color: #c0b8a8;
  letter-spacing: 4px;
}
.char-grid {
  display: flex;
  gap: 32px;
  margin-top: 20px;
}
.char-card {
  width: 220px;
  height: 320px;
  background: linear-gradient(180deg, #2a2540 0%, #1a1828 100%);
  border: 2px solid #4a3f6b;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.char-card:hover {
  transform: translateY(-8px);
  border-color: #ffd86a;
  box-shadow: 0 12px 30px rgba(255,216,106,0.25);
}
.char-card .portrait {
  width: 128px;
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.char-card .portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(2.2);
}
.char-card .name {
  font-size: 26px;
  color: #ffd86a;
  letter-spacing: 4px;
}
.char-card .desc {
  font-size: 13px;
  color: #c0b8a8;
  text-align: center;
  line-height: 1.5;
}
.char-card .hp-bar { width: 150px; }

/* === 戰鬥畫面 === */
#battle-screen {
  display: none;
  flex: 1;
  flex-direction: column;
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
#battle-screen.active { display: flex; }

/* --- 戰場 (上半部) --- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 24px 60px 8px;
  position: relative;
  background:
    radial-gradient(ellipse at 50% 100%, rgba(80,30,80,0.4) 0%, transparent 60%);
  border-bottom: 1px solid rgba(255,216,106,0.15);
}

.combatant {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
}
.combatant .sprite-box {
  position: relative;
  width: 260px;
  height: 280px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  filter: drop-shadow(0 12px 18px rgba(0,0,0,0.6));
}

/* 玩家：左、面向右；chibi 像素圖放大 */
.combatant.player { margin-left: 20px; }
.combatant.player .sprite-box img {
  position: absolute;
  bottom: 10px;
  left: 50%;
  width: auto;
  height: 110px;
  transform: translateX(-50%) scale(2.4);
  transform-origin: bottom center;
  image-rendering: pixelated;
}
.combatant.player .sprite-box img.flip-x {
  transform: translateX(-50%) scale(2.4) scaleX(-1);
}

/* 敵人：右、面向左（翻轉）；照片用 cover 並裁切兩側白邊 */
.combatant.enemy { margin-right: 20px; }
.combatant.enemy .sprite-box {
  width: 280px;
  height: 300px;
}
.combatant.enemy .sprite-box img {
  position: absolute;
  bottom: 0;
  left: 50%;
  height: 300px;
  width: auto;
  max-width: none;
  transform: translateX(-50%) scaleX(-1);
  image-rendering: auto;   /* 照片不用 pixelated */
}

/* 受擊閃光 */
.combatant.hurt-flash .sprite-box img {
  filter: brightness(2.5) saturate(2);
}

/* 拖曳瞄準時：目標高亮 */
.combatant.target-hover .sprite-box {
  filter: drop-shadow(0 0 24px #ffd86a) drop-shadow(0 0 12px #ff9090);
  transform: scale(1.04);
  transition: transform 0.15s, filter 0.15s;
}
.combatant.target-hover::after {
  content: '';
  position: absolute;
  inset: -8px;
  border: 2px dashed #ffd86a;
  border-radius: 16px;
  pointer-events: none;
  animation: target-pulse 1s ease-in-out infinite;
}
@keyframes target-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* 瞄準箭頭 SVG 覆蓋層 */
.targeting-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  z-index: 180;
  overflow: visible;
}
.targeting-overlay.show { display: block; }
#targeting-path {
  filter: drop-shadow(0 0 8px rgba(255,180,80,0.7));
}
#targeting-arrowhead {
  filter: drop-shadow(0 0 6px rgba(255,180,80,0.8));
}
.targeting-overlay.on-target #targeting-path {
  stroke-width: 12;
  filter: drop-shadow(0 0 14px rgba(255,80,80,0.9));
}
.targeting-overlay.on-target #targeting-arrowhead polygon {
  fill: #ff6868;
  transform-origin: 0 0;
}

/* play-zone 提示（拖牌時手牌上方亮起） */
.play-zone-hint {
  position: fixed;
  left: 0; right: 0;
  bottom: 230px;
  height: 60px;
  background: linear-gradient(180deg, transparent 0%, rgba(255,216,106,0.15) 100%);
  border-bottom: 2px dashed rgba(255,216,106,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  color: rgba(255,216,106,0.8);
  font-size: 14px;
  letter-spacing: 4px;
  pointer-events: none;
  z-index: 150;
}
.play-zone-hint.show { display: flex; }

/* HP bar */
.hp-bar {
  width: 220px;
  height: 20px;
  background: #2a1818;
  border: 1px solid #6a3030;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
.hp-bar .fill {
  height: 100%;
  background: linear-gradient(180deg, #ff5050 0%, #b02020 100%);
  transition: width 0.3s;
}
.hp-bar .text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  font-weight: bold;
}

.name-tag {
  font-size: 18px;
  color: #ffd86a;
  letter-spacing: 3px;
  text-shadow: 0 2px 4px #000;
}

.status-pills {
  display: flex;
  gap: 6px;
  min-height: 22px;
}
.block-pill, .buff-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
  color: #fff;
}
.block-pill { background: #5a8acc; box-shadow: 0 0 8px rgba(120,180,255,0.5); }
.buff-pill { background: #cc5a8a; box-shadow: 0 0 8px rgba(255,120,180,0.5); }

/* Intent bubble — 浮在敵人頭部上方，不遮角色 */
.intent-bubble {
  position: absolute;
  top: -68px;          /* 拉高，不蓋到立繪 */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.82);
  border: 2px solid #ff9090;
  border-radius: 22px;
  padding: 8px 18px;
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(255,80,80,0.4), 0 0 0 1px rgba(255,80,80,0.2);
  z-index: 5;
  white-space: nowrap;
}
/* 連接線，讓氣泡視覺上跟敵人有聯繫 */
.intent-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid rgba(0,0,0,0.82);
}
/* 不同 intent 類型的顏色主題 */
.intent-bubble.intent-attack  { border-color: #ff5050; box-shadow: 0 4px 16px rgba(255,60,60,0.5); }
.intent-bubble.intent-multi   { border-color: #ff8040; box-shadow: 0 4px 16px rgba(255,120,40,0.5); }
.intent-bubble.intent-buff    { border-color: #c070ff; box-shadow: 0 4px 16px rgba(180,80,255,0.4); }
.intent-bubble.intent-block   { border-color: #60a0ff; box-shadow: 0 4px 16px rgba(80,160,255,0.4); }
.intent-bubble .icon { font-size: 22px; }
.intent-bubble .label {
  color: #ffb0b0;
  font-size: 13px;
  letter-spacing: 2px;
}
.intent-bubble .value {
  color: #fff;
  font-weight: bold;
  font-size: 22px;
  text-shadow: 0 0 8px rgba(255,100,100,0.7);
}

/* --- 手牌區 --- */
.hand-area {
  height: 220px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 8px;
  position: relative;
}
.hand {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
  /* 不要 perspective / transform / filter — 任何這些屬性都會讓 .hand 變成
     position:fixed 子元素的 containing block，導致拖曳卡片定位錯亂 */
}

.card {
  width: 150px;
  height: 200px;
  border-radius: 14px;
  margin: 0 -22px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #3a2a2a 0%, #1a1010 100%);
  border: 3px solid #888;
  padding: 8px 8px 6px;
  cursor: grab;
  position: relative;
  /* 離開 hover 時慢一點，讓滑鼠不會因卡片移走而觸發反覆閃爍 */
  transition: transform 0.28s cubic-bezier(0.25, 0.8, 0.25, 1),
              margin 0.2s, box-shadow 0.28s ease;
  box-shadow: 0 6px 14px rgba(0,0,0,0.55);
  transform-origin: bottom center;
  will-change: transform;   /* GPU 加速，避免抖動 */
  touch-action: none;
}
/* hover-in 快、hover-out 靠上方的 transition 緩衝，避免游標剛好在邊界反覆閃爍 */
.card:hover:not(.dragging):not(.flying):not(.unplayable) {
  transform: translateY(-28px) rotate(0deg) scale(1.08) !important;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.15s ease;
  z-index: 100;
  box-shadow: 0 16px 28px rgba(0,0,0,0.75);
}
/* 拖曳中：position fixed，跟著游標，不要再吃 transition（避免延遲感） */
.card.dragging {
  position: fixed !important;
  margin: 0 !important;
  z-index: 200;
  cursor: grabbing;
  transition: none !important;
  transform-origin: top left !important;   /* 縮放錨左上，left/top 不偏移 */
  box-shadow: 0 24px 48px rgba(0,0,0,0.85);
  pointer-events: none;
  /* transform(scale) 由 JS 依縮放動態設定 */
}
.card.flying, .card.returning { transform-origin: top left !important; }
/* 飛行中：用 transition 平滑滑到目標位置 */
.card.flying {
  position: fixed !important;
  margin: 0 !important;
  z-index: 200;
  transition: transform 0.35s cubic-bezier(0.45, 0, 0.55, 1), opacity 0.3s ease 0.15s;
  pointer-events: none;
}
/* 回彈：跟 flying 一樣但彈性曲線 */
.card.returning {
  position: fixed !important;
  margin: 0 !important;
  z-index: 200;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.card.unplayable {
  filter: grayscale(0.6) brightness(0.55);
  cursor: not-allowed;
}
.card.unplayable:hover {
  transform: none !important;
}

/* 卡片類型配色 */
.card.attack { border-color: #d04040; background: linear-gradient(180deg, #5a2020 0%, #2a0808 100%); }
.card.skill  { border-color: #40b060; background: linear-gradient(180deg, #1a4030 0%, #08200f 100%); }
.card.power  { border-color: #5a8acc; background: linear-gradient(180deg, #1a2a5a 0%, #08102a 100%); }

.card .cost {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #5fb0ff 0%, #2060c0 60%, #0a2860 100%);
  border: 2px solid #80c8ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  box-shadow: 0 0 10px rgba(100,180,255,0.7);
  z-index: 3;
}
.card .name-banner {
  font-size: 15px;
  font-weight: bold;
  color: #ffd86a;
  text-align: center;
  letter-spacing: 2px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,216,106,0.3);
  margin-bottom: 4px;
}
.card .art {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0608;
  border-radius: 8px;
  margin: 4px 0;
  overflow: hidden;
  position: relative;
}
.card .art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;  /* 照片不用 pixelated */
  filter: contrast(1.05) saturate(0.95);
}
/* 攻擊類照片加暖色濾鏡，技能加冷色 */
.card.attack .art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,100,80,0.15) 0%, rgba(120,20,20,0.35) 100%);
  pointer-events: none;
}
.card.skill .art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(100,255,160,0.12) 0%, rgba(20,100,60,0.3) 100%);
  pointer-events: none;
}
.card.power .art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(120,180,255,0.12) 0%, rgba(40,80,180,0.35) 100%);
  pointer-events: none;
}

.card .desc-box {
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  color: #f0e8d0;
  padding: 4px 2px 2px;
  min-height: 44px;
}
.card .desc-box b { color: #ffd86a; }

/* --- 底部 HUD --- */
.bottom-hud {
  height: 90px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0 32px 16px;
  align-items: end;
}
.hud-left {
  display: flex;
  align-items: end;
  gap: 16px;
}
.hud-right {
  display: flex;
  align-items: end;
  gap: 16px;
  justify-content: flex-end;
}

.energy-orb {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #5fb0ff 0%, #2060c0 60%, #0a2860 100%);
  border: 3px solid #80c8ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 4px #000;
  box-shadow: 0 0 24px rgba(100,180,255,0.6);
}

.pile {
  width: 64px;
  height: 80px;
  background: linear-gradient(180deg, #3a3050 0%, #1a1428 100%);
  border: 2px solid #6a5f8a;
  border-radius: 8px;
  position: relative;
  cursor: default;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  /* 堆疊感：用偏移的偽元素假裝下面還有牌 */
}
.pile::before, .pile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  border: 2px solid #6a5f8a;
  border-radius: 8px;
  z-index: -1;
}
.pile::before { transform: translate(3px, 3px); opacity: 0.7; }
.pile::after { transform: translate(6px, 6px); opacity: 0.4; }
.pile .label {
  position: absolute;
  top: 8px;
  left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  color: #b0a0d0;
  letter-spacing: 2px;
}
.pile .count {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
  margin-bottom: 6px;
  text-shadow: 0 1px 2px #000;
}

.end-turn-btn {
  background: linear-gradient(180deg, #d4a040 0%, #a06820 100%);
  color: #fff;
  font-size: 18px;
  letter-spacing: 4px;
  padding: 16px 24px;
  border-radius: 10px;
  border: 2px solid #ffd86a;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: all 0.15s;
  height: 80px;
}
.end-turn-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(255,216,106,0.4); }
.end-turn-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* --- 戰鬥日誌 --- */
.log-area {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-height: 130px;
  overflow: hidden;
  background: rgba(0,0,0,0.45);
  border: 1px solid #4a3f6b;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #d0c8b0;
  pointer-events: none;
  z-index: 5;
}
.log-area p { margin-bottom: 3px; opacity: 0.95; }
.log-area p.dmg { color: #ff8080; }
.log-area p.heal { color: #80ff80; }
.log-area p.block { color: #80c8ff; }
.log-area p.buff { color: #ff80c8; }

/* --- 關卡指示器 --- */
.floor-indicator {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,216,106,0.4);
  color: #ffd86a;
  font-size: 13px;
  letter-spacing: 4px;
  padding: 4px 18px;
  border-radius: 20px;
  z-index: 10;
  pointer-events: none;
}

/* --- 選牌獎勵畫面 --- */
#reward-screen {
  display: none;
  position: fixed;   /* 全螢幕覆蓋，不被 flex 擠壓 */
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 32px;
  background: radial-gradient(ellipse at 50% 0%, #2a1838 0%, #0e0a18 70%);
  z-index: 800;
}
#reward-screen.active { display: flex; }
.reward-header { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.reward-floor-badge {
  display: inline-block;
  padding: 4px 20px;
  border-radius: 20px;
  border: 1px solid #ffd86a;
  color: #ffd86a;
  font-size: 13px;
  letter-spacing: 4px;
  background: rgba(0,0,0,0.5);
  align-self: center;
}
.reward-header h2 {
  font-size: 28px;
  color: #f5f0e6;
  letter-spacing: 6px;
}
.reward-header p { color: #b0a890; font-size: 14px; letter-spacing: 2px; }

.reward-cards {
  display: flex;
  gap: 40px;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

/* 選牌畫面的卡片放大且可點擊 */
#reward-screen .card {
  width: 190px !important;
  height: 260px !important;
  margin: 0 !important;        /* 覆蓋 hand 的 -22px 負邊距 */
  cursor: pointer !important;
  transform: none !important;  /* 覆蓋 hand 的扇形旋轉 */
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s !important;
}
#reward-screen .card:hover {
  transform: translateY(-18px) scale(1.06) !important;
  box-shadow: 0 22px 44px rgba(0,0,0,0.8) !important;
  z-index: 10;
}

/* 稀有度框線 */
.card.rarity-common  { }
.card.rarity-uncommon.attack { border-color: #5090e0; box-shadow: 0 4px 18px rgba(80,144,224,0.4); }
.card.rarity-uncommon.skill  { border-color: #5090e0; box-shadow: 0 4px 18px rgba(80,144,224,0.4); }
.card.rarity-uncommon.power  { border-color: #5090e0; box-shadow: 0 4px 18px rgba(80,144,224,0.4); }
.card.rarity-rare.attack { border-color: #d4a040; box-shadow: 0 4px 20px rgba(212,160,64,0.6); }
.card.rarity-rare.skill  { border-color: #d4a040; box-shadow: 0 4px 20px rgba(212,160,64,0.6); }
.card.rarity-rare.power  { border-color: #d4a040; box-shadow: 0 4px 20px rgba(212,160,64,0.6); }

/* 稀有度角標 */
.card .rarity-pip {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  border: 2px solid #1a1020;
  z-index: 3;
}
.rarity-pip.uncommon { background: #5090e0; }
.rarity-pip.rare     { background: #d4a040; box-shadow: 0 0 10px rgba(212,160,64,0.7); }

.reward-skip-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.4);
  font-size: 14px;
  padding: 8px 24px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.2s;
  font-family: inherit;
}
.reward-skip-btn:hover {
  border-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.7);
}

/* --- 結算畫面 --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 24px;
  z-index: 999;
}
.overlay.show { display: flex; }
.overlay h2 {
  font-size: 64px;
  letter-spacing: 12px;
}
.overlay h2.win { color: #ffd86a; text-shadow: 0 0 30px rgba(255,216,106,0.6); }
.overlay h2.lose { color: #ff5050; text-shadow: 0 0 30px rgba(255,80,80,0.6); }
.overlay button {
  background: linear-gradient(180deg, #d4a040 0%, #a06820 100%);
  color: #fff;
  font-size: 20px;
  letter-spacing: 4px;
  padding: 14px 36px;
  border-radius: 10px;
  border: 2px solid #ffd86a;
}

/* === 玩家受傷效果 === */
.combatant.player-hurt {
  animation: player-hurt-shake 0.4s ease-out;
}
.combatant.player-hurt .sprite-box::after {
  content: '';
  position: absolute;
  inset: -10px;
  background: radial-gradient(ellipse at center, rgba(255,50,50,0.6) 0%, transparent 70%);
  border-radius: 50%;
  animation: hit-flash 0.4s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}
@keyframes player-hurt-shake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(10px); }
  30%  { transform: translateX(-8px); }
  45%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

/* === 寵物投擲動畫 === */
.pet-projectile {
  position: fixed;
  pointer-events: none;
  z-index: 400;
  image-rendering: pixelated;
  width: 72px;
  height: 72px;
  object-fit: contain;
  /* 實際位置與動畫由 WAAPI 控制 */
}
/* 落地衝擊波 */
.pet-impact {
  position: fixed;
  pointer-events: none;
  z-index: 399;
  width: 0; height: 0;
}
.pet-impact-ring {
  position: absolute;
  border-radius: 50%;
  border: 4px solid rgba(255, 220, 80, 0.9);
  transform: translate(-50%, -50%);
  animation: pet-impact-expand 0.4s ease-out forwards;
}
@keyframes pet-impact-expand {
  0%   { width: 20px; height: 20px; opacity: 1; }
  100% { width: 120px; height: 120px; opacity: 0; }
}

/* === 攻擊效果：星之箭（Aity 魔法） === */
.star-effect {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  width: 0; height: 0;
}
.star-particle {
  position: absolute;
  font-size: 24px;
  transform-origin: center;
  animation: star-burst 0.55s ease-out forwards;
}
@keyframes star-burst {
  0%   { opacity: 1; transform: translate(-50%,-50%) scale(0.3) rotate(0deg); }
  40%  { opacity: 1; transform: translate(var(--tx), var(--ty)) scale(1.2) rotate(180deg); }
  100% { opacity: 0; transform: translate(var(--tx2), var(--ty2)) scale(0.4) rotate(360deg); }
}

/* === 攻擊效果：貓拳連擊（KUU 多段） === */
.paw-effect {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  font-size: 36px;
  transform: translate(-50%, -50%);
  animation: paw-hit 0.4s ease-out forwards;
}
@keyframes paw-hit {
  0%   { opacity: 1; transform: translate(-50%,-50%) scale(0.5) rotate(-20deg); }
  30%  { opacity: 1; transform: translate(-50%,-50%) scale(1.3) rotate(10deg); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(0.8) rotate(-5deg); }
}

/* === 攻擊效果：斬擊線 === */
.slash-effect {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  width: 0;
  height: 0;
}
.slash-line {
  position: absolute;
  width: 220px;
  height: 6px;
  border-radius: 3px;
  transform-origin: left center;
  animation: slash-anim 0.45s ease-out forwards;
}
.slash-line:nth-child(1) { background: linear-gradient(90deg, transparent 0%, #fff8a0 30%, #ff6060 70%, transparent 100%); top: -20px; transform: rotate(-30deg); animation-delay: 0ms; }
.slash-line:nth-child(2) { background: linear-gradient(90deg, transparent 0%, #ffe080 30%, #ff4040 70%, transparent 100%); top: 10px; transform: rotate(-15deg); width: 180px; animation-delay: 40ms; }
.slash-line:nth-child(3) { background: linear-gradient(90deg, transparent 0%, #ff9060 30%, #ff2020 70%, transparent 100%); top: 35px; transform: rotate(-22deg); width: 240px; animation-delay: 20ms; }
@keyframes slash-anim {
  0%   { opacity: 0; transform-origin: left center; clip-path: inset(0 100% 0 0); }
  20%  { opacity: 1; clip-path: inset(0 0% 0 0); }
  70%  { opacity: 0.8; }
  100% { opacity: 0; transform: scaleX(1.1) rotate(var(--r, -20deg)); }
}

/* 敵人受攻擊：紅色閃光 + 震動 */
.combatant.attack-hit {
  animation: enemy-shake 0.4s ease-out;
}
.combatant.attack-hit .sprite-box::after {
  content: '';
  position: absolute;
  inset: -10px;
  background: radial-gradient(ellipse at center, rgba(255,60,60,0.7) 0%, transparent 70%);
  border-radius: 50%;
  animation: hit-flash 0.4s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}
@keyframes enemy-shake {
  0%   { transform: translateX(0) rotate(0); }
  15%  { transform: translateX(-12px) rotate(-3deg); }
  30%  { transform: translateX(10px) rotate(2deg); }
  45%  { transform: translateX(-8px) rotate(-2deg); }
  60%  { transform: translateX(6px) rotate(1deg); }
  80%  { transform: translateX(-3px); }
  100% { transform: translateX(0) rotate(0); }
}
@keyframes hit-flash {
  0%   { opacity: 1; transform: scale(0.8); }
  40%  { opacity: 0.9; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* === 防禦效果：盾牌泡泡 === */
.shield-effect {
  position: fixed;
  pointer-events: none;
  z-index: 300;
  width: 0; height: 0;
}
.shield-ring {
  position: absolute;
  border-radius: 50%;
  border: 4px solid rgba(120, 200, 255, 0.9);
  box-shadow: 0 0 20px rgba(120, 200, 255, 0.8), inset 0 0 20px rgba(120, 200, 255, 0.3);
  transform: translate(-50%, -50%);
  animation: shield-expand 0.6s ease-out forwards;
}
.shield-ring:nth-child(1) { width: 120px; height: 120px; animation-delay: 0ms; }
.shield-ring:nth-child(2) { width: 80px; height: 80px; border-color: rgba(180,230,255,0.7); animation-delay: 80ms; }
.shield-hex {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 80px;
  animation: shield-icon 0.55s ease-out forwards;
  filter: drop-shadow(0 0 16px rgba(100,180,255,0.9));
}
@keyframes shield-expand {
  0%   { opacity: 0.9; transform: translate(-50%, -50%) scale(0.3); }
  50%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }
}
@keyframes shield-icon {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  30%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
}

/* 玩家防禦：藍色光暈 */
.combatant.shield-hit .sprite-box::after {
  content: '';
  position: absolute;
  inset: -15px;
  background: radial-gradient(ellipse at center, rgba(100,180,255,0.65) 0%, transparent 70%);
  border-radius: 50%;
  animation: shield-glow 0.55s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}
@keyframes shield-glow {
  0%   { opacity: 0; transform: scale(0.7); }
  35%  { opacity: 1; transform: scale(1.1); }
  100% { opacity: 0; transform: scale(1.4); }
}

/* --- 飄字 --- */
.popup {
  position: fixed;
  font-weight: bold;
  font-size: 38px;
  pointer-events: none;
  animation: popup-anim 1s ease-out forwards;
  text-shadow: 0 2px 4px #000, 0 0 10px currentColor;
  z-index: 50;
  transform: translate(-50%, 0);
}
.popup.dmg { color: #ff5050; }
.popup.block { color: #80c8ff; }
.popup.heal { color: #80ff80; }
@keyframes popup-anim {
  0%   { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  20%  { transform: translate(-50%, -20px) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -100px) scale(1); opacity: 0; }
}
