:root {
  --bg: #f4f1ea; --fg: #1f2421; --muted: #6b6f68; --card: #ffffff; --line: #e3ddd0;
  --accent: #2f6b4f; --accent-fg: #ffffff; --warn: #b4442f; --wood: #dcb36b; --wood2: #e8c886;
  --grid: #3b2a14; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 20px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151a17; --fg: #e8ebe6; --muted: #9aa39b; --card: #1f2622; --line: #2f3833;
    --accent: #4f9a74; --accent-fg: #0d130f; --warn: #e07a62; --shadow: 0 1px 3px rgba(0,0,0,.4); }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; }
button, select { font: inherit; color: inherit; }
.app { max-width: 1100px; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.logo { color: var(--accent); margin-right: 4px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; gap: 14px; } }

.board-wrap { min-width: 0; }
.status { font-weight: 600; padding: 8px 12px; border-radius: 10px; background: var(--card); box-shadow: var(--shadow);
  margin-bottom: 10px; min-height: 40px; display: flex; align-items: center; gap: 8px; }
.status.thinking::after { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted);
  border-top-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.board-box { width: 100%; display: flex; justify-content: center; aspect-ratio: 1 / 1; max-height: calc(100vh - 160px); margin: 0 auto; touch-action: none; }
@media (max-width: 860px) { .board-box { max-height: none; } }
#board { display: block; margin: 0 auto; border-radius: 10px; box-shadow: var(--shadow); cursor: pointer; }
.caps { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--muted); font-size: 14px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; margin-right: 6px; }
.dot.black { background: #111; } .dot.white { background: #fafafa; border: 1px solid #999; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); }

.panel { display: flex; flex-direction: column; gap: 12px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 8px; cursor: pointer;
  min-height: 44px; transition: transform .05s, background .2s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; width: 100%; }
button.warn { color: var(--warn); }
button.ghost { background: transparent; }
button.small { min-height: 34px; padding: 4px 10px; font-size: 13px; }
.card { background: var(--card); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.card-title { font-weight: 700; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); min-height: 42px; }
label.switch { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; }
label.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.stats { font-size: 14px; display: grid; gap: 4px; }
.stats .row { display: flex; justify-content: space-between; }
.tip { color: var(--muted); font-size: 13px; margin: 0; }
#scoreText { font-size: 15px; }

dialog { border: none; border-radius: 14px; padding: 20px; max-width: min(460px, calc(100vw - 32px)); background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-body h3 { margin: 4px 0 8px; }
.dlg-body ol, .dlg-body ul { padding-left: 20px; margin: 0 0 12px; }
.dlg-body li { margin: 4px 0; }
.big { font-size: 22px; font-weight: 700; margin: 4px 0 8px; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 6px; background: var(--card); padding: 4px; border-radius: 12px; box-shadow: var(--shadow); }
.tab { border: none; background: transparent; min-height: 38px; padding: 6px 14px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--accent); color: var(--accent-fg); }

/* ---------- 学棋 ---------- */
.learn-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "board text" "board dir"; gap: 16px 20px; align-items: start; }
.lesson-card { grid-area: text; }
.lesson-board { grid-area: board; }
.lesson-dir { grid-area: dir; }
@media (max-width: 860px) {
  .learn-layout { grid-template-columns: 1fr; grid-template-areas: "text" "board" "dir"; gap: 12px; }
  .lesson-board .board-box { max-height: none; }
}
.lesson-prog { font-size: 12px; color: var(--muted); }
.lesson-title { font-size: 20px; font-weight: 700; }
.lesson-text { font-size: 15.5px; line-height: 1.75; }
.task { background: #fff6dc; color: #5a4300; border: 1px solid #f0d99a; border-radius: 10px; padding: 10px 12px; font-weight: 600; margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { .task { background: #3a3218; color: #f3e2a8; border-color: #5a4c22; } }
.choices { display: grid; gap: 8px; margin-top: 10px; }
.choices button.right { background: #1f9d63; color: #fff; border-color: transparent; }
.choices button.wrongc { border-color: var(--warn); color: var(--warn); }
.feedback { margin-top: 10px; padding: 10px 12px; border-radius: 10px; line-height: 1.7; }
.feedback.ok { background: #e3f4ea; color: #145a37; border: 1px solid #b9e2c9; }
.feedback.bad { background: #fde9e5; color: #8a2a1a; border: 1px solid #f3c2b8; }
@media (prefers-color-scheme: dark) {
  .feedback.ok { background: #173a28; color: #bfe9cf; border-color: #245c3f; }
  .feedback.bad { background: #3d1d17; color: #f6c3b7; border-color: #6a2e22; }
}
.lesson-nav { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; margin-top: 10px; }
.lesson-nav .primary { width: auto; }
.lesson-list { display: grid; gap: 4px; }
.lesson-item { text-align: left; border: none; background: transparent; padding: 8px 10px; min-height: 40px; border-radius: 8px; }
.lesson-item.active { background: var(--bg); font-weight: 700; }
@media (min-width: 861px) { .lesson-board .board-box { max-height: calc(100vh - 250px); } }
