:root {
  --main: #FF8A3D;
  --main-dark: #E86A1C;
  --main-soft: #FFE7D6;
  --ink: #2A1B10;
  --ink-2: #6B5546;
  --ink-3: #A08D7E;
  --bg: #F4EDE4;
  --card: #FFFDF9;
  --line: #EADFD2;
  --red: #E5484D;
  --green: #2FA36B;
  --blue: #3D7BE0;
  --gold: #F5B93C;
  --shadow: 0 6px 18px rgba(120, 78, 40, .12);
  --shadow-sm: 0 2px 8px rgba(120, 78, 40, .10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
body { overflow: hidden; }

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% 0%, #FFD9BC 0%, rgba(255, 217, 188, 0) 62%),
    linear-gradient(180deg, #FFF3E6 0%, #F4EDE4 46%, #EFE4D6 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

/* ============ HUD ============ */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  gap: 10px;
}
.hud-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(160deg, #FFB27A, var(--main));
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(255, 138, 61, .35);
  flex: 0 0 auto;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .mp-icon { font-size: 22px; }
.hud-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nick {
  font-size: 15px; font-weight: 700; letter-spacing: .2px;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lv { font-size: 11px; color: var(--ink-3); }
.lv b { color: var(--main-dark); font-size: 12px; }

.hud-right { display: flex; align-items: center; gap: 8px; }
.coin {
  display: flex; align-items: center; gap: 5px;
  background: #FFF6E3; border: 1px solid #F3DFB4;
  border-radius: 999px; padding: 5px 11px 5px 8px;
  font-size: 13px; font-weight: 700; color: #8A5A12;
  box-shadow: var(--shadow-sm);
}
.coin .mp-icon { font-size: 16px; color: var(--gold); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--ink-2); display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: transform .12s ease;
}
.icon-btn .mp-icon { font-size: 18px; }
.icon-btn:active { transform: scale(.92); }
.icon-btn.off { color: var(--ink-3); opacity: .6; }

/* ============ 战场 ============ */
.battle {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 4px 16px 0;
  position: relative;
}

.enemy-side { display: flex; justify-content: center; }
.player-side { display: flex; justify-content: center; }

.enemy-card, .player-card {
  width: 100%;
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.enemy-card {
  background: linear-gradient(150deg, #FFF6F4 0%, #FFEDE9 100%);
  border: 1px solid #F3D2CB;
  box-shadow: var(--shadow);
}
.player-card {
  background: linear-gradient(150deg, #FFFDF9 0%, #FFF3E6 100%);
  border: 1px solid #F5DCC4;
  box-shadow: var(--shadow);
}

.enemy-portrait, .player-portrait {
  width: 58px; height: 58px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto; color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}
.enemy-portrait { background: linear-gradient(160deg, #FF8B7E, #D8453C); }
.player-portrait { background: linear-gradient(160deg, #FFB27A, var(--main)); }
.enemy-portrait .mp-icon, .player-portrait .mp-icon { font-size: 30px; }

.enemy-meta, .player-meta {
  display: flex; flex-direction: column; gap: 3px;
  flex: 1 1 auto; min-width: 0;
}
.enemy-name, .player-name {
  font-size: 16px; font-weight: 800; letter-spacing: .3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.enemy-tag, .player-tag {
  font-size: 11px; color: var(--ink-3);
  align-self: flex-start;
  background: rgba(255, 255, 255, .7);
  border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 8px;
}

.hpbar {
  position: absolute; left: 14px; right: 14px; bottom: 10px;
  height: 8px; border-radius: 999px;
  background: #EFE3D6; overflow: hidden;
}
.hpfill {
  height: 100%; width: 100%; border-radius: 999px;
  transition: width .32s cubic-bezier(.3, .9, .4, 1);
}
.hpfill.enemy { background: linear-gradient(90deg, #FF7A6E, #E5484D); }
.hpfill.player { background: linear-gradient(90deg, #FFB27A, var(--main)); }
.hptext {
  position: absolute; right: 14px; bottom: 22px;
  font-size: 11px; font-weight: 700; color: var(--ink-3);
}

.vs-row {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 2px 0;
}
.vs-badge {
  font-size: 12px; font-weight: 900; letter-spacing: 1px;
  color: #fff; background: linear-gradient(160deg, #FFA96B, var(--main-dark));
  border-radius: 999px; padding: 3px 12px;
  box-shadow: 0 3px 10px rgba(232, 106, 28, .35);
}
.combo {
  font-size: 12px; color: var(--ink-2);
  background: rgba(255, 255, 255, .8);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px;
}
.combo b { color: var(--main-dark); font-size: 13px; }
.combo.hot { border-color: #FFC79A; background: #FFF3E6; }

/* ============ 手牌 ============ */
.hand-wrap {
  flex: 0 0 auto;
  padding: 6px 16px 0;
}
.hand-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 2px 6px;
}
.hand-title { font-size: 13px; font-weight: 800; color: var(--ink); }
.hand-hint { font-size: 11px; color: var(--ink-3); }

.hand {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  scrollbar-width: none;
}
.hand::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 auto;
  width: 96px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 8px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer;
  position: relative;
  transition: transform .14s cubic-bezier(.3, .9, .4, 1), box-shadow .14s ease;
  user-select: none;
}
.card:active { transform: translateY(2px) scale(.97); box-shadow: var(--shadow-sm); }
.card.disabled { opacity: .45; pointer-events: none; filter: grayscale(.4); }
.card .cost {
  position: absolute; top: -6px; left: -6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(160deg, #6FA8FF, var(--blue));
  color: #fff; font-size: 12px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(61, 123, 224, .4);
}
.card .art {
  width: 100%; height: 52px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.card .art .mp-icon { font-size: 26px; }
.card .cname { font-size: 13px; font-weight: 800; letter-spacing: .2px; }
.card .cdesc { font-size: 10px; color: var(--ink-3); text-align: center; line-height: 1.35; min-height: 26px; }
.card .dmg {
  font-size: 11px; font-weight: 800; color: var(--main-dark);
  background: var(--main-soft); border-radius: 999px; padding: 1px 8px;
}

/* ============ 底部 ============ */
.footer {
  flex: 0 0 auto;
  display: flex; gap: 10px;
  padding: 4px 16px 14px;
}
.btn-main, .btn-ghost {
  border: none; border-radius: 14px;
  font-size: 15px; font-weight: 800; letter-spacing: .4px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease;
  font-family: inherit;
}
.btn-main {
  flex: 1 1 auto;
  height: 50px;
  color: #fff;
  background: linear-gradient(160deg, #FFA96B, var(--main-dark));
  box-shadow: 0 8px 20px rgba(232, 106, 28, .32);
}
.btn-main .mp-icon { font-size: 19px; }
.btn-main:active { transform: translateY(2px) scale(.985); box-shadow: 0 4px 12px rgba(232, 106, 28, .28); }
.btn-main.big { width: 100%; height: 52px; margin-top: 4px; }
.btn-ghost {
  flex: 0 0 auto; width: 92px; height: 50px;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.btn-ghost .mp-icon { font-size: 17px; }
.btn-ghost:active { transform: translateY(2px) scale(.985); }

/* ============ 飘字 ============ */
.float-layer {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
.float-num {
  position: absolute; font-size: 20px; font-weight: 900;
  color: var(--red); text-shadow: 0 2px 6px rgba(255, 255, 255, .9);
  animation: floatUp .85s ease-out forwards;
  transform: translate(-50%, -50%);
}
.float-num.heal { color: var(--green); }
.float-num.crit { font-size: 26px; color: #FF5A1F; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); }
  25% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}

.shake { animation: shake .3s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* ============ 遮罩 ============ */
.overlay {
  position: absolute; inset: 0;
  background: rgba(42, 27, 16, .48);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 20;
  transition: opacity .22s ease;
}
.overlay.hide { opacity: 0; pointer-events: none; }
.overlay-card {
  width: 100%; max-width: 330px;
  background: var(--card);
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px rgba(42, 27, 16, .28);
  padding: 22px 20px 20px;
  text-align: center;
}
.overlay-icon {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: 16px;
  background: linear-gradient(160deg, #FFB27A, var(--main));
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(255, 138, 61, .38);
}
.overlay-icon .mp-icon { font-size: 28px; }
.overlay-card h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: .5px; }
.overlay-card p { margin: 0; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.ov-stats {
  display: flex; justify-content: center; gap: 10px;
  margin: 14px 0 4px;
}
.ov-stat {
  flex: 1 1 0;
  background: #FFF6EC; border: 1px solid #F5DCC4;
  border-radius: 12px; padding: 8px 6px;
}
.ov-stat .v { display: block; font-size: 17px; font-weight: 900; color: var(--main-dark); }
.ov-stat .k { display: block; font-size: 10px; color: var(--ink-3); margin-top: 2px; }

@media (max-height: 640px) {
  .enemy-portrait, .player-portrait { width: 48px; height: 48px; }
  .enemy-portrait .mp-icon, .player-portrait .mp-icon { font-size: 24px; }
  .card .art { height: 42px; }
  .footer { padding-bottom: 10px; }
}
