:root {
  --bg-deep: #1a0f14;
  --bg-mid: #2d1a24;
  --bg-card: rgba(255, 240, 245, 0.08);
  --rose: #e8a0b4;
  --rose-light: #f5c6d0;
  --rose-dark: #b85c7a;
  --gold: #d4a574;
  --gold-light: #f0d4a8;
  --cream: #fff5f7;
  --text: #fce8ef;
  --text-muted: #c9a8b4;
  --male: #8eb8e8;
  --female: #e8a0c8;
  --success: #7ec8a0;
  --danger: #e87878;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Noto Sans TC', sans-serif;
  background: linear-gradient(145deg, var(--bg-deep) 0%, var(--bg-mid) 50%, #3d2030 100%);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
}

.bg-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cpath fill='%23e8a0b4' d='M30 52c-1-1-18-12-18-24 0-7 5-12 12-12 4 0 7 2 9 5 2-3 5-5 9-5 7 0 12 5 12 12 0 12-17 23-18 24z'/%3E%3C/svg%3E");
  background-size: 60px 60px;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

/* Header */
.app-header { text-align: center; margin-bottom: 1.5rem; }
.app-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 1.8rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--rose-light), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.12em;
}
.app-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
  letter-spacing: 0.15em;
}

/* Screens — 必須以 active 控制顯示，避免被 ID 選擇器覆蓋 */
.screen {
  display: none !important;
  animation: fadeIn 0.3s ease;
}
.screen.active {
  display: block !important;
}
/* 戰鬥畫面用 flex 排版，但仍受 active 控制 */
#screen-battle.active {
  display: flex !important;
  flex-direction: column;
  gap: 0.4rem;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 1.25rem;
  text-align: center;
  margin-bottom: 0.75rem;
  color: var(--rose-light);
}

/* Mode */
.mode-grid { display: flex; flex-direction: column; gap: 0.875rem; margin-bottom: 1rem; }
.mode-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 1.4rem;
  text-align: center;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  transition: transform 0.15s;
}
.mode-card:active { transform: scale(0.98); }
.mode-card.highlight { border-color: rgba(232,160,180,0.4); }
.mode-icon { display: block; font-size: 1.8rem; margin-bottom: 0.4rem; }
.mode-title { display: block; font-family: 'Noto Serif TC', serif; font-size: 1.15rem; font-weight: 600; margin-bottom: 0.3rem; }
.mode-desc { display: block; font-size: 0.85rem; color: var(--text-muted); }

.hint-text { text-align: center; font-size: 0.8rem; color: var(--gold-light); opacity: 0.9; }

/* Lobby */
.remote-status { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; min-height: 1.4rem; }
.room-code {
  text-align: center;
  font-family: 'Noto Serif TC', serif;
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.25em;
  margin: 1rem 0 1.25rem;
  padding: 0.9rem;
  background: rgba(212,165,116,0.15);
  border-radius: var(--radius);
  border: 1px dashed rgba(212,165,116,0.4);
}
.room-code.hidden { display: none; }
.lobby-card { margin-bottom: 1rem; }
.lobby-title { font-size: 1rem; color: var(--rose-light); margin-bottom: 0.3rem; }
.lobby-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.9rem; }
.role-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.room-input, .room-select {
  width: 100%;
  padding: 0.8rem 1rem;
  margin-bottom: 0.7rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  background: rgba(0,0,0,0.25);
  color: var(--cream);
  font-family: inherit;
  font-size: 1.1rem;
  text-align: center;
}
.waiting-panel { text-align: center; padding: 1.5rem 1rem; }
.waiting-panel.hidden { display: none; }
.waiting-text { color: var(--text-muted); margin-bottom: 1rem; }
#lobby-forms.hidden { display: none; }

/* Cards / Buttons */
.card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 1.15rem;
  backdrop-filter: blur(10px);
}

.btn {
  display: block;
  width: 100%;
  padding: 0.9rem 1.2rem;
  min-height: 46px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--rose-dark), var(--rose));
  color: white;
  box-shadow: 0 4px 18px rgba(184,92,122,0.35);
}
.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.15);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  margin-top: 0.7rem;
}

/* ========== Battle UI ========== */
.battle-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.turn-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 90px;
}
#turn-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--gold-light);
}
.live-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.gold-bar-wrap {
  flex: 1;
  width: 100%;
  height: 26px;
  background: rgba(0,0,0,0.45);
  border-radius: 13px;
  position: relative;
  overflow: hidden;
  border: 1.5px solid rgba(212,165,116,0.55);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.35);
}
.gold-bar {
  height: 100%;
  background: linear-gradient(90deg, #b8860b, #e8c878, #f0d4a8);
  border-radius: 13px;
  transition: width 0.4s ease;
  min-width: 0;
}
.gold-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff8e7;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 0 8px rgba(0,0,0,0.5);
  letter-spacing: 0.03em;
  z-index: 2;
  pointer-events: none;
}
.role-info { min-width: 50px; text-align: right; }
#my-role-badge {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border-radius: 10px;
  background: rgba(142,184,232,0.2);
  color: var(--male);
}

.section-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.6rem 0 0.4rem;
  letter-spacing: 0.05em;
}
.section-label small { opacity: 0.7; }

/* Parts Grid (魔王部位) */
.parts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.part-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 0.55rem 0.4rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.part-card:active { transform: scale(0.97); }
.part-card.selected { border-color: var(--female); box-shadow: 0 0 0 1px var(--female); }
.part-card.broken { opacity: 0.55; }
.part-name { font-size: 0.8rem; font-weight: 600; color: var(--cream); }
.part-def {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.part-gold {
  font-size: 0.7rem;
  color: var(--gold-light);
  margin-top: 0.1rem;
}
.def-bar {
  height: 4px;
  background: rgba(0,0,0,0.3);
  border-radius: 2px;
  margin-top: 0.3rem;
  overflow: hidden;
}
.def-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
  transition: width 0.3s;
}
.def-bar-fill.low { background: var(--danger); }
.def-bar-fill.mid { background: var(--gold); }

/* Categories Grid */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.cat-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 0.6rem 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.cat-card.selected { border-color: var(--male); box-shadow: 0 0 0 1px var(--male); }
.cat-card.can-break { border-color: var(--rose); animation: pulse-border 1.5s infinite; }
@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,160,180,0.4); }
  50% { box-shadow: 0 0 0 4px rgba(232,160,180,0.15); }
}
.cat-name { font-size: 0.85rem; font-weight: 600; }
.cat-def { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; }

/* Center Info */
.center-info {
  text-align: center;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  min-height: 2rem;
  font-size: 0.9rem;
  color: var(--gold-light);
}

/* Hand Area - 手機優化 */
.hand-area {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--bg-deep) 85%, rgba(26,15,20,0.92) 100%);
  padding: 0.5rem 0 calc(0.6rem + env(safe-area-inset-bottom, 0px));
  margin-top: 0.4rem;
  z-index: 20;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.mp-display {
  text-align: center;
  font-size: 0.8rem;
  color: var(--male);
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
}
.hand-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.2rem 0 0.4rem;
  overflow: visible;
  width: 100%;
  box-sizing: border-box;
}
.hand-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 72px;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1.5px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  padding: 0.4rem 0.3rem;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}
.hand-card-empty {
  border-style: dashed;
  border-color: rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.15);
  cursor: default;
  opacity: 0.55;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hand-card-empty .card-empty-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.hand-card:active { transform: scale(0.96); }
.hand-card.selected {
  border-color: var(--gold-light);
  transform: translateY(-4px);
  box-shadow: 0 6px 14px rgba(212,165,116,0.3);
  background: rgba(212,165,116,0.1);
}
.hand-card .card-name {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--cream);
  margin-bottom: 0.12rem;
  line-height: 1.2;
  word-break: break-word;
}
.hand-card .card-meta {
  font-size: 0.58rem;
  color: var(--text-muted);
  line-height: 1.2;
  word-break: break-word;
}
.hand-card .card-break {
  color: var(--rose-light);
  font-weight: 500;
}
.battle-actions {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 0.55rem;
  margin-top: 0.15rem;
  padding: 0 0.1rem;
}
.battle-actions .btn {
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 14px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.battle-actions .btn-primary {
  box-shadow: 0 4px 16px rgba(184,92,122,0.4);
}
.battle-actions .btn-secondary {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
  background: linear-gradient(160deg, #2d1a24, #3d2030);
  border: 1px solid rgba(232,160,180,0.3);
  border-radius: 16px;
  padding: 1.5rem 1.25rem;
  max-width: 360px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
}
.modal-content h3 {
  text-align: center;
  color: var(--rose-light);
  margin-bottom: 0.5rem;
  font-family: 'Noto Serif TC', serif;
}
.action-cat {
  text-align: center;
  color: var(--gold-light);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.action-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.action-option {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
  cursor: pointer;
  text-align: left;
  color: var(--cream);
}
.action-option.selected {
  border-color: var(--rose);
  background: rgba(232,160,180,0.12);
}
.action-option .type-tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  margin-bottom: 0.3rem;
}
.type-tag.short { background: rgba(126,200,160,0.2); color: var(--success); }
.type-tag.live { background: rgba(232,80,80,0.25); color: #ffaaaa; }
.timer-wrap {
  text-align: center;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.timer {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gold-light);
  font-family: 'Noto Serif TC', serif;
  margin-top: 0.2rem;
}
.action-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.modal-btns .btn {
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Result */
.result-card {
  text-align: center;
  padding: 2rem 1.5rem;
  background: rgba(126,200,160,0.12);
  border: 1px solid rgba(126,200,160,0.3);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.result-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
  color: var(--success);
}
.result-hint { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.75rem; }

/* Utility */
.hidden { display: none !important; }

/* Character Select */
.char-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.char-card {
  background: var(--bg-card);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  text-align: center;
}
.char-card:active { transform: scale(0.97); }
.char-card.selected {
  border-color: var(--gold-light);
  box-shadow: 0 0 0 2px rgba(212,165,116,0.3);
}
.char-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  object-position: top center;
  display: block;
  background: rgba(0,0,0,0.3);
}
.char-card .char-name {
  font-family: 'Noto Serif TC', serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.4rem 0.3rem 0.15rem;
  color: var(--cream);
}
.char-card .char-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.4rem 0.6rem;
}
.char-selected-info {
  text-align: center;
  min-height: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--gold-light);
  font-size: 0.9rem;
}

/* ===== Battle Heroes Layout ===== */
.battle-heroes {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.hero-panel {
  text-align: center;
}
.hero-img {
  width: 72px;
  height: 96px;
  object-fit: cover;
  object-position: top center;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.35);
  display: block;
  margin: 0 auto;
}
.male-panel .hero-img { border-color: rgba(142,184,232,0.45); }
.female-panel .hero-img { border-color: rgba(232,160,200,0.45); }
.hero-name {
  font-size: 0.7rem;
  margin-top: 0.25rem;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.battle-status-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}
.turn-pill {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gold-light);
  background: rgba(212,165,116,0.15);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}
.battle-status-center .gold-bar-wrap {
  width: 100%;
  height: 24px;
}
.battle-status-center .live-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Mobile polish */
.app {
  padding: 0.75rem 0.75rem 1.5rem;
  max-width: 440px;
}
.parts-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.part-card, .cat-card {
  padding: 0.45rem 0.35rem;
}
.hand-area {
  padding-bottom: env(safe-area-inset-bottom, 0.5rem);
}
.char-card img {
  height: 140px;
}
@media (max-width: 380px) {
  .battle-heroes { grid-template-columns: 56px 1fr 56px; gap: 0.35rem; }
  .hero-img { width: 56px; height: 74px; }
  .hand-cards { gap: 0.25rem; }
  .hand-card { min-height: 64px; padding: 0.3rem 0.22rem; border-radius: 8px; }
  .hand-card .card-name { font-size: 0.62rem; }
  .hand-card .card-meta { font-size: 0.54rem; }
  .app-title { font-size: 1.5rem; }
  .battle-actions { grid-template-columns: 1.4fr 1fr; gap: 0.45rem; }
  .battle-actions .btn { min-height: 46px; font-size: 0.98rem; padding: 0.75rem 0.6rem; }
}

/* 避免內容被底部手牌區遮住 */
#screen-battle {
  padding-bottom: 0.25rem;
}
#screen-battle .categories-grid {
  margin-bottom: 0.35rem;
}

/* ===== 對戰分區 ===== */
.zone {
  border-radius: 14px;
  padding: 0.55rem 0.5rem 0.65rem;
  margin-bottom: 0.55rem;
}
.zone-male {
  background: rgba(142, 184, 232, 0.08);
  border: 1px solid rgba(142, 184, 232, 0.22);
}
.zone-female {
  background: rgba(232, 160, 200, 0.08);
  border: 1px solid rgba(232, 160, 200, 0.22);
}
.zone-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--cream);
  margin-bottom: 0.45rem;
  letter-spacing: 0.04em;
}
.zone-title small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-left: auto;
}
.zone-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.male-dot { background: var(--male); box-shadow: 0 0 6px var(--male); }
.female-dot { background: var(--female); box-shadow: 0 0 6px var(--female); }

.hero-side-tag {
  font-size: 0.65rem;
  margin-top: 0.15rem;
  opacity: 0.75;
}
.male-tag { color: var(--male); }
.female-tag { color: var(--female); }

/* 手牌頂列 */
.hand-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.15rem;
  margin-bottom: 0.3rem;
}
.hand-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.8;
}

/* 手牌固定四欄，無需橫向捲動 */

/* 攻擊特效 */
.fx-layer {
  position: relative;
  pointer-events: none;
  min-height: 0;
}
.fx-float {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-family: 'Noto Serif TC', serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--rose-light);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  animation: fxFloatUp 0.9s ease-out forwards;
  white-space: nowrap;
  z-index: 30;
}
.fx-float.gold {
  color: var(--gold-light);
}
.fx-float.break {
  color: #ff6b8a;
  font-size: 1.5rem;
}
@keyframes fxFloatUp {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px) scale(0.85); }
  20% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.05); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-36px) scale(1); }
}

.hit-flash {
  animation: hitFlash 0.45s ease;
}
@keyframes hitFlash {
  0% { box-shadow: 0 0 0 0 rgba(255,107,138,0.0); }
  30% { box-shadow: 0 0 0 3px rgba(255,107,138,0.7); background: rgba(255,107,138,0.18); }
  100% { box-shadow: 0 0 0 0 rgba(255,107,138,0.0); }
}
.hit-shake {
  animation: hitShake 0.4s ease;
}
@keyframes hitShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.zone-pulse-male {
  animation: zonePulseMale 0.5s ease;
}
.zone-pulse-female {
  animation: zonePulseFemale 0.5s ease;
}
@keyframes zonePulseMale {
  0%, 100% { border-color: rgba(142,184,232,0.22); }
  40% { border-color: rgba(142,184,232,0.85); box-shadow: 0 0 16px rgba(142,184,232,0.25); }
}
@keyframes zonePulseFemale {
  0%, 100% { border-color: rgba(232,160,200,0.22); }
  40% { border-color: rgba(232,160,200,0.85); box-shadow: 0 0 16px rgba(232,160,200,0.25); }
}

/* 當前回合區域高亮 */
.zone.active-turn {
  border-width: 1.5px;
}
.zone-male.active-turn {
  border-color: rgba(142,184,232,0.5);
}
.zone-female.active-turn {
  border-color: rgba(232,160,200,0.5);
}

.part-card.hit-flash,
.cat-card.hit-flash {
  border-radius: 10px;
}

/* ===== 視角分區布局 ===== */
.battle-center-block {
  margin: 0.25rem 0 0.35rem;
  padding: 0.25rem 0.3rem 0.15rem;
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}
.battle-center-block .center-info {
  min-height: 0;
  padding: 0.15rem 0.25rem;
  margin-bottom: 0;
  font-size: 0.82rem;
}
.battle-center-block .center-info:empty,
.battle-center-block .center-info.msg-empty {
  display: none;
}
.battle-center-block .battle-heroes {
  margin-bottom: 0.15rem;
}
.battle-center-block .hero-img {
  width: 56px;
  height: 72px;
}
.battle-center-block .gold-bar-wrap {
  height: 20px;
}

.weakness-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

#zone-top, #zone-bottom {
  margin-bottom: 0.45rem;
}
#zone-top.zone-male,
#zone-bottom.zone-male {
  background: rgba(142, 184, 232, 0.08);
  border: 1px solid rgba(142, 184, 232, 0.22);
}
#zone-top.zone-female,
#zone-bottom.zone-female {
  background: rgba(232, 160, 200, 0.08);
  border: 1px solid rgba(232, 160, 200, 0.22);
}
#zone-top.active-attack,
#zone-bottom.active-attack {
  border-width: 1.5px;
}
#zone-top.zone-male.active-attack,
#zone-bottom.zone-male.active-attack {
  border-color: rgba(142,184,232,0.55);
}
#zone-top.zone-female.active-attack,
#zone-bottom.zone-female.active-attack {
  border-color: rgba(232,160,200,0.55);
}

/* 統一弱點卡片（部位 / 英雄弱點同一風格） */
.weak-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 0.5rem 0.35rem;
  text-align: center;
  transition: border-color 0.15s;
}
.weak-card .weak-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--cream);
}
.weak-card .weak-def {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.weak-card .weak-extra {
  font-size: 0.68rem;
  color: var(--gold-light);
  margin-top: 0.1rem;
}
.weak-card.can-break {
  border-color: var(--rose);
  animation: pulse-border 1.5s infinite;
}

/* 弱點連動特效 */
.weak-card.link-pulse {
  animation: linkPulse 0.7s ease;
}
@keyframes linkPulse {
  0% { box-shadow: 0 0 0 0 rgba(212,165,116,0); border-color: rgba(255,255,255,0.1); }
  35% { box-shadow: 0 0 12px 2px rgba(212,165,116,0.45); border-color: var(--gold-light); background: rgba(212,165,116,0.12); }
  100% { box-shadow: 0 0 0 0 rgba(212,165,116,0); }
}
.fx-float.combo {
  color: #ffd28a;
  font-size: 1.2rem;
}
.fx-float.link {
  color: #a8d4ff;
  font-size: 1rem;
}

/* =========================================================
   UI Polish v2 — 美工統一調整
   原則：呼吸感、對齊、層次、不貼邊、資訊密度適中
   ========================================================= */

/* 整體內距：左右留白，避免貼邊 */
.app {
  padding: 0.7rem 0.85rem 1.25rem !important;
  max-width: 420px !important;
}

#screen-battle.active {
  padding-bottom: 0.15rem !important;
}

/* ----- 弱點區域 ----- */
.zone {
  border-radius: 12px !important;
  padding: 0.5rem 0.55rem 0.55rem !important;
  margin-bottom: 0 !important;
}
.zone-title {
  font-size: 0.78rem !important;
  margin-bottom: 0.4rem !important;
  gap: 0.35rem !important;
}
.zone-title small {
  font-size: 0.68rem !important;
  opacity: 0.85;
}
.weakness-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 0.35rem !important;
}
.weak-card {
  padding: 0.4rem 0.3rem !important;
  border-radius: 9px !important;
  background: rgba(255,255,255,0.05) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
}
.weak-card .weak-name {
  font-size: 0.74rem !important;
  letter-spacing: 0.02em;
}
.weak-card .weak-def {
  font-size: 0.66rem !important;
  margin-top: 0.12rem !important;
}
.weak-card .weak-extra {
  font-size: 0.62rem !important;
  margin-top: 0.08rem !important;
}
.def-bar {
  height: 3px !important;
  margin-top: 0.28rem !important;
  border-radius: 2px !important;
  background: rgba(0,0,0,0.28) !important;
}

/* ----- 中央狀態區塊 ----- */
.battle-center-block {
  margin: 0 !important;
  padding: 0.35rem 0.45rem 0.3rem !important;
  border-radius: 12px !important;
  background: rgba(0,0,0,0.18) !important;
  border: 1px solid rgba(255,255,255,0.07) !important;
}
.battle-heroes {
  grid-template-columns: 52px 1fr 52px !important;
  gap: 0.45rem !important;
  margin-bottom: 0 !important;
  align-items: center !important;
}
.battle-center-block .hero-img {
  width: 52px !important;
  height: 68px !important;
  border-radius: 9px !important;
  border-width: 1.5px !important;
}
.hero-name {
  font-size: 0.65rem !important;
  margin-top: 0.2rem !important;
  opacity: 0.9;
}
.turn-pill {
  font-size: 0.78rem !important;
  padding: 0.2rem 0.65rem !important;
  letter-spacing: 0.06em;
}
.battle-center-block .gold-bar-wrap {
  height: 18px !important;
  border-radius: 10px !important;
}
.gold-text {
  font-size: 0.72rem !important;
}
.battle-center-block .center-info {
  padding: 0.1rem 0 0 !important;
  font-size: 0.78rem !important;
  min-height: 0 !important;
}

/* ----- 手牌區：縮小、不貼邊 ----- */
.hand-area {
  margin-left: 0 !important;
  margin-right: 0 !important;
  margin-top: 0.25rem !important;
  padding: 0.45rem 0.15rem calc(0.55rem + env(safe-area-inset-bottom, 0px)) !important;
  border-top: 1px solid rgba(255,255,255,0.06) !important;
  background: linear-gradient(to top, rgba(26,15,20,0.98) 75%, rgba(26,15,20,0.85) 100%) !important;
  border-radius: 14px 14px 0 0;
}
.hand-top-row {
  padding: 0 0.2rem 0.15rem !important;
  margin-bottom: 0.15rem !important;
}
.mp-display {
  font-size: 0.75rem !important;
  margin-bottom: 0 !important;
  letter-spacing: 0.06em;
}
.hand-hint {
  font-size: 0.65rem !important;
  opacity: 0.65 !important;
}

.hand-cards {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 0.3rem !important;
  padding: 0.15rem 0.2rem 0.35rem !important;
  width: 100% !important;
  overflow: visible !important;
}

.hand-card {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  min-height: 64px !important;
  padding: 0.35rem 0.28rem !important;
  border-radius: 9px !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  background: rgba(255,255,255,0.06) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.hand-card.selected {
  transform: translateY(-3px) !important;
  border-color: var(--gold-light) !important;
  background: rgba(212,165,116,0.12) !important;
  box-shadow: 0 4px 12px rgba(212,165,116,0.28) !important;
}
.hand-card .card-name {
  font-size: 0.62rem !important;
  line-height: 1.2 !important;
  margin-bottom: 0.1rem !important;
}
.hand-card .card-meta {
  font-size: 0.54rem !important;
  line-height: 1.2 !important;
}
.hand-card-empty {
  min-height: 64px !important;
  border: 1px dashed rgba(255,255,255,0.12) !important;
  background: rgba(0,0,0,0.12) !important;
  box-shadow: none !important;
  opacity: 0.5 !important;
}
.hand-card-empty .card-empty-label {
  font-size: 0.68rem !important;
}

/* ----- 底部按鈕 ----- */
.battle-actions {
  gap: 0.45rem !important;
  padding: 0 0.2rem !important;
  margin-top: 0.1rem !important;
}
.battle-actions .btn {
  min-height: 44px !important;
  font-size: 0.95rem !important;
  border-radius: 12px !important;
  padding: 0.7rem 0.8rem !important;
}

/* ----- 小螢幕再收斂 ----- */
@media (max-width: 380px) {
  .app { padding: 0.55rem 0.7rem 1rem !important; }
  .battle-heroes { grid-template-columns: 48px 1fr 48px !important; }
  .battle-center-block .hero-img { width: 48px !important; height: 62px !important; }
  .hand-cards { gap: 0.25rem !important; padding: 0.1rem 0.15rem 0.3rem !important; }
  .hand-card, .hand-card-empty { min-height: 58px !important; padding: 0.28rem 0.2rem !important; }
  .hand-card .card-name { font-size: 0.58rem !important; }
  .hand-card .card-meta { font-size: 0.5rem !important; }
  .zone { padding: 0.4rem 0.45rem 0.45rem !important; }
  .weak-card .weak-name { font-size: 0.68rem !important; }
}

/* 超時扣幣提示 */
.overtime-panel {
  margin: 0.75rem 0;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  background: rgba(232, 80, 80, 0.12);
  border: 1px solid rgba(232, 80, 80, 0.4);
  text-align: center;
}
.overtime-panel.hidden { display: none !important; }
.overtime-title {
  font-weight: 600;
  color: #ffaaaa;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}
.overtime-rate {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--danger);
  font-family: 'Noto Serif TC', serif;
}
.overtime-gold {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold-light);
  margin-top: 0.25rem;
}
.overtime-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.45rem;
}


/* 金幣條強制可見 */
.battle-status-center {
  width: 100%;
  min-width: 0;
}
.battle-status-center .gold-bar-wrap,
.battle-center-block .gold-bar-wrap {
  width: 100% !important;
  height: 26px !important;
  min-height: 26px !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  border: 1.5px solid rgba(212,165,116,0.6) !important;
  background: rgba(0,0,0,0.5) !important;
}
.gold-text {
  color: #fff8e7 !important;
  font-size: 0.75rem !important;
  font-weight: 700 !important;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9) !important;
}

.gold-label {
  font-size: 0.68rem;
  color: var(--gold-light);
  letter-spacing: 0.08em;
  margin: 0.1rem 0 0.15rem;
  opacity: 0.95;
}
.battle-status-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  min-width: 0;
}

/* 確保隱藏彈窗不會擋住下方按鈕 */
.modal.hidden {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}
