:root {
  --bg: #f4f6f5;
  --ink: #222b28;
  --muted: #78817d;
  --line: #e5eae7;
  --card: #ffffff;
  --accent: #1f6f5f;
  --accent-soft: #e7f3ef;
  --gold: #c79a3c;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --highlight: #f5e07a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(31, 55, 47, .07);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  background:
    radial-gradient(1100px 620px at 12% -8%, rgba(31, 111, 95, .10), transparent 62%),
    radial-gradient(900px 560px at 92% 4%, rgba(199, 154, 60, .10), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 26px 20px 30px;
}

button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 1060px; margin: 0 auto; }

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; font-size: 30px;
  color: #fff; background: linear-gradient(145deg, #278571, #165546);
  box-shadow: 0 6px 16px rgba(24, 87, 70, .24);
  font-family: "Segoe UI Symbol", "DejaVu Sans", serif;
}
.brand-text h1 {
  margin: 0; font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 25px; letter-spacing: 2px; font-weight: 700;
}
.brand-text span { font-size: 11px; letter-spacing: 2.4px; color: var(--muted); text-transform: uppercase; }
.top-actions { display: flex; gap: 10px; }
.ghost-btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.8);
  color: #4a5651; padding: 9px 15px; border-radius: 10px; font-size: 13px;
  transition: .18s ease;
}
.ghost-btn:hover { border-color: #b9d3cb; background: #fff; color: var(--accent); transform: translateY(-1px); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 322px; gap: 22px; align-items: start; }
.board-column { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 13px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.hint { font-size: 11px; color: var(--muted); }

/* ---------- Player bars ---------- */
.player-bar {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.72); border: 1px solid var(--line);
  border-radius: 13px; padding: 10px 13px; min-height: 62px;
}
.player-bar + .board-frame { margin-top: 12px; }
.board-frame + .player-bar { margin-top: 12px; }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; letter-spacing: .5px;
}
.avatar.ai { background: #2f3b37; color: #fff; }
.avatar.me { background: var(--accent-soft); color: var(--accent); }
.player-meta { min-width: 0; flex: 1; }
.player-name { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.player-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.badge {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px;
  background: #2f3b37; color: #fff; letter-spacing: .3px;
}
.badge.you { background: var(--accent-soft); color: var(--accent); }
.captured { display: flex; flex-wrap: wrap; gap: 0 1px; max-width: 168px; justify-content: flex-end; line-height: 1; }
.captured span { font-size: 19px; font-family: "Segoe UI Symbol", "DejaVu Sans", serif; }
.captured .white, .promo-options .white { color: #fffdf7; -webkit-text-stroke: 1.2px #3d3227; }
.captured .black, .promo-options .black { color: #2c2723; -webkit-text-stroke: .6px #8b755b; }
.advantage { min-width: 30px; text-align: right; font-size: 13px; font-weight: 700; color: var(--gold); }

/* ---------- Board ---------- */
.board-frame {
  position: relative; padding: 11px; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.board {
  --sq: 64px;
  width: 100%; aspect-ratio: 1 / 1;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 6px; overflow: hidden; touch-action: none; user-select: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.square {
  position: relative; display: grid; place-items: center;
  background: var(--light-sq); cursor: pointer;
}
.square.dark { background: var(--dark-sq); }
.square.light { background: var(--light-sq); }
.square::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  transition: background .16s ease;
}
.square.sq-last::before { background: rgba(245, 224, 122, .46); }
.square.sq-selected::before { background: rgba(93, 176, 148, .52); }
.square.sq-hover { box-shadow: inset 0 0 0 4px rgba(31, 111, 95, .55); }
.square.sq-check::before {
  background: radial-gradient(circle, rgba(214, 60, 48, .78) 0%, rgba(214, 60, 48, .42) 48%, transparent 74%);
}
.square.sq-selected.sq-check::before { background: radial-gradient(circle, rgba(214,60,48,.8), rgba(214,60,48,.4) 55%, transparent 76%); }

.coord {
  position: absolute; font-size: 10px; font-weight: 700; line-height: 1;
  pointer-events: none; z-index: 1; opacity: .8;
}
.coord-file { right: 4px; bottom: 3px; }
.coord-rank { left: 4px; top: 3px; }
.light .coord { color: #a97f55; }
.dark .coord { color: #f3ddbc; }

.piece {
  position: relative; z-index: 2; pointer-events: none;
  font-family: "Segoe UI Symbol", "DejaVu Sans", "Noto Sans Symbols 2", serif;
  font-size: calc(var(--sq) * .78); line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.28));
  transition: transform .14s ease;
}
.piece.white { color: #fffdf7; -webkit-text-stroke: 1.5px #3d3227; }
.piece.black { color: #2c2723; -webkit-text-stroke: .8px #8b755b; }
.piece.pop { animation: pop .22s ease; }
@keyframes pop { from { transform: scale(.82); } to { transform: scale(1); } }
.square.dragging .piece { opacity: .18; }

.marker { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.square.sq-target .marker::after {
  content: ''; position: absolute; width: 26%; height: 26%; border-radius: 50%;
  left: 37%; top: 37%; background: rgba(38, 62, 54, .34);
}
.square.sq-capture .marker::after {
  content: ''; position: absolute; inset: 6%; border-radius: 50%;
  border: 5px solid rgba(38, 62, 54, .36); background: transparent;
}
.dark.sq-target .marker::after { background: rgba(255, 250, 220, .55); }
.dark.sq-capture .marker::after { border-color: rgba(255, 250, 220, .55); }

.drag-ghost {
  position: fixed; z-index: 900; pointer-events: none; transform: translate(-50%, -55%);
  font-family: "Segoe UI Symbol", "DejaVu Sans", serif; line-height: 1;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,.3));
}
.drag-ghost.white { color: #fffdf7; -webkit-text-stroke: 1.5px #3d3227; }
.drag-ghost.black { color: #2c2723; -webkit-text-stroke: .8px #8b755b; }

/* ---------- Game over overlay ---------- */
.board-overlay {
  position: absolute; inset: 11px; z-index: 20; border-radius: 6px;
  display: grid; place-items: center; background: rgba(24, 38, 33, .62);
  backdrop-filter: blur(3px); animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  background: #fff; border-radius: 16px; padding: 26px 32px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); min-width: 240px;
}
.overlay-icon { font-size: 38px; font-family: "Segoe UI Symbol", serif; color: var(--gold); line-height: 1; }
.overlay-title { font-family: Georgia, "Songti SC", serif; font-size: 23px; font-weight: 700; margin: 9px 0 6px; }
.overlay-desc { font-size: 13px; color: var(--muted); margin-bottom: 18px; }

/* ---------- Status ---------- */
.status-card { padding-bottom: 15px; }
.status-row { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #c3ccc8; flex: none; }
.status-dot.turn { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.status-dot.busy { background: var(--gold); animation: pulse 1s infinite; }
.status-dot.danger { background: #d53f34; box-shadow: 0 0 0 4px rgba(213,63,52,.14); }
@keyframes pulse { 50% { opacity: .35; } }
.status-card p { margin: 8px 0 0 18px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.thinking { margin: 11px 0 0 18px; font-size: 11.5px; color: var(--gold); display: flex; align-items: center; gap: 7px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--gold); animation: bounce 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Difficulty ---------- */
.levels { display: flex; flex-direction: column; gap: 8px; }
.level {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); background: #fbfcfb; border-radius: 11px;
  padding: 10px 12px; width: 100%; transition: .18s ease;
}
.level:hover { border-color: #b9d3cb; transform: translateX(2px); }
.level.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.level-icon {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  font-size: 24px; font-family: "Segoe UI Symbol", serif;
  color: #6f7b76; background: #fff; border-radius: 9px; border: 1px solid var(--line);
}
.level.active .level-icon { color: var(--accent); border-color: #bcdcd2; }
.level-body { flex: 1; min-width: 0; }
.level-body strong { display: block; font-size: 13.5px; }
.level-body small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.level-check { width: 15px; height: 15px; border-radius: 50%; border: 1.5px solid #cfd8d4; flex: none; }
.level.active .level-check { border: 5px solid var(--accent); background: #fff; }

/* ---------- Settings ---------- */
.field-label { font-size: 11.5px; color: var(--muted); margin-bottom: 7px; }
.segment { display: flex; background: #f1f4f2; border-radius: 10px; padding: 3px; gap: 3px; }
.segment button {
  flex: 1; border: 0; background: transparent; border-radius: 8px;
  padding: 8px 4px; font-size: 12px; color: #6b7671; transition: .18s ease;
}
.segment button.active { background: #fff; color: var(--accent); font-weight: 700; box-shadow: 0 2px 6px rgba(31,55,47,.1); }
.btn-row { display: flex; gap: 9px; margin-top: 14px; }
.primary-btn {
  flex: 1; border: 0; border-radius: 10px; padding: 10px 14px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 12px rgba(31,111,95,.22); transition: .18s ease;
}
.primary-btn:hover { background: #185e50; transform: translateY(-1px); }
.secondary-btn {
  flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  background: #fff; color: #4a5651; font-size: 13px; font-weight: 600; transition: .18s ease;
}
.secondary-btn:hover:not(:disabled) { border-color: #b9d3cb; color: var(--accent); }
.secondary-btn:disabled { opacity: .42; cursor: not-allowed; }
.text-btn {
  display: block; margin: 11px auto 0; border: 0; background: transparent;
  color: var(--muted); font-size: 11.5px; text-decoration: underline; text-underline-offset: 3px;
}
.text-btn:hover { color: var(--accent); }

/* ---------- Move list ---------- */
.moves-card { display: flex; flex-direction: column; min-height: 158px; }
.moves {
  max-height: 196px; overflow-y: auto; font-size: 12.5px;
  font-family: "Segoe UI", Consolas, monospace; margin: -4px -6px -4px 0; padding-right: 6px;
}
.moves::-webkit-scrollbar { width: 6px; }
.moves::-webkit-scrollbar-thumb { background: #d7e0dc; border-radius: 3px; }
.moves-empty { color: #a3aca8; font-size: 12px; font-family: inherit; padding: 8px 0; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; padding: 3px 0; }
.move-row:nth-child(odd) { background: #f8faf9; }
.move-num { color: #a3aca8; text-align: center; }
.move-san { padding: 2px 6px; border-radius: 5px; white-space: nowrap; }
.move-san.last { background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- Footer / modals / toast ---------- */
.footer { margin-top: 18px; text-align: center; font-size: 11px; color: #96a19c; line-height: 1.7; }
.footer .sep { margin: 0 8px; color: #cdd5d1; }

.modal {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: rgba(24, 38, 33, .48); padding: 20px; backdrop-filter: blur(2px);
}
.modal-card {
  background: #fff; border-radius: 18px; padding: 24px 26px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.25); max-width: 420px; width: 100%;
  animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h3 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 20px; }
.modal-card > p { margin: 7px 0 18px; font-size: 12.5px; color: var(--muted); }
.promo-options { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.promo-options button {
  width: 68px; height: 68px; border: 1px solid var(--line); border-radius: 12px;
  background: #f8faf9; font-size: 40px; line-height: 1;
  font-family: "Segoe UI Symbol", "DejaVu Sans", serif; transition: .18s ease;
}
.promo-options button:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-3px); }
.rules-card { text-align: left; max-width: 520px; }
.rules-card h3 { text-align: center; margin-bottom: 14px; }
.rules-body { font-size: 12.5px; line-height: 1.75; color: #4a5651; max-height: 56vh; overflow-y: auto; }
.rules-body p { margin: 0 0 9px; }
.rules-body ul { margin: 0 0 9px; padding-left: 19px; }
.rules-body li { margin-bottom: 5px; }
.rules-body b { color: var(--ink); }
.rules-card .primary-btn { width: 100%; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #26332e; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 12.5px; z-index: 1100; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: rise .2s ease;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .moves-card { grid-column: 1 / -1; }
  .board-frame { max-width: 620px; margin-left: auto; margin-right: auto; }
  .player-bar { max-width: 642px; margin-left: auto; margin-right: auto; }
}
@media (max-width: 600px) {
  body { padding: 16px 12px 24px; }
  .topbar { flex-wrap: wrap; }
  .brand-text h1 { font-size: 21px; }
  .sidebar { display: flex; }
  .captured { max-width: 90px; }
  .player-sub { font-size: 10.5px; }
  .footer .sep { display: none; }
}
