:root {
  --paper: #f8f9f5;
  --card: #ffffff;
  --ink: #23392e;
  --muted: #667066;
  --line: #dfe4da;
  --accent: #2c6647;
  --accent-ink: #ffffff;
  --pale: #edf2e7;
  --gold: #e2a63b;
  --wood: #ecd3a1;
  --wood-edge: #c99a5b;
  --grain: #e3c48c;
  --lines: #6e4b25;
  --river-ink: #8a6538;
  --red-ink: #b3322a;
  --black-ink: #1f2b25;
  --dot: #2c6647;
  --shadow: 0 15px 45px #243d2814;
  --slide: 170ms;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "DFKai-SB", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --sans: Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  --mono: "Courier New", Courier, monospace;
  color-scheme: light;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --paper: #141d18;
  --card: #1c2820;
  --ink: #e6eddf;
  --muted: #9ba995;
  --line: #354333;
  --accent: #b2ce87;
  --accent-ink: #142018;
  --pale: #17241b;
  --wood: #8c6a3f;
  --wood-edge: #5b4224;
  --grain: #7f5f37;
  --lines: #2a1d0f;
  --river-ink: #3b2a15;
  --dot: #b2ce87;
  --shadow: 0 15px 45px #00000055;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button, a { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

a { color: inherit; text-decoration: none; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

button:disabled { cursor: default; opacity: 0.45; }

[hidden] { display: none !important; }

.site-header {
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  min-height: 76px;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 16px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.04em;
}

.brand-mark { font-weight: 400; font-size: 22px; }

.brand-dot { color: #82a85c; margin-left: -6px; }

nav {
  display: flex;
  gap: 26px;
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

nav a:hover,
nav .current { color: var(--ink); }

nav .current { position: relative; }

nav .current::after {
  content: "";
  position: absolute;
  left: calc(50% - 2px);
  bottom: -10px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pale);
  gap: 2px;
}

.lang button {
  min-width: 36px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.lang button.selected {
  background: var(--card);
  box-shadow: 0 1px 3px #22332a1a;
}

.theme-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
}

.theme-btn:hover,
.lang button:hover { background: var(--pale); }

.lang button.selected:hover { background: var(--card); }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 28px 0;
}

.back {
  display: inline-block;
  margin-bottom: 26px;
  font-size: 12px;
  color: var(--muted);
}

.back:hover { color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(400px, 560px);
  gap: 56px;
  align-items: start;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #73a056;
}

h1 {
  margin: 18px 0 12px;
  font-size: 96px;
  line-height: 0.9;
  letter-spacing: -0.06em;
  font-weight: 650;
}

.title-dot { color: #82a85c; }

.tagline {
  margin: 0 0 14px;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.description {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.how-to {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  max-width: 360px;
}

.how-to .eyebrow { color: var(--muted); margin-bottom: 12px; }

.instruction {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.instruction-number {
  font: 700 11px var(--mono);
  color: #8a9c84;
}

.instruction p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.55;
}

.tiny-note {
  display: flex;
  gap: 8px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tiny-note span:first-child { color: var(--accent); }

.game-shell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px 16px 16px;
  min-width: 0;
}

.game-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 4px 2px;
}

.game-wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font: 700 13px var(--mono);
  letter-spacing: 0.14em;
}

.scores {
  margin-left: auto;
  display: flex;
  gap: 18px;
}

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 52px;
}

.stat-label {
  color: var(--muted);
  font: 700 10px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat strong {
  font: 600 22px var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}


.score-add {
  position: absolute;
  left: 0;
  top: 12px;
  color: var(--accent);
  font: 700 16px var(--mono);
  pointer-events: none;
  animation: rise 650ms ease-out forwards;
}

@keyframes rise {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-22px); }
}

.new-game {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.new-game:hover { filter: brightness(1.08); }

.new-game:active { transform: translateY(1px); }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 12px;
  background: #e7eee2c7;
}

:root[data-theme="dark"] .overlay { background: #101812c7; }

.overlay-card {
  width: min(100%, 320px);
  text-align: center;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 50px #243d2824;
  padding: 26px 22px 20px;
}

.overlay-card .overlay-kicker {
  margin: 0;
  font: 700 11px var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6d8464;
}

:root[data-theme="dark"] .overlay-kicker { color: #acc28a; }

.overlay-card h2 {
  margin: 12px 0 10px;
  font-size: clamp(32px, 7vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.045em;
  font-weight: 650;
}

.overlay-card p { margin: 0 0 16px; }

.overlay-card .overlay-body {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.overlay-card .result-score {
  margin: 0 0 16px;
  color: var(--accent);
  font: 600 28px var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 9px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 700;
}

.primary:hover { filter: brightness(1.08); }

.primary span[aria-hidden] { font-weight: 400; font-size: 18px; }

.secondary {
  margin-top: 12px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.noscript {
  max-width: 40rem;
  margin: 24px auto;
  padding: 0 28px;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 28px;
  flex-wrap: wrap;
  margin-top: 48px;
  padding: 20px 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.credit-link {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.credit-link:hover { color: var(--accent); }

.footer-tag { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; }

html[lang="zh-CN"] .tagline,
html[lang="zh-CN"] h1,
html[lang="zh-CN"] .overlay-card h2 {
  letter-spacing: 0;
}

html[lang="zh-CN"] .overlay-card h2 { line-height: 1.2; }

html[lang="zh-CN"] .stat-label,
html[lang="zh-CN"] .eyebrow,
html[lang="zh-CN"] .overlay-kicker {
  letter-spacing: 0.08em;
}


/* ---------- Xiangqi ---------- */

.board-wrap { position: relative; }

.title-cn {
  margin: -2px 0 14px;
  font-family: var(--kai);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--red-ink);
}

.turn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  min-width: 0;
}

.turn-dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red-ink);
  box-shadow: 0 0 0 3px #b3322a22;
}

.turn.black .turn-dot { background: var(--black-ink); box-shadow: 0 0 0 3px #1f2b2522; }
:root[data-theme="dark"] .turn.black .turn-dot { background: #e6eddf; box-shadow: 0 0 0 3px #e6eddf33; }

.turn.thinking #turn-text { color: var(--muted); }

.check-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--red-ink);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  animation: badge-pulse 1.1s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.ai-options { display: flex; flex-wrap: wrap; gap: 8px; }

.seg {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--pale);
  gap: 2px;
}

.seg button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.seg button:hover { color: var(--ink); }

.seg button.selected {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 3px #22332a1a;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red-ink);
}

.swatch.black { background: var(--black-ink); }
:root[data-theme="dark"] .swatch.black { background: #e6eddf; }

.board {
  position: relative;
  padding: 4.2%;
  border-radius: 14px;
  background:
    radial-gradient(120% 80% at 20% 0%, #ffffff30, transparent 60%),
    repeating-linear-gradient(97deg, transparent 0 22px, #ffffff10 22px 24px, transparent 24px 47px),
    linear-gradient(180deg, var(--wood), var(--grain));
  box-shadow: inset 0 0 0 1px #ffffff40, inset 0 -6px 0 #00000014, 0 10px 26px #5a3c1426;
  border: 2px solid var(--wood-edge);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.field {
  position: relative;
  aspect-ratio: 9 / 10;
  container-type: inline-size;
}

.grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.grid .line { stroke: var(--lines); stroke-width: 3; fill: none; stroke-linecap: square; }
.grid .frame { stroke: var(--lines); stroke-width: 7; fill: none; }
.grid .mark { stroke: var(--lines); stroke-width: 3; fill: none; }
.grid .river {
  fill: var(--river-ink);
  font-family: var(--kai);
  font-size: 58px;
  font-weight: 700;
  letter-spacing: 0.4em;
}

.marks, .pieces, .points { position: absolute; inset: 0; }

.piece,
.mark-spot,
.point {
  position: absolute;
  transform: translate(-50%, -50%);
}

.piece {
  width: 10.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--kai);
  font-weight: 700;
  font-size: 6.3cqw;
  line-height: 1;
  color: var(--red-ink);
  background:
    radial-gradient(circle at 34% 28%, #fffaf0 0 12%, transparent 46%),
    radial-gradient(circle at 50% 50%, #f6e6c6 0 58%, #e8cf9f 74%, #d7b47a 100%);
  box-shadow:
    0 0.55cqw 0 #b48a4f,
    0 0.9cqw 0.3cqw #6b4a1f40,
    0 1.6cqw 2cqw #3a26102e,
    inset 0 -0.35cqw 0.5cqw #b98d4f55;
  transition: left var(--slide) cubic-bezier(0.2, 0.7, 0.25, 1), top var(--slide) cubic-bezier(0.2, 0.7, 0.25, 1), transform 120ms ease, box-shadow 120ms ease;
  z-index: 1;
}

.piece::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  border: 0.32cqw solid currentColor;
  opacity: 0.55;
}

.piece.black { color: var(--black-ink); }

.piece .glyph { position: relative; top: -0.1cqw; }

.piece.selected {
  transform: translate(-50%, -62%);
  box-shadow:
    0 0 0 0.6cqw var(--gold),
    0 1.6cqw 0 #b48a4f,
    0 2.6cqw 2.4cqw #3a261045;
  z-index: 3;
}

.piece.last { box-shadow: 0 0 0 0.45cqw #e2a63bcc, 0 0.55cqw 0 #b48a4f, 0 1.6cqw 2cqw #3a26102e; }

.piece.in-check {
  animation: check-glow 1s ease-in-out infinite;
}

@keyframes check-glow {
  0%, 100% { box-shadow: 0 0 0 0.5cqw #d23a2bcc, 0 0.55cqw 0 #b48a4f, 0 0 2cqw #d23a2b88; }
  50% { box-shadow: 0 0 0 0.9cqw #d23a2b66, 0 0.55cqw 0 #b48a4f, 0 0 3.5cqw #d23a2bbb; }
}

.piece.moving { z-index: 4; }

.board.no-motion .piece { transition: none; }

.mark-spot { pointer-events: none; }

.mark-spot.dot {
  width: 3.2%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 0.5cqw #ffffff8a;
  z-index: 2;
}

.mark-spot.capture {
  width: 12.4%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.7cqw solid var(--dot);
  z-index: 2;
}

.mark-spot.from {
  width: 5.2%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.5cqw dashed #b37a22;
  background: #e2a63b33;
}

.pieces { z-index: 1; }
.marks { z-index: 2; pointer-events: none; }
.points { z-index: 5; }

.point {
  width: 11.111%;
  height: 10%;
  border-radius: 50%;
  outline: none;
  cursor: pointer;
}

.point:focus-visible::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 3px solid var(--gold);
}

.board.locked .point { cursor: default; }

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.tool {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.tool span[aria-hidden] { font-size: 15px; line-height: 1; }

.tool:hover:not(:disabled) { background: var(--pale); }

.tool.is-muted { color: var(--muted); }

.mute-icon { width: 1em; text-align: center; font-weight: 400; }

.status {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.move-list {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.move-list summary {
  cursor: pointer;
  color: var(--muted);
  font: 700 11px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.move-count { letter-spacing: 0.04em; text-transform: none; }

.move-list ol {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  max-height: 180px;
  overflow: auto;
  display: grid;
  grid-template-columns: 2.6em minmax(5.5em, max-content) 1fr;
  column-gap: 18px;
  gap: 4px 8px;
}

.move-list li { display: contents; }

.move-list .n { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.move-list .r { color: var(--red-ink); font-weight: 700; }
.move-list .b { color: var(--ink); font-weight: 700; }
.move-list .latest { text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 2px; text-underline-offset: 3px; }

:root[data-theme="dark"] .move-list .r { color: #f08a7e; }

.no-moves { margin: 10px 0 0; color: var(--muted); }

.overlay { border-radius: 14px; }

html[lang="zh-CN"] .move-list summary { letter-spacing: 0.08em; }

@media (max-width: 1000px) {
  h1 { font-size: 76px; }
  .layout {
    gap: 32px;
    grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.3fr);
  }
  .tagline { font-size: 22px; }
}

@media (max-width: 760px) {
  .site-header-inner { padding: 10px 16px; min-height: 64px; }
  .brand { font-size: 16px; }
  nav { display: none; }
  .header-tools { margin-left: auto; }
  main { padding: 14px 12px 0; }
  .back { margin-bottom: 12px; }
  .layout { display: flex; flex-direction: column; gap: 22px; }
  .game-shell { order: -1; padding: 6px 10px 12px; border-radius: 14px; }
  h1 { font-size: 60px; margin: 8px 0; }
  .tagline { font-size: 20px; }
  .how-to { margin-top: 20px; }
  .game-topbar { gap: 10px; min-height: 56px; }
  .game-wordmark { font-size: 0; gap: 0; }
  .controls { gap: 6px; }
  .seg button { padding: 6px 8px; }
  .board { padding: 3.4%; border-radius: 10px; }
  .status { font-size: 11px; }
  footer { margin-top: 28px; }
}

@media (max-width: 380px) {
  .seg button { font-size: 11px; padding: 5px 6px; }
  .new-game { padding: 9px 10px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .check-badge,
  .piece.in-check {
    transition: none !important;
    animation: none !important;
  }
}
