:root {
  --walnut: #1d140e;
  --walnut-2: #2e2016;
  --gold: #d9ae5c;
  --gold-soft: rgba(217, 174, 92, .28);
  --paper: #f6ecd8;
  --paper-2: #ecdcbc;
  --ink: #2a1d14;
  --red: #b5302a;
  --kai: "KaiTi", "STKaiti", "Kaiti SC", "BiauKai", serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--paper); overflow-x: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 35%, #3b291b 0%, transparent 70%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0 2px, transparent 2px 7px),
    var(--walnut);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- 封面 ---------- */
#cover { display: flex; align-items: center; justify-content: center; padding: 24px 16px 60px; position: relative; overflow: hidden; }
#cover::before {
  content: "棋"; position: absolute; font-family: var(--kai); font-size: min(80vw, 640px); line-height: 1;
  color: rgba(217, 174, 92, .035); right: -6vw; bottom: -12vh; pointer-events: none;
}
.cover-inner { width: min(440px, 100%); display: flex; flex-direction: column; align-items: center; position: relative; }
#emblem { width: min(380px, 92vw); height: auto; overflow: visible; }
.title { margin: 2px 0 0; display: flex; align-items: center; gap: 14px; font-family: var(--kai); font-weight: 700; }
.title span {
  font-size: clamp(44px, 12vw, 64px); letter-spacing: .08em;
  background: linear-gradient(180deg, #f8e3b0 10%, #d9ae5c 60%, #a87a34);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.35));
}
.seal {
  font-style: normal; font-size: 14px; line-height: 1.15; letter-spacing: .1em; color: #fbe9de; background: var(--red);
  padding: 6px 5px 6px 7px; border-radius: 4px; transform: rotate(4deg);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25), 0 2px 6px rgba(0,0,0,.4);
}
.tagline { margin: 6px 0 22px; color: #bfa57c; letter-spacing: .25em; font-size: 13px; }
.setup {
  width: 100%; padding: 20px 20px 14px; border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--gold-soft); box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.lbl { width: 34px; flex: none; font-size: 13px; color: #bfa57c; }
.seg { flex: 1; display: flex; padding: 3px; border-radius: 11px; background: rgba(0,0,0,.3); border: 1px solid rgba(217,174,92,.15); }
.seg button { flex: 1; padding: 8px 4px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: #cdb48a; font-size: 14px; transition: background .15s, color .15s; }
.seg button.on { background: linear-gradient(180deg, #f3dca6, #d9ae5c); color: var(--ink); font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.cta {
  width: 100%; margin-top: 6px; padding: 13px; border: 0; border-radius: 12px; cursor: pointer;
  font-family: var(--kai); font-size: 22px; font-weight: 700; letter-spacing: .3em; color: #fff4e6;
  background: linear-gradient(180deg, #d2463c, #9e2620); box-shadow: 0 6px 0 #6e1712, 0 12px 24px rgba(0,0,0,.4);
  transition: transform .08s, box-shadow .08s;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 #6e1712, 0 6px 14px rgba(0,0,0,.4); }
.sub-actions { display: flex; justify-content: center; gap: 22px; margin-top: 14px; }
.link { background: none; border: 0; color: #cdb48a; cursor: pointer; font-size: 14px; padding: 4px; text-decoration: underline; text-underline-offset: 4px; text-decoration-color: rgba(205,180,138,.4); }
.link:hover { color: var(--gold); }

/* ---------- 对局 ---------- */
/* 底部留 56px：happydavid 外壳在左下角有一排悬浮按钮 */
#game { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 12px 12px 56px; }
.table { display: flex; flex-direction: column; align-items: stretch; gap: 8px; width: min(94vw, 580px, calc((100dvh - 220px) * .9)); }
.board-wrap { position: relative; }
#board { width: 100%; height: auto; display: block; user-select: none; touch-action: manipulation;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.55)); }

.tray {
  display: flex; align-items: center; gap: 4px; min-height: 54px; padding: 4px 10px; border-radius: 12px;
  background: linear-gradient(180deg, #3a2819, #2a1c12); border: 1px solid rgba(217,174,92,.14);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.45); transition: border-color .2s, box-shadow .2s;
}
.tray.active { border-color: rgba(217,174,92,.6); box-shadow: inset 0 2px 8px rgba(0,0,0,.45), 0 0 0 3px rgba(217,174,92,.12); }
.tray-label { font-size: 11px; line-height: 1.25; color: #a68b62; text-align: center; margin-right: 6px; writing-mode: vertical-rl; letter-spacing: .15em; }
.tray .empty { font-size: 12px; color: #6f5a40; }
.hp { position: relative; width: 42px; height: 46px; padding: 0; border: 0; border-radius: 9px; background: none; cursor: pointer; transition: transform .12s, background .12s; }
.hp svg { width: 100%; height: 100%; overflow: visible; }
.hp:disabled { cursor: default; }
.hp:not(:disabled):hover { transform: translateY(-2px); }
.hp.on { background: rgba(217,174,92,.25); box-shadow: 0 0 0 2px var(--gold); }
.hp b { position: absolute; right: -3px; bottom: -3px; min-width: 17px; background: var(--red); color: #fff; font-size: 11px; line-height: 17px; border-radius: 9px; padding: 0 4px; }

/* 侧边按键栏 */
.rail { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.turn { width: 64px; padding: 8px 2px; text-align: center; border-radius: 14px; background: rgba(0,0,0,.25); border: 1px solid rgba(217,174,92,.15); margin-bottom: 4px; }
.turn svg { width: 34px; height: 36px; display: block; margin: 0 auto 2px; overflow: visible; }
.turn .t1 { font-size: 12px; font-weight: 700; }
.turn .t2 { font-size: 10.5px; color: #bfa57c; min-height: 13px; }
.turn .t2.warn { color: #ff7a66; font-weight: 700; }
.turn.thinking svg { animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }
.ib {
  width: 56px; height: 56px; border-radius: 14px; border: 1px solid rgba(217,174,92,.2); cursor: pointer;
  background: rgba(255,255,255,.05); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: #e9d8b6; transition: background .15s, border-color .15s;
}
.ib:hover:not(:disabled) { background: rgba(217,174,92,.16); border-color: rgba(217,174,92,.5); }
.ib:disabled { opacity: .35; cursor: default; }
.ib svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ib span { font-size: 10.5px; color: #bfa57c; }
.ib.on { background: rgba(217,174,92,.2); border-color: var(--gold); }
.more-wrap { position: relative; }
.menu {
  position: absolute; right: calc(100% + 10px); bottom: 0; min-width: 150px; padding: 6px; border-radius: 12px; z-index: 5;
  background: var(--paper); color: var(--ink); box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.menu button, .menu label { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 14px; color: var(--ink); }
.menu button:hover, .menu label:hover { background: var(--paper-2); }
.menu hr { border: 0; border-top: 1px solid #d9c6a2; margin: 4px 6px; }

/* 棋谱抽屉 */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(300px, 86vw); z-index: 8; background: var(--paper); color: var(--ink);
  box-shadow: -10px 0 30px rgba(0,0,0,.4); transform: translateX(105%); transition: transform .25s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid #e0cfae; font-family: var(--kai); font-size: 20px; }
.drawer ol { flex: 1; overflow-y: auto; margin: 0; padding: 10px 16px 20px 40px; font-size: 13.5px; line-height: 1.9; }
.drawer li.r { color: var(--red); } .drawer li.b { color: var(--ink); }
.drawer li::marker { color: #a08a68; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: #8a6a48; padding: 2px 6px; }

/* ---------- 棋盘 SVG ---------- */
.grid { stroke: #5a3517; stroke-width: 1.3; }
.grid-out { fill: none; stroke: #5a3517; stroke-width: 3; }
.star { fill: none; stroke: #5a3517; stroke-width: 1.3; }
.river { fill: #6b4020; font-size: 30px; font-family: var(--kai); letter-spacing: 18px; opacity: .7; text-anchor: middle; }
.coord { fill: #caa25b; font-size: 11px; text-anchor: middle; font-family: Georgia, serif; }

.pc { fill: url(#pcFill); stroke: #7a4a22; stroke-width: 1.4; }
.pc-in { fill: none; stroke: rgba(122,74,34,.28); stroke-width: 1; }
.pc.promo { stroke: #c79a2a; stroke-width: 2.6; }
.pc.round { fill: url(#pcRound); }
.ring { fill: none; stroke-width: 1.4; }
.ring.r { stroke: var(--red); } .ring.b { stroke: #1f1a16; }
.ch { font-family: var(--kai); font-weight: 700; font-size: 26px; text-anchor: middle; }
.ch.two { font-size: 16px; }
.ch.r, .sub.r { fill: var(--red); }
.ch.b, .sub.b { fill: #1f1a16; }
.sub { font-size: 9.5px; text-anchor: middle; font-weight: 700; }
.glyph { font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; font-size: 46px; text-anchor: middle;
  paint-order: stroke; stroke: #f8e7c2; stroke-width: 3px; stroke-linejoin: round; }
.glyph.r { fill: var(--red); } .glyph.b { fill: #1f1a16; }
.gshadow { fill: rgba(40,20,5,.3); }
.gsub { font-size: 10px; text-anchor: middle; font-weight: 700; paint-order: stroke; stroke: #f8e7c2; stroke-width: 3px; }
.gsub.r { fill: var(--red); } .gsub.b { fill: #1f1a16; }

.pw { filter: drop-shadow(1px 2.5px 1.5px rgba(50,25,5,.45)); transition: filter .15s; }
.pw.lift { filter: drop-shadow(2px 7px 4px rgba(50,25,5,.45)); }
.pw .lifter { transition: transform .15s; }
.pw.lift .lifter { transform: translateY(-4px); }
.pw.pop { animation: pop .28s cubic-bezier(.2,1.4,.4,1); transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

.hl-from { fill: none; stroke: rgba(217,150,40,.85); stroke-width: 2; stroke-dasharray: 3 3; }
.hl-to { fill: url(#glowTo); }
.hl-sel { fill: url(#glowSel); }
.hl-check { fill: none; stroke: #e0301e; stroke-width: 3.5; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: .35; } }
.dot { fill: rgba(30, 95, 70, .65); }
.cap { fill: none; stroke: rgba(205, 40, 30, .9); stroke-width: 3; }
.castle { fill: none; stroke: #c79a2a; stroke-width: 3; stroke-dasharray: 5 4; }
.hit { fill: transparent; cursor: pointer; }

/* 结局浮层 */
.result { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,12,6,.45); border-radius: 18px; backdrop-filter: blur(1.5px); animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.res-card { background: var(--paper); color: var(--ink); border-radius: 18px; padding: 22px 26px 18px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); min-width: 240px; }
.res-seal { display: inline-block; font-family: var(--kai); font-size: 30px; font-weight: 700; color: #fff; background: var(--red); width: 54px; height: 54px; line-height: 54px; border-radius: 8px; transform: rotate(-6deg); margin-bottom: 8px; box-shadow: inset 0 0 0 3px rgba(255,255,255,.3); }
.res-seal.b { background: #2a2420; }
.res-card h2 { margin: 4px 0 2px; font-family: var(--kai); font-size: 30px; }
.res-card p { margin: 0 0 16px; color: #8a6a48; }
.res-card .cta { font-size: 18px; padding: 10px; }
.res-card .sub-actions .link { color: #8a6a48; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(15,9,5,.6); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.card { position: relative; background: var(--paper); color: var(--ink); border-radius: 16px; padding: 20px 24px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.45); }
.card h3 { margin: 0 0 14px; font-family: var(--kai); font-size: 24px; }
.card .x { position: absolute; right: 10px; top: 8px; }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.choices button { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 84px; padding: 8px 4px; font-size: 13px; border-radius: 12px; border: 1px solid #d6c09a; background: #fffaf0; cursor: pointer; color: var(--ink); }
.choices button:hover { background: var(--paper-2); border-color: #b48c4c; }
.choices svg { width: 52px; height: 56px; overflow: visible; }
.rules { width: 580px; max-height: 86vh; overflow-y: auto; line-height: 1.7; font-size: 14px; }
.rules li { margin-bottom: 4px; }
.muted { color: #8a7458; font-size: 13px; }

/* 窄屏：按键栏移到棋盘下方 */
@media (max-width: 760px) {
  #game { flex-direction: column; gap: 10px; padding: 8px 6px 60px; justify-content: flex-start; }
  .table { width: min(97vw, 580px); }
  .rail { flex-direction: row; gap: 6px; }
  .turn { width: auto; display: flex; align-items: center; gap: 6px; padding: 6px 10px; margin: 0 4px 0 0; text-align: left; }
  .turn svg { width: 26px; height: 28px; margin: 0; }
  .ib { width: 52px; height: 52px; }
  .menu { right: 0; bottom: calc(100% + 10px); }
}
