/* ============ 万弈棋阁 · 主题 ============ */
:root {
  --bg: #101218;
  --bg2: #161a22;
  --panel: #1b2029;
  --panel2: #222835;
  --line: #2e3543;
  --text: #e8e4d8;
  --muted: #9aa0ad;
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, .16);
  --jade: #4e9d8b;
  --red: #c25b4e;
  --danger: #e05d5d;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --wood: linear-gradient(135deg, #d9b073 0%, #c89b5e 40%, #d3a967 60%, #c1934f 100%);
  --wood-dark: linear-gradient(135deg, #3d3227 0%, #2e2620 100%);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(212,175,55,.07), transparent 60%),
    radial-gradient(900px 480px at -10% 110%, rgba(78,157,139,.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  overflow-x: hidden;
}
button { font-family: inherit; }
#app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 18, 24, .85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: var(--gold);
  background: var(--panel2);
  border: 1px solid rgba(212,175,55,.4);
  box-shadow: inset 0 0 14px rgba(212,175,55,.12);
}
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: 3px; }
.brand-text small { color: var(--muted); font-size: 11px; letter-spacing: 1px; }
.top-actions { display: flex; gap: 10px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: .18s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.primary {
  background: linear-gradient(135deg, #d8b545, #b8912b);
  border: none; color: #201a08; font-weight: 700;
  box-shadow: 0 6px 18px rgba(212,175,55,.25);
}
.btn.primary:hover { filter: brightness(1.08); color: #201a08; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; border-radius: 12px; }
.btn.danger { border-color: rgba(224,93,93,.4); color: var(--danger); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- 首屏 ---------- */
.screen { display: none; flex: 1; }
.screen.active { display: block; }
#screen-home { max-width: 1080px; margin: 0 auto; padding: 26px 20px 40px; }
.hero { text-align: center; margin: 12px 0 30px; }
.hero-line {
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  font-size: 26px; color: var(--gold); letter-spacing: 6px; margin: 0;
}
.game-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.game-card {
  border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  background: var(--panel); cursor: pointer; padding: 0; text-align: left;
  transition: .22s; position: relative;
}
.game-card:hover { transform: translateY(-5px); border-color: rgba(212,175,55,.55); box-shadow: var(--shadow); }
.card-art {
  height: 130px; position: relative; overflow: hidden;
  background: var(--wood); 
}
.art-go { background: var(--wood-dark); }
.art-gomoku { background: linear-gradient(135deg, #2c3444, #232a38); }
.card-art::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(0,0,0,.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.14) 1px, transparent 1px);
  background-size: 26px 26px;
}
.card-art .stone {
  position: absolute; left: var(--x); top: var(--y);
  width: 26px; height: 26px; border-radius: 50%;
  box-shadow: 0 3px 6px rgba(0,0,0,.5);
}
.stone.black { background: radial-gradient(circle at 32% 30%, #555, #111 65%); }
.stone.white { background: radial-gradient(circle at 32% 30%, #fff, #bbb 70%); }
.card-art .piece {
  position: absolute; left: var(--x); top: var(--y);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
  border: 2px solid currentColor; box-shadow: 0 3px 6px rgba(0,0,0,.5);
  font-family: "STKaiti", "KaiTi", serif;
}
.piece.r { color: #a33; background: radial-gradient(circle at 32% 30%, #f5e6c8, #e2cfa4 70%); }
.piece.b { color: #222; background: radial-gradient(circle at 32% 30%, #ddd, #b9b3a4 70%); }
.card-body { padding: 16px 18px 18px; }
.card-body h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: 2px; }
.card-body p { margin: 0; color: var(--muted); font-size: 13px; }

.feature-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 30px;
}
.feature {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; font-size: 13px; color: var(--muted); line-height: 1.55;
}
.feature b { display: block; color: var(--text); margin-bottom: 5px; font-size: 14px; }
.home-foot { text-align: center; color: #5b6270; font-size: 12px; margin-top: 34px; letter-spacing: 1px; }

/* ---------- 设置抽屉 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(5, 7, 10, .6);
  backdrop-filter: blur(3px); z-index: 90; opacity: 0; pointer-events: none; transition: .25s;
}
.mask.show { opacity: 1; pointer-events: auto; }
.mask.hidden { display: none; }
#screen-setup {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%);
  background: var(--bg2); border-left: 1px solid var(--line);
  z-index: 100; display: flex; flex-direction: column;
  transform: translateX(102%); transition: transform .3s cubic-bezier(.2,.8,.25,1);
}
#screen-setup.open { transform: none; }
.setup-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.setup-head h2 { flex: 1; margin: 0; font-size: 17px; letter-spacing: 2px; }
.setup-body { flex: 1; overflow-y: auto; padding: 16px 18px 30px; }
.setup-foot { padding: 14px 18px; border-top: 1px solid var(--line); background: var(--panel); }
.sec { margin-bottom: 20px; }
.sec > h3 {
  font-size: 13px; color: var(--gold); letter-spacing: 2px; margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.sec > h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; background: var(--panel); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--gold); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 74px; padding: 10px 8px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px;
  transition: .15s;
}
.seg button.on { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.check { display: flex; align-items: center; gap: 9px; padding: 9px 0; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--gold); }
.collapsible > .coll-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 14px; cursor: pointer; font-size: 14px;
}
.collapsible > .coll-head .arr { color: var(--muted); transition: .2s; }
.collapsible.open > .coll-head .arr { transform: rotate(90deg); }
.coll-body { display: none; padding: 12px 4px 2px; }
.collapsible.open > .coll-body { display: block; }
.hint { font-size: 12px; color: #6b7280; line-height: 1.6; margin: 6px 0 0; }

/* ---------- 对局页 ---------- */
#screen-game.active { display: flex; flex-direction: column; }
.game-wrap {
  flex: 1; display: grid; grid-template-columns: 1fr 330px;
  gap: 18px; padding: 16px 20px; max-width: 1240px; margin: 0 auto; width: 100%;
  align-items: start;
}
.board-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.board-shell {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: grid; place-items: center; position: relative;
}
.board-host { width: 100%; max-width: 620px; }
.player-bar {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px;
}
.player-bar.active { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(212,175,55,.25), 0 0 22px rgba(212,175,55,.08); }
.p-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
  background: var(--panel2); border: 1px solid var(--line);
}
.p-avatar.s1 { color: #111; background: radial-gradient(circle at 32% 30%, #eee, #aaa 70%); }
.p-avatar.s2 { color: #eee; background: radial-gradient(circle at 32% 30%, #444, #111 70%); }
.p-avatar.thinking { animation: pulse 1.1s infinite; border-color: var(--gold); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(212,175,55,.5);} 50% { box-shadow: 0 0 0 8px rgba(212,175,55,0);} }
.p-info { flex: 1; min-width: 0; }
.p-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-status { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 15px; }
.p-status.hl { color: var(--gold); }
.p-cards { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.skill-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--gold-soft); border: 1px solid rgba(212,175,55,.45);
  color: var(--gold); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer;
  transition: .15s; white-space: nowrap;
}
.skill-chip:hover { transform: translateY(-2px); }
.skill-chip.used { opacity: .35; pointer-events: none; text-decoration: line-through; }

/* ---------- 侧面板 ---------- */
.side-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
  height: min(72vh, 640px); position: sticky; top: 84px;
}
.panel-tabs { display: flex; border-bottom: 1px solid var(--line); }
.ptab {
  flex: 1; padding: 12px; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 14px; border-bottom: 2px solid transparent;
}
.ptab.active { color: var(--gold); border-bottom-color: var(--gold); }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 14px; }
.move-list { margin: 0; padding: 0 0 0 4px; list-style: none; font-size: 13.5px; line-height: 2; }
.move-list li { display: flex; gap: 8px; border-bottom: 1px dashed rgba(255,255,255,.05); }
.move-list .no { color: #566072; width: 34px; flex: none; }
.move-list .who.s1 { color: #e6d7ae; }
.move-list .who.s2 { color: #a8c6bd; }
.move-list .why { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; max-width: 45%; }
.move-list .tag { font-size: 11px; color: var(--gold); }
.event-log { font-size: 13px; line-height: 1.8; color: var(--muted); }
.event-log .ev { padding: 5px 0; border-bottom: 1px dashed rgba(255,255,255,.05); }
.event-log .ev b { color: var(--text); }
.event-log .ev.skill { color: var(--gold); }
.event-log .ev.warn { color: var(--danger); }
.hidden { display: none !important; }
.panel-actions {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border-top: 1px solid var(--line);
}
.panel-actions .btn { flex: 1; min-width: 88px; padding: 9px 8px; font-size: 13px; }
.mobile-controls { display: none; }

/* ---------- 弹窗 / Toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 120; display: grid; place-items: center;
  padding: 20px;
}
.modal-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px;
  padding: 26px; width: min(460px, 100%); box-shadow: var(--shadow);
  animation: pop .25s cubic-bezier(.2,.9,.3,1.2);
  max-height: 84vh; overflow-y: auto;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal-card h3 { margin: 0 0 12px; letter-spacing: 2px; }
.modal-card p { color: var(--muted); line-height: 1.7; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.versus-line { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 14px 0; }
.versus-line .vs { color: var(--gold); font-weight: 700; }
.toast-host {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(420px, 92vw);
}
.toast {
  background: rgba(24, 28, 36, .95); border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 10px; padding: 11px 16px; font-size: 13.5px;
  box-shadow: var(--shadow); animation: slideDown .3s;
  width: 100%;
}
.toast.err { border-left-color: var(--danger); }
.toast.skill { border-left-color: var(--jade); }
@keyframes slideDown { from { transform: translateY(-14px); opacity: 0; } }
.spin {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--gold); border-top-color: transparent;
  animation: rot .8s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ---------- 棋盘通用 ---------- */
.board-host canvas, .board-host .xq-board { display: block; width: 100%; height: auto; touch-action: manipulation; }
.board-host .xq-board { position: relative; aspect-ratio: 9 / 10; border-radius: 10px; overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.xq-board svg.lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.xq-piece {
  position: absolute; width: 9.2%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%);
  display: grid; place-items: center;
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  font-size: clamp(15px, 4.4vw, 30px); font-weight: 700; user-select: none;
  transition: left .3s cubic-bezier(.3,.9,.35,1.1), top .3s cubic-bezier(.3,.9,.35,1.1);
  box-shadow: 0 4px 8px rgba(0,0,0,.45), inset 0 0 0 2px currentColor, inset 0 0 12px rgba(0,0,0,.15);
  cursor: pointer; z-index: 2;
}
.xq-piece.r { color: #9e2b22; background: radial-gradient(circle at 32% 28%, #f7ecd2, #e6cf9f 72%); }
.xq-piece.b { color: #1c1c1c; background: radial-gradient(circle at 32% 28%, #e8e2d4, #bdb5a3 72%); }
.xq-piece.sel { outline: 3px solid var(--gold); outline-offset: 1px; z-index: 3; }
.xq-piece.captured { animation: cap .4s forwards; }
@keyframes cap { to { transform: translate(-50%,-50%) scale(.2); opacity: 0; } }
.dot-hint {
  position: absolute; width: 3.4%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(212,175,55,.85); box-shadow: 0 0 10px rgba(212,175,55,.8);
  z-index: 1; animation: pop .2s;
}
.last-mark {
  position: absolute; width: 4.6%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%); border: 2px solid var(--red);
  z-index: 1; pointer-events: none;
}

/* ---------- 响应式 ---------- */
@media (max-width: 960px) {
  .game-grid { grid-template-columns: 1fr; }
  .feature-row { grid-template-columns: 1fr 1fr; }
  .game-wrap { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .side-panel {
    position: static; height: auto; max-height: 300px; order: 2;
  }
  .board-host { max-width: 560px; }
  .hero-line { font-size: 20px; letter-spacing: 4px; }
  .panel-actions { display: none; }
  .mobile-controls { display: flex; flex-wrap: wrap; gap: 8px; }
  .mobile-controls .btn { flex: 1; min-width: 30%; padding: 12px 6px; }
  #topbar { padding: 10px 14px; }
  .brand-text small { display: none; }
  .xq-piece { font-size: clamp(13px, 4.8vw, 26px); }
}
@media (max-width: 560px) {
  .feature-row { grid-template-columns: 1fr; }
  .setup-body { padding: 14px; }
  .field-row { grid-template-columns: 1fr; }
}
