* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --wood: #e8b866;
  --wood-dark: #c99a4a;
  --line: #7a4a1f;
  --bg: #2b2620;
  --panel: #38322a;
  --text: #f0e8d8;
  --dim: #b0a68f;
  --accent: #ffb84d;
}
html, body { height: 100%; }
body {
  display: flex; flex-direction: column;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.sitebar {
  flex: none;
  height: 48px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: #1c1814;
  border-bottom: 1px solid #4a4237;
}
.site-brand {
  display: flex; align-items: center; gap: 8px;
  color: var(--accent); text-decoration: none;
  font-weight: 600; letter-spacing: .12em;
}
.site-seal {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: #b4332a; color: #f6efe4;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 15px; letter-spacing: 0;
}
.site-nav { display: flex; gap: 4px; }
.site-nav a {
  color: var(--dim); text-decoration: none;
  font-size: 14px; padding: 6px 12px; border-radius: 999px;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a[aria-current="page"] { color: #1a150f; background: var(--accent); font-weight: 600; }

#app { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 300px; min-width: 300px;
  background: var(--panel);
  border-right: 1px solid #4a4237;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  font-size: 18px; font-weight: 600;
  border-bottom: 1px solid #4a4237;
  color: var(--accent);
}
.logo { font-size: 22px; }
.view-tabs {
  display: flex; gap: 4px; padding: 8px 12px 0;
}
.view-tab {
  flex: 1; padding: 7px 0; border: 1px solid #5a5348; background: #2b2620;
  color: var(--dim); border-radius: 6px; font-size: 13.5px; cursor: pointer;
}
.view-tab.active { background: var(--accent); color: #1a150f; border-color: var(--accent); font-weight: 600; }
.toggle-side {
  width: 100%; padding: 12px 0; margin: 0;
  border: none; background: transparent; color: var(--accent);
  font-size: 20px; line-height: 1; cursor: pointer; text-align: center;
  display: none;
}
#catList {
  border-top: 1px solid #4a4237; padding: 8px 12px;
  flex: 1; overflow-y: auto; display: none;
}
.cat-head { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.cat-game {
  padding: 6px 8px; border-radius: 5px; cursor: pointer; margin-bottom: 2px;
}
.cat-game:hover { background: #3a332b; }
.cat-game.active { background: var(--accent); color: #1a150f; }
.cat-g-name { display: block; font-size: 13px; }
.cat-g-title { display: block; font-size: 11.5px; color: var(--dim); }
.cat-g-meta { display: block; font-size: 11.5px; color: var(--dim); }
.filter-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid #4a4237;
}
.filter-bar select {
  flex: 1; min-width: 0;
  background: #2b2620; color: var(--text);
  border: 1px solid #5a5348; border-radius: 6px;
  padding: 6px 8px; font-size: 13.5px; outline: none;
}
.filter-bar select:hover { border-color: var(--accent); }
#filterCount { font-size: 12px; color: var(--dim); white-space: nowrap; }
#tree {
  flex: 1; overflow-y: auto; padding: 10px 6px;
}
.tree-node { }
.tree-folder, .tree-file {
  padding: 5px 8px; border-radius: 6px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px; line-height: 1.5;
}
.tree-file-name { overflow: hidden; text-overflow: ellipsis; }
.tree-file-title { color: var(--dim); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-folder { color: var(--accent); font-weight: 600; }
.tree-file { color: var(--text); }
.tree-file:hover, .tree-folder:hover { background: #4a4237; }
.tree-file.active { background: var(--accent); color: #2b2620; font-weight: 600; }
.tree-toggle { display: inline-block; width: 18px; }
.tree-count { color: var(--dim); font-size: 12px; margin-left: 6px; }

/* ---------- 主区 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header#gamelabel { padding: 12px 20px; border-bottom: 1px solid #4a4237; }
.game-nav { display: flex; gap: 8px; margin-bottom: 6px; }
.game-nav button {
  padding: 5px 12px; border: 1px solid #5a5348; background: #2b2620;
  color: var(--dim); border-radius: 6px; font-size: 13px; cursor: pointer;
}
.game-nav button:disabled { opacity: .4; cursor: default; }
.game-nav button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.game-title { font-size: 18px; font-weight: 600; }
.game-internal { font-size: 13.5px; color: #ffd9a0; margin-top: 2px; }
.game-meta { font-size: 13px; color: var(--dim); margin-top: 3px; }

#stageRow { flex: 1; display: flex; min-height: 0; }
#stage {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: 16px 20px 8px; display: flex; flex-direction: column; align-items: center;
}

#boardWrap { position: relative; }
#board {
  width: min(72vh, 520px);
  max-width: 100%;
  height: auto;
  background: var(--wood);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  display: block;
}
#moveTip {
  margin-top: 8px; text-align: center;
  font-size: 14px; color: #7a4a1f; font-weight: 600; pointer-events: none;
}

#controls {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; flex-wrap: wrap; justify-content: center;
}
#controls button {
  background: var(--accent); border: none; color: #2b2620;
  font-size: 18px; width: 44px; height: 40px; border-radius: 8px;
  cursor: pointer; font-weight: 700;
}
#controls button:hover { filter: brightness(1.12); }
#stepInfo { font-size: 15px; min-width: 90px; text-align: center; color: var(--text); }

#btnMem { width: auto; padding: 0 12px; font-size: 15px; letter-spacing: 1px; }
#btnMem.active { background: #4dd0ff; color: #10222e; box-shadow: 0 0 0 2px #4dd0ff; }
#memTip { text-align: center; font-size: 14px; padding: 6px 8px; min-height: 20px; color: var(--text); }
#memTip.mem-ok { color: #8fd48f; }
#memTip.mem-err { color: #ff7777; font-weight: 600; }

#toast {
  position: fixed; top: 64px; left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: #c0392b; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 600; z-index: 999;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 998;
}
.modal-box {
  background: #1d2333; border: 1px solid #3a4256; border-radius: 12px;
  padding: 22px 26px; width: 320px; color: #d7dce6;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-row { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.modal-row input[type=number] {
  width: 84px; background: #0e1320; border: 1px solid #3a4256; color: #d7dce6;
  border-radius: 6px; padding: 6px 8px;
}
.modal-row input[type=checkbox] { width: 16px; height: 16px; accent-color: #5a8fd4; }
.modal-row input:disabled { opacity: .4; }
.modal-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-btns button {
  padding: 7px 16px; border-radius: 7px; border: 1px solid #3a4256;
  background: #2a3247; color: #d7dce6; cursor: pointer;
}
.modal-btns button:last-child { background: #5a8fd4; border-color: #5a8fd4; color: #fff; }

#commentBox {
  margin-top: 10px; padding: 10px 14px;
  background: #3f382e; border-left: 3px solid var(--accent);
  border-radius: 6px; font-size: 14px; color: var(--text);
  max-width: 620px; white-space: pre-wrap; line-height: 1.6;
  display: none;
}

/* ---------- 着法列表（固定在右侧） ---------- */
#movesPane {
  width: 300px; min-width: 300px; overflow-y: auto;
  padding: 10px 14px; border-left: 1px solid #4a4237;
}
.pane-head {
  font-size: 14px; font-weight: 700; color: var(--accent);
  padding-bottom: 8px; border-bottom: 1px solid #4a4237; margin-bottom: 8px;
}
#moveList { position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; }
.move-item {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 5px; font-size: 13.5px;
  cursor: pointer; color: var(--text);
}
.move-item .idx { color: var(--dim); font-size: 12px; min-width: 22px; }
.move-item.branch { color: #9fd4a0; }
.move-item:hover { background: #4a4237; }
.move-item.current { background: var(--accent); color: #2b2620; font-weight: 700; }

/* 滚动条 */
#tree::-webkit-scrollbar, #movesPane::-webkit-scrollbar { width: 8px; }
#tree::-webkit-scrollbar-thumb, #movesPane::-webkit-scrollbar-thumb { background: #5a5348; border-radius: 4px; }

/* ---------- 移动端（窄屏）---------- */
@media (max-width: 900px) {
  body { height: auto; }
  #app { flex-direction: column; flex: none; height: auto; min-height: calc(100vh - 48px); overflow: visible; }
  #sidebar { width: 100%; min-width: 0; max-height: 40vh; transition: max-height .25s ease; }
  #sidebar.collapsed { max-height: 96px; overflow: hidden; }   /* 点棋谱后收起列表，仅留标签和箭头 */
  .toggle-side { display: block; }   /* 手机端显示目录 收/开 按钮 */
  #main { }
  #stageRow { flex-direction: column; }
  #stage { overflow: visible; }
  #movesPane { width: 100%; min-width: 0; border-left: none; border-top: 1px solid #4a4237; max-height: 36vh; overflow-y: auto; }   /* 手机端谱区限高，走棋时内部滚动、屏幕不动 */
  #board { width: 100%; max-width: 460px; }
  #moveList { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  #controls button { width: 40px; height: 38px; font-size: 16px; }
}
