/* style.css — 自走棋对战 · 美术层 v0.5（帧级动画）
   ★ 颜色取自原版逐帧实测（d_008 空盘 / d_090 实战，480×1036）：
     纸底        #93a08c（灰绿宣纸，带水墨晕染）
     格 D 深块   #6b706a（L≈110）
     格 M 中块   #b4bcad（L≈184）
     格 C 米白   #faf8ee（L≈247）
     格线墨      #4c4d45
     单位牌白底  #f7f4e8 / 墨字 #1a1a16 / 星标黑墨小数字
     金卡边      #fecc45（内部仍白）
     血线红      #c22f35（常驻牌顶，宽度=血量百分比）
     城门楼砖红  #a06b62 / 描边 #4a322c
     墙带        #50514c（横贯 r4/r5 交界的墨带）
     征兵钮      身 #4a4b4d + 进度红棕 #a05a50 + 黑描边
   结构：8 列 × 10 行正方格（棋盘按宽度定尺寸 480×600），
   城门楼嵌在 (5,0)/(4,7)。 */

/* 书法字体：马善政体（Ma Shan Zheng, SIL OFL 1.1）
   子集 21.7KB，仅含棋子字/主将/UI 书法字（任务 #19）。 */
@font-face {
  font-family: "MaShanZheng";
  src: url("../fonts/MaShanZheng-sub.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --ink:        #1a1a16;   /* 墨字 */
  --ink-line:   #4c4d45;   /* 格线 */
  --ink-soft:   #5a5b52;
  --paper:      #93a08c;   /* 页面纸底（实测灰绿宣纸） */
  --paper-hi:   #a3ae99;
  --cell-d:     #6b706a;   /* 地形深（实测 ΔL+1.5，已校准） */
  --cell-m:     #b3b5aa;   /* 地形中（_pixel_cmp.py 校准：G-7） */
  --cell-c:     #faf8ee;   /* 地形米白（ΔL-0.4，已校准） */
  --card:       #f7f4e8;   /* 单位牌白 */
  --card-line:  #b9b4a2;
  --gold:       #e8c95a;   /* 钱数字 */
  --gold-card:  #fecc45;   /* 金卡边框（实测最黄） */
  --hp:         #c22f35;   /* 血线红 */
  --brick:      #a06b62;   /* 城门楼砖红 */
  --brick-dark: #4a322c;
  --wall:       #50514c;   /* 墙带 */
  --recruit:    #886658;   /* 征兵钮身（源 14.5s 帧实测红棕 #886658） */
  --recruit-fill:#a05a50;  /* 征兵进度红棕 */
  --accent:     #b5372a;   /* 关名朱红 */
  --radius:     8px;
  --brush: "MaShanZheng", "STKaiti", "KaiTi", "PingFang SC", serif; /* 书法字（任务#19 内嵌字体） */
}

* { 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: #3a3d36;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  width: 100%; height: 100%;
  max-width: 520px;
  margin: 0 auto;
  /* 灰绿宣纸：底色 + 水墨晕染 + 细噪点 */
  background:
    radial-gradient(90% 30% at 18% 6%, rgba(60,72,58,.28) 0 55%, transparent 60%),
    radial-gradient(80% 26% at 85% 10%, rgba(70,82,66,.22) 0 55%, transparent 62%),
    radial-gradient(70% 22% at 30% 96%, rgba(52,62,50,.30) 0 58%, transparent 64%),
    radial-gradient(60% 18% at 78% 90%, rgba(60,70,56,.24) 0 55%, transparent 62%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.016) 0 3px, transparent 3px 8px),
    var(--paper);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ── 对战界面：棋盘必须精确占满剩余空间 ── */
#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-hi);
  color: var(--ink);
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(20,22,18,.35);
  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: #6e2018; }
.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-family: var(--brush);
  font-size: 44px; letter-spacing: 8px; font-weight: 900;
  color: var(--ink);
  text-shadow: 2px 2px 0 rgba(255,255,255,.28), 4px 4px 0 rgba(20,22,18,.16);
}
.logo p { margin-top: 8px; font-size: 13px; color: #e8e6d8; letter-spacing: 2px;
  text-shadow: 0 1px 2px rgba(20,22,18,.5); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: #e8e6d8; font-weight: 600; text-shadow: 0 1px 2px rgba(20,22,18,.5); }
.field input {
  padding: 12px 14px; min-height: 44px;
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--cell-c); 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: #e8e6d8; font-size: 12px;
  text-shadow: 0 1px 2px rgba(20,22,18,.5); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: rgba(20,22,18,.3); }

.tip { font-size: 12px; color: #d8d6c6; line-height: 1.7; text-shadow: 0 1px 2px rgba(20,22,18,.45); }

/* ── 顶栏 ─────────────────────────────────
   原版：左「暂停」圆钮 + 墨块金数军饷；中「虎牢关」朱红书法 + 「第N波」黑字白边；
         右「手柄」圆钮 + 系统胶囊。背景是纸 + 远山。 */
.topbar {
  position: relative;
  display: flex; align-items: flex-start;
  /* ★ v0.4.1：原版页头高 ~149px（d_090 实测棋盘上沿 y=149），
     留白里放远山，棋盘从 ~y135 开始。 */
  padding: 8px 8px 4px;
  min-height: 132px;
  background: transparent;
  flex-shrink: 0;
  z-index: 5;
}
/* 远山剪影（压在顶栏底部） */
.topbar::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -2px; height: 24px;
  background:
    radial-gradient(70px 22px at 20% 100%, rgba(46,56,44,.35) 0 58%, transparent 62%),
    radial-gradient(90px 26px at 60% 100%, rgba(46,56,44,.28) 0 58%, transparent 62%),
    radial-gradient(60px 18px at 88% 100%, rgba(46,56,44,.24) 0 58%, transparent 62%);
  pointer-events: none;
}
.topbar .pause-btn,
.topbar .pad-btn {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 9px;                 /* 原版是圆角方块不是圆 */
  border: 2px solid rgba(20,22,18,.6);
  background: rgba(58,62,54,.72);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; 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; }

/* 军饷：墨块 swash + 白蛋 + 米白数字（原版数字是米白不是金） */
.gold {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 12px 2px 5px;
  background: var(--ink);
  border-radius: 6px 14px 8px 16px;   /* 不规则墨块边 */
  box-shadow: 2px 2px 0 rgba(20,22,18,.25);
  font-weight: 800; font-size: 15px;
  color: #f3efe0;
  font-variant-numeric: tabular-nums;
  position: relative;
}
.gold .coin {
  width: 17px; height: 15px;
  /* 白蛋：上圆下略尖 */
  border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  background: radial-gradient(circle at 38% 30%, #fffdf4, #ece2ca 70%, #d8ccae);
  border: 1.5px solid var(--ink);
  box-shadow: inset -1px -1px 2px rgba(0,0,0,.16);
}
/* 系统胶囊：白底 … ⊙ */
.sys-capsule {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 9px;
  background: rgba(255,255,255,.92);
  border: 2px solid rgba(20,22,18,.75);
  border-radius: 14px;
  z-index: 2;
}
.sys-capsule i { width: 5px; height: 5px; border-radius: 50%; background: var(--ink); display: block; }
.sys-capsule .ring {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--ink);
  position: relative;
}
.sys-capsule .ring::after {
  content: ""; position: absolute; inset: 3px;
  background: var(--ink); border-radius: 50%;
}

.round-info {
  flex: 1; text-align: center; line-height: 1.12; z-index: 2;
  padding-top: 1px;
}
/* 虎牢关：朱红书法字 */
.round-info .stage {
  font-family: var(--brush);
  font-size: clamp(19px, 6vw, 28px);
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 3px;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,.55), 1px -1px 0 rgba(255,255,255,.55),
    -1px 1px 0 rgba(255,255,255,.55), 1px 1px 0 rgba(255,255,255,.55),
    0 2px 2px rgba(0,0,0,.25);
}
/* 第N波：黑字白边 */
.round-info .round {
  font-size: clamp(12px, 3.8vw, 17px);
  font-weight: 900;
  color: var(--ink);
  letter-spacing: 1px;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,.75), 1px -1px 0 rgba(255,255,255,.75),
    -1px 1px 0 rgba(255,255,255,.75), 1px 1px 0 rgba(255,255,255,.75);
}
/* 计时器：右上角小字 */
.timer {
  position: absolute; right: 8px; top: 42px;
  font-size: 12px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  padding: 1px 6px; border-radius: 8px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(20,22,18,.35);
  z-index: 3;
}
.timer.urgent { color: #fff; background: var(--accent); border-color: #6e2018; animation: pulse .8s infinite; }
@keyframes pulse { 50% { opacity: .62; } }

/* ── 棋盘 ─────────────────────────────────
   ★ 实测（d_008 网格检测）：8 列 × 10 行，正方格 ~59.6×60px → 整体 4:5。
   ★ v0.4.1 修复：棋盘必须【按宽度定尺寸】（width:100% → 高=宽×1.25）。
     上一版 height:100% 让 flex 拉伸把正方格拉成了 60×80 长方形，与原版不符。
   城门楼嵌在 (5,0) 我方 / (4,7) 敌方，主将 (6,0)/(3,7)。
   格线是细墨线（非外框粗边），格子直接画在纸上。 */
.board-wrap {
  /* ★ v0.4.1：flex:0 0 auto —— 棋盘按宽度定尺寸（476 宽 → 595 高），
     绝不参与 flex 分割；否则会被压扁/拉长，正方格变长方形。 */
  flex: 0 0 auto;
  position: relative;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2px; min-height: 0; min-width: 0; overflow: hidden;
  background: transparent;
}
.board-frame {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;         /* 8:10 正方格：480 宽 → 600 高 */
  max-height: 100%;            /* 极矮屏幕兜底（此时允许轻微非正方） */
  margin: 0 auto;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 1px;
  background: var(--ink-line);  /* gap 透出 = 墨格线 */
  border: 2px solid var(--ink-line);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: visible;            /* 红心/塔檐允许出格 */
}

/* ── 格子：地形三色（d_008 实测矩阵，JS 加 terrain-* 类）── */
.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: box-shadow .12s;
  overflow: visible;
}
.cell.terrain-d { background: var(--cell-d); }
.cell.terrain-m { background: var(--cell-m); }
.cell.terrain-c { background: var(--cell-c); }
/* 地形块内的轻微斑驳（避免大面积纯色发闷） */
.cell.terrain-d { background-image: radial-gradient(rgba(255,255,255,.05) 0.7px, transparent 0.8px); background-size: 9px 9px; }
.cell.terrain-m { background-image: radial-gradient(rgba(0,0,0,.035) 0.7px, transparent 0.8px); background-size: 9px 9px; }
.cell.terrain-c { background-image: radial-gradient(rgba(120,110,90,.05) 0.7px, transparent 0.8px); background-size: 9px 9px; }

.cell.droppable::after {
  content: "";
  position: absolute; inset: 1px;
  background: rgba(255,244,190,.42);
  box-shadow: inset 0 0 0 2px rgba(232,201,90,.85);
  pointer-events: none;
  z-index: 3;
}
.cell.droppable:active::after { background: rgba(255,244,190,.6); }
.cell.not-allowed { cursor: not-allowed; }

/* ── 主将格底纹：淡金虚线框（提示，不阻挡）── */
.cell.hero-cell::before {
  content: "";
  position: absolute; inset: 2px;
  border: 1.5px dashed rgba(232,201,90,.6);
  pointer-events: none;
  z-index: 1;
}

/* ── 城墙带：横贯 r4/r5 交界的墨带（门楼处断开）──
   board.js 给 r5 且 c>0 的格加 .wall-top；墨带压在这些格的上沿。 */
.cell.wall-top::before {
  content: "";
  position: absolute;
  left: -1px; right: -1px; top: -8px;
  height: 16px;
  background:
    /* 笔触毛边：上下缘用透明齿打掉 */
    radial-gradient(4px 3px at 8% 0%, transparent 0 60%, #50514c 61%) 0 0 / 34px 6px repeat-x,
    linear-gradient(#50514c, #46473f);
  background-color: #50514c;
  box-shadow: 0 1px 2px rgba(20,22,18,.4);
  z-index: 4;
  pointer-events: none;
}

/* ── 城门楼（(5,0) 我方 / (4,7) 敌方）──────────
   砖红塔身 + 铆钉圆 + 白色箭窗 + 深棕描边。 */
.cell.gate-tower {
  background:
    /* 砖缝 */
    repeating-linear-gradient(0deg, rgba(58,36,30,.35) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(90deg, rgba(58,36,30,.22) 0 1.5px, transparent 1.5px 11px),
    var(--brick);
  box-shadow:
    inset 0 0 0 2px var(--brick-dark),
    inset 0 -3px 0 rgba(58,36,30,.4),
    0 1px 2px rgba(20,22,18,.4);
  z-index: 5;
}
/* 左半：三颗铆钉圆 */
.cell.gate-tower::before {
  content: "";
  position: absolute; left: 12%; top: 14%; bottom: 14%; width: 32%;
  background:
    radial-gradient(circle at 50% 17%, #57342c 0 31%, rgba(255,255,255,.5) 33% 40%, transparent 43%) 0 0 / 100% 33.4% repeat-y;
  pointer-events: none;
}
/* 右半：三枚白色箭窗（左向三角楔） */
.cell.gate-tower::after {
  content: "";
  position: absolute; right: 10%; top: 14%; bottom: 14%; width: 34%;
  background: repeating-conic-gradient(from 135deg at 38% 50%, #ece2cc 0 90deg, transparent 90deg 360deg);
  background-size: 100% 33.4%;
  pointer-events: none;
}

/* ── 单位牌：白卡黑墨字（原版无红蓝阵营配色）── */
.unit {
  position: absolute;
  inset: 4.5%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
  background: var(--card);
  box-shadow:
    inset 0 0 0 1.5px rgba(26,26,22,.72),   /* 原版卡有墨描边（d_090 骑/枪/刀） */
    0 2px 2px rgba(20,22,18,.35);
  font-weight: 900;
  transition: transform .22s ease-out, filter .12s;
  will-change: transform;
  z-index: 6;
}
.unit.self, .unit.opp { color: var(--ink); }   /* 阵营不再用色区分，保留类名兼容 */
.unit .char {
  font-family: var(--brush);
  font-size: clamp(18px, 7.2vw, 36px);   /* 原版字高约占牌面 70% */
  line-height: 1;
  color: var(--ink);
}
/* 星标：右上黑墨小数字（原版骑³/枪¹） */
.unit .star {
  position: absolute; top: 0; right: 2px;
  font-size: clamp(8px, 2.6vw, 12px); font-weight: 800;
  color: var(--ink); line-height: 1.1;
  font-family: ui-monospace, monospace;
}
/* 血线：牌顶常驻红线，宽度=血量百分比（d_090 实测：所有兵都带红条，
   满血满条、掉血变短 —— 上一版「满血隐藏」是误判）。 */
.unit .hpbar {
  position: absolute; top: 5%; left: 9%; right: 9%; height: 8%;
  background: rgba(20,22,18,.22);
  border-radius: 1.5px;
  overflow: hidden;
}
.unit .hpbar i { display: block; height: 100%; background: var(--hp); transition: width .2s; }

/* 金卡：白底 + 粗金边（原版「刘备²」实测：内部仍是白卡） */
.unit.upgradable {
  background: linear-gradient(160deg, #fffef6, #fdf6df);
  box-shadow:
    inset 0 0 0 2.5px var(--gold-card),
    0 0 0 1px #b8860b,
    0 2px 3px rgba(20,22,18,.4);
  animation: heroGlow 2s ease-in-out infinite;
}
@keyframes heroGlow {
  50% { box-shadow:
    inset 0 0 0 2.5px var(--gold-card),
    0 0 0 1px #b8860b,
    0 0 8px rgba(254,204,69,.8); }
}

/* ★ 同格多单位：并排 + 缩字 */
.cell.crowded { gap: 0; }
.cell.crowded > .unit {
  position: relative; inset: auto;
  width: auto; height: 92%;
  flex: 1 1 0; min-width: 0;
}
.cell.crowded > .unit .char { font-size: clamp(9px, 3vw, 16px); }
.cell.crowded > .unit .star { display: none; }
.cell.crowded > .unit .hpbar { height: 2px; }

/* 主将「斗」：大字 + 金冠帽，无卡底 */
.unit.hero-token {
  background: transparent !important;
  box-shadow: none !important;
  animation: none !important;
  inset: 0;
}
.unit.hero-token::before {
  content: "";
  position: absolute; top: 4%; left: 50%;
  width: 42%; height: 20%;
  transform: translateX(-50%) rotate(-4deg);
  background: linear-gradient(#f2ca55, #c89020);
  border: 1.5px solid #6b4a10;
  border-radius: 60% 60% 14% 14% / 95% 95% 12% 12%;
  box-shadow: 0 1px 1px rgba(20,22,18,.35);
  z-index: 2;
}
.unit.hero-token .char {
  font-size: clamp(26px, 9vw, 46px) !important;
  text-shadow: 0 2px 2px rgba(20,22,18,.3);
}

/* 红心血量：贴主将格上沿的小红果 */
.hearts {
  position: absolute;
  left: 0; right: 0; top: -3px;
  transform: translateY(-100%);
  display: flex; justify-content: center; gap: 2px;
  z-index: 9;
  pointer-events: none;
}
.hearts .heart {
  font-size: clamp(10px, 3.4vw, 15px);
  color: #d8232c;
  line-height: 1;
  text-shadow: 0 0 1.5px #5d0d10, 0 1px 1px rgba(0,0,0,.35);
}
.hearts .heart.empty { color: #6d6d64; text-shadow: none; opacity: .5; }

/* ════ 战斗动画 v0.5 —— 帧级还原 ═════════════════════════════
   素材：《赵云与阿斗》虎牢关实机录屏 30fps，dense/d_001–d_157 逐帧计测。
   原作实测参数（1 帧 = 33.3ms）：
   · 放置入场 d_028–031(r0c0)：1f 白底闪（格亮度 174→198）+ 2f 卡片淡入 ≈ 100ms
   · 字形战斗变形 d_080–098(r2c2 枪)：进入战斗后字形持续倾斜摆动，
     姿态角约 -63°↔-79°（摆幅 ≈16°），整周期 ≈6f ≈ 200ms
   · 命中反馈 d_069/d_078：整格压暗 1f + 黄色闪电符号 1–2f ≈ 66ms
   · 伤害数字 d_084–096：墨色数字带白晕，上浮 ≈1/4 格高，存活 3–5f ≈ 100–166ms
   · 死亡 d_035/056/088/091：1f 内消失 + 黑墨渍 1–2f + 白星闪 1f + 墨滴飞散 3–4f，
     总计 ≈4–5f ≈ 133–166ms
   · 移动 d_082→d_083：骑跨格 1 帧完成 —— 瞬移，无滑动补间
   · 近战武器 d_084–092：白色小刀图标在攻击者侧挥动，逐帧变角，存活 2–3f
   · 远程箭矢：小黑镖 1–2f 飞抵目标                                        */

/* ── 放置入场：白底闪 + 卡片两拍淡入（d_028–031，≈100ms）── */
.unit.spawn { animation: spawnIn .1s steps(2, jump-none) both; }
@keyframes spawnIn {
  0%   { opacity: 0; filter: brightness(1.7); }
  100% { opacity: 1; filter: none; }
}
.cell.spawn-flash::after {
  content: "";
  position: absolute; inset: 0;
  background: #fdfbf1;
  animation: spawnFlash .1s ease-out forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes spawnFlash { to { opacity: 0; } }

/* ── 受击：整格压暗 1f → 黄色闪电 1–2f（d_069/d_078，≈120ms）── */
.unit.hit { animation: hitDark .12s steps(3, jump-none); }
@keyframes hitDark {
  0%   { filter: brightness(.45); }
  34%  { filter: brightness(1.9) saturate(1.4); }
  100% { filter: none; }
}
.unit.hit::after {
  content: "";
  position: absolute; left: 20%; top: -10%;
  width: 60%; height: 120%;
  background: #ffd23f;
  clip-path: polygon(46% 0, 78% 0, 52% 38%, 74% 38%, 30% 100%, 44% 58%, 22% 58%);
  filter: drop-shadow(0 0 3px rgba(255,210,63,.9));
  animation: boltBlink .12s steps(2, jump-none);
  pointer-events: none;
  z-index: 8;
}
@keyframes boltBlink { 50% { opacity: .25; } }

/* ── 战斗字形变形：进入交战范围后字形持续摆动（d_080–098 枪实测）──
   摆幅 ≈16°、周期 ≈200–240ms；--lean=±1 决定朝向目标的镜像；
   --phase 让各单位错拍，不齐舞。 */
.unit.combat .char {
  animation: morphCycle .24s ease-in-out infinite;
  animation-delay: var(--phase, 0ms);
  transform: rotate(calc(var(--lean, 1) * -5deg));
  will-change: transform;
}
@keyframes morphCycle {
  0%   { transform: rotate(calc(var(--lean,1) * -6deg)) translate(0, 0); }
  38%  { transform: rotate(calc(var(--lean,1) * 10deg))
         translate(calc(var(--lean,1) * 7%), 2%); }
  62%  { transform: rotate(calc(var(--lean,1) * 7deg))
         translate(calc(var(--lean,1) * 5%), 1%); }
  100% { transform: rotate(calc(var(--lean,1) * -6deg)) translate(0, 0); }
}

/* ── 出手突刺：命中帧向前顶 16% + 额外倾斜（近战），覆盖 morphCycle ── */
.unit.strike .char { animation: strikeLunge .16s ease-out; }
@keyframes strikeLunge {
  0%   { transform: rotate(calc(var(--lean,1) * -6deg)); }
  45%  { transform: translate(calc(var(--sx,0) * 1%), calc(var(--sy,0) * 1%))
         rotate(calc(var(--lean,1) * 12deg)); }
  100% { transform: rotate(calc(var(--lean,1) * -6deg)); }
}

/* ── 近战白刃：白色小刀在攻击者格内朝目标挥动（d_084–092，≈120ms）── */
.weapon {
  position: absolute; left: 50%; top: 50%;
  width: 0; height: 0;
  z-index: 12;
  pointer-events: none;
}
.weapon i {
  position: absolute; left: -4px; top: -20px;
  width: 8px; height: 30px;
  background: linear-gradient(#fbf8ec 58%, #cfcabb 58%);
  clip-path: polygon(50% 0, 88% 12%, 62% 17%, 56% 72%, 80% 84%, 20% 84%, 44% 72%, 38% 17%, 12% 16%);
  filter: drop-shadow(0 1px 1px rgba(20,22,18,.55));
  transform-origin: 50% 74%;
  animation: weaponSwing .12s ease-out forwards;
}
@keyframes weaponSwing {
  0%   { transform: rotate(calc(var(--wrot, 90deg) - 38deg)); opacity: 1; }
  55%  { transform: rotate(calc(var(--wrot, 90deg) + 26deg)); opacity: 1; }
  100% { transform: rotate(var(--wrot, 90deg)); opacity: 0; }
}

/* ── 远程箭矢：小黑镖直飞（JS 用 WAAPI 从攻击格飞到目标格，≈100ms）── */
.dart {
  position: absolute;
  width: 11px; height: 3px;
  background: var(--ink);
  border-radius: 40% 60% 60% 40%;
  box-shadow: -2.5px 0 0 -.5px var(--ink);
  pointer-events: none;
  z-index: 12;
}

/* ── 死亡：1 帧消失（d_035：上一帧还在、下一帧只剩墨滴）── */
.unit.dying { animation: die .06s steps(1, end) forwards; }
@keyframes die { to { opacity: 0; } }

/* ── 击杀墨爆：黑墨渍 + 白星闪 + 墨滴飞溅（d_056/d_088/d_091，≈200ms）── */
.boom {
  position: absolute; left: 50%; top: 50%;
  width: 0; height: 0; z-index: 30; pointer-events: none;
}
.boom .ink {
  position: absolute; left: 0; top: 0;
  display: block;
}
/* 主墨渍：不规则黑团（d_088 实测：整格 70% 的墨渍）*/
.boom .ink.main {
  width: 42px; height: 42px; margin: -21px 0 0 -21px;
  background: var(--ink);
  border-radius: 46% 54% 58% 42% / 52% 44% 56% 48%;
  animation: blobPop .2s ease-out forwards;
}
@keyframes blobPop {
  0%   { transform: scale(.25) rotate(0deg); opacity: 1; }
  30%  { transform: scale(1.08) rotate(12deg); opacity: 1; }
  70%  { transform: scale(1) rotate(18deg); opacity: .85; }
  100% { transform: scale(.92) rotate(22deg); opacity: 0; }
}
/* 白星闪：黑渍之后弹出的白色星溅（d_090/d_091，1–2f）*/
.boom .ink.star {
  width: 40px; height: 40px; margin: -20px 0 0 -20px;
  background: #f7f4ea;
  clip-path: polygon(
    50% 0%, 58% 30%, 78% 18%, 72% 42%, 100% 50%, 72% 58%,
    80% 82%, 58% 70%, 50% 100%, 42% 70%, 20% 82%, 28% 58%,
    0% 50%, 28% 42%, 22% 18%, 42% 30%);
  filter: drop-shadow(0 0 1px var(--ink));
  animation: starPop .12s steps(2, jump-none) .04s forwards;
  opacity: 0;
}
@keyframes starPop {
  0%   { transform: scale(.5); opacity: 1; }
  100% { transform: scale(1.35); opacity: 0; }
}
/* 墨滴：3–4 粒向外飞散（d_035–039 的细小墨滴）*/
.boom .ink.s1, .boom .ink.s2, .boom .ink.s3, .boom .ink.s4 {
  width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px;
  border-radius: 50% 42% 55% 45%;
  background: var(--ink);
  animation: inkFly .16s ease-out forwards;
}
.boom .ink.s1 { --dx: -15px; --dy: -13px; }
.boom .ink.s2 { --dx: 14px;  --dy: -16px; }
.boom .ink.s3 { --dx: 17px;  --dy: 11px; }
.boom .ink.s4 { --dx: -12px; --dy: 15px; }
@keyframes inkFly {
  0%   { transform: translate(0, 0) scale(.5); opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

/* ── 飘字：墨色数字白晕（d_084–096 实测「4」「8」「23」），≈220ms ── */
.float-text {
  position: absolute; pointer-events: none;
  font-weight: 900; font-size: 16px;
  font-family: ui-monospace, monospace;
  color: var(--ink);
  text-shadow:
    -1.5px -1.5px 0 #f5f2e4, 1.5px -1.5px 0 #f5f2e4,
    -1.5px 1.5px 0 #f5f2e4, 1.5px 1.5px 0 #f5f2e4,
    0 2px 2px rgba(0,0,0,.25);
  animation: floatUp .22s ease-out forwards;
  z-index: 20;
}
/* 金色 "+N" 变体（原版「+1」：金黄字深描边，d_084–090 刘备旁实测）*/
.float-text.gold {
  color: #eaa816;
  text-shadow:
    -1.5px -1.5px 0 #3a2c08, 1.5px -1.5px 0 #3a2c08,
    -1.5px 1.5px 0 #3a2c08, 1.5px 1.5px 0 #3a2c08;
}
@keyframes floatUp {
  0%   { transform: translate(-50%, 2px) scale(.6); opacity: 0; }
  25%  { transform: translate(-50%, -4px) scale(1.06); opacity: 1; }
  70%  { transform: translate(-50%, -10px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -13px) scale(1); opacity: 0; }
}

/* ── 放兵飞行动画（源录屏 14.4–15.3s @59fps 实测）─────────────
   卡槽金爆 ≈80ms（源 0133–0137）→ 兵字抛物线飞行 ≈290ms（源 0139–0157）
   白色弧形拖尾多点渐隐 → 落地入场闪。 */
.fly-char {
  position: fixed; left: 0; top: 0; z-index: 90;
  font-family: var(--brush); font-weight: 900;
  font-size: 30px; line-height: 1; color: var(--ink);
  pointer-events: none;
  transform: translate(-50%, -50%);
  text-shadow:
    -2px -2px 0 #f5f2e4, 2px -2px 0 #f5f2e4,
    -2px 2px 0 #f5f2e4, 2px 2px 0 #f5f2e4,
    0 0 8px rgba(255, 255, 255, .95);
}
.fly-dot {
  position: fixed; left: 0; top: 0; z-index: 89;
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(250, 248, 240, .95);
  box-shadow: 0 0 3px rgba(255, 255, 255, .85);
  pointer-events: none;
  animation: flyDot .24s ease-out forwards;
}
@keyframes flyDot {
  from { transform: translate(-50%, -50%) scale(1); opacity: .95; }
  to   { transform: translate(-14px, -22px) scale(.25); opacity: 0; }
}
.slot-burst { position: fixed; z-index: 90; pointer-events: none; }
.slot-burst::before {
  content: "";
  position: absolute; left: -18px; top: -18px;
  width: 36px; height: 36px;
  background: radial-gradient(circle, #ffe9a0 0 32%, #e8b93c 58%, transparent 72%);
  clip-path: polygon(
    50% 0%, 58% 30%, 78% 18%, 72% 42%, 100% 50%, 72% 58%,
    80% 82%, 58% 70%, 50% 100%, 42% 70%, 20% 82%, 28% 58%,
    0% 50%, 28% 42%, 22% 18%, 42% 30%);
  animation: slotBurst .22s ease-out forwards;
}
@keyframes slotBurst {
  0%   { transform: scale(.4) rotate(0deg); opacity: 1; }
  100% { transform: scale(1.7) rotate(30deg); opacity: 0; }
}

/* ── 敌军来向 V 形箭头（源 14.5s/16.4s 帧：左缘指上、右缘指下的暗红 V）── */
.side-arrow {
  position: absolute; z-index: 4;
  width: 0; height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  opacity: .75;
  pointer-events: none;
  animation: arrowBob 1.6s ease-in-out infinite;
}
.side-arrow.right { right: 3px; top: 56%; border-top: 17px solid #8b3a2e; }
.side-arrow.left  { left: 3px;  top: 21%; border-bottom: 17px solid #8b3a2e; }
@keyframes arrowBob { 50% { transform: translateY(6px); opacity: .45; } }

/* ── VS 匹配转场（源 10–14s：紫粉天 + 蓝旗(敌)/红旗(我) + 交叉双剑）── */
.vs-overlay {
  position: fixed; inset: 0; z-index: 120;
  background: linear-gradient(#b3aed6 0 46%, #d9a8a4 54% 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  animation: vsFade 2.1s ease forwards;
  pointer-events: none;
}
.vs-overlay .vs-title {
  position: absolute; top: 26px; left: 0; right: 0;
  text-align: center;
  font-family: var(--brush); font-weight: 900;
  font-size: 34px; letter-spacing: 4px; color: #c0392b;
  text-shadow: -1.5px -1.5px 0 #fff, 1.5px -1.5px 0 #fff,
    -1.5px 1.5px 0 #fff, 1.5px 1.5px 0 #fff;
}
.vs-flag {
  width: min(78%, 360px);
  padding: 14px 16px 20px;
  color: #fff;
  font-weight: 900;
  position: relative;
  display: flex; align-items: center; gap: 10px;
}
.vs-flag .vs-name { font-size: 20px; letter-spacing: 2px; flex: 1; }
.vs-flag .vs-sub { font-size: 12px; opacity: .85; font-weight: 700; }
.vs-flag.blue {
  background: #3e5f96;
  border-radius: 6px 6px 14px 18px / 6px 6px 10px 22px;
  box-shadow: 0 4px 0 rgba(20,22,40,.3);
  animation: flagL .45s cubic-bezier(.2, .9, .3, 1.2) both;
}
.vs-flag.red {
  background: #b5504a;
  border-radius: 6px 6px 18px 14px / 6px 6px 22px 10px;
  box-shadow: 0 4px 0 rgba(60,20,20,.3);
  animation: flagR .45s cubic-bezier(.2, .9, .3, 1.2) .12s both;
}
.vs-swords {
  font-size: 40px; margin: 14px 0;
  filter: drop-shadow(0 2px 2px rgba(40,30,30,.45));
  animation: flagL .45s ease .2s both;
}
@keyframes flagL { from { transform: translateX(-60vw); } }
@keyframes flagR { from { transform: translateX(60vw); } }
@keyframes vsFade {
  0%, 72% { opacity: 1; }
  100%    { opacity: 0; visibility: hidden; }
}

/* ── 底部操作区（营 + 征兵）────────────────
   原版：棋盘下先一条草丛，再往下依次是「营」小屋 + 5 槽 + 征兵钮，
   全部压在底部，中间留大片纸底（flex:1 吃掉剩余空间）。v0.4.1 */
.bottom {
  flex: 1;
  min-height: 0;
  background: transparent;
  padding: 10px 8px 8px;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 6px;
  position: relative;
  z-index: 5;
}
/* 草丛贴地（棋盘正下方一条；v0.4.1 改 top:2px 防止叠上棋盘末行） */
.bottom::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 2px; height: 12px;
  background:
    radial-gradient(3px 10px at 6% 100%, rgba(46,60,42,.5) 0 60%, transparent 62%) 0 0 / 46px 12px repeat-x,
    radial-gradient(2.5px 8px at 55% 100%, rgba(46,60,42,.38) 0 60%, transparent 62%) 18px 0 / 64px 12px repeat-x;
  pointer-events: none;
}
/* 「营」小屋木牌 */
.camp-sign {
  flex-shrink: 0;
  width: 40px; height: 44px;
  display: flex; align-items: flex-end; justify-content: center;
  background: #45403c;
  border: 2px solid var(--ink);
  border-radius: 4px 4px 3px 3px;
  color: #f0ead8;
  font-family: var(--brush);
  font-weight: 900; font-size: 21px;
  position: relative;
  padding-bottom: 3px;
  box-shadow: 0 2px 0 rgba(20,22,18,.35);
}
/* 红陶屋顶（弧面） */
.camp-sign::before {
  content: "";
  position: absolute; left: -6px; right: -6px; top: -12px; height: 16px;
  background: linear-gradient(#b2604c, #7a3a28);
  border: 2px solid var(--ink);
  border-radius: 46% 46% 6px 6px / 92% 92% 6px 6px;
  box-shadow: 0 1px 0 rgba(20,22,18,.4);
}
.tray-row { display: flex; align-items: center; gap: 6px; }
.tray-row .slots { flex: 1; display: flex; gap: 5px; }
.tray-row .slots .slot {
  flex: 1; aspect-ratio: 1 / 1.08;
  border: 3px solid #3a3b34;
  border-radius: 2px;
  background: #f0ede0;          /* 原版空槽也是白纸（d_090 全部 5 槽白底） */
  display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer;
  min-height: 40px;
  transition: transform .1s, box-shadow .12s, background .12s;
  box-shadow: inset 0 1px 3px rgba(20,22,18,.14);
}
/* 槽内单位：墨字直接摆（原版槽里没有白卡） */
.tray-row .slots .slot .char {
  font-family: var(--brush);
  font-size: clamp(17px, 5.4vw, 28px);
  font-weight: 900; color: var(--ink);
}
/* 主将化身卡：金字（源 14.5s 帧实测「赵¹」黄字 #D5AD4C） */
.tray-row .slots .slot.goldchar .char {
  color: #d5ad4c;
  text-shadow: -1px -1px 0 rgba(93,68,8,.55), 1px -1px 0 rgba(93,68,8,.55),
    -1px 1px 0 rgba(93,68,8,.55), 1px 1px 0 rgba(93,68,8,.55);
}
.tray-row .slots .slot .star {
  position: absolute; top: 0; right: 3px;
  font-size: 11px; font-weight: 800; color: var(--ink);
  font-family: ui-monospace, monospace;
}
.tray-row .slots .slot.selected {
  background: rgba(255,244,190,.6);
  box-shadow: 0 0 0 2px var(--gold-card), inset 0 1px 3px rgba(20,22,18,.18);
  transform: translateY(-3px);
}
.tray-row .slots .slot.empty { background: #f0ede0; box-shadow: inset 0 1px 3px rgba(20,22,18,.14); cursor: default; }
.tray-row .slots .slot.disabled { opacity: .45; cursor: not-allowed; }
.tray-row .slots .slot.tool { background: rgba(254,236,170,.5); }

/* 征兵按钮：灰身 + 红棕进度（左→右）+ 黑描边 + 白书法字 + 蛋花费 */
.recruit-wrap { display: flex; justify-content: center; }
.recruit-btn {
  position: relative;
  min-width: 190px; min-height: 56px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--recruit);
  color: #fff;
  font-family: var(--brush);
  font-size: 24px; font-weight: 900;
  letter-spacing: 5px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(20,22,18,.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0;
  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(.35) brightness(.9); cursor: not-allowed; }
/* 进度条：红棕从左往右填（原版实测： gold/cost 比例 = 红棕宽度） */
.recruit-btn .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(180deg, #ad6456, var(--recruit-fill));
  transition: width .25s;
  pointer-events: none;
}
.recruit-btn .label { position: relative; z-index: 2; line-height: 1.1; }
.recruit-btn .cost {
  position: relative; z-index: 2;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; font-weight: 800; letter-spacing: 0;
}
.recruit-btn .cost .coin {
  width: 15px; height: 13px;
  border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  background: radial-gradient(circle at 38% 30%, #fffdf4, #ece2ca 70%, #d8ccae);
  border: 1.5px solid var(--ink);
}

.hand-hint {
  text-align: center; font-size: 11px; color: #d8d6c6;
  font-weight: 600; min-height: 13px;
  text-shadow: 0 1px 2px rgba(20,22,18,.45);
}

/* ── 弹层 ───────────────────────────────── */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(26,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(--cell-c);
  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-family: var(--brush); font-size: 26px; margin-bottom: 6px; letter-spacing: 3px; }
/* 结算横幅 + 三星（源 305–310s：金底红字横幅 / 灰蓝底「大营失守」+ ★★★） */
.result-banner {
  font-family: var(--brush); font-weight: 900;
  font-size: 24px; letter-spacing: 4px;
  padding: 8px 18px; border-radius: 8px;
  margin: -4px auto 4px; width: fit-content;
  border: 2.5px solid rgba(20,22,18,.55);
}
.result-banner.win  { background: linear-gradient(#f2ca55, #d8a428); color: #8c1f14;
  text-shadow: 0 1px 0 rgba(255,240,200,.6); }
.result-banner.lose { background: linear-gradient(#8e97a8, #6d7688); color: #f0ede2; }
.result-banner.draw { background: linear-gradient(#c9c4ae, #a8a390); color: #3a3a30; }
.result-stars {
  font-size: 26px; letter-spacing: 6px; margin: 2px 0;
  color: #e8a816;
  text-shadow: -1.5px -1.5px 0 #5d4408, 1.5px -1.5px 0 #5d4408,
    -1.5px 1.5px 0 #5d4408, 1.5px 1.5px 0 #5d4408;
}
.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(--card);
  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(181,55,42,.25); }
.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(26,26,22,.92); 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: #b8860b; 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: rgba(250,248,238,.6);
}
.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; }
  /* 矮屏兜底：棋盘改按高度定尺寸（允许轻微非正方，保内容完整） */
  .board-frame { width: auto; height: calc(100vh - 200px); }
}
