/* 布局：单列仪表——上方读数（下一手），中间棋盘，底部工具条；只用一种强调色标出“我的走法” */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #121a21;
  --muted: #67737f;
  --line: #e0e5ea;
  --accent: #2457e5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(36, 87, 229, 0.22);
  --opp-soft: rgba(242, 176, 5, 0.40);
  --sel-soft: rgba(36, 87, 229, 0.30);
  --danger: #d0453b;
  --sq-l: #eef1f4;
  --sq-d: #b4bfca;
  --coord-on-l: #8592a0;
  --coord-on-d: #f3f5f7;
  --shadow: 0 10px 40px rgba(18, 26, 33, 0.18);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --font-num: ui-rounded, -apple-system, "SF Pro Rounded", "SF Pro Text", "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1317; --surface: #161d23; --ink: #e7ecf1; --muted: #8b97a3; --line: #26313a;
    --accent: #6f95ff; --accent-ink: #0b1020; --accent-soft: rgba(111, 149, 255, 0.30);
    --opp-soft: rgba(240, 180, 30, 0.42); --sel-soft: rgba(111, 149, 255, 0.38); --danger: #ff6b60;
    --sq-l: #8a97a3; --sq-d: #5a6772; --coord-on-l: #4c5864; --coord-on-d: #c9d1d8;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1317; --surface: #161d23; --ink: #e7ecf1; --muted: #8b97a3; --line: #26313a;
  --accent: #6f95ff; --accent-ink: #0b1020; --accent-soft: rgba(111, 149, 255, 0.30);
  --opp-soft: rgba(240, 180, 30, 0.42); --sel-soft: rgba(111, 149, 255, 0.38); --danger: #ff6b60;
  --sq-l: #8a97a3; --sq-d: #5a6772; --coord-on-l: #4c5864; --coord-on-d: #c9d1d8;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* 顶栏 */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.02em; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; color: var(--muted); cursor: pointer;
}

/* 读数区 */
.status {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 12px;
  min-height: 116px;
  display: flex; flex-direction: column; gap: 2px;
  position: relative; overflow: hidden;
}
.status-row { display: flex; justify-content: space-between; align-items: baseline; }
.status-label { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; }
.status.mine .status-label { color: var(--accent); font-weight: 600; }
.status-eval { font: 600 15px/1 var(--font-num); font-variant-numeric: tabular-nums; color: var(--muted); }
.status-main {
  font-size: 28px; font-weight: 700; line-height: 1.2; min-height: 34px;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.status-main .san { font: 500 15px/1 var(--font-num); color: var(--muted); }
.status-main .extra { font-size: 17px; font-weight: 600; color: var(--muted); }
.status.thinking .status-main { color: var(--muted); }
.status-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 30px; }
.status-sub { font-size: 13px; color: var(--muted); min-width: 0; }
.evalbar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line); }
.evalbar i { display: block; height: 100%; width: 50%; background: var(--accent); transition: width 0.4s ease; }

/* 棋盘 */
.board-wrap {
  position: relative;
  width: 100%;
  max-width: min(560px, 64dvh);
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 0 var(--line);
}
.board { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); touch-action: manipulation; }
.sq { position: relative; background-color: var(--sq-l); cursor: pointer; }
.sq.d { background-color: var(--sq-d); }
.sq.lm-opp { background-image: linear-gradient(var(--opp-soft), var(--opp-soft)); }
.sq.lm-me { background-image: linear-gradient(var(--accent-soft), var(--accent-soft)); }
.sq.sel { background-image: linear-gradient(var(--sel-soft), var(--sel-soft)); }
.sq.chk { background-image: radial-gradient(circle, rgba(222, 52, 40, 0.85) 0%, rgba(222, 52, 40, 0.45) 40%, rgba(222, 52, 40, 0) 72%); }
.sq > i { position: absolute; inset: 0; background-position: center; background-size: 100% 100%; background-repeat: no-repeat; pointer-events: none; z-index: 1; }
.sq.tgt::after, .sq.tgt-cap::after, .sq.unsure::after { content: ""; position: absolute; pointer-events: none; z-index: 2; }
.sq.tgt::after { inset: 37%; border-radius: 50%; background: var(--accent); opacity: 0.45; }
.sq.tgt-cap::after { inset: 3%; border-radius: 50%; border: 4px solid var(--accent); opacity: 0.5; }
.sq.unsure::after { inset: 3px; border-radius: 6px; border: 2px dashed var(--danger); }

.pc-wK { background-image: url(pieces/wK.svg); } .pc-wQ { background-image: url(pieces/wQ.svg); }
.pc-wR { background-image: url(pieces/wR.svg); } .pc-wB { background-image: url(pieces/wB.svg); }
.pc-wN { background-image: url(pieces/wN.svg); } .pc-wP { background-image: url(pieces/wP.svg); }
.pc-bK { background-image: url(pieces/bK.svg); } .pc-bQ { background-image: url(pieces/bQ.svg); }
.pc-bR { background-image: url(pieces/bR.svg); } .pc-bB { background-image: url(pieces/bB.svg); }
.pc-bN { background-image: url(pieces/bN.svg); } .pc-bP { background-image: url(pieces/bP.svg); }

.coords { position: absolute; inset: 0; pointer-events: none; z-index: 3; font: 600 10px/1 var(--font-num); }
.coords span { position: absolute; }
.coords .rk { left: 3px; transform: translateY(3px); }
.coords .fl { bottom: 3px; transform: translateX(calc(-100% - 3px)); }
.coords .on-l { color: var(--coord-on-l); }
.coords .on-d { color: var(--coord-on-d); }

.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.arrows .arrow { fill: var(--accent); stroke: var(--accent); opacity: 0.82; }

/* 工具条 */
.toolbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: auto; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 4px 8px; font-size: 12px; color: var(--ink); cursor: pointer;
}
.tool:active { transform: scale(0.97); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:disabled { opacity: 0.4; }

/* 按钮与分段选择 */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 11px 14px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.lg { padding: 14px; font-size: 16px; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: transparent; border-radius: 8px; padding: 7px 12px; font-size: 14px;
  color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.seg button img { width: 20px; height: 20px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* 摆棋面板 */
.editor { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.palette { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.palette button {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  padding: 2px; cursor: pointer; display: grid; place-items: center; font-size: 12px; color: var(--muted);
}
.palette button img { width: 100%; height: 100%; }
.palette button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.palette button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }
.editor-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.editor-mini { display: flex; gap: 6px; }
.editor-error { margin: 0; color: var(--danger); font-size: 13px; }
.editor-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

/* 底部弹层 */
.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 12, 16, 0.42);
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}
.sheet-card {
  width: 100%; max-width: 480px; background: var(--surface); border-radius: 20px;
  padding: 20px 18px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet-card { animation: none; } .evalbar i { transition: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h1 { margin: 0; font-size: 24px; letter-spacing: 0.02em; }
.sheet-lead { margin: -6px 0 0; color: var(--muted); font-size: 14px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-label { font-size: 14px; color: var(--muted); margin: 0; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.sheet-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-note { margin: 0; font-size: 12px; color: var(--muted); }
.promo { align-items: stretch; }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-row button { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); cursor: pointer; padding: 4px; }
.promo-row img { width: 100%; height: 100%; }

/* 提示 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(max(12px, env(safe-area-inset-bottom, 0px)) + 84px);
  max-width: calc(100% - 32px); width: max-content;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; font-size: 14px;
  box-shadow: var(--shadow);
}

@media (max-height: 700px) {
  .status { min-height: 104px; padding: 10px 12px; }
  .status-main { font-size: 24px; }
  .app { gap: 10px; }
}
