/* ==========================================================================
   中国象棋 · 样式表
   - 颜色全部走 CSS 变量：<html data-theme="paper|ink|jade|night"> 切换配色
   - 对局页手机端一屏不滚动，桌面端右侧栏；其余页面保持居中卡片式
   ========================================================================== */

:root {
  --bg: #f4eee1;
  --bg-a: rgba(214, 178, 120, 0.24);
  --bg-b: rgba(166, 42, 34, 0.07);
  --card: #fffdf7;
  --card-soft: #fbf5e8;
  --ink: #322b23;
  --muted: #7d7264;
  --line: #e6d9c2;
  --line-dash: #f0e7d6;
  --red: #a62a22;
  --red-deep: #82201a;
  --green: #2e7d5b;
  --gold: #b8860b;
  --shadow: 0 12px 32px rgba(75, 52, 26, 0.14);
  --shadow-soft: 0 6px 20px rgba(75, 52, 26, 0.07);
  --mask: rgba(40, 30, 18, 0.44);
  --chip: #fffdf7;
  --bar-track: #3a3a3a;
  --seal-1: #b5352b;
  --seal-2: #82201a;
  --hover: #faf1df;
  --hover-line: #d5bd95;
  --sel-bg: #fbe9e7;
  --sel-line: #e3b4ad;
  --frame-1: #e8cf9f;
  --frame-2: #c99f63;
  --frame-3: #b8894c;
  --check-bg: #f6df8b;
  --check-ink: #7a4a00;
  --board-shadow: 0 10px 26px rgba(75, 52, 26, 0.2);
}

/* 墨白：冷灰、素净 */
[data-theme="ink"] {
  --bg: #eceeec;
  --bg-a: rgba(120, 132, 140, 0.16);
  --bg-b: rgba(60, 70, 78, 0.06);
  --card: #ffffff;
  --card-soft: #f4f6f5;
  --ink: #23262a;
  --muted: #6f757b;
  --line: #d9dedb;
  --line-dash: #e8ece9;
  --red: #b23a2c;
  --red-deep: #8a2a20;
  --green: #3b7a57;
  --gold: #a87b1f;
  --shadow: 0 12px 30px rgba(30, 40, 48, 0.12);
  --shadow-soft: 0 6px 18px rgba(30, 40, 48, 0.07);
  --mask: rgba(20, 26, 30, 0.46);
  --chip: #ffffff;
  --bar-track: #33383c;
  --seal-1: #b23a2c;
  --seal-2: #8a2a20;
  --hover: #f2f5f3;
  --hover-line: #bcc6c2;
  --sel-bg: #f7e9e6;
  --sel-line: #e0b3ad;
  --frame-1: #e7ecea;
  --frame-2: #cdd6d2;
  --frame-3: #b6c2bd;
  --check-bg: #f2e2a8;
  --check-ink: #6f4a06;
  --board-shadow: 0 10px 26px rgba(30, 40, 48, 0.16);
}

/* 青瓷：青绿清润 */
[data-theme="jade"] {
  --bg: #e8f1ea;
  --bg-a: rgba(110, 165, 140, 0.22);
  --bg-b: rgba(47, 109, 85, 0.08);
  --card: #fbfefb;
  --card-soft: #f2f8f4;
  --ink: #1e3a2f;
  --muted: #5f7a6d;
  --line: #cfe0d4;
  --line-dash: #e0ebe3;
  --red: #a8322a;
  --red-deep: #7f231d;
  --green: #2f6d55;
  --gold: #a8801f;
  --shadow: 0 12px 30px rgba(28, 62, 48, 0.14);
  --shadow-soft: 0 6px 18px rgba(28, 62, 48, 0.08);
  --mask: rgba(18, 40, 30, 0.44);
  --chip: #fbfefb;
  --bar-track: #2b4438;
  --seal-1: #a8322a;
  --seal-2: #7f231d;
  --hover: #eef7f1;
  --hover-line: #a9cbb8;
  --sel-bg: #fbeae7;
  --sel-line: #e2b3ac;
  --frame-1: #dcece1;
  --frame-2: #b6d3c2;
  --frame-3: #9cbfab;
  --check-bg: #f3e3a6;
  --check-ink: #6d4a08;
  --board-shadow: 0 10px 26px rgba(28, 62, 48, 0.18);
}

/* 夜棋：深色，夜里不刺眼 */
[data-theme="night"] {
  --bg: #14171a;
  --bg-a: rgba(70, 120, 140, 0.16);
  --bg-b: rgba(220, 90, 70, 0.07);
  --card: #1e2327;
  --card-soft: #232930;
  --ink: #e9e7e2;
  --muted: #98a0a5;
  --line: #2f353a;
  --line-dash: #2a3035;
  --red: #e4695a;
  --red-deep: #c2503f;
  --green: #4fae86;
  --gold: #d8ae52;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.35);
  --mask: rgba(0, 0, 0, 0.62);
  --chip: #232a2f;
  --bar-track: #0d0f11;
  --seal-1: #d4533f;
  --seal-2: #9c3325;
  --hover: #262d33;
  --hover-line: #46525a;
  --sel-bg: #33211f;
  --sel-line: #6d3a33;
  --frame-1: #333b41;
  --frame-2: #262d33;
  --frame-3: #1d2327;
  --check-bg: #6b4a12;
  --check-ink: #ffd98a;
  --board-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, var(--bg-a), transparent 34%),
    radial-gradient(circle at 88% 84%, var(--bg-b), transparent 38%),
    var(--bg);
  transition: background-color .2s ease;
}

.app {
  max-width: 1020px;
  margin: 0 auto;
  padding: 26px 20px 36px;
}

.hidden { display: none !important; }

.i {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ============================ 首页 ============================ */
.screen { animation: screenIn .18s ease; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.home-look {
  display: flex; justify-content: flex-end;
  margin: -6px -4px 0 0;
}
.icon-btn {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: none; color: var(--muted);
  font: inherit; cursor: pointer;
}
.icon-btn:active { background: var(--hover); }

.seal {
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--seal-1), var(--seal-2));
  color: #fff6e8;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 30px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(130, 32, 26, 0.28);
}

.home-head { text-align: center; padding: 26px 0 22px; }
.home-head h1 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: 40px; letter-spacing: 8px;
}
.seal-lg { width: 74px; height: 74px; margin: 0 auto 16px; border-radius: 18px; font-size: 44px; }
.home-sub { margin: 10px 0 0; font-size: 13px; color: var(--muted); letter-spacing: 4px; }

.home-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.home-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 22px 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  color: inherit; text-decoration: none;
  box-shadow: var(--shadow-soft);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.home-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--hover-line); }
.home-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 26px; color: #fff8ec;
}
.icon-play { background: linear-gradient(145deg, var(--seal-1), var(--seal-2)); }
.icon-learn { background: linear-gradient(145deg, #3c7a5c, #245c43); }
.icon-puzzle { background: linear-gradient(145deg, #b98a3c, #8a6224); }
.home-title { font-size: 19px; font-weight: 700; letter-spacing: 2px; }
.home-desc { flex: 1; font-size: 12.5px; line-height: 1.8; color: var(--muted); }
.home-go { font-size: 12px; font-weight: 700; color: var(--red); }

.home-foot { margin-top: 26px; text-align: center; font-size: 11.5px; color: var(--muted); }
.home-foot p { margin: 8px 0 0; }
.home-engine {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
}
.home-engine::before { content: '●'; color: var(--muted); font-size: 10px; }
.home-engine.online::before { color: var(--green); }
.home-engine.offline::before { color: var(--gold); }

/* ============================ 对局页（方案 A） ============================ */
body[data-screen="play"] .app { padding: 0; max-width: none; }
body[data-screen="play"] { overflow: hidden; }
/* 对局页是满屏应用：页脚会把它撑出滚动条，直接不显示 */
body[data-screen="play"] footer { display: none; }

.play {
  height: 100vh;
  height: 100dvh;
  max-width: 470px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.play-top {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 4px;
  height: 46px;
  padding: env(safe-area-inset-top) 8px 0;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.play-mid { flex: 1; min-width: 0; text-align: center; line-height: 1.25; }
.play-mid b {
  display: block; font-size: 14px; letter-spacing: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.play-mid span {
  display: block; font-size: 10.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.goal-bar {
  flex: 0 0 auto;
  margin: 6px 12px 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--sel-bg);
  color: var(--red);
  font-size: 12px; font-weight: 700;
  text-align: center;
}

/* 残局：目标条改成题目导航（‹ 第 3 / 10 关 · 局名 ›） */
.goal-bar.goal-nav-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 4px;
  text-align: left;
}
.goal-nav {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--red);
  font: inherit; font-size: 18px; font-weight: 700; line-height: 1;
  cursor: pointer;
}
.goal-nav:active { background: var(--hover); }
.goal-nav[disabled] { opacity: .28; cursor: default; }
.goal-text {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  line-height: 1.2;
}
.goal-text b { font-size: 12px; font-weight: 700; color: var(--red); letter-spacing: .3px; }
.goal-name {
  font-style: normal; font-size: 11px; color: var(--muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 玩家条 */
.player {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px;
  min-height: 52px;
}
.avatar {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 9px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 16px; color: #fff8ec;
}
.avatar.red { background: linear-gradient(145deg, var(--seal-1), var(--seal-2)); }
.avatar.black { background: linear-gradient(145deg, #4a4640, #26241f); }
[data-theme="night"] .avatar.black { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.who { flex: 1; min-width: 0; line-height: 1.32; }
.who b {
  display: block; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.who span {
  display: block; font-size: 10.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.player.active .who b { color: var(--red); }
.player.active .who b::after {
  content: '●'; margin-left: 5px; font-size: 8px; vertical-align: 2px; color: var(--green);
}

.engine-line {
  display: flex; align-items: center; gap: 5px;
  max-width: 45%;
  font-size: 10.5px; color: var(--muted);
}
.engine-line span:last-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.engine-dot {
  width: 7px; height: 7px; flex: 0 0 auto;
  border-radius: 50%;
  background: #c9a227;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, .16);
}
.engine-line.online .engine-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(46, 125, 91, .16); }

.turn-tag {
  font-size: 10.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.player.active .turn-tag { color: var(--red); border-color: var(--sel-line); background: var(--sel-bg); }

/* 棋盘区 */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 2px 4px;
  overflow: hidden;
}
.board-wrap canvas {
  display: block;
  border-radius: 6px;
  box-shadow: var(--board-shadow);
  touch-action: manipulation;
  cursor: pointer;
}

.toast {
  position: absolute;
  left: 50%; bottom: 8px;
  transform: translate(-50%, 6px);
  max-width: 88%;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(30, 24, 16, .88);
  color: #fff8e9;
  font-size: 12.5px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 3;
}
[data-theme="night"] .toast { background: rgba(240, 240, 238, .92); color: #1a1d20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 胜率 + 状态 */
.eval-row { flex: 0 0 auto; padding: 5px 12px 7px; }
.eval-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted);
}
.pct { display: flex; align-items: baseline; gap: 2px; }
.pct b { font-size: 15px; font-variant-numeric: tabular-nums; letter-spacing: -.2px; }
.pct.red b { color: var(--red); }
.pct.black b { color: var(--ink); }
.pct i { font-style: normal; font-size: 10px; }

.eval-status {
  display: flex; align-items: center; gap: 5px;
  min-width: 0; max-width: 58%;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink);
  white-space: nowrap;
}
.eval-status > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.chip-check {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--check-bg);
  color: var(--check-ink);
  font-size: 10px; font-weight: 700;
}

.rate-bar {
  height: 8px;
  margin-top: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bar-track);
}
.rate-bar-fill {
  height: 100%;
  width: 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, #d3503f, var(--red));
  transition: width .3s ease;
}
.eval-foot {
  display: flex; justify-content: space-between; gap: 6px;
  margin-top: 4px;
  font-size: 10px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.eval-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eval-foot #scoreText { flex: 1 1 auto; }
.eval-src { flex: 0 0 auto; opacity: .75; }

/* 桌面端右侧棋谱（手机端隐藏） */
.moves-desk { display: none; }
.moves-desk-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 0 6px;
  font-size: 12.5px; font-weight: 700; letter-spacing: 1px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

/* 棋谱一行 */
.moves-strip {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 12px;
  min-height: 34px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--card-soft);
  overflow: hidden;
}
.moves-text {
  flex: 1; min-width: 0;
  font-size: 11.5px; line-height: 1.72; color: var(--ink);
  max-height: 40px;            /* 两行，超出的截掉（完整棋谱在抽屉里） */
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.moves-text .n { color: var(--muted); margin-right: 2px; }
.moves-text .r { color: var(--red); }
.moves-text .b { color: var(--ink); }
.strip-btn {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit; font-size: 11px;
  cursor: pointer;
}

/* 操作栏 */
.actions {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 5px 8px calc(5px + env(safe-area-inset-bottom));
  background: var(--card);
}
.act {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 0 4px;
  border: none; border-radius: 10px;
  background: none;
  color: var(--muted);
  font: inherit; font-size: 12px;
  cursor: pointer;
}
.act .i { width: 21px; height: 21px; }
.act .i.flip { transform: scaleX(-1); }
.act.primary { color: var(--red); }
.act.primary .i { stroke-width: 1.9; }
.act:active { background: var(--hover); }
/* 窄屏（老机型 360 宽及以下）稍微收一点，保证五个按钮都完整 */
@media (max-width: 360px) {
  .act { font-size: 11px; }
  .act .i { width: 19px; height: 19px; }
}

/* 桌面端：棋盘在左，信息在右 */
@media (min-width: 900px) {
  body[data-screen="play"] { overflow: auto; padding: 16px 0; }
  .play {
    max-width: 1000px;
    height: auto;
    min-height: calc(100vh - 32px);
    margin: 0 auto;
    padding: 0;
    border-radius: 20px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "top    top"
      "goal   goal"
      "board  ptop"
      "board  eval"
      "board  pbot"
      "board  desk"
      "board  strip"
      "board  act";
    column-gap: 0;
  }
  .play-top { grid-area: top; border-radius: 20px 20px 0 0; padding-top: 0; height: 48px; }
  .board-wrap { grid-area: board; height: min(78vh, 640px); padding: 12px 0 12px 16px; }
  .play #playerTop { grid-area: ptop; align-self: end; }
  .play .eval-row { grid-area: eval; padding: 4px 16px 8px; }
  .play #playerBottom { grid-area: pbot; }
  .play .moves-strip { grid-area: strip; }
  .play .moves-desk {
    grid-area: desk;
    display: flex; flex-direction: column;
    min-height: 0;
    /* 撑满右侧剩余高度并画出卡片边界：空棋谱时也不会显得是一片空白 */
    margin: 4px 16px 10px 0;
    padding: 10px 12px 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  .play .moves-desk .moves-list { flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto; }
  .play .moves-strip { display: none; }
  .play .actions { grid-area: act; border-radius: 0 0 20px 0; padding-bottom: 8px; }
  .play .goal-bar { grid-area: goal; margin: 6px 16px 0; }
}

/* ============================ 卡片 / 通用控件 ============================ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
}
.card-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 10px;
  font-size: 13px; font-weight: 700; letter-spacing: 1px;
}
.card-note { font-size: 10.5px; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit; font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); border-color: var(--hover-line); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(145deg, var(--seal-1), var(--seal-2));
  border-color: transparent;
  color: #fff8ec;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-quiet { width: 100%; margin-top: 14px; background: transparent; color: var(--muted); }
.btn-small { padding: 8px 2px; font-size: 12px; }
.btn.btn-playing { background: var(--green); border-color: transparent; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.shortcuts { margin: 12px 0 0; font-size: 11px; color: var(--muted); text-align: center; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; margin-bottom: 5px; font-size: 12px; color: var(--muted); }
select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit; font-size: 13px;
}

/* 棋谱列表（抽屉里） */
.moves-list {
  max-height: 46vh;
  overflow-y: auto;
  font-size: 13px; line-height: 1.9;
  font-variant-numeric: tabular-nums;
}
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; border-bottom: 1px dashed var(--line-dash); }
.move-row:last-child { border-bottom: none; }
.move-no { color: var(--muted); }
.mr { color: var(--red); font-weight: 600; }
.mb { color: var(--ink); font-weight: 600; }
.empty { color: var(--muted); font-size: 12px; padding: 8px 0; }
.move-link { cursor: pointer; border-radius: 4px; padding: 0 4px; transition: background .12s; }
.move-link:hover { background: var(--hover); }
.move-link.active { background: var(--hover); box-shadow: inset 0 -2px 0 var(--green); }

.replay-tools {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card-soft);
  border: 1px solid var(--line);
}
.replay-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; font-size: 12px; font-weight: 700;
}
.replay-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }

/* 教学 / 残局页沿用卡片风 */
.subbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.back-btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 12.5px; font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.back-btn:hover { border-color: var(--hover-line); color: var(--ink); }
.subbar-title h2 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 24px; letter-spacing: 3px;
}
.subbar-title p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.board-frame {
  position: relative;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--frame-1), var(--frame-2) 60%, var(--frame-3));
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255, 255, 255, .28);
}
.board-frame canvas { display: block; width: 100%; height: auto; border-radius: 6px; cursor: pointer; touch-action: manipulation; }
.board-caption { margin: 12px 2px 0; font-size: 12px; color: var(--muted); text-align: center; }

.learn-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: start; }
.learn-side { display: flex; flex-direction: column; gap: 14px; }
.lesson-list { display: flex; flex-direction: column; gap: 6px; }
.lesson-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border: 1px solid transparent; border-radius: 9px;
  background: var(--card-soft);
  color: var(--ink);
  font-family: inherit; font-size: 13px; text-align: left;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.lesson-item:hover { background: var(--hover); }
.lesson-item.active { background: var(--sel-bg); border-color: var(--sel-line); color: var(--red); font-weight: 700; }
.lesson-idx {
  width: 20px; height: 20px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--line);
  font-size: 11px; color: var(--muted);
}
.lesson-item.active .lesson-idx { background: var(--red); color: #fff; }
.lesson-text { min-height: 104px; font-size: 13px; line-height: 1.95; color: var(--ink); }
.lesson-nav { display: flex; gap: 8px; margin-top: 12px; }
.lesson-nav .btn { flex: 1; }

.card.puzzle-mode .field { display: none; }

.puzzle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.puzzle-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card);
  font-family: inherit; text-align: left; color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.puzzle-card:hover { transform: translateY(-2px); border-color: var(--hover-line); box-shadow: var(--shadow); }
.puzzle-card.cleared { border-color: var(--green); background: var(--card-soft); }
.puzzle-top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.puzzle-stars { color: var(--gold); letter-spacing: 2px; }
.puzzle-state { color: var(--muted); font-size: 11px; }
.puzzle-card.cleared .puzzle-state { color: var(--green); font-weight: 700; }
.puzzle-title { font-family: "STKaiti", "KaiTi", serif; font-size: 19px; font-weight: 700; letter-spacing: 2px; }
.puzzle-desc { font-size: 12.5px; color: var(--muted); }
.puzzle-goal { margin-top: 2px; font-size: 11.5px; color: var(--red); }
/* ==================== 远程对弈：房间页 ==================== */
.icon-online { background: var(--sel-bg); color: var(--green); }
.room-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 10px;
}
.room-head h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--ink); }
.room-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-soft);
}
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.field-input {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  outline: none;
}
.field-input:focus { border-color: var(--red); }
.room-actions { margin-top: 20px; }
.room-or { display: block; text-align: center; font-size: 12px; color: var(--muted); margin: 12px 0; }
.room-join { display: flex; gap: 8px; }
.room-join .field-input { flex: 1; min-width: 0; }
.code-input { letter-spacing: 4px; text-transform: uppercase; font-weight: 700; }
.room-error { margin: 12px 0 0; color: var(--red); font-size: 12.5px; }
.room-code-label { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.room-code {
  font-family: var(--font-mono); font-size: 34px; font-weight: 700;
  letter-spacing: 8px; text-align: center; color: var(--red);
  padding: 12px 0 16px; border-bottom: 1px dashed var(--line);
  margin-bottom: 14px;
}
.room-status { text-align: center; font-size: 13px; color: var(--muted); margin: 14px 0; }
.room-seats { display: flex; gap: 10px; margin: 16px 0; }
.room-seat {
  flex: 1; padding: 10px; border-radius: 10px;
  background: var(--card-soft); border: 1px solid var(--line);
  text-align: center; font-size: 12px; color: var(--muted);
}
.room-seat b { display: block; margin-bottom: 4px; color: var(--ink); font-size: 13px; }
.room-tip { text-align: center; font-size: 11.5px; color: var(--muted); padding: 8px 12px 24px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.primary { background: var(--red); color: #fff; }

/* 残局页：闯关 / 古谱切换 + 搜索 */
.puzzle-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; padding: 3px; background: var(--chip); border: 1px solid var(--line); border-radius: 10px; }
.seg-btn {
  border: 0; background: none; font: inherit; font-size: 13px;
  padding: 6px 15px; border-radius: 8px; color: var(--muted); cursor: pointer;
}
.seg-btn.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-soft); }
.puzzle-search {
  flex: 1 1 150px; min-width: 110px; max-width: 260px;
  padding: 7px 10px; font: inherit; font-size: 13px;
  color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 9px;
}
.puzzle-search::placeholder { color: var(--muted); }
.puzzle-more { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; }
.btn.ghost { background: none; border: 1px dashed var(--line); color: var(--muted); }
.puzzle-empty { grid-column: 1 / -1; padding: 28px 0; text-align: center; color: var(--muted); font-size: 13px; }
.puzzle-tip { margin-top: 20px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.8; }

footer { margin-top: 22px; text-align: center; font-size: 11px; line-height: 1.8; color: var(--muted); }
footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
footer a:hover { color: var(--red); }

@media (max-width: 860px) {
  .home-grid { grid-template-columns: 1fr; }
  .learn-layout { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .app { padding: 16px 12px 28px; }
  .home-head { padding: 16px 0 18px; }
  .home-head h1 { font-size: 32px; letter-spacing: 6px; }
  .puzzle-grid { grid-template-columns: 1fr; }
  .board-frame { padding: 9px; }
}

/* ============================ 底部抽屉 ============================ */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-mask { position: absolute; inset: 0; background: var(--mask); animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet-panel {
  position: relative;
  width: 100%; max-width: 540px; max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  box-shadow: 0 -10px 40px rgba(20, 14, 8, .28);
  animation: sheetUp .22s ease;
}
@keyframes sheetUp {
  from { transform: translateY(30px); opacity: .5; }
  to { transform: none; opacity: 1; }
}
.sheet-grip { width: 44px; height: 4px; margin: 8px auto 6px; border-radius: 99px; background: var(--line); flex: 0 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 16px 8px; flex: 0 0 auto; }
.sheet-head h3 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 17px; letter-spacing: 1px;
}
.sheet-x {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: none; background: none; border-radius: 9px;
  color: var(--muted); font: inherit; cursor: pointer;
}
.sheet-x:active { background: var(--hover); }

.sheet-tabs { display: flex; gap: 6px; padding: 0 16px 10px; flex: 0 0 auto; }
.sheet-tab {
  flex: 1;
  padding: 7px 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-soft);
  color: var(--muted);
  font: inherit; font-size: 12.5px;
  cursor: pointer;
}
.sheet-tab.on {
  background: var(--red);
  border-color: transparent;
  color: #fff6ec;
  font-weight: 600;
}

.sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 0 16px 10px;
  -webkit-overflow-scrolling: touch;
}
.sheet-note { margin: 2px 0 8px; font-size: 11.5px; line-height: 1.75; color: var(--muted); }
.sheet-note-row { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.sheet-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--card-soft);
  color: var(--muted);
  font-size: 10.5px; font-weight: 600;
}
.sheet-badge.custom { background: var(--sel-bg); color: var(--red); }
.sheet-foot {
  flex: 0 0 auto;
  display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
body.sheet-open { overflow: hidden; }

.slider-row { padding: 9px 0; border-bottom: 1px dashed var(--line-dash); }
.slider-row:last-child { border-bottom: none; }
.slider-label { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; font-size: 13px; }
.slider-label b { color: var(--red); font-size: 14px; font-variant-numeric: tabular-nums; }
.slider-hint { min-height: 15px; font-size: 11px; color: var(--muted); }
.slider-group { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.slider-group-title { margin-bottom: 4px; font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--ink); }

/* 外观选择 */
.look-group { margin: 12px 0; }
.look-title { margin-bottom: 6px; font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--ink); }
.look-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.look-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.look-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 7px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card-soft);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: border-color .14s, box-shadow .14s, transform .1s;
}
.look-item:active { transform: scale(.97); }
.look-item.on {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(166, 42, 34, .16);
}
[data-theme="night"] .look-item.on { box-shadow: 0 0 0 2px rgba(228, 105, 90, .28); }
.look-name { font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.look-note { font-size: 9.5px; color: var(--muted); text-align: center; line-height: 1.3; }
.look-grid-4 .look-item { padding: 7px 3px 6px; gap: 3px; }
.look-grid-4 .look-name { font-size: 11px; letter-spacing: -.2px; }
.look-grid-4 .look-swatch { font-size: 10px; }
.look-dots { display: flex; gap: 3px; height: 14px; align-items: center; }
.look-dot { width: 12px; height: 12px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.look-swatch {
  width: 100%; height: 20px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  display: grid; place-items: center;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 13px; font-weight: 700;
  overflow: hidden;
}

.look-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px;
  font-size: 12.5px;
}
.switch {
  display: flex; align-items: center; gap: 8px;
  border: none; background: none; padding: 0;
  color: var(--ink); font: inherit; font-size: 12px;
  cursor: pointer;
}
.switch b { font-weight: 500; font-size: 11.5px; }
.switch-knob {
  position: relative;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--line);
  transition: background .18s;
}
.switch-knob::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .28);
  transition: left .18s;
}
.switch.on .switch-knob { background: var(--green); }
.switch.on .switch-knob::after { left: 18px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px;
  background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border: 2px solid var(--red);
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 2px 6px rgba(120, 40, 20, .26);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--line); }
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  border: 2px solid var(--red);
  border-radius: 50%;
  background: var(--card);
}

@media (hover: none) {
  .home-card:hover, .puzzle-card:hover { transform: none; box-shadow: var(--shadow-soft); }
}
