/* style.css — 自走棋对战
   竖屏优先（参考原版 720×1554 比例），上下分屏。
   主题：水墨 + 卷轴，配色取自视频逐帧。 */

:root {
  --ink:        #1d1a16;
  --ink-soft:   #4a443c;
  --paper:      #e8e2d2;
  --paper-dark: #d8cfba;
  --grid-light: #f5f1e6;   /* 可放置格 */
  --grid-dark:  #7d8578;   /* 障碍格 */
  --grid-empty: #c9c3b2;
  --self-bg:    #c46b6b;   /* 我方半场：红 */
  --opp-bg:     #6b86b5;   /* 敌方半场：蓝 */
  --gold:       #c9a227;
  --hp:         #c0392b;
  --hp-bg:      #3a3530;
  --split:      #8b6f47;
  --accent:     #b8392f;
  --ok:         #4a7c59;
  --warn:       #b8860b;
  --radius:     8px;
  --shadow:     0 2px 8px rgba(29,26,22,.22);
}

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

html, body {
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  background: #23201c;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  width: 100%; height: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--paper);
  display: flex; flex-direction: column;
  overflow: hidden;      /* 防止子元素撑破容器 */
}

/* ── 对战界面：不用 .screen 的滚动布局，棋盘必须精确占满剩余空间 ── */
#screen-game {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;   /* 对战界面不滚动，否则棋盘高度算不出来 */
  padding: 0;
  gap: 0;
}

/* ── 通用 ───────────────────────────────── */
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-dark);
  color: var(--ink);
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s, filter .12s;
}
.btn:active { transform: translateY(1px); filter: brightness(.94); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: #7d241c; }
.btn-ghost   { background: transparent; box-shadow: none; }

/* ── 大厅 ───────────────────────────────── */
.screen {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  padding: 20px; gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
}
/* 所有直接子元素不许超出容器宽度（修过：输入框/按钮右侧被切掉） */
.screen > * { max-width: 100%; min-width: 0; }

.logo { text-align: center; padding: 18px 0 6px; }
.logo h1 {
  font-size: 40px; letter-spacing: 8px; font-weight: 900;
  color: var(--ink);
  text-shadow: 2px 2px 0 var(--paper-dark), 4px 4px 0 rgba(29,26,22,.14);
}
.logo p { margin-top: 8px; font-size: 13px; color: var(--ink-soft); letter-spacing: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.field input {
  padding: 12px 14px; min-height: 44px;
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--grid-light); color: var(--ink);
  font-size: 17px; font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }
.field input.code { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--paper-dark); }

.tip { font-size: 12px; color: var(--ink-soft); line-height: 1.7; }

/* ── 顶栏 ─────────────────────────────────
   原版：左「暂停」圆钮 + 军饷椭圆；中「虎牢关」红字 + 「第N波」黑字白边；
         右「手柄」圆钮 + 系统胶囊。背景是水墨远山。 */
.topbar {
  position: relative;
  display: flex; align-items: flex-start;
  padding: 6px 8px 4px;
  background:
    linear-gradient(#dfe4d8, #d3dac8),
    linear-gradient(#d3dac8, #cbd3be);
  border-bottom: 3px solid #17140f;
  flex-shrink: 0;
  min-height: 62px;
}
/* 远山剪影 */
.topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 26px;
  background:
    radial-gradient(60px 22px at 22% 100%, rgba(122,138,118,.55) 0 60%, transparent 61%),
    radial-gradient(80px 26px at 62% 100%, rgba(110,126,106,.45) 0 60%, transparent 61%);
  pointer-events: none;
}
.topbar .pause-btn,
.topbar .pad-btn {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(23,20,15,.55);
  background: rgba(70,76,66,.55);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.topbar .pad-btn { font-size: 15px; }
.topbar .left-cluster { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; z-index: 2; }
.topbar .right-cluster { display: flex; align-items: center; gap: 6px; z-index: 2; }

/* 军饷：白色椭圆 + 黑底描边数字（原版特征） */
.gold {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 10px 1px 4px;
  background: #fff;
  border: 2px solid #17140f;
  border-radius: 16px;
  font-weight: 800; font-size: 15px;
  color: #17140f;
  font-variant-numeric: tabular-nums;
  position: relative;
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
.gold .coin {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffdf5, #e4dcc8);
  border: 1px solid #6f6a5c;
  box-shadow: inset -1px -1px 2px rgba(0,0,0,.18);
}
/* 系统胶囊：白底 … ⊙ */
.sys-capsule {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 9px;
  background: #fff;
  border: 2px solid #17140f;
  border-radius: 14px;
  z-index: 2;
}
.sys-capsule i { width: 5px; height: 5px; border-radius: 50%; background: #17140f; display: block; }
.sys-capsule .ring {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid #17140f;
  position: relative;
}
.sys-capsule .ring::after {
  content: ""; position: absolute; inset: 3px;
  background: #17140f; border-radius: 50%;
}

.round-info {
  flex: 1; text-align: center; line-height: 1.15; z-index: 2;
  padding-top: 1px;
}
/* 虎牢关：红色手写感 + 白边 */
.round-info .stage {
  font-size: clamp(17px, 5.4vw, 25px);
  font-weight: 900;
  color: #b8392f;
  letter-spacing: 2px;
  text-shadow:
    -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff,
    0 2px 2px rgba(0,0,0,.28);
  font-family: "STKaiti", "KaiTi", "PingFang SC", serif;
}
/* 第N波：黑字白边 */
.round-info .round {
  font-size: clamp(12px, 3.8vw, 17px);
  font-weight: 900;
  color: #17140f;
  letter-spacing: 1px;
  text-shadow:
    -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff,
    0 1px 2px rgba(0,0,0,.3);
}
/* 计时器：原版没有显式倒计时，这里放右上角小字，不抢视觉 */
.timer {
  position: absolute; right: 8px; top: 42px;
  font-size: 12px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #3d3a32;
  padding: 1px 6px; border-radius: 8px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(23,20,15,.35);
  z-index: 3;
}
.timer.urgent { color: #fff; background: var(--accent); border-color: #7d241c; animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: .62; } }

/* ── 棋盘 ─────────────────────────────────
   ★ 实测比例（原版 f_014 抽帧）：格宽 40.1px / 格高 60.0px → 竖长方形 1:1.5
     9 列 × 12 行 → 整体 362 : 720 ≈ 9 : 17.9
     关口列宽 = 1.37 × 格宽
   ★ 用 grid 的 fr 单位表达"格宽 1 / 格高 1.5"，由 aspect-ratio 保证整体比例。 */
.board-wrap {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 4px; min-height: 0; min-width: 0; overflow: hidden;
  /* 水墨底色：米黄纸 + 淡远山 */
  background:
    radial-gradient(120% 60% at 50% 100%, #cdd6c6 0%, #c3cdba 40%, transparent 70%),
    linear-gradient(#e9e5d8, #dfe3d6);
}
/* 三层结构：左关口 | 主棋盘 | 右关口
   ★ 三列宽度的比 = 关口 : 棋盘 : 关口 = 1.37 : 9 : 1.37（实测）
     用无单位 fr 表达（calc() 里不能放 fr，会整条声明失效 → 列宽塌成 0，实测踩过）。 */
.board-frame {
  display: grid;
  grid-template-columns: 1.37fr 9fr 1.37fr;
  grid-template-rows: 100%;
  gap: 0;
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 11.74 / 18;
  margin: 0 auto;
  align-items: stretch;
}
/* 主棋盘：9 列 × 12 行，格子竖长方形（格宽:格高 = 1:1.5） */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(12, 1fr);
  gap: 1px;
  background: #6f6a5e;
  border: 3px solid #17140f;
  padding: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.cell {
  position: relative;
  background: var(--grid-light);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .12s;
  overflow: visible;
}
/* 障碍格：原版是灰绿实心块 #8A9080 */
.cell.obstacle {
  background: #8a9080;
  cursor: default;
  box-shadow: inset 0 0 0 1px #7c8272;
}
.cell.opp-side { background: #f2efe4; }   /* 对手半场：略灰白 */
.cell.self-side { background: var(--grid-light); } /* 自己半场：米白 */
.cell.droppable:hover, .cell.droppable:active { background: #fff8d8; box-shadow: inset 0 0 0 2px var(--gold); }
.cell.not-allowed { cursor: not-allowed; }

/* ── 长城分界线 ──────────────────────────
   压在 splitRow 这一行的上沿：砖纹墙身 + 顶部雉堞齿（一排小方块）。
   用 repeating-linear-gradient 画砖，::before 画雉堞。 */
.cell.wall-top::before,
.gate-cell.wall-top::before {
  content: "";
  position: absolute;
  left: -1px; right: -1px; top: -9px;
  height: 9px;
  background:
    /* 雉堞齿：一排小方块 */
    repeating-linear-gradient(90deg, #4a463c 0 5px, transparent 5px 10px),
    /* 砖纹墙身 */
    repeating-linear-gradient(0deg, #9a8f82 0 4px, #8b8074 4px 5px),
    repeating-linear-gradient(90deg, transparent 0 9px, rgba(60,54,46,.55) 9px 10px);
  background-color: #9a8f82;
  border-top: 1px solid #4a463c;
  border-bottom: 1px solid #4a463c;
  z-index: 5;
  pointer-events: none;
}

/* ── 关口列 ─────────────────────────────
   棋盘外的独立一列：主将「斗」+ 红心 + 关口兵位。
   与主棋盘之间有粗黑边框隔开（原版特征）。 */
.gate {
  display: grid;
  grid-template-rows: repeat(12, 1fr);
  gap: 1px;
  background: #8d9484;
  border: 3px solid #17140f;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.gate.gate-left  { border-right-width: 3px; }
.gate.gate-right { border-left-width: 3px; }

.gate-cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #b9bfaf;
  transition: background .12s;
  overflow: visible;
}
.gate-cell.gate-idle { background: #aab0a0; }
/* 关口兵位：原版是偏红棕的木格 */
.gate.gate-left  .gate-cell.gate-slot { background: #c9a89c; box-shadow: inset 0 0 0 1px #a8837a; }
.gate.gate-right .gate-cell.gate-slot { background: #a8b0c9; box-shadow: inset 0 0 0 1px #7a83a8; }
.gate-cell.gate-slot { cursor: pointer; }
.gate-cell.gate-slot.droppable:hover { background: #fff8d8; box-shadow: inset 0 0 0 2px var(--gold); }
.gate-cell.gate-slot.not-allowed { cursor: not-allowed; }
/* 主将格：底色偏深，突出「斗」 */
.gate-cell.gate-hero-slot { background: #b0b6a6; }

.gate-cell .unit {
  width: 100%; height: 100%;
  border-radius: 0;
  box-shadow: none;
}
.gate-cell .unit .char { font-size: clamp(18px, 6.2vw, 30px); }
/* 主将「斗」：手写体感 + 金色描边 */
.unit.hero-token {
  background: transparent !important;
  box-shadow: none !important;
}
.unit.hero-token .char {
  color: #17140f;
  font-size: clamp(24px, 8.4vw, 42px) !important;
  text-shadow:
    -1.5px -1.5px 0 var(--gold), 1.5px -1.5px 0 var(--gold),
    -1.5px 1.5px 0 var(--gold), 1.5px 1.5px 0 var(--gold),
    0 2px 3px rgba(0,0,0,.35);
}

/* ── 红心血量 ───────────────────────────
   贴在主将格上沿，一排小红心，受伤后变空。 */
.hearts {
  position: absolute;
  left: 50%; top: -3px;
  transform: translate(-50%, -100%);
  display: flex; gap: 1px;
  z-index: 8;
  pointer-events: none;
}
.hearts .heart {
  font-size: clamp(9px, 3.1vw, 15px);
  color: #d1202a;
  line-height: 1;
  text-shadow: 0 0 1px #7d0f14, 0 1px 1px rgba(0,0,0,.3);
}
.hearts .heart.empty {
  color: #6f6a60;
  text-shadow: none;
  opacity: .55;
}

/* 单位 —— 用汉字呈现，贴原版风格（方形浅底 + 深描边） */
.unit {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  font-weight: 900;
  transition: transform .18s ease-out;
}
.unit.self { color: #7d241c; background: #f2d9d5; box-shadow: inset 0 0 0 1.5px #b8392f; }
.unit.opp  { color: #2c4470; background: #d9e2f2; box-shadow: inset 0 0 0 1.5px #3f5f96; }
.unit .char { font-size: clamp(14px, 4.6vw, 26px); line-height: 1; }

/* ★ 同格多单位：模拟器允许敌人穿越、允许近战兵站上敌方主将格，
   所以"一格两兵"是合法状态。.unit 默认 100% 层叠会互相盖住、字叠成乱码，
   这里改成横向并排 + 缩字号，保证两个单位都看得清。 */
.cell.crowded { padding: 0; gap: 0; }
.cell.crowded > .unit,
.gate-cell.crowded > .unit {
  width: auto; flex: 1 1 0; min-width: 0;
}
.cell.crowded > .unit .char { font-size: clamp(8px, 2.6vw, 14px); }
.cell.crowded > .unit .hpbar { left: 0; right: 0; height: 2px; }
.cell.crowded > .unit .star { display: none; }
/* 原版角标：右上角小数字（等级/星级） */
.unit .star {
  position: absolute; top: 0; right: 1px;
  font-size: clamp(7px, 2.4vw, 11px); font-weight: 700;
  color: #17140f; line-height: 1;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
}
.unit .hpbar {
  position: absolute; bottom: 0; left: 3px; right: 3px; height: 3px;
  background: var(--hp-bg); overflow: hidden;
}
.unit .hpbar i { display: block; height: 100%; background: var(--hp); transition: width .2s; }

/* 战斗动画：受击闪红 */
.unit.hit { animation: hitFlash .22s; }
@keyframes hitFlash { 0%,100% { filter: none; } 50% { filter: brightness(1.7) saturate(2); } }
.unit.dying { animation: die .35s forwards; }
@keyframes die { to { opacity: 0; transform: scale(.5) rotate(18deg); } }

/* 飘字（军饷 +N / 伤害） */
.float-text {
  position: absolute; pointer-events: none;
  font-weight: 800; font-size: 14px;
  animation: floatUp 1s ease-out forwards;
  z-index: 20; text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
@keyframes floatUp { to { transform: translateY(-34px); opacity: 0; } }

/* ── 底部操作区（营 + 征兵）────────────────
   原版结构：左侧木牌「营」+ 5 个方格 + 中央大红「征兵」按钮（带花费）。
   没有"开战"按钮 —— 兵是持续投入的，战斗自动进行。 */
.bottom {
  flex-shrink: 0;
  border-top: 3px solid #17140f;
  background:
    linear-gradient(#c6cebb, #bcc5b0);
  padding: 6px 8px 8px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
}
/* 「营」木牌 */
.camp-sign {
  flex-shrink: 0;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: #2b2620;
  border: 2px solid #17140f;
  color: #f0ead8; font-weight: 900; font-size: 19px;
  position: relative;
  box-shadow: 0 2px 0 rgba(0,0,0,.3);
}
/* 木牌屋顶（三角）+ 描边 */
.camp-sign::before {
  content: "";
  position: absolute; left: -4px; right: -4px; top: -9px; height: 9px;
  background: #8a5a3c;
  border: 2px solid #17140f;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
}
.tray-row { display: flex; align-items: center; gap: 6px; }
.tray-row .slots { flex: 1; display: flex; gap: 4px; }
.tray-row .slots .slot {
  flex: 1; aspect-ratio: 1 / 1.1;
  border: 2px solid #17140f;
  background: #e8e4d8;
  display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer;
  min-height: 40px;
  transition: transform .1s, box-shadow .12s;
  box-shadow: 0 2px 0 rgba(0,0,0,.22);
}
.tray-row .slots .slot .char { font-size: clamp(15px, 4.8vw, 26px); font-weight: 900; color: #17140f; }
/* 原版角标：右上小数字 */
.tray-row .slots .slot .star {
  position: absolute; top: 0; right: 2px;
  font-size: 10px; font-weight: 700; color: #17140f;
}
.tray-row .slots .slot.selected {
  box-shadow: 0 0 0 2px var(--gold), 0 2px 0 rgba(0,0,0,.22);
  transform: translateY(-3px);
}
.tray-row .slots .slot.empty { border-style: dashed; border-color: #8a8578; box-shadow: none; cursor: default; background: #dcd8ca; }
.tray-row .slots .slot.disabled { opacity: .42; cursor: not-allowed; }
/* 道具格（铲除）：底色偏黄 */
.tray-row .slots .slot.tool { background: #f0e2b8; }

/* 征兵按钮：大红棕 + 黑粗描边 + 花费 + 进度条（攒够就亮） */
.recruit-wrap { display: flex; justify-content: center; }
.recruit-btn {
  position: relative;
  min-width: 168px; min-height: 54px;
  border: 3px solid #17140f;
  border-radius: 8px;
  background: #8a4038;
  color: #fff;
  font-size: 21px; font-weight: 900;
  letter-spacing: 3px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transition: transform .08s, filter .12s;
}
.recruit-btn:active { transform: translateY(1px); filter: brightness(.95); }
.recruit-btn:disabled { filter: grayscale(.6) brightness(.86); cursor: not-allowed; }
/* 进度条：军饷攒到花费整条点亮 */
.recruit-btn .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(255,255,255,.22);
  transition: width .25s;
  pointer-events: none;
}
.recruit-btn .label { position: relative; z-index: 2; }
.recruit-btn .cost {
  position: relative; z-index: 2;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 15px; letter-spacing: 0;
}
.recruit-btn .cost .coin {
  width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e0, #e8dcc0);
  border: 1px solid #8a7c5c;
}

.hand-hint {
  text-align: center; font-size: 11px; color: #3d3a32;
  font-weight: 600; min-height: 13px;
}

/* ── 弹层 ───────────────────────────────── */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(29,26,22,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; } }
.panel {
  width: 100%; max-width: 400px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 20px; text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: popIn .24s cubic-bezier(.2,1.4,.4,1);
  max-height: 88%; overflow-y: auto;
}
@keyframes popIn { from { transform: scale(.88); opacity: 0; } }
.panel h2 { font-size: 24px; margin-bottom: 6px; letter-spacing: 2px; }
.panel .sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.panel .big { font-size: 34px; font-weight: 900; letter-spacing: 4px; margin: 10px 0; }
.panel .win  { color: var(--accent); }
.panel .lose { color: #4a5568; }

.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 14px; }
.hero-card {
  border: 2px solid var(--ink-soft); border-radius: 8px;
  padding: 11px 9px; cursor: pointer; background: var(--grid-light);
  text-align: left; transition: border-color .12s, transform .1s;
}
.hero-card:active { transform: scale(.97); }
.hero-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,57,47,.22); }
.hero-card .name { font-size: 16px; font-weight: 800; margin-bottom: 3px; }
.hero-card .hp { font-size: 11px; color: var(--ink-soft); }
.hero-card .passive { font-size: 11px; color: var(--ink-soft); margin-top: 5px; line-height: 1.45; }

.toast {
  position: absolute; left: 50%; top: 16%;
  transform: translateX(-50%);
  padding: 10px 18px; border-radius: 8px;
  background: rgba(29,26,22,.9); color: #fff;
  font-size: 14px; z-index: 90; white-space: nowrap;
  animation: toastIn .22s; pointer-events: none;
  max-width: 92%;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ── 连接状态 ───────────────────────────── */
.conn-badge {
  position: absolute; right: 8px; top: 8px; z-index: 60;
  padding: 4px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 700;
}
.conn-badge.warn { background: var(--warn); color: #fff; }
.conn-badge.err  { background: var(--accent); color: #fff; }

/* ── 房间码展示 ─────────────────────────── */
.room-code-box {
  text-align: center; padding: 16px;
  border: 2px dashed var(--ink-soft); border-radius: 10px;
  background: var(--grid-light);
}
.room-code-box .code {
  font-size: 40px; font-weight: 900; letter-spacing: 10px;
  color: var(--accent); margin: 6px 0;
}
.room-code-box .hint { font-size: 12px; color: var(--ink-soft); }

.waiting-dots::after {
  content: ""; animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* 对手棋盘遮罩（未开战时对方半场不可点） */
@media (max-height: 700px) {
  .logo h1 { font-size: 32px; }
  .bottom { padding: 5px 7px 7px; gap: 5px; }
}

/* ══════════════════════════════════════════════════════════
   美术还原层（v0.3.1）
   对齐 docs/05_原版还原规格.md §2 棋盘 / §4 棋子 / §10 战斗特效
   放在文件末尾，方便整块替换而不动布局代码。
   ══════════════════════════════════════════════════════════ */

/* ── 棋盘：纸纹底 + 深灰格线（§2.2）───────────────
   原版可通行格是米白带极淡纸纹；障碍格是灰绿实心块。 */
.board {
  background: #6f6a5e;                       /* 格线颜色（gap 透出来） */
  gap: 1px;
}
.cell.self-side,
.cell.opp-side {
  /* 极淡的纸纹：斜向细线 + 轻微噪点，避免大面积纯色显得"空" */
  background-image:
    repeating-linear-gradient(45deg, rgba(0,0,0,.018) 0 3px, transparent 3px 7px),
    radial-gradient(rgba(0,0,0,.05) 0.6px, transparent 0.7px);
  background-size: auto, 7px 7px;
}
.cell.self-side { background-color: #f3efe2; }
.cell.opp-side  { background-color: #eee9dc; }
/* 障碍格：灰绿实心 + 内描边（§2.2 #8A9080） */
.cell.obstacle {
  background: #8a9080;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 2px, transparent 2px 5px);
  box-shadow: inset 0 0 0 1px #7c8272, inset 0 -2px 0 rgba(0,0,0,.08);
}

/* ── 长城：加厚到约 0.4 格高（§2.4）───────────────
   原版城墙压在格子上，砖纹 + 顶部雉堞齿，占约 0.4 个格高。 */
.cell.wall-top::before,
.gate-cell.wall-top::before {
  height: 14px;
  top: -14px;
  background:
    /* 雉堞齿：一排小方块（间隔更接近原版） */
    repeating-linear-gradient(90deg, #4a463c 0 6px, transparent 6px 12px),
    /* 砖纹墙身：横砖 + 竖缝 */
    repeating-linear-gradient(0deg, #9a8f82 0 6px, #8b8074 6px 7px),
    repeating-linear-gradient(90deg, transparent 0 13px, rgba(60,54,46,.5) 13px 15px);
  background-color: #9a8f82;
  border-top: 2px solid #4a463c;
  border-bottom: 2px solid #4a463c;
  box-shadow: 0 2px 3px rgba(0,0,0,.28);
}

/* ── 棋子：方形浅色底 + 深色描边 + 过渡动画（§4.1）──
   ★ 关键：位置变化走 transform/left 过渡，单位就"走"过去而不是瞬移。 */
.unit {
  transition: transform .22s ease-out, filter .12s;
  will-change: transform;
}
.unit.self { color: #7d241c; background: #f6ded9; box-shadow: inset 0 0 0 2px #b8392f, inset 0 -3px 0 rgba(184,57,47,.28); }
.unit.opp  { color: #24406e; background: #dbe3f4; box-shadow: inset 0 0 0 2px #3f5f96, inset 0 -3px 0 rgba(63,95,150,.28); }
.unit .char {
  font-family: "STKaiti", "KaiTi", "PingFang SC", serif;
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
}
/* 金色高亮框：主将化身 / 可升级（§4.1「刘备²」「张飞²」） */
.unit.upgradable {
  box-shadow:
    inset 0 0 0 2px var(--gold),
    0 0 0 1px #7d6414,
    0 0 6px rgba(201,162,39,.65);
  background: linear-gradient(#fff6d8, #f4e3ad);
  animation: heroGlow 2s ease-in-out infinite;
}
@keyframes heroGlow {
  50% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 1px #7d6414, 0 0 11px rgba(201,162,39,.95); }
}
/* 飞兵翅膀装饰（§4.1） */
.unit.winged .wing {
  position: absolute; inset: -3px -5px auto -5px; height: 46%;
  background:
    radial-gradient(ellipse 40% 100% at 20% 100%, rgba(255,255,255,.85) 0 70%, transparent 71%),
    radial-gradient(ellipse 40% 100% at 80% 100%, rgba(255,255,255,.85) 0 70%, transparent 71%);
  pointer-events: none;
  opacity: .9;
}
.unit.winged .wing::after {
  content: ""; position: absolute; left: 8%; right: 8%; bottom: 0; height: 3px;
  background: rgba(160,140,90,.7); border-radius: 3px;
}

/* 受击：白闪 + 抖动（§10） */
.unit.hit { animation: hitFlash .2s; }
@keyframes hitFlash {
  0%   { filter: brightness(2.4) saturate(.4); transform: translateX(0); }
  25%  { transform: translateX(-2px); }
  50%  { transform: translateX(2px); }
  100% { filter: none; transform: translateX(0); }
}

/* 攻击刀光：白色斜线划过（§10） */
.unit.slashing::after {
  content: "";
  position: absolute; inset: -20%;
  background: linear-gradient(115deg, transparent 42%, rgba(255,255,255,.95) 50%, transparent 58%);
  animation: slashSweep .18s ease-out;
  pointer-events: none;
}
@keyframes slashSweep {
  from { transform: translateX(-60%); opacity: 1; }
  to   { transform: translateX(60%); opacity: 0; }
}

/* 死亡：下沉淡出（§10 配合爆炸） */
.unit.dying { animation: die .3s forwards; }
@keyframes die {
  to { opacity: 0; transform: scale(.45) rotate(20deg); filter: grayscale(1); }
}

/* ── 击杀爆炸：黑色星形放射 + 尘土圈（§10）─────────── */
.boom {
  position: absolute; left: 50%; top: 50%;
  width: 0; height: 0; z-index: 30; pointer-events: none;
}
.boom .boom-star {
  position: absolute; left: 0; top: 0;
  width: 46px; height: 46px; margin: -23px 0 0 -23px;
  /* 多角尖刺：用两枚错位的尖角星叠出"放射"感 */
  background: #17140f;
  clip-path: polygon(
    50% 0%, 60% 35%, 100% 50%, 60% 65%, 50% 100%, 40% 65%,
    0% 50%, 40% 35%);
  animation: boomStar .42s ease-out forwards;
}
.boom .boom-star::after {
  content: ""; position: absolute; inset: 0;
  background: #17140f;
  clip-path: polygon(
    50% 0%, 60% 35%, 100% 50%, 60% 65%, 50% 100%, 40% 65%,
    0% 50%, 40% 35%);
  transform: rotate(45deg) scale(.62);
}
@keyframes boomStar {
  0%   { transform: scale(.2) rotate(0deg);   opacity: 1; }
  55%  { transform: scale(1.25) rotate(22deg); opacity: 1; }
  100% { transform: scale(1.5) rotate(40deg);  opacity: 0; }
}
.boom .boom-dust {
  position: absolute; left: 0; top: 0;
  width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border: 3px solid rgba(90,80,66,.7);
  border-radius: 50%;
  animation: boomDust .42s ease-out forwards;
}
@keyframes boomDust {
  0%   { transform: scale(.3); opacity: .9; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ── 水墨背景 + 城墙剪影（§6 / §13）──────────────── */
.board-wrap {
  background:
    /* 草丛剪影（底部两簇） */
    radial-gradient(58px 26px at 12% 100%, rgba(104,120,100,.5) 0 60%, transparent 62%),
    radial-gradient(74px 30px at 68% 100%, rgba(96,112,92,.42) 0 60%, transparent 62%),
    /* 远山 */
    radial-gradient(120% 46% at 50% 0%, rgba(150,164,146,.5) 0 55%, transparent 72%),
    /* 米黄纸底 */
    linear-gradient(#eae6d9, #dfe3d6);
}
/* 城墙剪影条：贴左右关口外侧 */
.board-wrap::before,
.board-wrap::after {
  content: ""; position: absolute; top: 10%; bottom: 10%; width: 10px;
  background:
    repeating-linear-gradient(0deg, rgba(70,64,54,.5) 0 7px, transparent 7px 12px);
  opacity: .5; pointer-events: none;
}
.board-wrap::before { left: 2px; }
.board-wrap::after  { right: 2px; }

/* ── 关口主将：让「斗」更有存在感（§3）─────────────── */
.unit.hero-token .char {
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(26px, 9vw, 46px) !important;
  color: #17140f;
  text-shadow:
    -2px -2px 0 var(--gold), 2px -2px 0 var(--gold),
    -2px 2px 0 var(--gold), 2px 2px 0 var(--gold),
    0 3px 4px rgba(0,0,0,.4);
}
/* 红心：更接近原版的小实心红心 */
.hearts .heart {
  font-size: clamp(10px, 3.4vw, 16px);
  color: #d8232c;
  text-shadow: 0 1px 0 #8d0f14, 0 1px 2px rgba(0,0,0,.25);
}
.hearts .heart.empty { color: #8b8478; opacity: .5; text-shadow: none; }
