* { box-sizing: border-box; }

:root {
  --cell: clamp(22px, min(calc((100vw - 350px) / 13), calc((100dvh - 160px) / 13)), 110px);
  --gap: 2px;
  --bg: #0a0e16;
  --panel: #131a29;
  --panel2: #19223a;
  --line: #26324c;
  --text: #e8eefb;
  --muted: #7f8ca6;
  --blue: #4a8cff;
  --red: #ff5d5d;
  --gold: #f0c05a;
  --cream: #f3ead3;
  --mauve: #c9a2b4;
  --green: #46d18b;
}

html, body { height: 100%; }

body {
  margin: 0;
  background:
    linear-gradient(rgba(64, 128, 220, .08) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(90deg, rgba(64, 128, 220, .08) 1px, transparent 1px) 0 0 / 36px 36px,
    radial-gradient(1200px 800px at 50% -10%, #f4fbff 0%, #d8ecff 55%, #c4e2ff 100%);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(8, 26, 52, .20) 100%);
}

body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: repeating-linear-gradient(0deg, rgba(10, 40, 80, .03) 0 1px, transparent 1px 3px);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 8px;
  gap: 8px;
  overflow: hidden;
}

/* 框：左栏 + 棋盘 + 右栏 */
.frame { flex: 1; display: flex; gap: 8px; min-height: 0; }

.side { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.side.left {
  width: 96px; background: rgba(9, 18, 34, .55);
  border: 1px solid rgba(120, 160, 220, .22); border-radius: 14px; padding: 8px;
}
.side.right { width: 200px; transition: width .2s ease; }
.side.left .energy { margin-top: auto; }
.side.right .icon-btn { align-self: flex-end; }

/* ---------- 左栏 ---------- */

.turn { font-size: 12px; font-weight: 700; letter-spacing: .2px; line-height: 1.5; white-space: nowrap; }
.turn .side { display: block; width: fit-content; margin-top: 3px; padding: 1px 6px; border-radius: 999px; font-size: 10px; color: #0b1020; }
.turn .side.p0 { background: var(--blue); }
.turn .side.p1 { background: var(--red); }

.hps { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.hps .p0 { color: var(--blue); }
.hps .p1 { color: var(--red); }
.hps b { color: var(--text); }

.energy {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.energy .e-val {
  display: flex; align-items: center; gap: 4px;
  font-size: 20px; font-weight: 700; color: var(--gold); line-height: 1.1;
}
.energy .e-val .ic { width: 18px; height: 18px; }
.energy .e-lab { font-size: 9px; color: var(--muted); white-space: nowrap; }

/* ---------- 右栏 ---------- */

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); font-size: 16px; cursor: pointer;
}
.icon-btn:hover { background: var(--panel2); }

.log-panel {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
}
.log-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; background: transparent; border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px; font-size: 11px; color: var(--muted);
  cursor: pointer; font-family: inherit; text-align: left;
  flex: 0 0 auto;
}
.log-head:hover { color: var(--text); }
.log-chev { transition: transform .15s; }

/* 横向收起：右栏收成一条竖条，棋盘使用让出的宽度 */
.app.log-collapsed { --cell: clamp(22px, min(calc((100vw - 210px) / 13), calc((100dvh - 160px) / 13)), 110px); }
.app.log-collapsed .side.right { width: 44px; }

.log-panel.collapsed .log-body { display: none; }
.log-panel.collapsed .log-head {
  flex: 1; width: 100%; height: 100%;
  flex-direction: column; justify-content: flex-start; align-items: center;
  gap: 10px; padding: 12px 0;
  writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 2px;
  border-bottom: 0;
}
.log-panel.collapsed .log-chev { transform: rotate(180deg); }
.log-body { flex: 1; overflow-y: auto; padding: 6px 8px; font-size: 11px; line-height: 1.55; color: #aab6cc; }
.log-m { font-weight: 700; }
.coop { color: #ff2d2d; font-weight: 800; }
.log-line { padding: 3px 0 3px 7px; border-left: 2px solid transparent; }
.log-line.p0 { border-left-color: var(--blue); }
.log-line.p1 { border-left-color: var(--red); }
.log-line.sys { border-left-color: #44506a; color: var(--muted); }

/* ---------- 棋盘 ---------- */

.stage {
  flex: 1; display: flex; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: rgba(74, 140, 255, .45) transparent;
  touch-action: pan-y;
}
.stage::-webkit-scrollbar { width: 6px; }
.stage::-webkit-scrollbar-thumb { background: rgba(74, 140, 255, .4); border-radius: 3px; }
.stage.panning { cursor: grabbing; }

.board {
  --cell-w: clamp(28px, calc((100vw - 380px) / 13), 84px);
  width: 100%;
  aspect-ratio: 3 / 4;
  height: auto;
  align-self: flex-start;
  flex: 0 0 auto;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-template-rows: repeat(13, 1fr);
  gap: var(--gap);
  padding: 6px;
  background: transparent;
  border: 1px solid rgba(74, 140, 255, .25);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(30, 80, 160, .12);
  flex: 0 0 auto;
}

.cell {
  width: 100%; height: 100%;
  background: rgba(255, 255, 255, .22); border: 1px solid #000; border-radius: 6px;
  position: relative; cursor: pointer;
  transition: background .1s;
}
.cell.alt { background: rgba(255, 255, 255, .06); }
.cell::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 0;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .45), inset 0 -2px 3px rgba(20, 50, 90, .16);
}
.cell > .token { z-index: 2; }
.cell.reach { background: rgba(74, 140, 255, .25); box-shadow: inset 0 0 0 2px rgba(74, 140, 255, .55); }
.cell.drop-ok { box-shadow: inset 0 0 0 2px rgba(70, 209, 139, .85); }
.cell.parasite { background: rgba(255, 179, 71, .28); box-shadow: inset 0 0 0 2px rgba(255, 179, 71, .9); }
.cell.summon { background: rgba(70, 209, 139, .22); box-shadow: inset 0 0 0 2px rgba(70, 209, 139, .7); }
.cell.target { background: rgba(255, 93, 93, .22); box-shadow: inset 0 0 0 2px rgba(255, 93, 93, .8); }
.cell.ability { background: rgba(143, 208, 240, .25); box-shadow: inset 0 0 0 2px rgba(143, 208, 240, .75); }
.cell.zone-fog::before, .cell.snow::before, .cell.zone-sun::before, .cell.zone-moon::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
}
.cell.zone-fog::before {
  background:
    radial-gradient(circle at 30% 40%, rgba(0, 0, 0, .92), transparent 55%),
    radial-gradient(circle at 70% 70%, rgba(0, 0, 0, .85), transparent 60%);
  animation: fogDrift 7s ease-in-out infinite alternate;
}
.cell.snow::before {
  background-image:
    radial-gradient(rgba(180, 220, 255, .9) 1px, transparent 1.3px),
    radial-gradient(rgba(200, 235, 255, .7) 1px, transparent 1.2px);
  background-size: 14px 18px, 21px 26px;
  background-position: 0 0, 7px 9px;
  opacity: .5;
  animation: snowDrift 7s linear infinite;
}
.cell.zone-sun::before {
  background: radial-gradient(circle at 50% 50%, rgba(255, 230, 150, .6), transparent 70%);
  animation: sunPulse 3s ease-in-out infinite;
}
.cell.zone-moon::before {
  background: radial-gradient(circle at 35% 35%, rgba(235, 230, 255, .75), transparent 65%);
  animation: moonGlow 4s ease-in-out infinite;
}
@keyframes fogDrift {
  0% { transform: translate(0, 0) scale(1); opacity: .85; }
  100% { transform: translate(3px, -2px) scale(1.08); opacity: 1; }
}
@keyframes snowDrift {
  0% { background-position: 0 0, 7px 9px; }
  100% { background-position: 0 18px, 7px 35px; }
}
@keyframes sunPulse {
  0%, 100% { opacity: .5; transform: scale(.95); }
  50% { opacity: .9; transform: scale(1.05); }
}
@keyframes moonGlow {
  0%, 100% { opacity: .45; }
  50% { opacity: .85; }
}
.turn-banner {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%);
  padding: 10px 30px; border-radius: 999px; z-index: 80; pointer-events: none;
  font-size: 18px; font-weight: 800; letter-spacing: 1px;
  background: rgba(10, 18, 34, .88); border: 1px solid var(--line);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  animation: bannerFx 1.5s ease forwards;
}
.turn-banner.p0 { color: var(--blue); }
.turn-banner.p1 { color: var(--red); }
@keyframes bannerFx {
  0% { opacity: 0; transform: translate(-50%, -14px) scale(.92); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(.98); }
}
.energy.gain { animation: energyGlow .7s ease; }
@keyframes energyGlow {
  0% { box-shadow: 0 0 0 rgba(255, 215, 107, 0); }
  40% { box-shadow: 0 0 18px rgba(255, 215, 107, .7); }
  100% { box-shadow: 0 0 0 rgba(255, 215, 107, 0); }
}
.energy.gain .e-val { animation: energyPop .6s ease; }
@keyframes energyPop {
  40% { transform: scale(1.25); color: #fff3c4; }
}
.app.shake { animation: screenShake .35s ease; }
@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, -1px); }
  80% { transform: translate(2px, 1px); }
}
.cell.zone-fog { background: #101010; }
.cell.zone-moon { background: linear-gradient(135deg, #f3f4fb 0%, #cdd2ee 100%); }
.cell.zone-sun { background: #f5a623; }
.cell.snow { background: #fff; }
.cell.snow, .cell.zone-fog, .cell.zone-sun, .cell.zone-moon {
  outline: 1px solid rgba(40, 70, 120, .22); outline-offset: -1px;
}

.token { position: absolute; z-index: 1; }

.token.char {
  inset: 8%;
  border-radius: 9px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700;
  background: linear-gradient(160deg, #4a8cff, #2f5fd0);
  box-shadow: 0 0 0 2px var(--gold), 0 2px 10px rgba(0, 0, 0, .5);
}
.token.char.p1 { background: linear-gradient(160deg, #ff6b6b, #d63b3b); }
.token.char .face { font-size: calc(var(--cell-w) * .45); line-height: 1; }
.token.char .hp { font-size: calc(var(--cell-w) * .26); opacity: .9; }

.token.monster {
  inset: 4%;
  border-radius: 8px;
  background-color: var(--faction);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.token.monster.p0 { box-shadow: inset 0 0 0 2px var(--blue), 0 2px 8px rgba(0, 0, 0, .5); }
.token.monster.p1 { box-shadow: inset 0 0 0 2px var(--red), 0 2px 8px rgba(0, 0, 0, .5); }
.token.monster .hp {
  position: absolute; right: 2px; bottom: 2px;
  font-size: calc(var(--cell-w) * .26);
  background: rgba(0, 0, 0, .5); color: #fff;
  border-radius: 4px; padding: 0 3px; line-height: 1.35;
}

.token.sel { outline: 2px solid #fff; outline-offset: 2px; }
.token.attacking { animation: lungeFx .32s ease; }
@keyframes lungeFx {
  0% { transform: translate(0, 0); }
  40% { transform: translate(var(--dx, 0), var(--dy, 0)); }
  100% { transform: translate(0, 0); }
}
.token.hit { animation: hitFx .34s ease; }
@keyframes hitFx {
  0%, 100% { filter: none; transform: translateX(0); }
  25% { filter: brightness(1.5) sepia(1) saturate(3) hue-rotate(-30deg); transform: translateX(-2px); }
  55% { transform: translateX(2px); }
}
.token.hit .hp { animation: hpBump .35s ease; }
@keyframes hpBump {
  40% { transform: scale(1.35); color: #ff6b6b; }
}
.token .hp { display: inline-block; }
.hpbar {
  position: absolute; left: 10%; right: 10%; bottom: 2px; height: 4px;
  border-radius: 2px; background: rgba(0, 0, 0, .45); overflow: hidden;
  z-index: 3; pointer-events: none;
}
.hpbar i { display: block; height: 100%; background: #4ade80; transition: width .25s; }
.hpbar.mid i { background: #fbbf24; }
.hpbar.low i { background: #ef4444; }
.dmg-float {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  color: #ff5d5d; font-weight: 800; font-size: 15px;
  text-shadow: 0 1px 2px #000; pointer-events: none; z-index: 6;
  animation: dmgFloat .8s ease-out forwards;
}
@keyframes dmgFloat {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(.7); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(.95); }
}
.summon-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid #ffd76b; pointer-events: none; z-index: 4;
  animation: ringFx .7s ease-out forwards;
}
@keyframes ringFx {
  0% { transform: scale(.25); opacity: .95; }
  100% { transform: scale(1.35); opacity: 0; }
}
.fly-card {
  position: fixed; border-radius: 8px; background-size: cover; background-position: center;
  z-index: 90; pointer-events: none; box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  transition: transform .5s cubic-bezier(.2, .8, .3, 1), opacity .5s;
}
.token.sel::after {
  content: ''; position: absolute; inset: -6px; border-radius: 12px;
  border: 2px solid rgba(70, 209, 139, .9);
  animation: selPulse 1.4s ease-out infinite; pointer-events: none;
}
@keyframes selPulse {
  0% { transform: scale(.85); opacity: .9; }
  70% { transform: scale(1.18); opacity: 0; }
  100% { opacity: 0; }
}

.token.parasite { opacity: .55; outline: 2px dashed #c9a2b4; outline-offset: -2px; }
.token .tag-p {
  position: absolute; left: 2px; top: 2px;
  font-size: calc(var(--cell-w) * .24); line-height: 1.2;
  background: #c9a2b4; color: #2a1d24; border-radius: 3px; padding: 0 2px;
}

/* ---------- 阵营 ---------- */

.f-instinct { --faction: #fdf3dd; --ink: #2a2118; --glow: #fff3d6; }
.f-good { --faction: #ffd76b; --ink: #3a2c10; --glow: #ffe08a; }
.f-malice { --faction: #cdb9e0; --ink: #2a1d33; --glow: #e0d2ee; }

/* ---------- 底部卡片条 ---------- */

.bottom {
  flex: 0 0 98px; display: flex; gap: 10px; align-items: flex-end; min-width: 0;
  background: rgba(9, 18, 34, .55); border: 1px solid rgba(120, 160, 220, .22);
  border-radius: 14px; padding: 6px 10px;
}

.hands { flex: 1 1 0; min-width: 0; display: flex; justify-content: center; gap: 12px; overflow-x: auto; padding-bottom: 2px; }
.hand-group { flex: 0 0 auto; display: flex; flex-direction: column; gap: 4px; }
.hand-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.card-slots { display: flex; gap: 4px; }

.slot {
  width: 58px; height: 80px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .38);
  background: rgba(255, 255, 255, .16);
  display: flex; flex-direction: column; overflow: hidden;
  padding: 0; cursor: pointer; position: relative;
  font-family: inherit;
}
.slot.empty {
  background: rgba(255, 255, 255, .55);
  border-color: rgba(255, 255, 255, .75);
}
.slot.filled { background: var(--faction); color: var(--ink); border-color: rgba(255, 255, 255, .38); }
.slot-art {
  height: 52px; flex: 0 0 auto; margin-top: 6px;
  background-size: contain; background-position: center 60%; background-repeat: no-repeat;
}
.slot-name {
  font-size: 9px; font-weight: 700; text-align: center; color: var(--faction);
  padding: 2px 0; white-space: nowrap; overflow: hidden;
}
.slot.pickable { box-shadow: 0 0 0 2px var(--green); }
.slot.active { box-shadow: 0 0 0 2px var(--green), 0 0 10px rgba(70, 209, 139, .5); }
.slot.pick { box-shadow: 0 0 0 2px var(--green); background: rgba(70, 209, 139, .14); }
.slot.glow {
  z-index: 3;
  animation: slotGlow 1.6s ease-in-out infinite;
}
@keyframes slotGlow {
  0%, 100% { box-shadow: 0 0 0 2px var(--green), 0 0 12px 3px var(--glow); }
  50% { box-shadow: 0 0 0 2px var(--green), 0 0 26px 10px var(--glow); }
}

.end-turn {
  flex: 0 0 auto;
  background: var(--blue); border: 0; border-radius: 10px;
  color: #fff; font-size: 13px; font-weight: 700;
  padding: 12px 18px; cursor: pointer; font-family: inherit;
}
.end-turn:hover { filter: brightness(1.08); }

/* ---------- 树状菜单 ---------- */

.menu-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

.unit-tree {
  position: absolute;
  display: flex; align-items: center; gap: 24px;
  padding: 4px; pointer-events: auto;
}
.unit-tree.mirror { flex-direction: row-reverse; }

.tree-col { display: flex; flex-direction: column; gap: 6px; }

.tnode {
  border: 0; border-radius: 8px;
  padding: 7px 12px; font-size: 12px; font-weight: 700;
  color: #2a1d24; cursor: pointer; font-family: inherit;
  white-space: nowrap; position: relative; z-index: 1;
}
.tnode.action { background: var(--cream); }
.tnode.name { background: var(--faction); color: var(--ink); }
.tnode.move, .tnode.sub { background: var(--mauve); }
.tnode.sub.long { white-space: normal; text-align: left; max-width: 150px; line-height: 1.35; }
.tnode:disabled { opacity: .35; cursor: not-allowed; }

.tree-lines {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; overflow: visible;
}

/* ---------- 浮条 ---------- */

.move-chip {
  position: fixed; left: 50%; bottom: 112px;
  transform: translateX(-50%) translateY(8px);
  background: var(--mauve); color: #2a1d24;
  border: 0; border-radius: 999px;
  padding: 9px 18px; font-size: 12px; font-weight: 700;
  cursor: pointer; opacity: 0; pointer-events: none;
  transition: .15s; z-index: 35; font-family: inherit;
}
.move-chip.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

/* ---------- 卡片正反面 ---------- */

.card-modal {
  position: fixed; inset: 0; background: rgba(4, 7, 13, .82);
  display: none; align-items: center; justify-content: center;
  z-index: 70;
}
.card-modal.show { display: flex; }

.card-close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); font-size: 20px; cursor: pointer; z-index: 2;
}

.card-big {
  width: 270px; height: 420px;
  background: linear-gradient(180deg, #1b2438, #121828);
  border: 1px solid #35466a; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  overflow: hidden; cursor: pointer; position: relative;
}

.cb-face { display: flex; flex-direction: column; height: 100%; }
#cardBig { perspective: 1000px; }
.cb-flip {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .5s ease;
}
.cb-flip.flipped { transform: rotateY(180deg); }
.cb-flip-front, .cb-flip-back {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.cb-flip-back { transform: rotateY(180deg); }
.cb-art {
  height: 210px; margin-top: 10px;
  background-color: var(--faction);
  background-size: contain; background-position: center 60%; background-repeat: no-repeat;
}
.cb-name { font-size: 20px; font-weight: 800; padding: 12px 16px 2px; color: var(--faction); }
.cb-sub { font-size: 11px; color: var(--muted); padding: 0 16px; }
.cb-stats {
  display: grid; grid-template-columns: repeat(4, auto);
  justify-content: start; gap: 6px 10px;
  padding: 10px 16px 4px; font-size: 12px; font-weight: 600;
}
.cb-stats span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.cb-stats .ic { width: 14px; height: 14px; }
.cb-cost {
  padding: 0 16px 6px; font-size: 11px; color: var(--muted);
  display: flex; align-items: center; gap: 5px;
}
.cb-cost b { color: var(--text); font-size: 12px; display: inline-flex; align-items: center; gap: 3px; }
.cb-hint { margin-top: auto; padding: 10px 16px; font-size: 10px; color: var(--muted); text-align: center; }

.cb-back { background: #141b2b; }
.cb-title { font-size: 10px; letter-spacing: 1px; color: var(--muted); padding: 12px 16px 6px; }
.cb-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; padding: 0 16px; font-size: 12px; }
.cb-panel div { display: flex; justify-content: space-between; align-items: center; }
.cb-panel span { color: var(--muted); }
.cb-panel b { display: inline-flex; align-items: center; gap: 4px; }

.cb-abilities { padding: 0 16px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.ab { background: #19223a; border: 1px solid #26324c; border-radius: 8px; padding: 7px 9px; }
.ab-head { font-size: 12px; font-weight: 700; }
.ab-tag { display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 4px; margin-right: 5px; vertical-align: 1px; }
.ab-tag.active { background: var(--mauve); color: #2a1d24; }
.ab-tag.passive { background: #3b5bdb; color: #fff; }
.ab-text { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 3px; }

/* ---------- 图例 ---------- */

.ic { width: 12px; height: 12px; fill: currentColor; vertical-align: -2px; }
.tic { display: inline-flex; width: 13px; height: 13px; vertical-align: -2px; }
.tic .ic { width: 100%; height: 100%; }
.ic.hp { color: #e0555f; }
.ic.def { color: #c9a227; }
.ic.atk { color: #cfd6e4; }
.ic.spd { color: #6fc7e8; }
.ic.energy { color: #6b8cff; }

/* ---------- 能力飘字 ---------- */

.ability-pop {
  position: fixed; transform: translate(-50%, -100%);
  color: #fff; font-size: 11px; font-weight: 700; white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9);
  pointer-events: none; z-index: 80;
  animation: abilityPop 1s ease-out forwards;
}
@keyframes abilityPop {
  0% { opacity: 0; transform: translate(-50%, -86%) scale(.9); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}

/* ---------- 解离碎片 ---------- */

.shard {
  position: fixed; width: 4px; height: 4px; border-radius: 1px;
  pointer-events: none; z-index: 75;
  animation: shatter .8s ease-out forwards;
}
@keyframes shatter {
  from { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(180deg) scale(.2); opacity: 0; }
}

/* ---------- 弹层 ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(4, 7, 13, .72);
  display: none; align-items: center; justify-content: center; z-index: 90;
}
.overlay.show { display: flex; }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 26px 34px; text-align: center; min-width: 260px;
}
.overlay-card h2 { margin: 0 0 8px; font-size: 22px; }
.overlay-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.btn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 18px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #22304d; }

.toast {
  position: fixed; left: 50%; bottom: 108px;
  transform: translateX(-50%) translateY(10px);
  background: #2a1720; border: 1px solid #7a2b3a; color: #ffb4c0;
  padding: 8px 16px; border-radius: 10px; font-size: 12px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 95;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 窄屏 ---------- */

/* ---------- 左栏按钮 ---------- */

.rail-btn {
  flex: 0 0 auto; margin-top: 8px; padding: 6px 4px;
  background: #131a29; color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  font-size: 11px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.rail-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ---------- 选怪 / 图鉴弹层 ---------- */

.pick, .gal {
  width: min(980px, 94vw); max-height: 90vh;
  background: linear-gradient(180deg, #141c2e, #0f1624);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
  padding: 18px 20px; display: flex; flex-direction: column; overflow: hidden;
}
.pick h2, .gal-head h2 { margin: 0; font-size: 16px; }
.pick-hint { margin: 4px 0 12px; font-size: 11px; color: var(--muted); }
.pick-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; overflow-y: auto; padding: 2px;
}
.pick-search, .gal-search { display: flex; justify-content: center; padding: 2px 0 10px; }
.pick-search input, .gal-search input {
  width: min(320px, 72%); padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #0e1522; color: var(--text);
  font-size: 12px; font-family: inherit; outline: none;
}
.pick-search input:focus, .gal-search input:focus { border-color: var(--blue); }
.pick-pager {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 8px 0 2px; font-size: 12px; color: var(--muted);
}
.pick-pager input {
  width: 52px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line);
  background: #0e1522; color: var(--text); text-align: center; font-family: inherit;
}
.pick-card {
  position: relative; text-align: left; font-family: inherit;
  background: #131a29; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 0 8px; cursor: pointer; color: var(--text); overflow: hidden;
}
.pick-card .pc-art {
  display: block; height: 92px; background-color: var(--faction);
  background-size: contain; background-position: center; background-repeat: no-repeat;
}
.pick-card .pc-name { display: block; font-size: 12px; font-weight: 700; margin: 6px 8px 0; }
.pick-card .pc-sub { display: block; font-size: 10px; color: var(--muted); margin: 2px 8px 0; }
.pick-card.on { border-color: var(--green); box-shadow: 0 0 0 2px var(--green); }
.pick-card .pc-check {
  position: absolute; right: 6px; top: 6px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--green); color: #06231a;
  font-size: 13px; font-weight: 800; line-height: 20px; text-align: center;
}
.pick-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.pick-foot span { font-size: 12px; color: var(--muted); }
.pick-actions { display: flex; gap: 8px; }
.pi-card {
  width: min(520px, 92vw); max-height: 80vh; overflow-y: auto;
  background: linear-gradient(180deg, #141c2e, #0f1624);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
}
.pi-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pi-head h3 { margin: 0; font-size: 18px; }
.pi-sub { font-size: 11px; color: var(--muted); margin: 6px 0 12px; }
.pi-ab { margin-bottom: 10px; }
.pi-ab-head { font-size: 13px; font-weight: 700; display: flex; gap: 6px; align-items: center; }
.pi-ab .ab-tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; }
.pi-ab .ab-text { font-size: 11px; color: var(--muted); line-height: 1.6; margin-top: 4px; }
.btn.primary { background: var(--green); color: #06231a; border-color: transparent; }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.gal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.gal-grid {
  display: grid; grid-template-columns: repeat(auto-fill, 200px);
  gap: 14px; overflow-y: auto; padding: 2px; justify-content: center;
}
.gcard { width: 200px; height: 300px; perspective: 900px; cursor: pointer; outline: none; }
.gcard-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .45s; }
.gcard.flipped .gcard-inner { transform: rotateY(180deg); }
.gface {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 12px;
  overflow: hidden; border: 1px solid var(--line);
  background: linear-gradient(180deg, #1b2438, #121828);
  display: flex; flex-direction: column;
}
.gback { transform: rotateY(180deg); }
.gfront .gart {
  height: 168px; background-color: var(--faction);
  background-size: contain; background-position: center; background-repeat: no-repeat;
}
.gfront .gname { font-size: 14px; font-weight: 800; padding: 8px 10px 0; color: var(--faction); }
.gfront .gsub { font-size: 10px; color: var(--muted); padding: 2px 10px 0; }
.ghint { margin-top: auto; text-align: center; font-size: 9px; color: var(--muted); padding: 6px; }
.gtitle { font-size: 9px; letter-spacing: 1px; color: var(--muted); padding: 8px 10px 4px; }
.gpanel { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; padding: 0 10px; font-size: 11px; }
.gpanel div { display: flex; justify-content: space-between; }
.gpanel span { color: var(--muted); }
.gabs { padding: 0 10px; display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.gab { background: #19223a; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }
.gab b { font-size: 10px; }
.gab .tag { font-size: 8px; padding: 0 3px; border-radius: 3px; margin-right: 3px; }
.gab .tag.active { background: #c9a2b4; color: #2a1d24; }
.gab .tag.passive { background: #3b5bdb; color: #fff; }
.gab p { margin: 2px 0 0; font-size: 9px; color: var(--muted); line-height: 1.45; }

/* 特殊区域名词与说明 */

.atk-bonus { font-style: normal; color: var(--green); font-size: 10px; font-weight: 800; margin-left: 2px; }
.zone-term {
  text-decoration: underline;
  text-decoration-color: #fff;
  text-underline-offset: 2px;
  cursor: pointer;
}
.zone-card {
  width: min(420px, 90vw);
  background: linear-gradient(180deg, #141c2e, #0f1624);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
}
.zone-swatch {
  width: 46px; height: 46px; border-radius: 10px;
  margin: 0 auto; border: 1px solid var(--line);
}
.zone-card h3 { margin: 10px 0 6px; font-size: 16px; }
.zone-card p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.zone-card .btn { margin-top: 12px; }
.fog-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.parasite-cells { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.parasite-cell {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #16203a; color: var(--text); cursor: pointer; font-family: inherit;
}
.parasite-cell:hover { background: var(--panel2); }
.multi-layer { position: fixed; inset: 0; display: none; z-index: 70; }
.multi-layer.show { display: block; }
.multi-menu {
  position: fixed; width: 200px; background: #141c2e; border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.multi-item {
  display: flex; gap: 8px; align-items: center; width: 100%;
  background: none; border: 0; color: var(--text); padding: 6px;
  border-radius: 8px; cursor: pointer; text-align: left; font-family: inherit;
}
.multi-item:hover { background: rgba(255, 255, 255, .07); }
.mi-art { width: 36px; height: 36px; border-radius: 6px; background-size: cover; background-position: center; flex: 0 0 auto; }
.mi-info { display: flex; flex-direction: column; font-size: 11px; }
.mi-info i { color: var(--muted); font-style: normal; font-size: 10px; }
.stack {
  position: absolute; left: 2px; top: 2px; z-index: 3;
  background: #ff5d5d; color: #fff; font-size: 9px; font-weight: 800;
  border-radius: 7px; padding: 0 4px; line-height: 14px; pointer-events: none;
}

.rules-card {
  width: min(640px, 94vw); max-height: 86vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #141c2e, #0f1624);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
}
.rules-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.rules-head h2 { margin: 0; font-size: 18px; }
.rules-body {
  overflow-y: auto; padding: 12px 18px 18px;
  font-size: 12px; line-height: 1.7; color: var(--muted);
}
.rules-body h3 { color: var(--text); font-size: 13px; margin: 14px 0 4px; }
.rules-body p { margin: 3px 0; }
.rules-body b { color: var(--text); }

.app.ratio-23 .board { aspect-ratio: 2 / 3; }
.app.ratio-34 .board { aspect-ratio: 3 / 4; }
.app.ratio-11 .board { aspect-ratio: 1 / 1; }
.settings-card { width: min(440px, 92vw); text-align: left; }
.settings-card h3 { margin: 0 0 6px; font-size: 18px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0; }
.setting-row > span { font-size: 12px; color: var(--muted); }
.ratio-btns { display: flex; gap: 6px; }
.ratio-btn { padding: 5px 8px; font-size: 11px; }
.ratio-btn.on, .art-btn.on, .guide-btn.on { border-color: var(--green); color: var(--green); }
#panToggle.on { border-color: var(--green); color: var(--green); }
.settings-card #settingsClose { margin-top: 10px; }

/* 无限·不定形态弹层 */

.swap {
  width: min(860px, 94vw); max-height: 90vh;
  background: linear-gradient(180deg, #141c2e, #0f1624);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px; display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
}
.swap h2 { margin: 0; font-size: 16px; }
.swap-hint { margin: 4px 0 12px; font-size: 11px; color: var(--muted); }
.swap-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; overflow-y: auto; max-height: 60vh; }
.swap-col { display: flex; flex-direction: column; gap: 6px; }
.swap-col-title { font-size: 11px; color: var(--muted); }
.swap-ab {
  text-align: left; background: #19223a; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; color: var(--text);
  cursor: pointer; font-family: inherit;
}
.swap-ab.on { border-color: var(--green); box-shadow: 0 0 0 2px var(--green); }
.swap-ab b { font-size: 12px; }
.swap-ab p { margin: 3px 0 0; font-size: 10px; color: var(--muted); line-height: 1.45; }
.swap-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* ---------- 中等宽度：仍然是框式，只收窄两侧 ---------- */

@media (max-width: 1000px) and (min-width: 521px) {
  :root { --cell: clamp(20px, min(calc((100vw - 300px) / 13), calc((100dvh - 160px) / 13)), 90px); }
  .app.log-collapsed { --cell: clamp(20px, min(calc((100vw - 186px) / 13), calc((100dvh - 160px) / 13)), 90px); }
  .side.left { width: 72px; }
  .side.right { width: 150px; }
  .turn { font-size: 11px; }
  .hps { font-size: 10px; }
  .energy { padding: 6px 2px; }
  .energy .e-val { font-size: 17px; }
  .log-head { padding: 6px 8px; }
  .log-body { font-size: 10px; }
}

/* ---------- 手机：堆叠 ---------- */

@media (max-width: 520px) {
  :root { --cell: clamp(22px, calc((100vw - 58px) / 13), 64px); }
  .app.log-collapsed { --cell: clamp(22px, calc((100vw - 58px) / 13), 64px); }
  .app.log-collapsed .side.right { width: auto; }
  .log-panel.collapsed { flex: 0 0 auto; }
  .log-panel.collapsed .log-head {
    flex: 0 0 auto; width: auto; height: auto;
    flex-direction: row; justify-content: space-between; align-items: center;
    writing-mode: horizontal-tb; letter-spacing: 0; gap: 8px; padding: 8px 10px;
  }
  .log-panel.collapsed .log-chev { transform: rotate(90deg); }

  .frame { flex-direction: column; }
  .side.left { width: auto; flex-direction: row; align-items: center; gap: 10px; }
  .side.left .turn { font-size: 12px; }
  .side.left .hps { flex-direction: row; gap: 8px; font-size: 11px; }
  .side.left .energy { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 5px; padding: 4px 10px; }
  .side.left .energy .e-val { font-size: 16px; }
  .side.right { width: auto; flex-direction: row; align-items: flex-start; }
  .side.right .icon-btn { align-self: flex-start; }
  .log-panel { flex: 1; max-height: 22vh; }
  .bottom { flex: 0 0 auto; flex-wrap: wrap; gap: 8px; }
  .hands { flex: 1 0 100%; }
  .end-turn { flex: 1 0 100%; padding: 10px 12px; font-size: 12px; }
  .slot { width: 44px; height: 64px; }
  .slot-art { height: 42px; }
  .slot-name { font-size: 8px; }
  .card-big { width: 244px; height: 384px; }
  .cb-art { height: 190px; }
}



































/* ===== 木制棋盘与背景 ===== */
body {
  background:
    radial-gradient(ellipse at 50% 8%, #f6e6c6 0%, #d9b483 30%, #a9743f 62%, #6b3f1e 85%, #3a2312 100%);
}
.bg-deco {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.bg-deco i { position: absolute; inset: 0; display: block; }
.bg-grid {
  background:
    repeating-linear-gradient(90deg, rgba(60, 30, 10, .12) 0 2px, transparent 2px 110px),
    repeating-linear-gradient(0deg, rgba(255, 220, 160, .05) 0 1px, transparent 1px 34px);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 40%, transparent 88%);
  mask-image: radial-gradient(ellipse at center, #000 40%, transparent 88%);
}
.bg-glow {
  background: radial-gradient(700px 500px at 50% 22%, rgba(255, 225, 170, .55), transparent 72%);
}
.bg-sweep { display: none; }
.bg-dust {
  background-image:
    radial-gradient(rgba(255, 235, 200, .75) 1px, transparent 1.4px),
    radial-gradient(rgba(200, 160, 110, .5) 1px, transparent 1.4px);
  background-size: 90px 110px, 140px 170px;
  animation: dustFx 30s linear infinite;
  opacity: .45;
}
@keyframes dustFx {
  0% { background-position: 0 0, 0 0; }
  100% { background-position: 20px -120px, -30px -180px; }
}
.bg-grain {
  background-image: radial-gradient(rgba(60, 35, 15, .08) 1px, transparent 1.2px);
  background-size: 5px 5px;
  opacity: .5;
}
.app { position: relative; z-index: 1; }
.stage { position: relative; }
.stage::before {
  content: ''; position: absolute; inset: 4%; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255, 220, 160, .35), transparent 70%);
  filter: blur(22px);
}
.board {
  background:
    repeating-linear-gradient(90deg, rgba(80, 45, 18, .18) 0 2px, transparent 2px 46px),
    repeating-linear-gradient(0deg, rgba(255, 240, 210, .06) 0 1px, transparent 1px 7px),
    linear-gradient(160deg, #c99a5b 0%, #b07f45 45%, #8f5e2c 100%);
  border: 10px solid #4a2c15;
  border-radius: 10px;
  padding: 10px;
  box-shadow:
    inset 0 0 40px rgba(50, 25, 8, .55),
    inset 0 0 0 2px rgba(255, 220, 160, .18),
    0 24px 60px rgba(30, 15, 5, .55);
  position: relative;
  z-index: 1;
  align-self: flex-start;
  flex: 0 0 auto;
  margin: 0 auto;
  width: 100%;
  aspect-ratio: 3 / 4;
  height: auto;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-template-rows: repeat(13, 1fr);
  gap: var(--gap);
}
.board::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background-image:
    repeating-linear-gradient(88deg, rgba(60, 30, 10, .08) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(2deg, rgba(255, 230, 190, .03) 0 1px, transparent 1px 5px);
  opacity: .8;
}
.cell {
  border-color: rgba(55, 30, 12, .75);
  background: rgba(255, 235, 200, .13);
  border-radius: 4px;
}
.cell.alt { background: rgba(80, 45, 18, .10); }
.cell:hover { background: rgba(255, 235, 200, .28); box-shadow: 0 2px 6px rgba(40, 20, 8, .35); }
.cell.spawn0 { box-shadow: inset 0 0 0 2px rgba(90, 160, 255, .75); }
.cell.spawn1 { box-shadow: inset 0 0 0 2px rgba(255, 110, 100, .75); }

/* ===== 透明棋盘（原版） ===== */
body.art-clear {
  background:
    linear-gradient(rgba(64, 128, 220, .08) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(90deg, rgba(64, 128, 220, .08) 1px, transparent 1px) 0 0 / 36px 36px,
    radial-gradient(1200px 800px at 50% -10%, #f4fbff 0%, #d8ecff 55%, #c4e2ff 100%);
}
body.art-clear .bg-deco { display: none; }
body.art-clear .stage::before { display: none; }
body.art-clear .board {
  background: transparent;
  border: 1px solid rgba(74, 140, 255, .25);
  border-radius: 14px;
  padding: 6px;
  box-shadow: none;
}
body.art-clear .board::before { display: none; }
body.art-clear .cell {
  border-color: #000;
  background: rgba(255, 255, 255, .22);
  border-radius: 6px;
}
body.art-clear .cell.alt { background: rgba(255, 255, 255, .06); }
body.art-clear .cell:hover { background: rgba(255, 255, 255, .28); box-shadow: none; }
body.art-clear .cell.spawn0, body.art-clear .cell.spawn1 { box-shadow: none; }


/* ===== 指引框颜色 ===== */
body {
  --guide-bg: rgba(232, 180, 90, .24);
  --guide-line: rgba(232, 180, 90, .90);
}
body.art-clear {
  --guide-bg: rgba(74, 140, 255, .25);
  --guide-line: rgba(74, 140, 255, .85);
}
body.guide-blue {
  --guide-bg: rgba(74, 140, 255, .25);
  --guide-line: rgba(74, 140, 255, .85);
}
body.guide-gold {
  --guide-bg: rgba(232, 180, 90, .24);
  --guide-line: rgba(232, 180, 90, .90);
}
.cell.reach, .cell.summon, .cell.drop-ok, .cell.parasite, .cell.target, .cell.ability {
  background: var(--guide-bg);
  box-shadow: inset 0 0 0 2px var(--guide-line);
}
