:root {
  --bg: #f7f3ef;
  --card: #ffffff;
  --orange: #fb8147;
  --orange-soft: #fdece1;
  --ink: #1f2329;
  --muted: #8a8f96;
  --line: #e9e1d6;
  --red: #c0392b;
  --black: #2b3038;
  --green: #3f8f6b;
  --blue: #2f6fb0;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  padding: 18px clamp(14px, 3vw, 40px) 40px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--orange);
  color: #fff;
  display: grid; place-items: center;
  font-size: 24px;
  font-weight: 700;
  font-family: "Kaiti SC", KaiTi, serif;
  box-shadow: 0 4px 14px rgba(251,129,71,.32);
}

.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: .5px; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.eval-wrap { min-width: 260px; flex: 0 1 340px; }
.eval-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; margin-bottom: 6px;
}
#evalText { font-weight: 600; }
.turn-badge {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  background: var(--orange-soft); color: #c05f2a;
}
.eval-bar {
  position: relative; height: 9px; border-radius: 999px;
  background: #ece5da; overflow: hidden;
}
.eval-fill {
  position: absolute; inset: 0 auto 0 0; width: 50%;
  background: linear-gradient(90deg, #e05a3a, var(--orange));
  transition: width .35s ease;
}
.eval-mid {
  position: absolute; left: 50%; top: -2px; width: 2px; height: 13px;
  background: rgba(31,35,41,.25);
}

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(320px, 1fr);
  gap: clamp(16px, 2.4vw, 32px);
  align-items: start;
}

.board-area { min-width: 0; }

.board-box {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px;
  box-shadow: 0 10px 34px rgba(120,95,60,.10);
  overflow: hidden;
}

canvas { display: block; width: 100%; border-radius: 14px; cursor: pointer; }

.board-tools {
  display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap;
}
.tool {
  flex: 1 1 auto;
  min-width: 78px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: .16s;
}
.tool:hover { border-color: #d9cdbb; background: #fffdfa; }
.tool:active { transform: translateY(1px); }
.tool.accent {
  background: var(--orange); color: #fff; border-color: var(--orange);
  box-shadow: 0 6px 18px rgba(251,129,71,.28);
}
.tool.accent:hover { background: #f97434; }

/* ---------- 面板 ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 4px 18px rgba(120,95,60,.06);
}

.row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
.row > label { width: 62px; font-size: 13px; color: var(--muted); flex: none; }

.seg {
  display: flex; gap: 4px; background: #f3ede4; padding: 3px;
  border-radius: 11px; flex: 1;
}
.seg button {
  flex: 1; border: 0; background: transparent; color: #6b7076;
  padding: 7px 4px; font-size: 13px; border-radius: 9px; cursor: pointer;
  transition: .16s; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  background: var(--card); color: var(--ink);
  box-shadow: 0 1px 5px rgba(120,95,60,.16); font-weight: 600;
}

/* ---------- 教练卡 ---------- */
.coach { position: relative; overflow: hidden; }
.coach::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
}
#cardRed::before { background: var(--red); }
#cardBlack::before { background: var(--black); }

.coach-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.coach-head h2 { margin: 0; font-size: 14.5px; flex: 1; letter-spacing: .3px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.red { background: var(--red); }
.dot.black { background: var(--black); }

.score {
  font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  background: #f6f1e9; padding: 2px 9px; border-radius: 999px;
}

.placeholder { color: var(--muted); font-size: 13.5px; margin: 4px 0; }

.best-move {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 8px;
  animation: fadeUp .3s cubic-bezier(.22, .61, .36, 1) both;
}
.best-move .mv {
  font-size: 26px; font-weight: 700;
  font-family: "Kaiti SC", "STKaiti", KaiTi, serif;
  letter-spacing: 1px;
}
#cardRed .best-move .mv { color: var(--red); }
#cardBlack .best-move .mv { color: var(--black); }

.badge {
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  background: #eef4f1; color: var(--green);
}
.badge.warn { background: #fdf0e8; color: #c05f2a; }
.badge.info { background: #eef2f8; color: var(--blue); }

.notes { margin: 0 0 10px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.notes li {
  font-size: 12px; color: #6b7076; background: #f6f1e9;
  padding: 3px 9px; border-radius: 8px;
}

.cands { border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px;
         animation: fadeUp .34s cubic-bezier(.22, .61, .36, 1) .04s both; }
.cand {
  display: flex; align-items: center; gap: 10px; font-size: 13.5px;
  padding: 6px 8px; border-radius: 9px; cursor: pointer; transition: .14s;
}
.cand:hover { background: #faf6f0; }
.cand .idx {
  width: 18px; height: 18px; border-radius: 6px; background: #f0e9de;
  display: grid; place-items: center; font-size: 11px; color: #8a7a63; flex: none;
}
.cand .txt { font-family: "Kaiti SC", KaiTi, serif; font-size: 16px; font-weight: 600; }
.cand .eval { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }
.cand .eval.up { color: var(--green); }
.cand .eval.down { color: #c05f2a; }

.reply-line {
  margin-top: 10px; font-size: 12.5px; color: var(--muted);
  border-left: 2px solid var(--line); padding-left: 10px;
  animation: fadeUp .34s cubic-bezier(.22, .61, .36, 1) .08s both;
}
.reply-line b { color: #5c636b; font-weight: 600; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- AI 教练讲解（大模型生成） ---------- */
.coach-talk {
  display: none;
  margin-top: 11px;
  padding: 11px 13px 12px;
  background: linear-gradient(180deg, #fdf8f2, #fbf5ed);
  border: 1px solid #f2e6d6;
  border-radius: 11px;
  font-size: 13.5px;
  line-height: 1.75;
  color: #4a5058;
}
.coach-talk.on { display: block; animation: fadeUp .32s cubic-bezier(.22, .61, .36, 1) both; }
.coach-talk::before {
  content: "⟡ 教练说";
  display: block;
  font-size: 11px;
  letter-spacing: .6px;
  color: var(--orange);
  margin-bottom: 5px;
}
.coach-talk.loading { color: #b0a493; }
.coach-talk.loading::after {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-left: 6px;
  vertical-align: -2px;
  border: 2px solid #e8d9c5;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#rowLLM label { color: #b0a493; }

/* ---------- 局势走势曲线 ---------- */
.curve-card { padding-bottom: 12px; }
.curve-box {
  position: relative;
  margin-top: 2px;
  border-radius: 10px;
  overflow: hidden;
  background: #fdfaf5;
  border: 1px solid #f2e9dc;
}
#curve { display: block; width: 100%; cursor: crosshair; }

.curve-legend {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: #b0a493; letter-spacing: .3px;
}
.curve-legend .lg {
  width: 8px; height: 8px; border-radius: 2px; display: inline-block;
  margin-left: 6px;
}
.curve-legend .lg.red { background: var(--red); }
.curve-legend .lg.black { background: var(--black); }

/* ---------- 记录 ---------- */
.move-list {
  margin: 0; padding: 0; list-style: none;
  max-height: 190px; overflow-y: auto;
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px 8px;
  font-size: 13.5px;
}
.move-list li { min-width: 0; }
.move-list .no { color: #b3a894; font-variant-numeric: tabular-nums; }
.move-list .m {
  font-family: "Kaiti SC", KaiTi, serif; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.move-list .m.red { color: var(--red); }
.move-list .m.black { color: var(--black); }
.mini {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  font-size: 12px; padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.mini:hover { color: var(--ink); border-color: #d9cdbb; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  background: rgba(31,35,41,.92); color: #fff; font-size: 13.5px;
  padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .22s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .board-area { max-width: 560px; margin: 0 auto; width: 100%; }
  .panel { max-width: 560px; margin: 0 auto; width: 100%; }
}
