:root {
  --light: #f0d9b5;
  --dark: #b58863;
  --light-sel: #f7ec74;
  --dark-sel: #dac34b;
  --last: rgba(255, 213, 79, 0.5);
  --check: rgba(229, 57, 53, 0.65);
  --panel: #ffffff;
  --text: #34404a;
  --muted: #7a8694;
  --accent: #4a90d6;
  --accent-2: #6aa6e0;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --board-size: min(94vw, 88vh, 680px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(160deg, #dbeeff 0%, #e9e3ff 55%, #ffe9f2 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  gap: 12px;
}

.topbar {
  width: var(--board-size);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-size: 22px; font-weight: 800; margin: 0; color: var(--accent); text-shadow: 0 2px 0 #fff; }
.back-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: #fff;
  color: var(--accent); text-decoration: none; font-size: 20px; font-weight: 800;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.back-btn:active { transform: scale(0.92); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.sound-toggle {
  appearance: none; border: none; background: #fff; color: var(--accent);
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.sound-toggle.off { opacity: 0.5; }
.sound-toggle:active { transform: scale(0.92); }
.status {
  font-size: 15px; font-weight: 700;
  color: var(--muted);
  background: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.status.check { color: #e0524f; }

.online-banner {
  width: var(--board-size); margin: 0 auto; text-align: center;
  background: #fff; color: var(--accent); font-weight: 800; font-size: 14px;
  border-radius: 999px; padding: 8px 14px; box-shadow: var(--shadow);
}
.online-banner[hidden] { display: none; }

/* 复盘悬浮按钮：结束弹窗收起后用它唤回结果 */
.result-fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px);
  z-index: 60; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 15px;
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow);
}
.result-fab[hidden] { display: none; }
.result-fab:active { transform: scale(0.94); }

.stage { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.board-wrap { position: relative; }

.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--board-size) / 8 * 0.78);
  line-height: 1;
  cursor: pointer;
}
.sq.light { background: var(--light); }
.sq.dark  { background: var(--dark); }
.sq.sel.light { background: var(--light-sel); }
.sq.sel.dark  { background: var(--dark-sel); }
.sq.last::after {
  content: ""; position: absolute; inset: 0; background: var(--last); pointer-events: none;
}
.sq.check::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, var(--check) 0%, transparent 70%);
  pointer-events: none;
}

/* coordinate labels */
.sq .coord {
  position: absolute; font-size: 10px; font-weight: 700; opacity: 0.55;
  pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

/* pieces: cburnett SVG sprite, referenced via <use> */
.sq .piece {
  position: relative; z-index: 2; pointer-events: none;
  width: 88%; height: 88%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28));
  transition: transform 0.12s ease;
}

/* legal-move markers（仅限棋盘格子；曾因通用 .dot::after 误中在线列表状态点而产生大椭圆阴影） */
.sq.dot::after {
  content: ""; position: absolute; width: 30%; height: 30%;
  border-radius: 50%; background: rgba(20, 20, 20, 0.28); z-index: 1;
}
.sq.light.dot::after { background: rgba(90,60,30,.28); }
.capture-ring::after {
  content: ""; position: absolute; inset: 8%; border-radius: 50%;
  border: 4px solid rgba(20, 20, 20, 0.28); z-index: 1;
}
.sq.light.capture-ring::after { border-color: rgba(90,60,30,.28); }

.thinking {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 6px 14px; border-radius: 999px;
  font-size: 13px; display: flex; align-items: center; gap: 8px; z-index: 10;
}
.spinner {
  width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.captured {
  width: var(--board-size); min-height: 22px; display: flex; flex-wrap: wrap;
  gap: 1px; font-size: 18px; line-height: 1; color: var(--muted);
}
.captured-top { justify-content: flex-start; }
.captured .piece { width: 20px; height: 20px; vertical-align: middle; }

.controls {
  width: var(--board-size); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.btn {
  appearance: none; border: none; border-radius: 14px; padding: 13px 8px;
  background: #fff; color: var(--accent); font-size: 15px; font-weight: 800;
  box-shadow: var(--shadow);
  cursor: pointer; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-2); }

.overlay {
  position: fixed; inset: 0; background: rgba(30,40,55,.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.overlay[hidden] { display: none; }

.setup-card, .promo-card {
  background: var(--panel); border-radius: 26px; padding: 26px 22px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow); text-align: center;
}
.setup-card h2 { margin: 0 0 18px; font-size: 24px; color: var(--accent); }
.setup-card p { color: var(--muted); margin: 0 0 18px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; text-align: left; }
.field > label { font-size: 14px; color: var(--muted); font-weight: 700; }
.seg { display: flex; gap: 8px; }
.seg-diff { flex-wrap: wrap; }
.seg-btn {
  flex: 1; min-width: 56px; border: 2px solid #cfe0f0; background: #f4faff; color: var(--text);
  padding: 11px 6px; border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* 1–20 级难度网格 */
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.level-grid .seg-btn { min-width: 0; padding: 10px 0; border-radius: 10px; }
/* “开始”按钮：与其他游戏一样满宽 */
.setup-card .btn-primary { width: 100%; margin-top: 18px; border-radius: 16px; padding: 16px; font-size: 18px; }

/* 联网对战面板 */
.ol-actions { display: flex; gap: 8px; margin-bottom: 10px; }
/* 两个按钮尺寸统一（覆盖 .setup-card .btn-primary 的大按钮样式），仅颜色区分 */
.setup-card .ol-actions .btn { flex: 1; width: auto; margin-top: 0; padding: 13px 8px; font-size: 15px; border-radius: 14px; }
.ol-join { display: flex; gap: 8px; margin-bottom: 10px; }
.ol-join input { flex: 1; -webkit-appearance: none; appearance: none; border: 2px solid #cfe0f0; background: #f4faff; border-radius: 12px; padding: 11px; font-size: 15px; outline: none; box-shadow: none; }
.ol-join .btn { flex: none; padding: 11px 16px; }
.ol-note { color: var(--accent); font-weight: 700; font-size: 13px; margin: 2px 0 10px; text-align: center; min-height: 16px; }
.ol-label { text-align: left; font-size: 13px; color: var(--muted); font-weight: 700; margin: 8px 0 6px; }
.ol-list { max-height: 150px; overflow-y: auto; }
.ol-row { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-top: 1px solid #eef2f6; }
.ol-row:first-child { border-top: none; }
.ol-row .nm { flex: 1; text-align: left; font-weight: 700; color: var(--text); }
.ol-row .dot { width: 8px; height: 8px; border-radius: 50%; background: #2faa4a; }
.ol-row .dot.off { background: #cfcfcf; }
.ol-row .mini { border: none; background: var(--accent); color: #fff; font-weight: 800; border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.ol-row .mini.ghost { background: #fff; color: var(--accent); border: 2px solid #cfe0f0; }
.ol-empty { color: var(--muted); text-align: center; font-weight: 600; font-size: 13px; padding: 10px; margin: 0; }

.promo-card p { margin: 0 0 14px; color: var(--muted); font-weight: 600; }
.promo-row { display: flex; gap: 8px; justify-content: center; }
.promo-row button {
  width: 60px; height: 60px; padding: 6px; border-radius: 14px; border: 2px solid #e3ecf5;
  background: #f4faff; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.promo-row button .piece { width: 100%; height: 100%; }
.promo-row button:active { background: var(--accent); }

@media (min-width: 820px) {
  :root { --board-size: min(90vh, 92vw, 820px); }
}
