:root {
  --bg: #f4f1ea; --panel: #fffdf8; --ink: #23201b; --muted: #7a7266; --line: #e2dccf;
  --accent: #2f6f5e; --accent-ink: #fff; --warn: #b4552d; --good: #2f7d4f; --bad: #b23b3b;
  --wood: #e2b565; --wood-line: #5b4320; --shadow: 0 1px 2px rgba(40,30,10,.06), 0 8px 24px rgba(40,30,10,.07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614; --panel: #211f1c; --ink: #ece7dc; --muted: #9a9284; --line: #35312b;
    --accent: #5fb39b; --accent-ink: #0e1a16; --warn: #e08a5f; --good: #6cc08c; --bad: #e07a7a;
    --wood: #c99b4f; --wood-line: #3d2c12; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif; }
h1, h2 { font-family: "Songti SC", "Noto Serif SC", "STSong", serif; margin: 0; }
button, select, input { font: inherit; color: inherit; }
.top { display: flex; align-items: center; gap: 20px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 24px; letter-spacing: 4px; }
.brand .sub { color: var(--muted); font-size: 13px; }
.logo { width: 22px; height: 22px; border-radius: 50%; align-self: center; background: radial-gradient(circle at 35% 30%, #666, #111 70%); box-shadow: 9px 0 0 -2px var(--panel), 9px 0 0 0 var(--muted); margin-right: 8px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab { border: 0; background: none; padding: 7px 16px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tab:hover { color: var(--ink); }
.tab.on { background: var(--ink); color: var(--panel); }
.chip { margin-left: auto; font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.auth { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.auth img { width: 26px; height: 26px; border-radius: 50%; }
.auth button { padding: 4px 10px; font-size: 13px; }
.grow { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.grow .t { font-weight: 600; }
.grow .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.grow .acts button { padding: 4px 10px; font-size: 13px; }
.chip.ok { color: var(--good); border-color: currentColor; }
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.view { display: none; } .view.on { display: block; }

.play { display: grid; grid-template-columns: minmax(0, 640px) minmax(300px, 1fr); gap: 24px; align-items: start; }
.boardcol { min-width: 0; }
.boardbox { background: var(--wood); border-radius: 10px; box-shadow: var(--shadow); padding: 0; aspect-ratio: 1; width: 100%; overflow: hidden; }
.boardbox canvas { width: 100%; height: 100%; display: block; cursor: pointer; touch-action: manipulation; }
.boardbox.small { max-width: 440px; }
.players { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.pl { display: flex; align-items: center; gap: 8px; padding: 4px 10px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.pl.turn { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pl .cap { color: var(--muted); font-size: 12px; }
.st { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
.st.b { background: radial-gradient(circle at 35% 30%, #666, #111 70%); }
.st.w { background: radial-gradient(circle at 35% 30%, #fff, #cfcabf 80%); border: 1px solid #b9b3a6; }
.wr { flex: 1; height: 18px; border-radius: 999px; background: #efeadd; border: 1px solid var(--line); position: relative; overflow: hidden; min-width: 60px; }
.wr #wrFill { position: absolute; inset: 0 auto 0 0; width: 50%; background: #2a2723; transition: width .4s; }
.wr span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 17px; color: #fff; mix-blend-mode: difference; }
.status { margin: 10px 2px 8px; min-height: 24px; color: var(--muted); }
.status b { color: var(--ink); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
button { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { color: var(--bad); }
button.on { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.review { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.review button { padding: 4px 9px; }
.review #rvLabel { min-width: 64px; text-align: center; font-size: 13px; color: var(--muted); }
.review canvas { flex: 1; min-width: 0; height: 44px; }

.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin-bottom: 12px; }
.card.wide { max-width: 760px; margin: 0 auto 16px; }
.row { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: center; gap: 10px; margin-bottom: 10px; }
.row > label:first-child { color: var(--muted); font-size: 13px; }
select, input[type=text], input[type=password], input:not([type]) { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; padding: 6px 4px; background: var(--bg); font-size: 13px; }
.seg button.on { background: var(--ink); color: var(--panel); }
.lvl { display: flex; align-items: center; gap: 10px; }
.lvl input { flex: 1; accent-color: var(--accent); min-width: 0; }
.lvl span { font-size: 13px; min-width: 84px; }
.sw { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.sw input { display: none; }
.sw span { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: .2s; }
.sw span::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .2s; }
.sw input:checked + span { background: var(--accent); }
.sw input:checked + span::after { left: 16px; }
.sw em { font-style: normal; font-size: 12px; color: var(--muted); }
#btnNew { width: 100%; margin-top: 4px; }
.muted { color: var(--muted); font-size: 13px; }
.coach p { margin: 0 0 8px; }
.grade { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; margin-right: 6px; color: #fff; }
.g1 { background: var(--good); } .g2 { background: #6b8f3a; } .g3 { background: #b08a2e; } .g4 { background: var(--warn); } .g5 { background: var(--bad); }
.cand { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-top: 1px dashed var(--line); }
.cand > b { width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; flex: none; }
.llm { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.llm > button { width: 100%; }
.ask { display: flex; gap: 6px; margin-top: 8px; }
.llmout { margin-top: 10px; white-space: pre-wrap; font-size: 14px; }
.llmout:empty { display: none; }
.sumgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; text-align: center; margin: 8px 0; }
.sumgrid div { border: 1px solid var(--line); border-radius: 8px; padding: 6px 2px; font-size: 12px; color: var(--muted); }
.sumgrid div b { display: block; font-size: 18px; color: var(--ink); }
.big { font-family: "Songti SC", "Noto Serif SC", serif; font-size: 26px; margin: 4px 0; }

.learn { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.lessons { display: flex; flex-direction: column; gap: 4px; }
.lessons button { text-align: left; border: 0; background: none; padding: 8px 12px; }
.lessons button.on { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.lessons button.done::after { content: " ✓"; color: var(--good); }
.lesson { display: grid; grid-template-columns: minmax(0, 440px) 1fr; gap: 24px; align-items: start; }
.lesson.full { grid-column: 1 / -1; max-width: 960px; margin: 0 auto; width: 100%; }
.ltext h2 { font-size: 20px; margin-bottom: 8px; }
.body { white-space: pre-wrap; margin-bottom: 12px; }
.fb { min-height: 28px; margin-bottom: 12px; padding: 0; }
.fb.ok, .fb.no { padding: 10px 12px; border-radius: 8px; }
.fb.ok { background: color-mix(in srgb, var(--good) 14%, transparent); }
.fb.no { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.prog { height: 6px; background: var(--line); border-radius: 3px; margin-bottom: 14px; overflow: hidden; }
.prog div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.test { max-width: 800px; margin: 0 auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 500; }
.statusbox { margin-top: 12px; font-size: 13px; white-space: pre-wrap; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 8px 18px; border-radius: 999px; box-shadow: var(--shadow); z-index: 20; font-size: 14px; max-width: 90vw; }

@media (max-width: 900px) {
  .play, .learn, .lesson { grid-template-columns: 1fr; }
  .lessons { flex-direction: row; overflow-x: auto; }
  .lessons button { white-space: nowrap; }
  .top { padding: 10px 16px; gap: 10px; }
  .tabs { margin-left: 0; order: 3; width: 100%; }
  .tab { flex: 1; padding: 7px 4px; }
  .boardbox.small { max-width: 100%; }
}

.lessons button.on { color: var(--ink); }
.dlg { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 20px 22px; width: min(400px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg h2 { font-size: 19px; margin-bottom: 6px; }
.dlg .ask button { white-space: nowrap; }
.dlg #lgMsg { min-height: 20px; margin-top: 10px; }
