@charset "UTF-8";
/* ===========================================================================
 * chess.css — 二次开发重写
 * ---------------------------------------------------------------------------
 * 上游该文件的问题：
 *   1. 文件为 GBK 编码，且 font 里的中文字体名已损坏（"寰?杞???榛?"），
 *      在声明 charset=UTF-8 的页面里必然乱码；
 *   2. 全部使用固定像素宽高（316px / 214px / 194px），没有任何媒体查询，
 *      移动端基本不可用，是本项目最大的短板；
 *   3. 布局依赖图片背景与写死的 padding，无法随屏幕伸缩。
 * 本文件整体重写为：移动端优先、弹性布局、可随视口缩放、高对比度配色。
 * =========================================================================== */

:root {
  --paper: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1c1a17;
  --ink-2: #5b564e;
  --ink-3: #8b857a;
  --line: #e3ded4;
  --line-strong: #cfc7b8;
  --accent: #b4531f;
  --accent-soft: #f6ece5;
  --ok: #0f7a52;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(28, 26, 23, .05), 0 8px 24px rgba(28, 26, 23, .06);
  --shadow-lg: 0 12px 40px rgba(28, 26, 23, .16);
  --skin-bg: none;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  position: relative;
}

/* 皮肤底纹：虚化后作为氛围背景，并叠加纸色遮罩，保证文字始终高对比 */
body::before {
  content: "";
  position: fixed;
  inset: -40px;
  background-image: var(--skin-bg);
  background-size: cover;
  background-position: center;
  filter: blur(30px) saturate(.75);
  opacity: .30;
  z-index: 0;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.brand-mark {
  width: 30px; height: 30px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .01em; }

/* ---------------- 主体 ---------------- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 0;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.turn-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--ink-3);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, .05);
}
.turn-dot.red   { background: #c8342b; box-shadow: 0 0 0 3px rgba(200, 52, 43, .16); }
.turn-dot.black { background: #26262a; box-shadow: 0 0 0 3px rgba(38, 38, 42, .16); }
.turn-dot.think { background: var(--accent); box-shadow: 0 0 0 3px rgba(180, 83, 31, .18);
                  animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.board-holder {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#chess {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  /* 关键：消除移动端 300ms 点击延迟与双击缩放，并禁止长按选中/呼出菜单 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  cursor: pointer;
}

/* ---------------- 侧栏 ---------------- */
.side { flex: none; display: flex; flex-direction: column; gap: 8px; min-height: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.panel-hd-sub { font-weight: 500; color: var(--ink-3); }

.movelog {
  margin: 0;
  padding: 6px 10px 8px;
  list-style: none;
  max-height: 30vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 13px;
}
.movelog li {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px dashed var(--line);
}
.movelog li:last-child { border-bottom: 0; }
.movelog .no { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.movelog .r { color: #a5281f; font-weight: 600; }
.movelog .b { color: #26262a; font-weight: 600; }
.movelog .empty { color: var(--ink-3); font-weight: 400; }

.engine-info {
  padding: 7px 11px 9px;
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  line-height: 1.7;
}

/* ---------------- 工具条 ---------------- */
.toolbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #9d4718; border-color: #9d4718; }

.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-block + .btn-block { margin-top: 9px; }

/* ---------------- 覆盖层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(28, 26, 23, .42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 20px;
  margin: auto;
}

.sheet-title { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: .01em; }
.sheet-sub { margin: 0 0 16px; font-size: 13px; color: var(--ink-3); }

.pane[hidden] { display: none; }

.back {
  appearance: none; border: 0; background: none;
  color: var(--accent); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 2px 0; margin-bottom: 10px; cursor: pointer;
}

/* 菜单项 */
.menu-list { display: flex; flex-direction: column; gap: 8px; }

.menu-item {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  font: inherit;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .06s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.menu-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.menu-item:active { transform: scale(.985); }
.mi-title { font-size: 15px; font-weight: 700; color: var(--ink); }
.mi-desc { font-size: 12.5px; color: var(--ink-3); }
.mi-desc b { color: var(--accent); }

/* 选项 */
.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-3);
  margin-bottom: 7px;
  letter-spacing: .04em;
}

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.chips-vertical { grid-template-columns: 1fr; }

.chip { position: relative; display: block; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip span {
  display: block;
  text-align: center;
  padding: 10px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s ease;
  touch-action: manipulation;
}
.chip span:hover { border-color: var(--ink-3); }
.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 结果 */
.sheet-result { text-align: center; }
.result-icon {
  width: 62px; height: 62px;
  margin: 2px auto 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
}
.result-icon.lose { background: #3f3c37; }
.result-icon.draw { background: var(--ink-3); }
.result-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }

/* ===========================================================================
 * 响应式
 * =========================================================================== */

/* 窄屏（手机竖屏）：棋谱面板限高，避免挤压棋盘 */
@media (max-width: 719px) {
  .stage { padding: 8px 10px 0; gap: 8px; }
  .side { flex-direction: row; gap: 8px; }
  .side .panel { flex: 1; min-width: 0; }
  .panel-info { display: none; }
  .movelog { max-height: 20vh; }
  .toolbar { gap: 6px; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .btn { font-size: 12.5px; padding: 9px 6px; }
}

/* 宽屏（平板/桌面）：棋盘与侧栏并排 */
@media (min-width: 720px) {
  .stage {
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
    padding: 16px 20px 0;
    max-width: 1180px;
    width: 100%;
    margin: 0 auto;
  }
  .board-wrap { flex: 1 1 auto; }
  .side { width: 268px; flex: 0 0 268px; }
  .movelog { max-height: none; flex: 1; }
  .panel:first-child { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .toolbar {
    max-width: 1180px;
    margin: 0 auto;
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 150px));
    justify-content: center;
    padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  }
  .topbar { padding-left: 20px; padding-right: 20px; }
}

/* 横屏矮视口（手机横屏）：纵向空间紧张，把状态栏折成左侧竖条，
   把高度尽量让给棋盘。横屏本来就有大量闲置宽度，这样用最划算。 */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { padding: 3px 12px; }
  .brand-name { display: none; }
  .brand-mark { width: 24px; height: 24px; font-size: 13px; border-radius: 7px; }

  .stage { padding: 6px 12px 0; gap: 8px; align-items: stretch; }
  /* display:contents 让状态栏与棋盘成为 .stage 的直接子项，从而三栏并排；
     不支持该属性的浏览器会退回原来的上下布局，不影响可用性 */
  .board-wrap { display: contents; }

  .status {
    flex: 0 0 auto;
    width: 92px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    padding: 9px 10px;
    font-size: 12px;
    line-height: 1.4;
  }

  .board-holder { flex: 1 1 auto; min-width: 0; min-height: 0; }

  .side { width: 186px; flex-basis: 186px; gap: 6px; }
  .movelog { max-height: none; flex: 1; }
  .engine-info { padding: 6px 10px 8px; font-size: 11.5px; line-height: 1.6; }

  .toolbar {
    gap: 6px;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(5, minmax(0, 130px));
  }
  .btn { padding: 7px 8px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
