/* 西游·八十一难 —— 明快国风：宣纸暖底 + 朱砂/藤黄/石绿 */
@font-face {
  font-family: "TsangerJinKai";
  src: url("../static/fonts/tsanger-jinkai-w04.woff2") format("woff2");
  font-weight: 300 500;
  font-display: swap;
}
@font-face {
  font-family: "TsangerJinKai";
  src: url("../static/fonts/tsanger-jinkai-w05.woff2") format("woff2");
  font-weight: 600 900;
  font-display: swap;
}
:root {
  --paper: #f6ead2;
  --paper-deep: #efe0bd;
  --ink: #3b2b20;
  --ink-soft: #7a6248;
  --sand: #d9c592;
  --red: #c8381f;
  --red-deep: #a02714;
  --gold: #e8a93c;
  --green: #3f8f5f;
  --indigo: #46557a;
  --brown: #9c6b4f;
  --font-display: "TsangerJinKai", "Yuanti SC", "YouYuan", "Kaiti SC", "STKaiti", "PingFang SC", sans-serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --card: #fffaf0;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 22px;
  --shadow-sm: 0 1px 4px rgba(59,43,32,.1);
  --shadow-md: 0 2px 10px rgba(59,43,32,.12);
  --shadow-lg: 0 6px 22px rgba(59,43,32,.25);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  background: var(--paper);
  background-image: url("../static/paper.png"),
                    radial-gradient(circle at 20% 10%, rgba(255,255,255,.5), transparent 42%),
                    radial-gradient(circle at 85% 85%, rgba(216,186,124,.18), transparent 50%);
  color: var(--ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- 通用按钮 ---------- */
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  width: 100%; padding: 13px 18px; border-radius: 999px;
  background: var(--card); color: var(--ink);
  box-shadow: 0 1px 3px rgba(59,43,32,.14), 0 4px 12px rgba(59,43,32,.08);
  transition: transform .12s ease, box-shadow .12s ease;
  font-size: 16px;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .42; }
.btn-primary { background: var(--red); color: #fff9ee; }
.btn-danger { color: var(--red-deep); }
.btn-big { font-size: 18px; padding: 16px 18px; }
.btn-label { font-weight: 700; font-family: var(--font-display); letter-spacing: .06em; }
.btn-detail { font-size: 12px; opacity: .82; font-weight: 400; line-height: 1.45; }

/* ---------- 首页 ---------- */
.screen { min-height: 100dvh; }
#home { display: flex; flex-direction: column; align-items: center; padding: max(24px, env(safe-area-inset-top)) 20px 32px; gap: 22px; }
.home-hero { text-align: center; margin-top: 26px; }
/* 品牌标记：与 App 图标同构的双卡（大圣复用 #av-wukong 立绘） */
.hero-mark {
  display: block; width: 126px; height: auto; margin: 0 auto;
  filter: drop-shadow(0 4px 10px rgba(59,43,32,.22));
}
.hero-title {
  font-family: var(--font-display); font-size: clamp(34px, 10vw, 48px); font-weight: 900; white-space: nowrap;
  letter-spacing: .12em; margin-top: 10px; color: var(--ink);
}
.hero-sub { color: var(--ink-soft); font-size: 15px; letter-spacing: .18em; margin-top: 6px; }
.hero-byline { color: #b39b6b; font-size: 12px; letter-spacing: .22em; margin-top: 8px; }
.home-foot { color: #b39b6b; font-size: 12px; letter-spacing: .1em; margin-top: auto; }

.resume-box {
  width: min(480px, 100%); background: var(--card); border-radius: 18px; padding: 16px;
  box-shadow: 0 2px 10px rgba(59,43,32,.1);
}
.resume-box p { font-size: 14px; color: var(--ink-soft); margin-bottom: 12px; }
.resume-btns { display: flex; gap: 10px; }

.setup { width: min(480px, 100%); display: flex; flex-direction: column; gap: 14px; }
.setup-title { font-family: var(--font-display); font-size: 20px; letter-spacing: .08em; }
.setup-title small { font-size: 13px; color: var(--ink-soft); font-weight: 400; margin-left: 8px; }
.slot { background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: 0 1px 4px rgba(59,43,32,.09); margin-bottom: 10px; }
.slot-off { opacity: .62; }
.slot-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.slot-no { font-family: var(--font-display); font-weight: 800; color: var(--ink-soft); }
.seg-group { display: flex; background: var(--paper-deep); border-radius: 999px; padding: 3px; }
.seg {
  padding: 12px 18px; border-radius: 999px; font-size: 15px; color: var(--ink-soft);
  transition: all .15s; min-height: 44px; display: flex; align-items: center;
}
.seg.on { background: var(--ink); color: #fff7e8; font-weight: 700; }
.char-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.char-pick {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 2px; border-radius: 12px; font-size: 12px; color: var(--ink-soft);
  background: var(--paper); transition: all .15s;
}
.char-pick .char-face {
  width: 34px; height: 34px; border-radius: 50%; background: var(--c);
  color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 17px;
  display: flex; align-items: center; justify-content: center; opacity: .45; transition: opacity .15s;
}
.char-pick.on { background: #fff; box-shadow: 0 0 0 2px var(--c), 0 2px 8px rgba(59,43,32,.12); color: var(--ink); font-weight: 700; }
.char-pick.on .char-face { opacity: 1; }
.avatar-art { width: 90%; height: 90%; display: block; }
.char-pick.taken { opacity: .3; }
.char-pick:active { transform: scale(.95); }

/* ---------- 对局框架 ---------- */
#game { display: flex; flex-direction: column; height: 100dvh; }
#game-top {
  display: flex; align-items: center; gap: 10px;
  /* 底部只留 5px：剩下的 3px 挪给玩家条当上边距，给选中光环让位（见 #players-strip） */
  padding: max(10px, env(safe-area-inset-top)) 12px 5px;
  background: rgba(246,234,210,.92); backdrop-filter: blur(6px);
  position: relative; z-index: 5;
  box-shadow: 0 1px 0 rgba(59,43,32,.08);
}
/* 菜单键是对局里最常戳的按钮，保证 44×44 的可点面积 */
#btn-menu {
  font-size: 20px; padding: 6px 10px; border-radius: 10px; color: var(--ink-soft);
  min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
}
#btn-menu:active { transform: scale(.9); }
/* 轮次条分两行：轮数是主角，妖王进度是压低一号的副行。
   合作模式的副行较长，早先写成单行 nowrap，窄屏被截、宽屏把玩家条挤出视野。 */
#turn-indicator { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.turn-round { font-family: var(--font-display); font-weight: 800; letter-spacing: .05em; white-space: nowrap; }
.turn-sub {
  font-size: 11px; color: var(--ink-soft); letter-spacing: .02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.turn-sub.urgent { color: var(--red-deep); font-weight: 700; }
#players-strip {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px;
  /* 上边距必须留住：当前玩家的方框是向外扩 2px 的 box-shadow，padding-top 为 0 时它会画进
     顶栏的地盘，而顶栏 z-index 更高、背景不透明，那一横就被盖没了。 */
  padding: 3px 12px 8px; background: rgba(246,234,210,.92); backdrop-filter: blur(6px);
  position: relative; z-index: 4; box-shadow: 0 1px 0 rgba(59,43,32,.08);
}
.chip {
  display: flex; align-items: flex-start; gap: 6px; min-width: 142px; padding: 5px 8px 5px 5px;
  background: var(--card); border-radius: 13px; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(59,43,32,.1);
  transition: box-shadow .2s;
}
.chip.active { box-shadow: 0 0 0 2px var(--c), 0 2px 6px rgba(59,43,32,.16); }
.chip-avatar {
  width: 27px; height: 27px; border-radius: 50%; background: var(--c);
  color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.chip-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 2px; }
.chip-line { display: flex; align-items: baseline; gap: 5px; }
.chip-name { font-family: var(--font-display); font-size: 11.5px; color: var(--ink); }
.chip-info { font-size: 10px; color: var(--ink-soft); }
.chip-effects { display: flex; flex-wrap: wrap; gap: 3px; }
.chip-effect {
  display: inline-flex; align-items: center; height: 16px; padding: 0 5px; border-radius: 999px;
  background: #eee1c8; color: #695637; font-size: 9.5px; font-weight: 800; line-height: 1;
}
.chip-effect.auto { background: #f8e3a3; color: #8a5b00; }
.chip-effect.buff { background: #dfead5; color: #3f6c43; }
.chip-effect.warning { background: #f6ded5; color: #a33e27; }
.chip-effect.cooldown { background: #dde4ef; color: #465a80; }

#board-wrap { position: relative; flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
#board { display: block; width: 100%; height: auto; }

/* ---------- 棋盘 SVG：水墨长卷 ---------- */
.road-halo { fill: none; stroke: #41504a; stroke-width: 60; stroke-linejoin: round; stroke-linecap: round; opacity: .08; }
.road-edge { fill: none; stroke: #41504a; stroke-width: 46; stroke-linejoin: round; stroke-linecap: round; opacity: .28; }
.road-outer { fill: none; stroke: #c9ad7f; stroke-width: 40; stroke-linejoin: round; stroke-linecap: round; }
.road-inner { fill: none; stroke: #efe2c0; stroke-width: 30; stroke-linejoin: round; stroke-linecap: round; }
.road-dash { fill: none; stroke: #93a099; stroke-width: 2.6; stroke-dasharray: 2 15; stroke-linecap: round; opacity: .75; }
.region-label { font-family: var(--font-display); font-size: 21px; font-weight: 700; fill: #7d8b85; letter-spacing: 7px; opacity: .95; }
.region-tag-box { fill: rgba(248,241,222,.72); stroke: #b4bfb7; stroke-width: 1.4; }
.cell-glyph { font-family: var(--font-display); font-size: 19px; font-weight: 800; }
.cell-num-plain { font-family: var(--font-display); font-size: 13px; font-weight: 700; fill: #99917b; }
.cell-num-badge { font-family: var(--font-display); font-size: 10.5px; font-weight: 800; fill: #41504a; }
.cell-idx-cp { font-family: var(--font-display); font-size: 14px; font-weight: 800; fill: var(--red); }
.seal-caption { font-family: var(--font-display); font-size: 14px; font-weight: 700; fill: #7a6248; }
.cloud-drift-a, .cloud-drift-b, .bg-ink, .buddha-rays { pointer-events: none; }
.cloud-drift-a { animation: cloudDriftA 90s ease-in-out infinite alternate; }
.cloud-drift-b { animation: cloudDriftB 140s ease-in-out infinite alternate; }
@keyframes cloudDriftA { to { transform: translateX(46px); } }
@keyframes cloudDriftB { from { transform: translateX(30px); } to { transform: translateX(-38px); } }
@media (prefers-reduced-motion: reduce) {
  .cloud-drift-a, .cloud-drift-b, .halo,
  #dice-overlay.waiting .die, .battle-stamp.battle-win::after,
  .rank-row:first-child > span:first-child, .flip-back-hint { animation: none; }
}
.seal { stroke-width: 0; }
.seal-red { fill: var(--red); filter: drop-shadow(0 2px 3px rgba(160,39,20,.4)); }
.seal-gold { fill: var(--gold); filter: drop-shadow(0 2px 4px rgba(184,124,20,.5)); }
.seal-green { fill: var(--green); filter: drop-shadow(0 2px 3px rgba(38,94,60,.35)); }
.seal-char { font-family: var(--font-display); font-size: 26px; font-weight: 900; fill: #fff7e8; }
.seal-name { font-family: var(--font-display); font-size: 16px; font-weight: 800; fill: #fff7e8; }
.halo { fill: none; stroke: var(--gold); stroke-width: 3; stroke-dasharray: 6 10; opacity: .8; animation: haloSpin 14s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes haloSpin { to { transform: rotate(360deg); } }
.deco-cloud { pointer-events: none; }

.token { transition: transform .17s ease; }
.token-body { stroke: #fff; stroke-width: 2.5; filter: drop-shadow(0 2px 3px rgba(59,43,32,.35)); }
.token-glyph { font-family: var(--font-display); font-size: 15px; font-weight: 900; fill: #fff; text-anchor: middle; }
.token.active .token-body { animation: tokenPulse 1.6s ease-in-out infinite; }
@keyframes tokenPulse { 0%,100% { stroke-width: 2.5; } 50% { stroke-width: 5.5; } }
.token.hopping .token-body { animation: hop .17s ease-in-out infinite; transform-box: fill-box; transform-origin: center bottom; }
@keyframes hop { 0%,100% { transform: scale(1,1); } 40% { transform: scale(.92,1.12) translateY(-4px); } 70% { transform: scale(1.08,.9); } }
.token.leaping { transition: transform .42s cubic-bezier(.3,-.4,.4,1.4); }

/* ---------- 日志行 & 底部面板 ---------- */
#log-line {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px;
  font-size: 12.5px; color: var(--ink-soft); background: rgba(255,250,240,.86);
  white-space: nowrap; overflow: hidden; cursor: pointer;
  box-shadow: 0 -1px 0 rgba(59,43,32,.07);
}
#log-line-text { overflow: hidden; text-overflow: ellipsis; }
.log-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); flex: none; }
.log-list { max-height: 55dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.log-item { font-size: 13.5px; line-height: 1.55; color: var(--ink-soft); padding-bottom: 8px; border-bottom: 1px dashed rgba(178,148,96,.3); }

#panel {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 3px solid var(--panel-color, var(--red));
  box-shadow: 0 -5px 18px rgba(59,43,32,.13); position: relative; z-index: 5;
}
#panel-avatar {
  width: 50px; height: 50px; border-radius: 50%; flex: none;
  color: #fff; font-family: var(--font-display); font-weight: 900; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 3px #fffaf0, 0 2px 8px rgba(59,43,32,.28);
}
.panel-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.panel-row1 { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; }
.panel-row1 b { font-family: var(--font-display); font-size: 16px; }
#panel-skill { font-size: 11.5px; color: var(--ink-soft); line-height: 1.35; }
.panel-row2 { display: flex; align-items: center; gap: 14px; }
.mana { width: 13px; height: 13px; border-radius: 50%; display: inline-block; background: var(--paper-deep); margin-right: 3px; }
.mana.on { background: var(--red); box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }
.gongde-box { font-size: 13px; color: var(--ink-soft); }
.gongde-box b { color: var(--gold); font-size: 16px; text-shadow: 0 1px 0 rgba(138,91,0,.3); }
#panel-effects {
  display: flex; align-items: center; gap: 6px; min-height: 29px; overflow-x: auto;
  padding: 5px 0 3px; border-top: 1px solid rgba(178,148,96,.26); border-bottom: 1px solid rgba(178,148,96,.2);
  scrollbar-width: none;
}
#panel-effects::-webkit-scrollbar { display: none; }
.effects-label { flex: none; color: var(--panel-color, var(--red)); font-size: 10px; font-weight: 900; letter-spacing: .12em; }
.effect-pill {
  display: inline-flex; align-items: center; gap: 4px; flex: none; border-radius: 999px; padding: 3px 7px 3px 4px;
  background: #f1e7d2; color: #695637; font-size: 11px; font-weight: 800; line-height: 1.25; white-space: nowrap;
}
.effect-pill i {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: currentColor; color: #fffaf0; font-style: normal; font-family: var(--font-display); font-size: 10px;
}
.effect-auto { background: #f8e3a3; color: #8a5b00; }
.effect-buff { background: #dfead5; color: #3f6c43; }
.effect-warning { background: #f6ded5; color: #a33e27; }
.effect-cooldown { background: #dde4ef; color: #465a80; }
/* 横向滚动容器会把子元素的投影裁掉，四周各留 3px 给手牌的阴影 */
#panel-hand { display: flex; gap: 8px; overflow-x: auto; padding: 3px; margin: -3px; }
.hand-card {
  display: flex; flex-direction: column; align-items: center; gap: 1px; flex: none;
  width: 52px; min-height: 44px; justify-content: center; padding: 5px 2px; border-radius: 10px;
  background: var(--paper); font-family: var(--font-display); font-weight: 800; font-size: 16px; color: var(--red);
  box-shadow: 0 1px 3px rgba(59,43,32,.12);
}
.hand-card em { font-style: normal; font-size: 9.5px; color: var(--ink-soft); font-weight: 400; white-space: nowrap; }
.hand-card:active { transform: scale(.93); }
.hand-card-back { background: #ece0c4; color: #b8a37e; box-shadow: inset 0 0 0 2px #dccfa9; }
.hand-card-back em { color: #b8a37e; }
.hand-card-back:active { transform: none; }
.hand-empty { font-size: 12px; color: #c2ab84; }

/* ---------- 遇妖震屏 ---------- */
@keyframes gameShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 1px); }
  80% { transform: translate(2px, -1px); }
}
#game.shake { animation: gameShake .4s ease-out; }

/* ---------- 台词气泡 ---------- */
.token-quip {
  position: absolute; z-index: 5; transform: translate(-50%, -100%) scale(.6); opacity: 0;
  background: #fff7e8; color: var(--ink); border: 2px solid var(--ink-soft);
  border-radius: 12px; padding: 5px 10px; font-family: var(--font-display); font-weight: 800; font-size: 14px;
  white-space: nowrap; pointer-events: none; box-shadow: 0 3px 8px rgba(59,43,32,.25);
  transition: transform .18s cubic-bezier(.2,1.4,.4,1), opacity .18s;
}
.token-quip::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--ink-soft); border-bottom: 0;
}
.token-quip.show { transform: translate(-50%, -100%) scale(1); opacity: 1; }

/* ---------- 降妖录 ---------- */
.dex-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.dex-cell {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: rgba(255,255,255,.45); border-radius: 12px; padding: 8px 2px 6px;
}
.dex-face {
  width: 44px; height: 44px; border-radius: 50%; background: var(--indigo);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); color: #f2ecdd; font-weight: 800;
}
.dex-face svg { width: 38px; height: 38px; }
.dex-cell em { font-style: normal; font-size: 10.5px; color: var(--ink); white-space: nowrap; }
.dex-unknown .dex-face { background: #b8ab90; }
.dex-unknown em { color: #a8946e; }
.dex-stamp {
  position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; line-height: 18px; text-align: center;
  background: var(--red); color: #fff7e8; font-size: 11px; font-family: var(--font-display); font-weight: 800;
  border-radius: 5px; font-style: normal; transform: rotate(8deg);
}
.dex-hint { margin-top: 8px; font-size: 11.5px; color: var(--ink-soft); }

/* ---------- 战报行 ---------- */
.rank-copy { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rank-copy .rank-detail { margin-left: 0; }
.rank-stats { font-size: 11px; color: var(--ink-soft); }

/* ---------- 回合横幅 ---------- */
.turn-banner {
  position: fixed; left: 0; top: 21%; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px 10px 14px; border-radius: 0 999px 999px 0;
  background: var(--c); color: #fff7e8;
  font-family: var(--font-display); font-weight: 800; font-size: 21px;
  box-shadow: 0 4px 14px rgba(59,43,32,.35);
  transform: translateX(-105%); transition: transform .28s cubic-bezier(.2,1.2,.4,1);
  pointer-events: none;
}
.turn-banner.show { transform: translateX(0); }
.turn-banner.out { transform: translateX(-105%); transition: transform .25s ease-in; }
.tb-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: rgba(255,247,232,.28); display: flex; align-items: center; justify-content: center;
}
.tb-avatar .avatar-art { width: 36px; height: 36px; }

/* ---------- 首次引导 ---------- */
.sheet-onboard { text-align: center; }
.ob-art { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 14px 0 4px; flex-wrap: wrap; }
.ob-seal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 60px; height: 60px; border-radius: 13px;
  font-family: var(--font-display); font-weight: 800; font-size: 17px; color: #fff;
  box-shadow: 0 2px 6px rgba(59,43,32,.25);
}
.ob-seal-red { background: var(--red); }
.ob-seal-gold { background: #d9a441; }
.ob-arrow { font-size: 24px; color: var(--ink-soft); }
.ob-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--c); color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 17px;
}
.ob-dot-cp { border-radius: 11px; background: var(--red); }
.ob-choice {
  display: inline-flex; padding: 9px 16px; border-radius: 11px;
  background: var(--paper); font-family: var(--font-display); font-weight: 800; font-size: 16px; color: var(--red);
  box-shadow: 0 1px 3px rgba(59,43,32,.15);
}
.ob-dots { display: flex; justify-content: center; gap: 6px; margin: 10px 0 2px; }
.ob-dots i { width: 7px; height: 7px; border-radius: 50%; background: #d8c9a5; }
.ob-dots i.on { background: var(--red); }

/* ---------- 弹层 ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(59,43,32,0); transition: background .22s;
}
.modal-wrap.show { background: rgba(59,43,32,.42); }
.sheet {
  width: min(520px, 100%); max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(40px); opacity: 0; transition: transform .22s ease, opacity .22s ease;
}
.modal-wrap.show .sheet { transform: translateY(0); opacity: 1; }
.sheet-kicker {
  display: inline-block; font-size: 12px; letter-spacing: .25em; color: #fff7e8;
  background: var(--ink); border-radius: 6px; padding: 3px 9px 3px 11px; margin-bottom: 10px;
  font-family: var(--font-display);
}
.sheet-title { font-family: var(--font-display); font-size: 21px; font-weight: 900; letter-spacing: .04em; margin-bottom: 8px; }
.sheet-body { font-size: 14px; line-height: 1.65; color: var(--ink-soft); }
/* 面板内容长到要滚动时，滚动容器会削掉最后一颗按钮的投影，垫 3px 让它完整 */
.sheet-btns { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; padding-bottom: 3px; }
.enc-hint { background: rgba(70,85,122,.1); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.cp-intro { font-size: 15px; line-height: 1.8; }
.sheet-checkpoint .sheet-kicker { background: var(--red); }
.rules h4 { font-family: var(--font-display); margin: 14px 0 4px; color: var(--ink); }
.rules p { margin-bottom: 4px; }

/* 卡牌 */
.sheet-card { display: flex; flex-direction: column; align-items: center; }
.game-card {
  width: min(300px, 82vw); border-radius: 18px; padding: 26px 22px 18px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: var(--shadow-lg);
  animation: cardIn .3s cubic-bezier(.2,1.4,.5,1);
  position: relative;
  background-image: url("../static/paper.png");
}
.game-card::before {
  content: ""; position: absolute; inset: 7px; border-radius: 12px; pointer-events: none;
  border: 1.5px solid currentColor; opacity: .3;
}
.game-card::after {
  content: ""; position: absolute; inset: 11px; border-radius: 9px; pointer-events: none;
  border: 1px solid currentColor; opacity: .14;
}
@keyframes cardIn { from { transform: scale(.7) rotate(-3deg); opacity: 0; } }
.card-glyph {
  width: 62px; height: 62px; border-radius: 50%; font-family: var(--font-display);
  font-size: 32px; font-weight: 900; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.25); position: relative;
  box-shadow: 0 0 0 3px rgba(255,255,255,.28), 0 0 0 7px rgba(255,255,255,.1);
}
.card-demon .card-glyph::before, .card-demon .card-glyph::after {
  content: ""; position: absolute; top: -9px; width: 15px; height: 16px; background: #2f3c59;
}
.card-demon .card-glyph::before { left: 3px; clip-path: polygon(15% 100%, 0% 0%, 100% 70%); transform: rotate(-8deg); }
.card-demon .card-glyph::after { right: 3px; clip-path: polygon(85% 100%, 100% 0%, 0% 70%); transform: rotate(8deg); }
/* 有立绘的妖怪卡：撤掉字符和通用小角，立绘占满圆章 */
.card-demon .card-art::before, .card-demon .card-art::after { display: none; }
.card-art svg { width: 56px; height: 56px; }
.card-name { font-family: var(--font-display); font-size: 23px; font-weight: 900; letter-spacing: .1em; }
.card-power { font-size: 13px; font-weight: 700; opacity: .95; }
.card-text { font-size: 13.5px; line-height: 1.65; opacity: .92; }
.card-source { font-size: 11px; opacity: .65; margin-top: 4px; }
.card-treasure { background: #fdf3dd; color: var(--ink); box-shadow: 0 0 0 4px var(--gold) inset, 0 6px 22px rgba(59,43,32,.25); }
.card-treasure .card-glyph { background: var(--gold); color: #fff7e8; }
.card-fortune { background: var(--gold); color: #4a3405; }
.card-fortune .card-glyph { background: rgba(255,255,255,.4); color: #7a5410; }
.card-mishap { background: var(--brown); color: #fdf0e2; }
.card-demon { background: var(--indigo); color: #f2ecdd; }
.card-demon .card-glyph { background: #2f3c59; color: #fff; }

/* 斗法 */
.sheet-battle { text-align: center; }
.battle-line { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0; }
.battle-math { font-size: 20px; color: var(--ink); }
.battle-math b { font-size: 28px; }
.battle-math em { font-style: normal; color: var(--ink-soft); font-size: 15px; }
.battle-vs { font-family: var(--font-display); color: var(--ink-soft); }
.battle-stamp {
  display: inline-block; font-family: var(--font-display); font-size: 34px; font-weight: 900;
  width: 64px; height: 64px; line-height: 64px; border-radius: 14px; margin: 4px auto;
  transform: rotate(-6deg); animation: stampIn .25s cubic-bezier(.2,1.6,.5,1);
  position: relative;
}
@keyframes stampIn { from { transform: scale(2.2) rotate(-6deg); opacity: 0; } }
.battle-win { background: var(--red); color: #fff7e8; box-shadow: 0 3px 10px rgba(160,39,20,.4); }
.battle-stamp.battle-win::after {
  content: ""; position: absolute; inset: -22px; border-radius: 50%; z-index: -1;
  background: radial-gradient(circle, rgba(232,169,60,.6), rgba(232,169,60,.18) 55%, transparent 72%);
  animation: winBurst .8s ease-out .12s both;
}
@keyframes winBurst {
  0% { transform: scale(.2); opacity: 0; }
  45% { opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}
.battle-lose { background: #6b6257; color: #f2ecdd; }
.stamp-plain { background: var(--paper-deep); color: var(--ink-soft); box-shadow: inset 0 0 0 2px var(--sand); }

/* 骰子 */
#dice-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; pointer-events: none;
  perspective: 620px;
}
#dice-overlay[hidden] { display: none; }
.die {
  width: 92px; height: 92px; background: var(--card); border-radius: 20px;
  display: grid; grid-template-columns: repeat(3, 1fr); padding: 14px; gap: 4px;
  box-shadow: 0 8px 24px rgba(59,43,32,.35), 0 0 0 3px rgba(200,56,31,.15);
}
#dice-overlay.settle .die { animation: diePop .3s cubic-bezier(.2,1.6,.4,1); }
@keyframes diePop { 40% { transform: scale(1.18) rotate(4deg); } }
.die i { border-radius: 50%; }
.die .pip { background: var(--red); box-shadow: inset 0 -2px 2px rgba(0,0,0,.2); }
#dice-label {
  font-family: var(--font-display); font-weight: 800; letter-spacing: .1em;
  background: var(--ink); color: #fff7e8; border-radius: 999px; padding: 6px 18px; font-size: 15px;
}

/* 胜利榜 */
.rank-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.rank-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.rank-row .rank-detail { margin-left: auto; font-size: 12.5px; color: var(--ink-soft); }
.rank-row:first-child {
  background: linear-gradient(160deg, #fff8e3, #ffeec4);
  box-shadow: inset 0 0 0 2px var(--gold), 0 2px 8px rgba(184,124,20,.22);
}
.rank-row:first-child > span:first-child { animation: trophyPulse 1.3s ease-in-out infinite; }
@keyframes trophyPulse { 50% { transform: scale(1.22) rotate(-6deg); } }
.sheet:has(.rank-list) {
  background-image:
    repeating-conic-gradient(from 0deg at 50% -80px, rgba(232,169,60,.09) 0 7deg, transparent 7deg 14deg),
    url("../static/paper.png");
}

/* 提示条 */
.toast {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; z-index: 70;
  transform: translate(-50%, -16px); opacity: 0;
  background: var(--ink); color: #fff7e8; font-size: 13.5px;
  border-radius: 999px; padding: 8px 18px; pointer-events: none;
  transition: all .25s ease; max-width: 86vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* 移动端：玩家条两列铺开，避免横向裁切 */
@media (max-width: 719px) {
  .chip { min-width: 0; }
  .chip-line { flex-wrap: wrap; }
}

/* 矮屏（iPhone SE 一档，再算上 Safari 底部地址栏）：棋盘一度只剩四成屏幕。
   这里逐项收紧非棋盘区域的留白——可点的东西（头像 44、手牌）一律不动。 */
@media (max-height: 800px) {
  #game-top { padding: max(6px, env(safe-area-inset-top)) 12px 2px; }
  #players-strip { padding: 3px 10px 6px; gap: 5px; }
  .chip { padding: 4px 7px 4px 4px; gap: 5px; }
  .chip-avatar { width: 24px; height: 24px; font-size: 12px; }
  #log-line { padding: 5px 12px; }
  #panel { padding: 8px 14px calc(9px + env(safe-area-inset-bottom)); gap: 10px; }
  #panel-avatar { width: 44px; height: 44px; font-size: 19px; }
  .panel-main { gap: 4px; }
  #panel-effects { min-height: 26px; padding: 4px 0 2px; }
}

/* 桌面端 */
@media (min-width: 720px) {
  #game { max-width: 720px; margin: 0 auto; box-shadow: 0 0 40px rgba(59,43,32,.12); }
  /* 玩家条保持两列：720 宽挤四个的话「第18格 · 7法力 · 4功德」会被截掉 */
  .modal-wrap { align-items: center; }
  .sheet { border-radius: 22px; }
}

/* 悬赏令只在宽屏边栏常驻；窄屏仍走菜单里的「本局悬赏」，不跟棋盘抢地方 */
#rail-bounties { display: none; }

/* 宽屏：棋盘两侧本来是大片空白，把玩家条和本局悬赏整块挪到右边做成记分栏。
   顶栏因此只剩菜单和轮次，再长的妖王进度也挤不着谁。 */
@media (min-width: 1024px) {
  #game {
    max-width: 1040px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 272px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "top   rail"
      "board rail"
      "log   rail"
      "panel rail";
    column-gap: 16px;
    padding-right: 16px;
  }
  #game-top { grid-area: top; }
  #board-wrap { grid-area: board; }
  #log-line { grid-area: log; }
  #panel { grid-area: panel; }
  #rail {
    grid-area: rail; min-height: 0; overflow-y: auto;
    /* 左右各留 6px：overflow-y:auto 会让横向也变成裁切框。3px 只够那圈实心方框，
       卡片本身还有一层 0 2px 6px 的柔光投影，要 6px 才不被削。 */
    display: flex; flex-direction: column; gap: 14px; padding: 12px 6px;
  }
  #players-strip {
    grid-template-columns: 1fr; gap: 8px;
    padding: 0; background: none; backdrop-filter: none; box-shadow: none;
  }
  /* 竖排时每块有整行可用，名字和状态各占一行读起来更清楚 */
  #players-strip .chip { padding: 8px 10px; }
  #players-strip .chip-line { flex-wrap: wrap; }
  #rail-bounties { display: block; }
  .turn-sub { white-space: normal; }
}

/* ---------- 宽屏边栏的悬赏令 ---------- */
.rail-title {
  display: flex; align-items: baseline; gap: 6px; margin: 0 2px 8px;
  font-family: var(--font-display); font-weight: 800; font-size: 13px; color: var(--ink);
}
.rail-title small { font-size: 11px; font-weight: 400; color: var(--ink-soft); }
.rail-bounty {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--card); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid rgba(59,43,32,.08);
}
.rail-bounty.claimed { opacity: .5; }
.rail-bounty .rb-glyph {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 14px;
  background: var(--paper-deep); color: var(--red-deep);
}
.rail-bounty.claimed .rb-glyph { background: #e6dcc6; color: var(--ink-soft); }
.rb-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rb-copy b { font-size: 12.5px; letter-spacing: .03em; }
.rb-copy small { font-size: 11px; color: var(--ink-soft); line-height: 1.4; }
.rb-copy .rb-reward { color: var(--red-deep); font-weight: 700; }
.rb-copy .rb-claimed { color: var(--ink-soft); font-weight: 700; }

/* ---------- 路线选择 ---------- */
#routes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.route {
  background: var(--card); border-radius: 14px; padding: 10px 12px;
  border: 2px solid transparent; text-align: left;
  box-shadow: 0 1px 4px rgba(59,43,32,.09);
  display: flex; flex-direction: column; gap: 2px;
  transition: border-color .12s, transform .12s;
}
.route:active { transform: scale(.97); }
.route b { font-family: var(--font-display); font-size: 15px; }
.route small { font-size: 12px; color: var(--ink-soft); }
.route.on { border-color: var(--red); }
.route.on b { color: var(--red-deep); }

/* ---------- 抽卡翻牌 ---------- */
.flip-box { perspective: 900px; }
.flip-inner { position: relative; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.35,1.2,.4,1); }
.flip-inner.flipped { transform: rotateY(180deg); }
/* iOS Safari：flip-back-hint 的动画会生成独立合成层，无视父级 backface-visibility，
   翻转后背面文字会镜像透在正面上，故转到侧面时就隐藏背面。
   缓动 cubic-bezier(.35,1.2,.4,1) 有回弹，进度 0.5（正面开始朝向观众）出现在 15.7% ≈ 86ms，
   延迟必须卡在这之前——早先写 .25s 太晚，中间约 164ms 正反面同时可见。 */
.flip-inner.flipped .flip-back { visibility: hidden; transition: visibility 0s .08s; }
.flip-face { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-front { transform: rotateY(180deg); }
.flip-back {
  position: absolute; inset: 0; border-radius: 18px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  box-shadow: 0 6px 22px rgba(59,43,32,.3);
  background-image: repeating-radial-gradient(circle at 50% 42%, rgba(255,255,255,.1) 0 14px, transparent 14px 30px);
}
.flip-back-glyph {
  width: 84px; height: 84px; border-radius: 50%; background: rgba(255,250,240,.92);
  font-family: var(--font-display); font-size: 44px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.flip-back-hint {
  font-family: var(--font-display); font-weight: 800; font-size: 14px; letter-spacing: .12em;
  color: rgba(255,250,240,.95);
  /* 只动颜色：transform/opacity 动画会把元素提升为独立合成层，
     那样它就不再受父级 backface-visibility 约束，翻面后会镜像透到正面上 */
  animation: hintFade 1.1s ease-in-out infinite;
}
@keyframes hintFade { 50% { color: rgba(255,250,240,.55); } }
.flip-back-treasure { background-color: var(--red); }
.flip-back-treasure .flip-back-glyph { color: var(--red-deep); }
.flip-back-fortune { background-color: var(--gold); }
.flip-back-fortune .flip-back-glyph { color: #7a5410; }
.flip-back-fortune .flip-back-hint { color: #4a3405; }
.flip-back-mishap { background-color: var(--brown); }
.flip-back-mishap .flip-back-glyph { color: var(--brown); }
.flip-back-demon { background-color: var(--indigo); }
.flip-back-demon .flip-back-glyph { color: var(--indigo); }
@keyframes hintPulse { 50% { transform: scale(1.08); opacity: .8; } }

/* ---------- 骰子等待点击 ---------- */
#dice-overlay.waiting { pointer-events: auto; cursor: pointer; background: rgba(59,43,32,.28); }
#dice-overlay.waiting .die { animation: dieWobble 1.1s ease-in-out infinite; }
@keyframes dieWobble {
  0%, 100% { transform: rotate(-7deg) rotateX(14deg) rotateY(-16deg) translateY(0); }
  25% { transform: rotate(6deg) rotateX(-18deg) rotateY(12deg) translateY(-8px); }
  50% { transform: rotate(-5deg) rotateX(10deg) rotateY(20deg) translateY(-2px); }
  75% { transform: rotate(7deg) rotateX(-12deg) rotateY(-14deg) translateY(-6px); }
}
#dice-overlay.waiting #dice-label { animation: hintPulse 1.1s ease-in-out infinite; }

/* ---------- 选角基础数据展示 ---------- */
.char-pick .char-power { font-size: 12px; color: var(--ink-soft); letter-spacing: .02em; }
.char-pick.on .char-power { color: var(--red-deep); font-weight: 800; }
.char-pick .char-specialty { font-size: 11.5px; color: var(--c); font-weight: 800; letter-spacing: .05em; }
.char-info {
  margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--paper);
  font-size: 12px; line-height: 1.6; color: var(--ink-soft);
  display: flex; flex-direction: column; gap: 2px;
}
.char-info b {
  display: inline-block; background: var(--paper-deep); color: var(--ink);
  border-radius: 6px; padding: 0 6px; margin-right: 6px; font-size: 11px;
}

/* ---------- 悬赏令 ---------- */
.bounty-list { display: flex; flex-direction: column; gap: 10px; }
.bounty-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--paper); border-radius: 12px; position: relative;
}
.bounty-row.claimed { opacity: .55; }
.bounty-glyph {
  flex: none; width: 40px; height: 48px; display: grid; place-items: center;
  background: var(--red); color: #fff7e8; border-radius: 8px;
  font-family: var(--font-display); font-size: 22px; font-weight: 800;
  transform: rotate(-3deg); box-shadow: 0 2px 6px rgba(160,39,20,.3);
}
.bounty-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bounty-copy b { font-size: 15px; letter-spacing: .04em; }
.bounty-copy small { font-size: 12px; color: var(--ink-soft); line-height: 1.45; }
.bounty-copy .bounty-reward { color: var(--red-deep); font-weight: 700; }
.bounty-stamp {
  margin-left: auto; flex: none; font-family: var(--font-display); font-size: 12px; font-weight: 800;
  color: var(--red-deep); border: 2px solid var(--red-deep); border-radius: 8px;
  padding: 3px 6px; text-align: center; line-height: 1.3; transform: rotate(8deg); opacity: .9;
}

/* ---------- 玩法模式选择与妖王棋子 ---------- */
#modes { display: grid; gap: 8px; margin-bottom: 8px; }
#coop-levels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
#modes .route { width: 100%; }
/* 玩法与难度和「走哪条路」一样是单选，选中态就沿用同一套红框，别自成一格 */
.token-hunter .token-glyph { font-size: 15px; }
.token-hunter { filter: drop-shadow(0 2px 5px rgba(47,42,51,.5)); }

/* ---------- 徽章墙 ---------- */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge-cell {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 12px 6px 9px; background: var(--paper); border-radius: 12px; text-align: center;
}
.badge-cell .badge-medal {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; background: #d9cdb4; color: #a99a7c;
  font-family: var(--font-display); font-size: 22px; font-weight: 800;
  border: 2.5px dashed #bfb094;
}
.badge-cell.on .badge-medal {
  background: radial-gradient(circle at 35% 30%, #f3c96a, var(--gold) 60%, #c8862a);
  color: #6b4a00; border: 2.5px solid #b9821c;
  box-shadow: 0 2px 8px rgba(200,134,42,.45);
}
.badge-cell em { font-style: normal; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.badge-cell.on em { color: var(--ink); }
.badge-cell small { font-size: 10.5px; color: var(--ink-soft); line-height: 1.4; opacity: .85; }
.badge-solo { background: none; }
.badge-solo .badge-medal { width: 64px; height: 64px; font-size: 32px; margin: 0 auto; }

/* ---------- 选角长短板与评分 ---------- */
.char-ratings {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px;
  padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px dashed var(--sand);
}
.char-ratings span {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--ink); font-weight: 700; letter-spacing: .06em;
}
.char-ratings i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--paper-deep); box-shadow: inset 0 0 0 1px var(--sand);
}
.char-ratings i.on { background: var(--gold); box-shadow: inset 0 0 0 1px #b9821c; }
.char-ratings i:first-of-type { margin-left: auto; }
.char-info .ci-pros b { background: #dbeadf; color: #2c6b45; }
.char-info .ci-cons b { background: #f3ded8; color: #a02714; }
.char-info .ci-note {
  color: var(--ink-soft); opacity: .8; font-size: 12px; margin-right: 5px;
}


/* ---------- 选角摘要：评分条 + 「看看本事」按钮（详情走弹层，避免选角页过长） ---------- */
.char-brief { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.char-brief .char-ratings { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.char-more {
  width: 100%; min-height: 44px; padding: 11px 14px; border-radius: 12px;
  background: var(--paper); color: var(--ink);
  font-family: var(--font-display); font-size: 14px; font-weight: 700; letter-spacing: .04em;
  box-shadow: inset 0 0 0 1.5px var(--sand);
  transition: transform .12s ease;
}
.char-more::after { content: " ›"; color: var(--ink-soft); font-weight: 800; }
.char-more:active { transform: scale(.97); }

/* ---------- 对局中点头像看角色卡 ---------- */
#panel-avatar { cursor: pointer; position: relative; }
/* 头像右下角一个「?」，暗示可以点开角色卡 */
#panel-avatar::after {
  content: "?"; position: absolute; right: -2px; bottom: -2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--card); color: var(--ink-soft);
  font-size: 11px; font-weight: 800; line-height: 16px; text-align: center;
  box-shadow: 0 1px 3px rgba(59,43,32,.25);
}
#panel-avatar:active { transform: scale(.94); }
.char-info-solo { background: none; padding: 0; }
