﻿:root {
  color-scheme: dark;
  --page: #201f1d;
  --surface: #2f2e2c;
  --surface-soft: #3b3936;
  --line: #4a4742;
  --ink: #f1eee8;
  --muted: #b9b2a8;
  --gold: #d8a441;
  --green: #7fa650;
  --green-dark: #66883f;
  --danger: #d66b5d;
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --light-hover: #f6e4c6;
  --dark-hover: #c89a70;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at top left, rgba(127, 166, 80, .16), transparent 34rem), var(--page);
}
button, select { font: inherit; }
a { color: var(--muted); text-decoration: none; }
a:hover { color: var(--ink); }

.site-header {
  width: min(1220px, calc(100vw - 28px));
  margin: 0 auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 22px;
}
.site-brand {
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 800;
}
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.site-nav a {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 3px;
  color: var(--muted);
  font-weight: 700;
}
.site-nav a:hover { background: var(--surface); }

.app-shell {
  width: min(1220px, calc(100vw - 28px));
  min-height: calc(100vh - 58px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(330px, 780px) minmax(300px, 360px);
  gap: 22px;
  align-items: center;
  padding: 12px 0 24px;
}
.board-area, .side-panel { min-width: 0; }
.top-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: .78rem;
  letter-spacing: 0;
}
h1, h2, p { margin: 0; }
h1 { font-size: 2.8rem; line-height: .95; letter-spacing: 0; }
h2 { font-size: 1.12rem; }
.turn-pill {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 3px;
  background: var(--surface);
  color: var(--gold);
  font-weight: 800;
  white-space: nowrap;
}

.player-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.player-strip.opponent { border-bottom: 0; border-radius: 4px 4px 0 0; }
.player-strip:not(.opponent) { border-top: 0; border-radius: 0 0 4px 4px; }
.player-name { display: block; font-weight: 800; }
.check-tag { display: inline-block; min-height: 18px; color: var(--danger); font-size: .82rem; font-weight: 800; }
.clock { min-width: 76px; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; font-size: 1.25rem; }

.board-wrap {
  border: 1px solid #1a1816;
  background: #1a1816;
  box-shadow: 0 18px 42px rgba(0,0,0,.32);
}
.board {
  width: min(100%, calc(100vh - 178px));
  max-width: 780px;
  min-width: 312px;
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: #181614;
  font-size: 2.2rem;
  line-height: 1;
  user-select: none;
}
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.light:hover { background: var(--light-hover); }
.square.dark:hover { background: var(--dark-hover); }
.square.selected { box-shadow: inset 0 0 0 4px rgba(127,166,80,.95); }
.square.legal::after, .square.capture::after {
  content: "";
  position: absolute;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(32,31,29,.42);
}
.square.capture::after {
  width: 78%;
  background: transparent;
  border: 5px solid rgba(32,31,29,.46);
}
.square.last-move { box-shadow: inset 0 0 0 999px rgba(216,164,65,.23); }
.coord {
  position: absolute;
  left: 5px;
  top: 4px;
  color: rgba(32,31,29,.72);
  font-size: .68rem;
  font-weight: 800;
}
.piece { display: block; filter: drop-shadow(0 2px 1px rgba(0,0,0,.24)); }
.piece.black { color: #151515; }
.piece.white { color: #fffdf6; -webkit-text-stroke: 1px rgba(23,32,42,.5); }

.side-panel { display: grid; gap: 12px; }
.quick-play, .status-panel, .controls, .tabs {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(47,46,44,.94);
}
.quick-play { display: grid; gap: 8px; padding: 12px; }
.status-panel { display: grid; gap: 10px; padding: 15px; }
.status-panel p:last-child { color: var(--muted); line-height: 1.55; }
.controls { display: grid; gap: 11px; padding: 12px; }
.control-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

button, select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-soft);
  color: var(--ink);
}
button { cursor: pointer; font-weight: 800; }
button:hover, select:hover { border-color: #7d756c; background: #45423e; }
button:disabled { cursor: not-allowed; color: #7f7970; background: #2a2927; }
.primary-action {
  min-height: 48px;
  background: linear-gradient(#8ab75b, var(--green));
  border-color: var(--green-dark);
  color: #11150d;
  font-size: 1.08rem;
}
.primary-action:hover { background: linear-gradient(#93c364, #719847); }
.field { display: grid; gap: 6px; color: var(--muted); font-size: .86rem; font-weight: 700; }
.field select { width: 100%; padding: 0 10px; }

.tabs { overflow: hidden; }
.tab-list { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.tab { border: 0; border-right: 1px solid var(--line); border-radius: 0; background: #292826; }
.tab:last-child { border-right: 0; }
.tab.active { background: var(--surface); color: var(--gold); }
.tab-panel { display: none; min-height: 230px; max-height: 340px; overflow: auto; padding: 12px; }
.tab-panel.active { display: block; }
.move-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.move-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 3px;
  background: #262522;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.move-num { color: var(--muted); }
.rule-grid { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 10px 12px; line-height: 1.5; }
.rule-grid span {
  display: grid;
  place-items: center;
  height: 32px;
  border-radius: 3px;
  background: #1f1e1c;
  color: var(--gold);
  font-weight: 900;
}
.rule-grid p { color: var(--muted); }
.resource-list, .search-chips { display: grid; gap: 9px; }
.resource-list a, .search-chips a {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #262522;
  color: var(--ink);
  font-weight: 800;
}
.search-chips { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 10px; }
.search-chips a { text-align: center; font-size: .86rem; }

.promotion-dialog {
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  background: var(--surface);
  color: var(--ink);
}
.promotion-dialog::backdrop { background: rgba(0,0,0,.48); }
.promotion-dialog h2 { margin-bottom: 14px; }
.promotion-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promotion-grid button { min-height: 68px; font-size: 2rem; }

@media (max-width: 920px) {
  .site-header { align-items: start; flex-direction: column; gap: 8px; padding: 10px 0; }
  .app-shell { grid-template-columns: 1fr; align-items: start; min-height: auto; padding-top: 8px; }
  .board { width: min(100%, calc(100vh - 164px)); }
  .side-panel { padding-bottom: 18px; }
}
@media (max-width: 520px) {
  .site-header, .app-shell { width: min(100vw - 16px, 480px); }
  .site-nav { width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); }
  .site-nav a { padding: 0 4px; font-size: .86rem; }
  .top-bar { align-items: start; flex-direction: column; }
  h1 { font-size: 2.25rem; }
  .turn-pill { width: 100%; }
  .board { min-width: 0; }
  .square { font-size: 1.85rem; }
  .control-row, .search-chips { grid-template-columns: 1fr; }
  .tab-panel { max-height: 320px; }
}
