/* ============================================================================
 * 国际象棋 界面样式
 * ==========================================================================*/
:root {
  --bg: #14181f;
  --bg2: #1c232e;
  --card: #232a37;
  --card-border: #2e3646;
  --text: #e8eaf0;
  --text-dim: #9aa3b2;
  --accent: #4a90d9;
  --accent2: #f0b429;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --danger: #e5484d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  min-height: 100%;
  background: radial-gradient(1200px 700px at 20% -10%, #232d3d 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

header { text-align: center; padding: 22px 16px 6px; }
header h1 { font-size: 30px; letter-spacing: 2px; }
header .sub { color: var(--text-dim); font-size: 13px; margin-top: 6px; }

.layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 20px 30px;
  max-width: 1260px;
  margin: 0 auto;
}

/* ---------- 棋盘区 ---------- */
.board-wrap {
  flex: 0 0 auto;
  width: min(74vh, 680px, calc(100vw - 420px));
  min-width: 320px;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 15px;
  min-height: 42px;
}
.player-bar .pname { font-weight: 600; }
.player-bar .captured {
  flex: 1;
  font-size: 17px;
  letter-spacing: 1px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
}
.player-bar .adv { color: var(--accent2); font-size: 13px; font-weight: 700; }
.player-bar .clock {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 18px;
  font-weight: 700;
  background: #161b23;
  border: 1px solid var(--card-border);
  padding: 4px 10px;
  border-radius: 8px;
  min-width: 64px;
  text-align: center;
}
.player-bar .clock.active { color: var(--accent2); border-color: var(--accent2); }
.player-bar .clock.low { color: var(--danger); border-color: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .45; } }

.board-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .04);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.square.light { background: var(--sq-light); }
.square.dark { background: var(--sq-dark); }

.square.selected { box-shadow: inset 0 0 0 4px #f7ec59; }
.square.last { background-image: linear-gradient(rgba(255, 216, 60, .38), rgba(255, 216, 60, .38)); }
.square.hint { background-image: linear-gradient(rgba(60, 200, 120, .5), rgba(60, 200, 120, .5)); }
.square.check { background-image: radial-gradient(circle at center, #e5484d 0%, #e5484d 30%, transparent 68%); }

.piece {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  font-size: 9.4cqw;
  line-height: 1;
  z-index: 2;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.piece.w { color: #fdfdfd; -webkit-text-stroke: 1px #4a4a4a; }
.piece.b { color: #1b1b1b; -webkit-text-stroke: 1px #6d6d6d; }

/* 合法落点 */
.square.target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(20, 30, 20, .28);
  z-index: 3;
  pointer-events: none;
}
.square.target-cap::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 4px solid rgba(20, 30, 20, .30);
  z-index: 3;
  pointer-events: none;
}

.coord {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  opacity: .85;
}
.coord.rank { top: 3px; left: 4px; }
.coord.file { bottom: 2px; right: 4px; }
.square.light .coord { color: var(--sq-dark); }
.square.dark .coord { color: var(--sq-light); }

/* 思考中遮罩 */
.thinking {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 20, .45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.thinking.show { display: flex; }
.think-card {
  background: #202735;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.dots i {
  display: inline-block;
  width: 6px; height: 6px;
  margin: 0 2px;
  background: var(--accent2);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* 评估条 */
.eval-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}
.eval-bar {
  flex: 1;
  height: 8px;
  background: linear-gradient(to right, #1b1b1b 0%, #1b1b1b 50%, #f5f5f5 50%, #f5f5f5 100%);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
}
.eval-fill {
  height: 100%;
  width: 50%;
  background: #f5f5f5;
  border-radius: 6px;
  transition: width .5s;
}
.eval-row > span { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.status {
  margin-top: 10px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent2);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 9px 12px;
}

/* ---------- 面板 ---------- */
.panel {
  width: 340px;
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-right: 4px;
}
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px;
}
.card-title {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.card-title .tip { color: #6c768a; font-size: 11px; letter-spacing: 0; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

.btn {
  background: #2b3443;
  color: var(--text);
  border: 1px solid #38414f;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.btn:hover:not(:disabled) { background: #36414f; border-color: #4a5568; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.active { background: var(--accent); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #5aa0e8; }
.btn.small { padding: 8px 10px; font-size: 13px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.level-row { display: flex; gap: 6px; }
.lvl {
  flex: 1;
  background: #2b3443;
  color: var(--text);
  border: 1px solid #38414f;
  border-radius: 9px;
  padding: 7px 2px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.lvl:hover { background: #36414f; }
.lvl.active { background: var(--accent2); border-color: var(--accent2); color: #1d1400; font-weight: 700; }
.level-desc { margin-top: 10px; font-size: 12px; color: var(--text-dim); line-height: 1.6; }

select {
  width: 100%;
  background: #2b3443;
  color: var(--text);
  border: 1px solid #38414f;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

/* 记谱 */
.moves-card .moves {
  max-height: 150px;
  overflow-y: auto;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13.5px;
  line-height: 1.9;
  background: #1a2029;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 10px;
}
.moverow { display: flex; gap: 10px; }
.moverow .num { color: #6c768a; min-width: 28px; }
.moverow .msan { min-width: 64px; }
.moverow .msan.last { color: var(--accent2); font-weight: 700; }
.moves:empty::after { content: "— 暂无着法 —"; color: #55617a; }

/* 规则 */
details {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
details summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 13.5px;
  background: #28303e;
  user-select: none;
}
details summary:hover { background: #2f3847; }
.rules { padding: 10px 14px 10px 30px; font-size: 12.5px; color: var(--text-dim); line-height: 1.75; }
.rules li { margin-bottom: 4px; }
.rules b { color: var(--text); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .18s;
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } }

.modal-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 26px 30px;
  min-width: 300px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  animation: pop .2s;
}
@keyframes pop { from { transform: scale(.92); opacity: .5; } }
.modal-title { font-size: 16px; margin-bottom: 16px; }

.promo-row { display: flex; gap: 12px; justify-content: center; }
.promo-btn {
  width: 74px;
  background: #2b3443;
  color: var(--text);
  border: 1px solid #38414f;
  border-radius: 12px;
  padding: 12px 0 10px;
  cursor: pointer;
  font-size: 38px;
  line-height: 1;
  transition: all .15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}
.promo-btn span { font-size: 12px; color: var(--text-dim); }
.promo-btn:hover { background: var(--accent); border-color: var(--accent); transform: translateY(-2px); }

.result-icon { font-size: 46px; margin-bottom: 8px; }
.result-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.result-sub { color: var(--text-dim); font-size: 14px; }
.result-reason {
  margin-top: 10px;
  font-size: 13px;
  color: var(--accent2);
  background: #1a2029;
  border-radius: 8px;
  padding: 8px 12px;
  display: inline-block;
}

/* toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #202735;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

footer {
  text-align: center;
  color: #5c6678;
  font-size: 12px;
  padding: 10px 16px 26px;
  line-height: 1.7;
}

/* ---------- 响应式 ---------- */
@media (max-width: 920px) {
  .layout { flex-direction: column; align-items: center; }
  .board-wrap { width: min(92vw, 560px); }
  .panel { width: min(92vw, 560px); flex: 0 0 auto; max-height: none; }
  .moves-card .moves { max-height: 120px; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #38414f; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
