:root {
  --ink: #e9dfd0;
  --muted: #9b8f80;
  --gold: #d9b26a;
  --red: #e0574a;
  --line: #7c5433;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 22px 20px 40px;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 50% -12%, #2b231d 0%, #17120f 58%, #0e0b09 100%);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

h1 {
  margin: 0;
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif;
  font-size: 30px;
  letter-spacing: .14em;
  color: #f2e3c6;
  text-shadow: 0 2px 14px rgba(217, 178, 106, .28);
}

.sub {
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: .06em;
}

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

.speed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.speed select {
  appearance: none;
  padding: 7px 26px 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(217, 178, 106, .25);
  background: #1d1713 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%23a99270'/></svg>") no-repeat right 9px center;
  color: var(--ink);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}

.btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(217, 178, 106, .28);
  background: rgba(255, 255, 255, .05);
  color: #ded1bd;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}

.btn:hover { background: rgba(255, 255, 255, .1); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #b0402f, #8d2c20);
  border-color: rgba(255, 160, 130, .4);
  color: #fff3e6;
  box-shadow: 0 4px 14px rgba(150, 40, 25, .35);
}

.btn.primary:hover { background: linear-gradient(180deg, #c14a37, #9a3225); }

/* ---------- 布局 ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 288px;
  gap: 26px;
  align-items: start;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(217, 178, 106, .16);
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .015));
}

.card h3 {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .16em;
  color: var(--gold);
}

.card ul {
  margin: 0;
  padding-left: 17px;
  font-size: 13px;
  line-height: 1.8;
  color: #cdbfae;
}

.card li::marker { color: rgba(217, 178, 106, .55); }

.tip {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.75;
  color: #a99a86;
}

.status {
  margin: 0;
  padding-top: 9px;
  border-top: 1px dashed rgba(217, 178, 106, .16);
  font-size: 12.5px;
  color: #c8b79f;
  min-height: 20px;
}

.status.warn { color: #ff8f7a; }

/* ---------- 行动点 ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
  font-size: 12.5px;
  color: #b7a894;
}

.hud.top { margin-bottom: 9px; }
.hud.bottom { margin-top: 10px; }

.hud .who {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.chip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.chip.red { background: var(--red); box-shadow: 0 0 8px rgba(224, 87, 74, .5); }
.chip.black { background: #cbb191; }

.hud .left {
  margin-left: auto;
  color: #85796b;
  font-variant-numeric: tabular-nums;
}

.hud .left b { color: #d8c8b1; font-weight: 600; }

.ap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.ap i {
  position: relative;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, .07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}

.ap i::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--f, 0) * 100%);
  background: currentColor;
}

.ap i.full { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16), 0 0 10px currentColor; }

#apR { color: #e0574a; }
#apB { color: #cbb191; }

.ap.flash i { animation: apflash .3s ease; }

@keyframes apflash {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(.8); }
}

/* ---------- 棋盘 ---------- */
/* 手机上点/拖棋盘时不要出现浏览器的蓝色高亮和文字选中框 */
.board, .grid, .marks, .pieces {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.board {
  position: relative;
  padding: 4.8%;
  border-radius: 14px;
  background:
    radial-gradient(120% 90% at 28% 8%, rgba(255, 255, 255, .3), transparent 62%),
    repeating-linear-gradient(91deg, rgba(120, 80, 40, .05) 0 2px, transparent 2px 8px),
    linear-gradient(160deg, #f3ddb4, #e6c491 54%, #d6b078);
  box-shadow:
    0 18px 42px rgba(0, 0, 0, .55),
    inset 0 0 0 1px rgba(255, 255, 255, .4),
    inset 0 0 60px rgba(120, 76, 35, .16);
  touch-action: manipulation;
}

.board::before {
  content: "";
  position: absolute;
  inset: 2.1%;
  border: 1.5px solid rgba(110, 70, 36, .38);
  border-radius: 6px;
  pointer-events: none;
}

.grid {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 9;
  container-type: inline-size;
  touch-action: manipulation;
  cursor: pointer;
}

.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.marks, .pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.marks { z-index: 5; }
.pieces { z-index: 2; }

/* ---------- 棋子 ---------- */
.piece {
  position: absolute;
  width: 11.6%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, #fff4d9, #ecd2a2 58%, #d3ac73);
  box-shadow:
    0 3px 6px rgba(60, 35, 12, .4),
    inset 0 0 0 2px rgba(122, 80, 43, .32),
    inset 0 -4px 8px rgba(122, 80, 43, .22);
  font-family: "KaiTi", "STKaiti", "Kaiti SC", "Songti SC", serif;
  font-size: 6.3cqw;
  font-weight: 700;
  line-height: 1;
  user-select: none;
  transition: box-shadow .15s, transform .15s;
}

/* 在路上的子才提高图层，别给 32 枚都开一个（手机 GPU 吃不消） */
.piece.moving {
  cursor: default;
  will-change: left, top;
}

.piece::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  border: 1px solid rgba(122, 80, 43, .3);
}

.piece.r { color: #a8271c; }
.piece.b { color: #221e1a; }

.piece.sel {
  box-shadow:
    0 0 0 3px rgba(240, 198, 118, .95),
    0 0 22px rgba(240, 200, 120, .6),
    0 4px 10px rgba(60, 35, 12, .45);
  z-index: 8;
  transform: translate(-50%, -50%) scale(1.04);
}

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

@keyframes checkPulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(210, 50, 35, .8), 0 3px 6px rgba(60, 35, 12, .4);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(255, 90, 70, .9), 0 0 22px rgba(255, 70, 50, .75);
  }
}

.piece.deny {
  animation: deny .3s ease;
}

@keyframes deny {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-56%, -50%); }
  75% { transform: translate(-44%, -50%); }
}

.piece.landed {
  animation: landed .2s ease-out;
}

@keyframes landed {
  0% { transform: translate(-50%, -50%) scale(.9); }
  55% { transform: translate(-50%, -50%) scale(1.05); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.piece.dying {
  animation: die .22s ease forwards;
  pointer-events: none;
  z-index: 1;
}

@keyframes die {
  to {
    opacity: 0;
    filter: blur(2px);
    transform: translate(-50%, -50%) scale(.45) rotate(18deg);
  }
}

/* ---------- 落点标记 ---------- */
.mark {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.mark.move {
  width: 3.6%;
  aspect-ratio: 1;
  background: rgba(46, 110, 72, .85);
  box-shadow: 0 0 0 3px rgba(46, 110, 72, .2);
}

.mark.take {
  width: 8.4%;
  aspect-ratio: 1;
  border: 2px solid rgba(190, 55, 40, .9);
  background: rgba(190, 55, 40, .1);
  box-shadow: 0 0 14px rgba(190, 55, 40, .45);
}

/* ---------- 撞子小火花 ---------- */
.clash {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 3.2%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 216, 140, .95);
  color: #ffd98a;
  font: 700 2.1cqw/1 "KaiTi", "STKaiti", serif;
  text-shadow: 0 0 6px rgba(255, 190, 90, .8);
  animation: clash .4s ease-out forwards;
}

@keyframes clash {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  25%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.75); }
}

/* ---------- 结算层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(10, 8, 6, .66);
  backdrop-filter: blur(3px);
  animation: fade .22s ease;
}

.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  min-width: 240px;
  padding: 26px 30px;
  text-align: center;
  border-radius: 14px;
  border: 1px solid rgba(217, 178, 106, .3);
  background: linear-gradient(180deg, #241c17, #17120f);
  box-shadow: 0 24px 50px rgba(0, 0, 0, .6);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 26px;
  letter-spacing: .12em;
  color: #f2d9a8;
}

.overlay-card p {
  margin: 0 0 18px;
  font-size: 13px;
  color: #b3a390;
}

/* ---------- 暂停 ---------- */
body.paused .board { filter: saturate(.55) brightness(.82); }
body.paused .grid { cursor: default; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; gap: 20px; }
  .board-wrap { max-width: 480px; }
  .panel { max-width: 480px; margin: 0 auto; width: 100%; }
  body { padding: 16px 14px 32px; }
  h1 { font-size: 25px; }
}

@media (max-width: 420px) {
  .sub { display: none; }
  .btn { padding: 7px 11px; }
  .ap i { width: 13px; height: 13px; }
}
