:root {
  --bg0: #120c07;
  --bg1: #1b120a;
  --panel: #24170e;
  --panel2: #2d1d11;
  --line: #5b4025;
  --line2: #8b6838;
  --gold: #f0c674;
  --gold2: #b8863b;
  --text: #f6e8cb;
  --muted: #c8ac7f;
  --danger: #e4574d;
  --green: #89c06f;
  --blue: #7da7d9;
  --shadow: 0 10px 24px rgba(0, 0, 0, .35);
  --serif: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif SC", serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: PingFang SC, Microsoft YaHei, sans-serif;
  touch-action: none;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 214, 140, .08), transparent 30%),
    radial-gradient(circle at 80% 90%, rgba(120, 60, 20, .12), transparent 35%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .015) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #1c120a, #0d0906);
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* =========================
   背景装饰
========================= */

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.bg-1 {
  background: radial-gradient(circle at 50% 0%, rgba(255, 219, 150, .12), transparent 36%);
}

.bg-2 {
  background: radial-gradient(circle at 50% 110%, rgba(0, 0, 0, .52), transparent 42%);
}

.bg-3 {
  opacity: .18;
  background: repeating-linear-gradient(90deg, rgba(255, 235, 190, .05) 0 1px, transparent 1px 72px);
}

.bg-seal {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: min(38vw, 220px);
  color: rgba(255, 214, 140, .045);
  letter-spacing: 2vw;
  transform: rotate(-8deg);
  font-weight: 900;
}

/* =========================
   通用屏幕
========================= */

.screen {
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.screen-enter {
  animation: screenFade .35s ease;
}

@keyframes screenFade {
  from {
    opacity: .35;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#mapScreen {
  overflow-y: auto;
  padding: 14px;
  gap: 12px;
}

#battleScreen {
  overflow: hidden;
}

h1 {
  font-size: 30px;
  text-align: center;
  margin-top: 12px;
  font-family: var(--serif);
  color: var(--gold);
  letter-spacing: 8px;
  text-shadow:
    0 0 16px rgba(240, 198, 116, .25),
    0 2px 0 rgba(0, 0, 0, .6);
}

.sub {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.5;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

/* =========================
   面板
========================= */

.panel {
  background:
    linear-gradient(180deg, rgba(255, 224, 170, .04), transparent 18%),
    linear-gradient(180deg, #28190d, #1d1208);
  border: 1px solid #664726;
  border-radius: 16px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 160, .05),
    var(--shadow);
}

.panel::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(180deg, #8b6838, #4d3316);
  opacity: .65;
  pointer-events: none;
}

.panel h3 {
  font-size: 16px;
  color: var(--gold);
  margin-bottom: 8px;
  font-family: var(--serif);
  letter-spacing: 3px;
  border-bottom: 1px dashed rgba(240, 198, 116, .25);
  padding-bottom: 6px;
}

.panel button {
  width: 100%;
  margin-bottom: 8px;
}

.panel button:last-child {
  margin-bottom: 0;
}

#mapStats {
  font-size: 14px;
  line-height: 1.8;
  color: #ead8b2;
}

#mapNodes {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#mapRelics {
  font-size: 13px;
  line-height: 1.7;
  color: #e6cf9f;
}

/* =========================
   按钮
========================= */

button {
  min-height: 46px;
  border: 1px solid #7a5a2e;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 236, 190, .08), transparent 22%),
    linear-gradient(180deg, #4a3115, #2b1c0c);
  color: #ffe9bd;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow:
    inset 0 1px 0 rgba(255, 230, 180, .14),
    inset 0 -2px 0 rgba(0, 0, 0, .3),
    0 6px 14px rgba(0, 0, 0, .26);
  white-space: normal;
  line-height: 1.3;
  padding: 8px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .5);
  transition: filter .14s ease, transform .14s ease, box-shadow .14s ease;
}

button:active {
  transform: translateY(1px) scale(.99);
  filter: brightness(1.08);
}

button:disabled {
  opacity: .42;
  filter: grayscale(.35);
}

#resetRunBtn {
  background:
    linear-gradient(180deg, rgba(255, 120, 90, .08), transparent 24%),
    linear-gradient(180deg, #5a2317, #34110b);
  border-color: #a15638;
}

/* =========================
   地图节点
========================= */

.nodeBtn {
  position: relative;
  padding: 13px 12px 13px 56px;
  text-align: left;
  font-size: 16px;
  background:
    linear-gradient(90deg, rgba(255, 214, 140, .07), rgba(255, 214, 140, 0) 26%),
    linear-gradient(180deg, #362310, #241609);
  border-color: #8a6430;
}

.nodeBtn small {
  display: block;
  font-size: 12px;
  color: #b49669;
  font-weight: 500;
  margin-top: 4px;
}

.nodeIcon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(0, 0, 0, .22);
  border-radius: 10px;
  border: 1px solid rgba(240, 198, 116, .18);
  box-shadow: inset 0 1px 0 rgba(255, 235, 190, .08);
}

/* =========================
   战斗顶部
========================= */

#top {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 4px;
  font-size: 12px;
  color: #d8c39a;
}

.stat {
  background:
    linear-gradient(180deg, rgba(255, 235, 190, .05), transparent 24%),
    linear-gradient(180deg, #2d1d10, #20130a);
  border: 1px solid #6a4b26;
  border-radius: 10px;
  padding: 6px 7px;
  min-width: 54px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 225, 170, .08);
}

.stat span {
  color: var(--gold);
  font-weight: 800;
}

/* =========================
   血条
========================= */

#bars {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.barWrap {
  position: relative;
  height: 26px;
  border-radius: 12px;
  overflow: hidden;
  background: #160d07;
  border: 1px solid #6a4b26;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .5);
}

.barWrap span {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  z-index: 2;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}

.bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  transition: width .2s ease;
}

#baseBar {
  background: linear-gradient(90deg, #3b7f5f, #95cf7d);
  box-shadow: 0 0 14px rgba(122, 204, 122, .28);
}

#enemyBar {
  background: linear-gradient(90deg, #a12c22, #ff8c42);
  box-shadow: 0 0 14px rgba(255, 111, 60, .24);
}

/* =========================
   战场提示
========================= */

#banner {
  margin: 0 12px 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background:
    linear-gradient(90deg, rgba(255, 209, 102, .16), rgba(255, 209, 102, .08));
  border: 1px solid rgba(240, 198, 116, .42);
  color: #ffe8a3;
  font-size: 13px;
  line-height: 1.5;
  min-height: 46px;
  font-family: var(--serif);
  letter-spacing: .5px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .03),
    0 8px 18px rgba(0, 0, 0, .18);
}

#banner.ready {
  animation: bannerPulse 1.4s infinite;
}

@keyframes bannerPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(240, 198, 116, .35);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(240, 198, 116, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(240, 198, 116, 0);
  }
}

/* =========================
   棋盘
========================= */

#boardWrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  margin: 2px 8px 8px;
  padding: 6px;
  position: relative;
  border-radius: 20px;
  background:
    radial-gradient(circle at center, rgba(255, 220, 160, .04), rgba(0, 0, 0, .16)),
    linear-gradient(180deg, #22150b, #150d06);
  border: 1px solid #664726;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 170, .04),
    inset 0 0 42px rgba(0, 0, 0, .42),
    var(--shadow);
}

#boardWrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 20px;
  background: radial-gradient(circle at center, transparent 55%, rgba(0, 0, 0, .34) 100%);
}

canvas {
  display: block;
  background: transparent;
  border-radius: 16px;
  touch-action: none;
  filter: saturate(1.05) contrast(1.05);
}

/* =========================
   控制按钮
========================= */

#controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 8px 12px;
}

#controls button {
  font-size: 12px;
}

#recommendBtn {
  background: linear-gradient(180deg, #375735, #22351f);
  border-color: #78a86d;
}

#resolveBtn {
  background: linear-gradient(180deg, #7d2d1d, #47150d);
  border-color: #d06a45;
}

#ultimateBtn {
  background: linear-gradient(180deg, #5c4084, #34204e);
  border-color: #a67ce0;
}

#endBtn {
  background: linear-gradient(180deg, #32506f, #1d2f43);
  border-color: #7da7d9;
}

#resolveBtn.ready,
#ultimateBtn.ready {
  animation: readyPulse 1.2s infinite;
}

@keyframes readyPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(240, 198, 116, .45);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(240, 198, 116, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(240, 198, 116, 0);
  }
}

/* =========================
   手牌
========================= */

#hand {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px 6px;
  min-height: 136px;
  scrollbar-width: none;
}

#hand::-webkit-scrollbar {
  display: none;
}

.card {
  flex: 0 0 auto;
  width: 94px;
  min-height: 118px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 236, 190, .06), transparent 24%),
    linear-gradient(180deg, #28190d, #171008);
  border: 2px solid #353c4b;
  padding: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow:
    0 10px 18px rgba(0, 0, 0, .32),
    inset 0 1px 0 rgba(255, 235, 190, .08);
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

.card:hover {
  transform: translateY(-4px) scale(1.02);
}

.card.selected {
  border-color: var(--gold) !important;
  box-shadow:
    0 0 0 2px rgba(240, 198, 116, .66),
    0 0 24px rgba(240, 198, 116, .28);
}

.card.disabled {
  filter: grayscale(.6) brightness(.72);
}

.card .cost {
  position: absolute;
  right: -6px;
  top: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, #fff3cf, #f0c674 42%, #9a6a24);
  color: #311d08;
  font-weight: 900;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  border: 1px solid #74511d;
  box-shadow:
    0 3px 7px rgba(0, 0, 0, .4),
    inset 0 1px 0 rgba(255, 255, 255, .5);
}

.card .name {
  font-size: 10px;
  color: #e9d6ab;
  text-align: center;
  min-height: 14px;
  font-family: var(--serif);
  letter-spacing: .5px;
}

.card .conn {
  font-size: 11px;
  text-align: center;
  color: #99d68a;
  min-height: 14px;
  font-weight: 700;
}

.card .desc {
  font-size: 9px;
  color: #ab9167;
  line-height: 1.35;
  min-height: 34px;
}

.card .ends {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.end {
  height: 31px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-weight: 900;
  font-size: 18px;
  color: #101010;
  border: 1px solid rgba(0, 0, 0, .28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .24),
    inset 0 -3px 0 rgba(0, 0, 0, .18);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .2);
}

.end small {
  font-size: 12px;
  opacity: .82;
}

/* =========================
   消息
========================= */

#msg {
  padding: 6px 12px 10px;
  min-height: 40px;
  max-height: 58px;
  overflow: hidden;
  font-size: 13px;
  color: #bfa77b;
  display: flex;
  flex-direction: column-reverse;
}

#msg div {
  line-height: 1.35;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .5);
}

/* =========================
   弹窗
========================= */

.modalBase {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
  z-index: 99;
  padding: 24px;
}

.modalBase.show {
  display: flex;
}

.modalPanel {
  width: 100%;
  max-width: 400px;
  max-height: 88vh;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(255, 230, 180, .06), transparent 20%),
    linear-gradient(180deg, #2b1b0e, #190f07);
  border: 1px solid #83602f;
  border-radius: 22px;
  padding: 24px 18px;
  text-align: center;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, .5),
    inset 0 0 0 1px rgba(255, 225, 170, .06);
}

.modalPanel h2 {
  font-size: 26px;
  margin-bottom: 12px;
  font-family: var(--serif);
  color: var(--gold);
  letter-spacing: 4px;
  text-shadow: 0 0 18px rgba(240, 198, 116, .24);
}

.modalPanel p {
  color: #c8ac7f;
  font-size: 14px;
  margin-bottom: 18px;
  line-height: 1.6;
  white-space: pre-line;
}

.modalActions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modalActions button {
  width: 100%;
  min-height: 52px;
  background: linear-gradient(180deg, #8a5d23, #5b3a12);
  border: 1px solid #d8a857;
  color: #fff2d0;
  font-size: 14px;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, .26),
    inset 0 1px 0 rgba(255, 240, 200, .2);
}

.modalActions button:disabled {
  background: #4b4136;
  border-color: #655947;
  color: #9d917c;
}

/* =========================
   牌库
========================= */

.deckControls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.deckControls button {
  background: linear-gradient(180deg, #3a2712, #241507);
}

.deckList {
  max-height: 52vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  padding-right: 2px;
}

.deckItem {
  background:
    linear-gradient(180deg, rgba(255, 235, 190, .04), transparent 20%),
    linear-gradient(180deg, #26170d, #190f07);
  border: 1px solid #6a4b26;
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: inset 0 1px 0 rgba(255, 225, 170, .05);
}

.deckItem b {
  color: var(--gold);
}

/* =========================
   卡牌详情
========================= */

.cardDetailBody {
  text-align: left;
  font-size: 14px;
  line-height: 1.75;
  background:
    linear-gradient(180deg, rgba(255, 235, 190, .04), transparent 18%),
    #10131a;
  border: 1px solid #6a4b26;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.cardDetailEnds {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.cardDetailEnd {
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-weight: 900;
  font-size: 20px;
  color: #101010;
  border: 1px solid rgba(0, 0, 0, .25);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .25),
    inset 0 -3px 0 rgba(0, 0, 0, .18);
}

/* =========================
   大招演出
========================= */

#ultOverlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  opacity: 0;
  z-index: 200;
  transition: opacity .18s ease;
}

#ultOverlay.show {
  opacity: 1;
  background:
    radial-gradient(circle at center, rgba(255, 214, 140, .12), transparent 32%),
    rgba(0, 0, 0, .62);
}

.ultBox {
  text-align: center;
  transform: scale(.7);
  animation: ultPop .9s ease forwards;
  filter: drop-shadow(0 0 28px rgba(255, 209, 102, .35));
}

#ultHero {
  font-size: 24px;
  color: #f4e7ce;
  letter-spacing: 6px;
  margin-bottom: 8px;
  font-family: var(--serif);
  text-shadow: 0 0 18px rgba(255, 209, 102, .5);
}

#ultName {
  font-size: 58px;
  font-weight: 900;
  color: var(--gold);
  font-family: var(--serif);
  text-shadow:
    0 0 28px rgba(255, 209, 102, .8),
    0 3px 0 rgba(0, 0, 0, .65);
  margin-bottom: 10px;
}

#ultDesc {
  font-size: 16px;
  color: #d8d2c4;
  letter-spacing: 1px;
}

@keyframes ultPop {
  0% {
    transform: scale(.6);
    opacity: 0;
  }
  25% {
    transform: scale(1.12);
    opacity: 1;
  }
  55% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* =========================
   回放
========================= */

#replayCanvas {
  border: 1px solid #6a4b26;
  border-radius: 14px;
  background: #0e0a06;
}

#replayInfo {
  white-space: pre-line;
  text-align: left;
  margin-bottom: 10px;
  color: #d9c294;
  font-size: 13px;
  line-height: 1.55;
}

/* =========================
   震动
========================= */

#battleScreen.shake {
  animation: screenShake .5s ease;
}

@keyframes screenShake {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 2px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
  100% { transform: translate(0, 0); }
}