/* ============ 基础 ============ */
:root {
  --bg: #0b0e12;
  --bg-2: #0f141a;
  --card: #151b22;
  --card-2: #11161c;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #ece5d8;
  --muted: #98a2ac;
  --muted-2: #6f7a85;
  --accent: #e0b25f;
  --accent-2: #c98f3c;
  --accent-soft: rgba(224, 178, 95, 0.14);
  --red: #c8503f;
  --green: #74c28f;
  --blue: #7fa6d8;
  --radius: 16px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(224, 178, 95, 0.09), transparent 60%),
    radial-gradient(900px 600px at 92% 4%, rgba(70, 110, 150, 0.12), transparent 55%),
    linear-gradient(180deg, #0d1116 0%, #0a0d11 55%, #080b0e 100%);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.app {
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 24px 44px;
}

/* ============ 顶栏 ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 230px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  color: #2a1c0c;
  background: linear-gradient(145deg, #f0cf8d, #c9973f);
  box-shadow: 0 8px 20px rgba(201, 151, 63, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.1;
}

.brand-text p {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted-2);
  letter-spacing: 0.04em;
}

.game-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.game-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: all 0.18s ease;
}

.game-tabs button:hover { color: var(--text); }

.game-tabs button.active {
  background: linear-gradient(145deg, #f3d79b, #d3a352);
  color: #241706;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(201, 151, 63, 0.25);
}

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.ghost-btn {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13px;
  transition: all 0.16s ease;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: rgba(224, 178, 95, 0.5);
  background: var(--accent-soft);
}

.primary {
  border: 0;
  background: linear-gradient(145deg, #f3d79b, #d0a04e);
  color: #241706;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 20px rgba(201, 151, 63, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary:hover { transform: translateY(-1px); box-shadow: 0 12px 26px rgba(201, 151, 63, 0.3); }
.primary:active { transform: translateY(0); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ============ 主布局 ============ */
.stage {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 396px;
  gap: 30px;
  align-items: start;
  margin-top: 24px;
}

.board-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* ============ 棋手条 ============ */
.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px;
  min-height: 32px;
  font-size: 14px;
}

.player-row strong { letter-spacing: 0.06em; font-weight: 600; }

.player-row.bottom { flex-direction: row; }

.side-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #9aa3ad;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.side-dot.stone {
  width: 15px;
  height: 15px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.5), 0 1px 2px rgba(0, 0, 0, 0.5);
}

.turn-chip {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: #241706;
  background: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}

/* ============ 棋盘 ============ */
.board-outer {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  width: 100%;
  max-width: 596px;
  aspect-ratio: 9 / 10;
  border-radius: 14px;
  overflow: hidden;
  container-type: size;
  touch-action: manipulation;
  user-select: none;
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.55),
    0 2px 0 rgba(255, 255, 255, 0.06) inset,
    0 0 0 1px rgba(0, 0, 0, 0.6);
  background: #e6cda2;
}

.board.chess {
  aspect-ratio: 1 / 1;
  max-width: 560px;
  background: #b58863;
}

.board.go {
  aspect-ratio: 1 / 1;
  max-width: 620px;
  background: #e3c795;
}

.board-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hit-layer, .piece-layer, .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.piece-layer { pointer-events: none; z-index: 2; }
.overlay { pointer-events: none; z-index: 4; }
.hit-layer { z-index: 3; }

.hit {
  position: absolute;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 6px;
  outline: none;
}

.hit:focus-visible { box-shadow: inset 0 0 0 2px rgba(36, 23, 6, 0.5); }

/* 棋子 */
.piece {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  line-height: 1;
  will-change: left, top;
}

.board.xiangqi .piece {
  width: 9.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  font-family: "KaiTi", "STKaiti", "Kaiti SC", "SimSun", serif;
  font-weight: 700;
  font-size: 6.2cqw;
  background:
    radial-gradient(circle at 34% 26%, #fffaf0 0%, #f7e8c8 42%, #e8d0a4 78%, #d8ba85 100%);
  box-shadow:
    0 3px 6px rgba(60, 38, 12, 0.34),
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 -2px 4px rgba(120, 84, 40, 0.25) inset;
  border: 1px solid rgba(126, 90, 45, 0.55);
}

.board.xiangqi .piece::after {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: 1px solid rgba(140, 100, 50, 0.35);
}

.board.xiangqi .piece.red { color: #b13a2c; }
.board.xiangqi .piece.black { color: #27313a; }

.board.xiangqi .piece.last-moved { box-shadow: 0 0 0 3px rgba(224, 178, 95, 0.75), 0 4px 10px rgba(60, 38, 12, 0.4); }

.board.chess .piece {
  width: 11.5%;
  aspect-ratio: 1;
  font-size: 9.4cqw;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", sans-serif;
}

.board.chess .piece.white {
  color: #fffdf7;
  text-shadow:
    0 0 1px #5c3f20,
    1px 0 0 #5c3f20, -1px 0 0 #5c3f20, 0 1px 0 #5c3f20, 0 -1px 0 #5c3f20,
    1px 1px 0 #5c3f20, -1px -1px 0 #5c3f20, 1px -1px 0 #5c3f20, -1px 1px 0 #5c3f20,
    0 4px 7px rgba(0, 0, 0, 0.32);
}

.board.chess .piece.black {
  color: #241f1a;
  text-shadow:
    0 0 1px rgba(246, 234, 208, 0.9),
    0 0 1px rgba(246, 234, 208, 0.9),
    1px 2px 3px rgba(0, 0, 0, 0.45);
}

.board.chess .piece.outline {
  color: #3b2a17;
  text-shadow:
    0 0 1px #fffaf0,
    1px 0 0 #fffaf0, -1px 0 0 #fffaf0, 0 1px 0 #fffaf0, 0 -1px 0 #fffaf0,
    0 4px 7px rgba(0, 0, 0, 0.3);
}

.board.chess .piece.last-moved { filter: drop-shadow(0 0 6px rgba(255, 224, 150, 0.9)); }

.board.go .piece {
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow:
    0 3px 7px rgba(40, 24, 8, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.board.go .piece.black {
  background: radial-gradient(circle at 34% 28%, #6d727a 0%, #303237 42%, #141518 100%);
  border: 1px solid rgba(0, 0, 0, 0.55);
}

.board.go .piece.white {
  background: radial-gradient(circle at 34% 28%, #ffffff 0%, #f6efe1 55%, #d9d0be 100%);
  border: 1px solid rgba(120, 100, 70, 0.5);
}

.board.go .piece.pop { animation: stonePop 0.16s ease-out; }

@keyframes stonePop {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.4; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.piece.pop { animation: pop 0.18s ease-out; }

@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.86); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* 棋盘提示 */
.hint-ring {
  animation: hintPulse 1.8s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 0.45; }
}

.board-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(12, 15, 19, 0.88);
  color: #ffe6b8;
  padding: 14px 26px;
  border-radius: 12px;
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: 0.3em;
  border: 1px solid rgba(224, 178, 95, 0.5);
  box-shadow: var(--shadow);
  z-index: 9;
  pointer-events: none;
  animation: toastIn 0.25s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.94); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.promo-menu {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  display: flex;
  gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(14, 18, 23, 0.96);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.promo-menu button {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #1b222a;
  color: #f4ead8;
  font-size: 30px;
  line-height: 1;
}

.promo-menu button:hover { border-color: var(--accent); background: #232b34; }

/* ============ 棋盘工具条 ============ */
.board-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 4px;
}

.board-toolbar button, .edit-actions button {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  transition: all 0.16s ease;
}

.board-toolbar button:hover, .edit-actions button:hover {
  color: var(--text);
  border-color: rgba(224, 178, 95, 0.45);
}

.board-toolbar button.toggle.on {
  color: #241706;
  background: var(--accent);
  border-color: transparent;
  font-weight: 700;
}

/* ============ 摆棋 ============ */
.edit-tools {
  border: 1px dashed rgba(224, 178, 95, 0.4);
  border-radius: 14px;
  padding: 14px;
  background: rgba(224, 178, 95, 0.04);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.edit-head {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.palette button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(126, 90, 45, 0.45);
  background: radial-gradient(circle at 34% 26%, #fffaf0, #e8d0a4 80%);
  font-family: "KaiTi", "STKaiti", "SimSun", serif;
  font-weight: 700;
  font-size: 19px;
  color: #b13a2c;
  padding: 0;
  line-height: 1;
}

.palette button.black { color: #27313a; }
.palette button.eraser { background: #1a2028; color: #cfd8e2; border-color: var(--line-strong); font-size: 16px; }
.palette button.active { box-shadow: 0 0 0 3px var(--accent); }

.edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.side-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

select {
  background: #1a2129;
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  font-family: inherit;
}

/* ============ 右栏 ============ */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 18px;
}

.coach-card {
  background:
    radial-gradient(120% 100% at 0% 0%, rgba(224, 178, 95, 0.12), transparent 55%),
    linear-gradient(170deg, #171e26, #12171d 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.coach-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.coach-title {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.24em;
  color: var(--accent);
}

.coach-meta {
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.coach-main {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  margin: 16px 0 6px;
}

.coach-move {
  font-family: var(--serif);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.05;
  color: #f6dfb0;
  text-shadow: 0 6px 24px rgba(224, 178, 95, 0.22);
}

.coach-move.loading {
  font-size: 24px;
  color: var(--muted);
  letter-spacing: 0.2em;
}

.coach-side {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.eval-bar {
  position: relative;
  height: 8px;
  margin: 16px 0 8px;
  border-radius: 999px;
  background: #0c1014;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.eval-bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #c98f3c, #f0d59a);
  transition: left 0.4s ease, width 0.4s ease;
}

.eval-bar-mid {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: rgba(255, 255, 255, 0.22);
}

.coach-eval {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.coach-reason {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.65;
  color: #cfd6dd;
  min-height: 21px;
}

.coach-pv {
  margin-top: 9px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted-2);
  min-height: 18px;
  word-break: break-all;
}

.coach-pv .pv-label { color: var(--muted); }

.coach-actions {
  display: flex;
  gap: 9px;
  margin-top: 16px;
}

.coach-actions .primary.big { flex: 1; padding: 12px 18px; font-size: 15px; }
.coach-actions .ghost-btn { flex: 0 0 auto; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.strength {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.moves-card {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.moves-head {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.moves-head span:last-child { letter-spacing: 0.04em; color: var(--muted-2); }

.moves {
  list-style: none;
  margin: 0;
  padding: 8px;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.moves-empty {
  padding: 16px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted-2);
}

.move-row {
  display: grid;
  grid-template-columns: 42px 1fr 1fr;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 7px;
}

.move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.018); }

.move-no {
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.move-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #d7dee5;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.05em;
  padding: 5px 7px;
  border-radius: 6px;
  text-align: left;
  transition: all 0.14s ease;
}

.move-btn:hover { background: rgba(255, 255, 255, 0.05); }

.move-btn.current {
  border-color: rgba(224, 178, 95, 0.5);
  background: var(--accent-soft);
  color: #f6dfb0;
}

.move-btn .suffix { font-size: 11px; color: var(--accent); margin-left: 2px; }
.move-btn.mate { color: #ffb9a8; }

.status-line {
  font-size: 12px;
  color: var(--muted-2);
  letter-spacing: 0.1em;
  text-align: center;
  padding: 2px;
}

.status-line.alert { color: #ff9d8a; }

/* ============ 页脚 / 弹窗 ============ */
.footer {
  margin-top: 38px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.06em;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.footer .dot { opacity: 0.5; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 9, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: min(560px, 100%);
  background: linear-gradient(170deg, #182028, #11161b);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 24px 26px;
  box-shadow: var(--shadow);
  max-height: 86vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: 0.16em;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }

.help-list {
  margin: 18px 0 0;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.9;
  color: #ccd4dc;
}

.help-list li { margin-bottom: 8px; }
.help-list strong { color: var(--accent); font-weight: 600; }

.help-note {
  margin: 18px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(200, 80, 63, 0.08);
  border: 1px solid rgba(200, 80, 63, 0.22);
  font-size: 12.5px;
  line-height: 1.7;
  color: #e2b6ad;
}

/* ============ 响应式 ============ */
@media (max-width: 1040px) {
  .stage {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .panel { position: static; }
  .board { max-width: 540px; }
  .board.chess { max-width: 500px; }
  .board.go { max-width: 540px; }
  .board-panel { align-items: center; }
  .player-row, .board-toolbar, .edit-tools { width: 100%; max-width: 596px; }
  .board.chess ~ .player-row { max-width: 560px; }
}

@media (max-width: 640px) {
  .app { padding: 16px 14px 32px; }
  .topbar { gap: 12px; }
  .brand-mark { width: 40px; height: 40px; font-size: 22px; }
  .brand-text h1 { font-size: 21px; }
  .brand-text p { font-size: 11px; }
  .game-tabs { order: 3; width: 100%; justify-content: center; }
  .top-actions { margin-left: 0; }
  .coach-move { font-size: 38px; }
  .coach-card { padding: 16px; }
  .moves { max-height: 200px; }
  .board { max-width: 100%; }
}
