:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --violet: #8b5cf6;
  --bg: #f4f5fb;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1e293b;
  --text-2: #64748b;
  --good: #10b981;
  --bad: #ef4444;
  --board: #dcb35c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.5;
}

/* ===================== 顶栏 ===================== */
header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
header h1 { font-size: 20px; font-weight: 700; color: var(--primary); letter-spacing: 0.5px; }
header h1 .sub { font-size: 13px; color: var(--text-2); font-weight: 400; letter-spacing: 0; }

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

/* 模式切换（分段控件） */
.mode-toggle { display: flex; background: #eef0f7; border-radius: 9px; padding: 3px; gap: 2px; }
.mode-toggle button {
  padding: 7px 16px; border: none; border-radius: 7px;
  background: transparent; color: var(--text-2); cursor: pointer;
  font-size: 15px; font-weight: 500; transition: all 0.15s;
}
.mode-toggle button.active {
  background: #fff; color: var(--primary); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10);
}

.controls label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }
.controls select {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; color: var(--text); background: #fff; cursor: pointer;
}

/* 操作按钮 */
.controls > button {
  padding: 7px 14px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: background 0.15s;
}
.controls > button:hover { background: var(--primary-dark); }
.controls > button#btn-save { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.controls > button#btn-save:hover { background: var(--primary-light); }

/* ===================== 主区 ===================== */
main { flex: 1; display: flex; gap: 0; min-height: 0; }

#board-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start; padding: 16px; overflow-y: auto;
}
#board {
  background: var(--board);
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  border-radius: 4px;
}
#status {
  margin-top: 10px; font-size: 15px; color: var(--text-2); min-height: 22px; text-align: center;
}

/* 复盘导航栏 */
#nav-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
#nav-bar button {
  padding: 6px 14px; border: none; border-radius: 8px;
  background: #fff; color: var(--primary); cursor: pointer;
  font-size: 16px; border: 1px solid var(--border); transition: all 0.15s;
}
#nav-bar button:hover:not(:disabled) { background: var(--primary); color: #fff; }
#nav-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
#nav-info {
  min-width: 130px; text-align: center; font-size: 14px; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.ownership-toggle {
  font-size: 14px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.ownership-toggle input { cursor: pointer; accent-color: var(--primary); }

/* ===================== 分析面板 ===================== */
#side-panel {
  width: 400px; background: var(--card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
#analysis {
  padding: 16px 18px; border-bottom: 1px solid var(--border); flex: none;
}
.winrate-row { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; }
.winrate-row span { white-space: nowrap; }
.winrate-row #wr-black { color: var(--primary); }
.winrate-row #wr-white { color: var(--text-2); }
.winrate-bar { flex: 1; height: 18px; background: #eef0f7; border-radius: 9px; overflow: hidden; display: flex; }
.winrate-fill { background: linear-gradient(90deg, var(--primary), var(--violet)); transition: width 0.4s ease; }
.analysis-detail { display: flex; justify-content: space-between; margin-top: 10px; font-size: 14px; color: var(--text-2); }
#move-delta { font-weight: 700; }
#move-delta.good { color: var(--good); }
#move-delta.bad { color: var(--bad); }
.candidates-row { margin-top: 10px; font-size: 14px; color: var(--text); }
.candidates-row .cand {
  display: inline-block; background: var(--primary-light); color: var(--primary-dark);
  border-radius: 6px; padding: 3px 10px; margin-right: 6px; margin-top: 4px; font-weight: 600; font-size: 14px;
}
#wr-curve {
  width: 100%; margin-top: 12px; background: #fafbff;
  border-radius: 8px; border: 1px solid var(--border);
}

/* ===================== 聊天面板 ===================== */
#chat-panel {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
}
#chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { margin-bottom: 14px; max-width: 88%; }
.msg.user { margin-left: auto; }
.msg .bubble {
  display: inline-block; padding: 10px 15px; border-radius: 14px;
  font-size: 15px; line-height: 1.65; text-align: left; white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.msg.teacher .bubble { background: #f1f5f9; color: var(--text); border-bottom-left-radius: 5px; }
.msg .label { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
#chat-input-wrap { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
#chat-input {
  flex: 1; resize: none; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; font-family: inherit; outline: none;
}
#chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
#chat-send {
  padding: 0 20px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; cursor: pointer; font-size: 15px; font-weight: 500;
}
#chat-send:hover { background: var(--primary-dark); }
#chat-send:disabled { background: #c7c9d4; cursor: not-allowed; }

/* ===================== 棋谱库 ===================== */
#library {
  width: 100%; max-width: 640px; background: var(--card); border-radius: 12px;
  padding: 18px 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  border: 1px solid var(--border); max-height: 74vh; display: flex; flex-direction: column;
}
.library-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.library-head h3 { font-size: 18px; font-weight: 700; color: var(--text); }
.library-head button {
  padding: 8px 16px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; cursor: pointer; font-size: 14px; font-weight: 500;
}
.library-head button:hover { background: var(--primary-dark); }
#library-list { flex: 1; overflow-y: auto; }
.game-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 6px; border-bottom: 1px solid var(--border); gap: 12px;
}
.game-item:last-child { border-bottom: none; }
.game-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.game-title { font-size: 16px; font-weight: 600; color: var(--text); }
.game-title .vs { color: var(--text-2); font-weight: 400; font-size: 13px; margin: 0 2px; }
.game-meta { font-size: 13px; color: var(--text-2); }
.game-actions { display: flex; gap: 8px; flex-shrink: 0; }
.game-actions button {
  padding: 6px 14px; border: none; border-radius: 8px;
  background: var(--primary); color: #fff; cursor: pointer; font-size: 14px;
}
.game-actions button:hover { background: var(--primary-dark); }
.game-actions button.del { background: #fff; color: var(--bad); border: 1px solid var(--bad); }
.game-actions button.del:hover { background: #fef2f2; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-2); font-size: 15px; }

/* ===================== 移动端适配 ===================== */
#board { touch-action: manipulation; }
@media (max-width: 768px) {
  header { gap: 8px; padding: 8px 12px; }
  header h1 { font-size: 16px; }
  main { flex-direction: column; overflow-y: auto; }
  #board-wrap { flex: none; padding: 10px; }
  #side-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); flex: none; }
  #analysis { border-bottom: 1px solid var(--border); }
  #library { max-width: 100%; max-height: 62vh; }
  #chat-panel { height: 40vh; flex: none; }
  #chat-input-wrap { padding: 10px; }
}
