:root {
  --wood: #3a2a1a;
  --wood-dark: #24180f;
  --ink: #1a1410;
  --cream: #f4ead8;
  --gold: #c9a227;
  --gold-dim: #8a6a1a;
  --red: #b42318;
  --red-deep: #7a140e;
  --mute: #8a7b68;
  --line: #d4c4a8;
  --cell-a: #e8d7b5;
  --cell-b: #c4a574;
  --xq-line: #6b4a2b;
  --river: #7a8b6a;
  --panel: #2a1e14;
  --ok: #2f7d4a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Serif SC", "Songti SC", "SimSun", "Source Han Serif SC", serif;
  background:
    radial-gradient(ellipse at top, #4a3422 0%, #1a120c 55%, #0d0906 100%);
  color: var(--cream);
  min-height: 100%;
}

#app { min-height: 100%; }

/* ===== setup ===== */
.setup {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 48px;
  gap: 22px;
}
.brand { text-align: center; }
.brand h1 {
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #f3e6c8;
  text-shadow: 0 2px 0 #0008;
}
.brand .en {
  margin-top: 6px;
  letter-spacing: 0.32em;
  font-size: 12px;
  color: var(--gold);
  text-transform: uppercase;
}
.brand p {
  margin-top: 10px;
  color: var(--mute);
  font-size: 14px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: min(720px, 100%);
}
.card {
  background: linear-gradient(180deg, #3a2b1d, #26190f);
  border: 1px solid #5a4330;
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: 0 10px 30px #0006;
}
.card h2 {
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 0.14em;
  margin-bottom: 12px;
  font-weight: 600;
}
.choices { display: flex; gap: 10px; flex-wrap: wrap; }
.choice {
  flex: 1;
  min-width: 120px;
  background: #1c130c;
  border: 1px solid #5a4330;
  color: var(--cream);
  border-radius: 10px;
  padding: 12px 10px;
  cursor: pointer;
  font: inherit;
  text-align: center;
  transition: 0.15s ease;
}
.choice small { display: block; color: var(--mute); font-size: 11px; margin-top: 4px; }
.choice:hover { border-color: var(--gold-dim); }
.choice.on {
  border-color: var(--gold);
  background: linear-gradient(180deg, #4a3218, #2a1c0c);
  box-shadow: inset 0 0 0 1px #c9a22755;
}
.choice.red.on { border-color: #e25b4a; background: linear-gradient(180deg, #4a1c16, #2a100c); }
.choice.blk.on { border-color: #888; background: linear-gradient(180deg, #2a2a2a, #151515); }

.diffs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.start-btn {
  width: min(720px, 100%);
  border: 0;
  border-radius: 12px;
  padding: 16px;
  font: inherit;
  font-size: 18px;
  letter-spacing: 0.28em;
  color: #1a1008;
  background: linear-gradient(180deg, #e3c56a, #b8860b);
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 8px 20px #0005;
}
.start-btn:hover { filter: brightness(1.06); }

.note {
  width: min(720px, 100%);
  color: var(--mute);
  font-size: 12px;
  line-height: 1.7;
}

/* ===== play ===== */
.play {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(320px, 1fr) minmax(220px, 280px);
  gap: 18px;
  padding: 18px;
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  align-items: start;
}
@media (max-width: 960px) {
  .play {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .side { width: min(520px, 100%); }
}

.side {
  background: linear-gradient(180deg, #322418, #1e140c);
  border: 1px solid #5a4330;
  border-radius: 14px;
  padding: 14px;
}
.side h3 {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--gold);
  margin-bottom: 8px;
}
.who {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #4a3828;
}
.badge {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.badge.r { background: #b42318; color: #f6e2b8; }
.badge.b { background: #1a1a1a; color: #ddd; border: 1px solid #666; }
.turn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #444; margin-left: auto;
}
.turn-dot.on { background: #e3c56a; box-shadow: 0 0 8px #e3c56a; }

.status {
  margin: 12px 0;
  min-height: 44px;
  font-size: 14px;
  line-height: 1.55;
  color: #f0e2c6;
}
.status.check { color: #ff8a7a; }
.status.over { color: #e3c56a; font-size: 16px; }

.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  border: 1px solid #5a4330;
  background: #1c130c;
  color: var(--cream);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--gold-dim); }
.btn.danger { color: #ffb4a8; }
.btn.gold { border-color: var(--gold-dim); color: #e3c56a; }

.log {
  max-height: 240px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.7;
  color: #d7c8ac;
  font-family: ui-monospace, "Noto Sans Mono CJK SC", monospace;
}
.log div:nth-child(odd) { color: #f0d2b0; }

.caps { min-height: 36px; display: flex; flex-wrap: wrap; gap: 4px; }
.mini {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px;
  background: #4a2018; color: #f6e2b8;
}
.mini.b { background: #222; color: #ddd; border-radius: 4px; }

/* board wrap */
.board-wrap {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.board-frame {
  width: 100%;
  max-width: 590px;
  background: #5a3c22;
  padding: 14px 14px 18px;
  border-radius: 10px;
  box-shadow:
    0 0 0 2px #2a180c,
    0 16px 40px #0008,
    inset 0 0 0 1px #c9a22755;
}
.files, .ranks-col { color: #e8d2a8; font-size: 11px; letter-spacing: 0.04em; }
.files {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  text-align: center;
  margin-top: 6px;
  width: 100%;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%;
  aspect-ratio: 9 / 10;
  background: #d7bc8b;
  border: 2px solid #4a3018;
  user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.sq.dark { background: #c4a06a; }
.sq.light { background: #e4cf9e; }
.sq.river { background: repeating-linear-gradient(90deg, #c9b889 0 12px, #b9c4a0 12px 24px); }
.sq.palace { box-shadow: inset 0 0 0 1px #8a5a28aa; }
.sq.hi { background: #e8d36a; }
.sq.can::after {
  content: "";
  width: 12px; height: 12px; border-radius: 50%;
  background: #2f7d4a88;
  position: absolute;
}
.sq.eat::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid #b42318cc;
  border-radius: 50%;
}
.sq.last { outline: 2px solid #c9a227; outline-offset: -2px; }
.sq.check-sq { background: #e08a72; }

.piece {
  width: 86%;
  height: 86%;
  display: grid;
  place-items: center;
  font-weight: 700;
  z-index: 1;
  pointer-events: none;
  transition: transform 0.12s ease;
}
.sq:hover .piece { transform: translateY(-1px); }
.piece.r {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e36a55, #9a1c14 55%, #6a100c);
  color: #f6e2b8;
  font-size: clamp(14px, 2.6vw, 22px);
  box-shadow: 0 2px 3px #0007, inset 0 0 0 2px #f0d48a88;
}
.piece.b {
  border-radius: 18%;
  background: radial-gradient(circle at 30% 25%, #555, #161616 60%);
  color: #e8e8e8;
  font-size: clamp(16px, 3vw, 26px);
  box-shadow: 0 2px 4px #0008;
}

/* palace X overlay via extra lines */
.grid-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, #5a3a1888 1px, transparent 1px) 0 0 / calc(100% / 9) 100%,
    linear-gradient(to bottom, #5a3a1888 1px, transparent 1px) 0 0 / 100% calc(100% / 10);
}

.river-label {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.6em;
  color: #5a4020aa;
  font-size: clamp(11px, 2vw, 15px);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1a120ccc;
  border: 1px solid var(--gold-dim);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 20;
}
.toast.show { opacity: 1; }

.modal {
  position: fixed; inset: 0;
  background: #0008;
  display: none;
  place-items: center;
  z-index: 30;
}
.modal.show { display: grid; }
.modal .box {
  background: #2a1e14;
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 20px;
  width: min(360px, 92vw);
  text-align: center;
}
.modal h4 { color: var(--gold); margin-bottom: 14px; letter-spacing: 0.12em; }
.promo-row { display: flex; gap: 8px; justify-content: center; }
.promo-row button {
  width: 64px; height: 64px;
  font-size: 28px;
  background: #161616;
  color: #eee;
  border: 1px solid #666;
  border-radius: 10px;
  cursor: pointer;
}

.hidden { display: none !important; }
