:root {
  --bg: #f4ede1;
  --panel: #fffaf2;
  --ink: #2b2118;
  --muted: #7a6a58;
  --line: #dccfbd;
  --wood: #e9c98f;
  --wood2: #dcb170;
  --grid: #5a3b1c;
  --red: #b3261e;
  --black: #1f1a17;
  --accent: #8a3b12;
  --good: #2f7d32;
  --inacc: #b7860b;
  --mistake: #d4661a;
  --blunder: #c0261e;
  --blue: #1f5fa8;
  --radius: 16px;
  --fs: 20px;
}
html.big { --fs: 23px; }
html.huge { --fs: 26px; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: var(--fs); line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 60px; padding: 0 10px; padding-top: env(safe-area-inset-top);
  background: #6b2d0f; color: #fff7ea;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.1em; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .tb-btn {
  min-width: 64px; height: 46px; border: 0; border-radius: 12px; padding: 0 12px;
  background: rgba(255,255,255,.14); color: #fff7ea; font-size: .95em; cursor: pointer;
}
.topbar .tb-btn:active { background: rgba(255,255,255,.3); }

.screen { min-height: calc(100vh - 60px); }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 58px; padding: 8px 14px; border-radius: 14px;
  border: 2px solid #c9b597; background: #fff; color: var(--ink);
  font-size: 1em; font-weight: 600; cursor: pointer; user-select: none;
  box-shadow: 0 2px 0 #c9b597;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); border-color: #6b2d0f; color: #fff; box-shadow: 0 2px 0 #4c1f09; }
.btn.red { background: #fbeaea; border-color: #e0a9a5; color: var(--red); }
.btn.small { min-height: 44px; font-size: .9em; padding: 4px 12px; }
.btn.block { width: 100%; }
.btn-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.btn-grid .btn { padding: 6px 4px; white-space: nowrap; }
.btn-grid.two { grid-template-columns: repeat(2, 1fr); }

/* ---------- 首页 ---------- */
.home { max-width: 760px; margin: 0 auto; padding: 18px 14px 40px; }
.home .hello { font-size: 1.05em; color: var(--muted); margin: 4px 4px 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 6px;
  min-height: 150px; padding: 18px; border-radius: 20px; border: 0; text-align: left; cursor: pointer;
  background: var(--panel); box-shadow: 0 3px 0 var(--line), 0 6px 18px rgba(80,50,20,.08);
}
.tile:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.tile .ico { font-size: 2.1em; line-height: 1; }
.tile b { font-size: 1.2em; }
.tile span { color: var(--muted); font-size: .85em; }
.tile.wide { grid-column: span 2; min-height: 96px; flex-direction: row; align-items: center; gap: 16px; }
.tile.continue { background: #fff3d6; }

/* ---------- 对局布局 ---------- */
.game { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 6px 30px; }
.board-wrap { width: min(calc(100vw - 12px), 720px); position: relative; }
.side { width: min(calc(100vw - 16px), 720px); display: flex; flex-direction: column; gap: 10px; }
@media (orientation: landscape) and (min-width: 860px) {
  .game { flex-direction: row; align-items: flex-start; justify-content: center; gap: 16px; padding: 10px 12px; }
  .board-wrap { width: min(calc((100vh - 84px) * 0.86), calc(100vw - 420px)); width: min(calc((100dvh - 84px) * 0.86), calc(100vw - 420px)); position: sticky; top: 70px; }
  .side { width: auto; flex: 1; max-width: 560px; min-width: 360px; }
}
.board-wrap svg { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

.card {
  background: var(--panel); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 2px 0 var(--line);
}
.status { display: flex; align-items: center; gap: 10px; font-size: 1.15em; font-weight: 700; min-height: 40px; }
.status .dot { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 2px solid rgba(0,0,0,.15); }
.status .dot.r { background: var(--red); }
.status .dot.b { background: var(--black); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #e3d3bc; border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.judge { border-left: 8px solid var(--line); }
.judge.best, .judge.good { border-left-color: var(--good); }
.judge.inacc { border-left-color: var(--inacc); }
.judge.mistake { border-left-color: var(--mistake); }
.judge.blunder { border-left-color: var(--blunder); }
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; color: #fff; font-weight: 700; font-size: .9em; margin-right: 6px; }
.tag.best, .tag.good { background: var(--good); }
.tag.inacc { background: var(--inacc); }
.tag.mistake { background: var(--mistake); }
.tag.blunder { background: var(--blunder); }
.tag.info { background: var(--blue); }
.judge .line { margin: 4px 0; }
.judge .acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.bar { height: 14px; border-radius: 7px; background: #3a2a1d; overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #d8453b, #f08a5d); }
.bar.me > i { background: linear-gradient(90deg, #2f7d32, #64b56a); }
.small-muted { color: var(--muted); font-size: .85em; }
.explain { white-space: pre-wrap; line-height: 1.7; }
.explain .who { font-weight: 700; color: var(--accent); }
.zh { font-weight: 700; color: var(--accent); }

.moves { max-height: 260px; overflow: auto; display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 2px 8px; font-size: .95em; }
.moves .n { color: var(--muted); text-align: right; }
.moves .m { padding: 2px 6px; border-radius: 8px; cursor: pointer; }
.moves .m.cur { background: #f3dcb6; }
.moves .m .mk { font-size: .75em; margin-left: 3px; font-weight: 700; }
.mk.inacc { color: var(--inacc); } .mk.mistake { color: var(--mistake); } .mk.blunder { color: var(--blunder); }
details summary { cursor: pointer; font-weight: 700; padding: 4px 0; }

/* ---------- 复盘 ---------- */
.nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nav .btn { font-size: 1.3em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; cursor: pointer; font-size: .9em; }
.chip.mistake { border-color: var(--mistake); }
.chip.blunder { border-color: var(--blunder); background: #fdeceb; }
.chart svg { width: 100%; height: 90px; display: block; }
.progress { height: 10px; border-radius: 5px; background: #eadfcf; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ---------- 摆棋 ---------- */
.palette { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.pbtn {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid #b79a73; background: radial-gradient(circle at 40% 35%, #fffaf0, #f0dfbf);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", serif; font-weight: 700; font-size: clamp(18px, 5.2vw, 30px); line-height: 1; cursor: pointer; padding: 0; width: 100%; min-width: 0;
  display: flex; align-items: center; justify-content: center;
}
.pbtn.r { color: var(--red); border-color: #d18a84; }
.pbtn.b { color: var(--black); }
.pbtn.sel { outline: 4px solid var(--blue); outline-offset: 2px; }
.pbtn.tool { border-radius: 14px; font-family: inherit; font-size: clamp(13px, 3.4vw, 18px); }
.seg { display: inline-flex; border: 2px solid #c9b597; border-radius: 14px; overflow: hidden; }
.seg button { border: 0; background: #fff; min-height: 50px; padding: 0 16px; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.errs { color: var(--blunder); font-weight: 600; }
.ok { color: var(--good); font-weight: 600; }
.cand { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-top: 1px dashed var(--line); }
.cand:first-child { border-top: 0; }
.cand .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cand .rank { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.cand .pv { color: var(--muted); font-size: .9em; }
.photo-thumb { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin-top: 8px; }

/* ---------- 练习列表 ---------- */
.list { max-width: 760px; margin: 0 auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.list h2 { margin: 12px 4px 0; font-size: 1.15em; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; background: var(--panel);
  box-shadow: 0 2px 0 var(--line); cursor: pointer; border: 0; text-align: left; width: 100%;
}
.item:active { transform: translateY(2px); box-shadow: none; }
.item .t { flex: 1; }
.item .t b { display: block; }
.item .t span { color: var(--muted); font-size: .85em; }
.item .done { color: var(--good); font-weight: 700; }
.item .badge { min-width: 54px; text-align: center; padding: 4px 8px; border-radius: 10px; background: #f3e6d2; font-size: .85em; }

/* ---------- 弹窗 ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(30,20,10,.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal { background: var(--panel); border-radius: 20px; width: min(560px, 100%); max-height: calc(100vh - 28px); overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 12px; font-size: 1.25em; }
.modal .acts { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.levels button { min-height: 72px; border-radius: 14px; border: 2px solid #c9b597; background: #fff; cursor: pointer; padding: 4px; line-height: 1.25; }
.levels button b { display: block; font-size: 1em; }
.levels button span { font-size: .72em; color: var(--muted); }
.levels button.on { background: var(--accent); color: #fff; border-color: #6b2d0f; }
.levels button.on span { color: #ffe9d4; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row label { min-width: 5em; font-weight: 600; }
.toast {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 60;
  background: rgba(40,20,10,.9); color: #fff; padding: 16px 30px; border-radius: 18px; font-size: 1.2em; font-weight: 700;
  pointer-events: none; animation: pop .25s ease-out;
}
.toast.check { background: rgba(179,38,30,.95); font-size: 2.2em; padding: 18px 40px; letter-spacing: .2em; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.7); opacity: 0; } }

/* ---------- 登录 / 设置 ---------- */
.center-box { max-width: 520px; margin: 40px auto; padding: 24px 20px; }
.center-box h1 { text-align: center; font-size: 1.6em; margin: 10px 0 6px; }
.center-box .logo { text-align: center; font-size: 4em; line-height: 1; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.field label { font-weight: 700; }
.field .hint { color: var(--muted); font-size: .8em; }
.input { width: 100%; min-height: 58px; padding: 10px 14px; border-radius: 14px; border: 2px solid #c9b597; background: #fff; font-size: 1.1em; }
.input:focus { outline: 3px solid #e7b77d; border-color: var(--accent); }
.msg { margin: 8px 0; font-weight: 600; }
.msg.err { color: var(--blunder); }
.msg.ok { color: var(--good); }
.pc-t, .river { font-family: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", "Songti SC", serif; }
.chk { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

.stars { color: #c98a12; letter-spacing: 1px; font-size: .9em; }
.stars .off { color: #e3d6c2; }
.tabs { display: flex; width: 100%; }
.tabs button { flex: 1; font-size: 1.05em; }
.starf .chip { min-height: 44px; min-width: 64px; color: #c98a12; font-weight: 700; }
.starf .chip:first-child { color: var(--ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff !important; }
details.grp { padding: 4px 14px; }
details.grp summary { padding: 12px 0; font-size: 1.05em; }
.grp-items { display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; }
.grp-items .item { box-shadow: none; border: 2px solid var(--line); }
.item .t span.stars { color: #c98a12; font-size: 1em; }
.item .t span.stars .off { color: #e3d6c2; font-size: 1em; }
