/* The 14 piece characters, subset from Noto Sans CJK (SIL Open Font License 1.1, see
   FONT-LICENSE.txt). Embedded so the pieces read the same on a device with no CJK font. */
@font-face {
  font-family: "BP Xiangqi";
  src: url("xiangqi-pieces.woff2") format("woff2");
  font-display: block;
  unicode-range: U+4E00-9FFF;
}

/* Xiangqi, a warm boxwood board with inked lines; red and black discs. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1ece1;
  --card: #fffcf5;
  --ink: #241f1a;
  --muted: #766d60;
  --line: #ded5c3;
  --board: #efd9ab;
  --board2: #e6ca94;
  --grid: #6b4f2a;
  --frame: #4a331d;
  --red: #b3322c;
  --red-dark: #7e1f16;
  --black: #22262c;
  --black-dark: #0c0e11;
  --disc: #fdf5e3;
  --hl: rgba(246, 203, 92, .5);
  --sel: rgba(246, 203, 92, .9);
  --dot: rgba(40, 30, 16, .34);
  --check: #e5533d;
  --gold: #e3a72f;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e3a72f;
  --tut-accent-ink: #241f1a;
  --tut-bubble: #fffcf5;
  --tut-ink: #241f1a;
  --tut-muted: #766d60;
  --tut-dim: rgba(28, 22, 14, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(36, 31, 26, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .pt:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px; padding-bottom: 14px;
}
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.turn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.check { box-shadow: 0 0 0 1.5px rgba(229, 83, 61, .55); }
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.net { color: var(--muted); }
.net .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 6px; }
.net .dot.on { background: #4f8f5a; }
.toast {
  justify-self: center; min-height: 24px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }

.side-icon { display: inline-block; flex: none; width: 18px; height: 18px; border-radius: 50%; }
.side-icon.s0 { background: var(--red); box-shadow: inset 0 0 0 1.5px var(--red-dark); }
.side-icon.s1 { background: var(--black); box-shadow: inset 0 0 0 1.5px var(--black-dark); }
.side-icon.none { background: var(--line); }

/* ---------- board ----------
   The pieces stand on the intersections, so the grid area is inset half a cell all round: the
   whole board is 9 × 10 cells and the lines span 8 × 9 of them. Everything is positioned in
   percentages of the board, so it scales with the screen. */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board-frame {
  width: min(100%, calc((100vh - 210px) * 0.9), 560px);
  padding: 2.4%;
  background: linear-gradient(160deg, #6a4a29, var(--frame));
  border-radius: 14px;
  box-shadow: 0 7px 0 #2e2011, 0 18px 34px rgba(36, 31, 26, .22);
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board-frame { width: min(100cqw, calc((100cqh - 12px) * 0.9), 560px); }
}
.board {
  position: relative; width: 100%; aspect-ratio: 9 / 10; border-radius: 4px; overflow: hidden;
  background: linear-gradient(175deg, var(--board), var(--board2));
}
.board .lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.points, .pieces { position: absolute; inset: 0; }
.pieces { pointer-events: none; }

/* A tap target on every intersection: 1 cell across, centred on the point. */
.pt {
  position: absolute; width: 11.111%; height: 10%;
  transform: translate(-50%, -50%);
  border: 0; padding: 0; margin: 0; background: transparent; cursor: default;
  display: grid; place-items: center; border-radius: 50%;
}
.pt.mine, .pt.dot, .pt.cap { cursor: pointer; }
.pt.dot::before { content: ''; width: 34%; height: 34%; border-radius: 50%; background: var(--dot); transition: transform .15s; }
.pt.cap::before {
  content: ''; position: absolute; width: 86%; height: 86%; border-radius: 50%;
  box-shadow: 0 0 0 3px var(--dot) inset;
}
@media (hover: hover) { .pt.dot:hover::before { transform: scale(1.3); } }
.pt.dot:active::before { transform: scale(1.45); }
.pt.last::after {
  content: ''; position: absolute; width: 88%; height: 88%; border-radius: 50%; background: var(--hl); z-index: -1;
}
.pt.sel::after { content: ''; position: absolute; width: 92%; height: 92%; border-radius: 50%; background: var(--sel); z-index: -1; }
.pt.check::after {
  content: ''; position: absolute; width: 110%; height: 110%; border-radius: 50%;
  background: radial-gradient(circle, rgba(229, 83, 61, .9) 0, rgba(229, 83, 61, .5) 45%, rgba(229, 83, 61, 0) 72%);
  z-index: -1;
}

/* ---------- pieces ---------- */
.pc {
  position: absolute; width: 10.2%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid; place-items: center; z-index: 1;
  /* Its own container, so the character below scales to the disc and not to the whole board. */
  container-type: inline-size;
  transition: left .22s cubic-bezier(.3, .1, .3, 1), top .22s cubic-bezier(.3, .1, .3, 1), opacity .2s;
}
.pc .disc {
  position: relative; width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #fffdf6, var(--disc) 62%, #e8dcc0);
  box-shadow: 0 1.5px 2px rgba(36, 31, 26, .35), inset 0 0 0 1.5px rgba(107, 79, 42, .5);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
}
/* Two marks, stacked: the Chinese character names the piece wherever a CJK font exists, and the
   Latin initial under it is always drawn, so the pieces stay tellable apart on a device with no
   Chinese font at all, where the character would otherwise come out as an empty box. */
.pc .ch {
  font-size: 34cqw; font-weight: 700; line-height: .95;
  font-family: "BP Xiangqi", "Noto Sans CJK SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Heiti SC", system-ui, sans-serif;
}
.pc .mark {
  font-size: 36cqw; font-weight: 800; line-height: .95; letter-spacing: .02em;
}
/* No Chinese font on this device: drop the character (it would be an empty box) and let the
   initial stand alone, larger. render.js sets the class after measuring. */
.pc.r .disc { box-shadow: 0 1.5px 2px rgba(36, 31, 26, .35), inset 0 0 0 2px var(--red); }
.pc.r .ch, .pc.r .mark { color: var(--red); }
.pc.b .disc { box-shadow: 0 1.5px 2px rgba(36, 31, 26, .35), inset 0 0 0 2px var(--black); }
.pc.b .ch, .pc.b .mark { color: var(--black); }
.pc.lift { z-index: 2; }
.pc.gone { opacity: 0; transform: translate(-50%, -50%) scale(.55); }

.pc.pop { animation: pop .35s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(.7); } 60% { transform: translate(-50%, -50%) scale(1.1); } 100% { transform: translate(-50%, -50%) scale(1); } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(36, 31, 26, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 236, 225, .5); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(36, 31, 26, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(36, 31, 26, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.over-mark .disc-mark {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 34% 28%, #fffdf6, var(--disc) 62%, #e8dcc0);
  font-size: 34px; font-weight: 700;
}
.over-mark .disc-mark.r { color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }
.over-mark .disc-mark.b { color: var(--black); box-shadow: inset 0 0 0 2px var(--black); }
.over-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 20px; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }
.pieces-table { width: 100%; border-collapse: collapse; margin: 6px 0 2px; }
.pieces-table td { padding: 5px 4px; border-bottom: 1px solid var(--line); font-size: 14.5px; vertical-align: middle; }
.pieces-table .gl { width: 3.2em; font-size: 20px; font-weight: 700; white-space: nowrap; }
.pieces-table .gl .r { color: var(--red); }
.pieces-table .gl .b { color: var(--black); }
.pieces-table .lt { width: 1.8em; font-weight: 700; color: var(--muted); }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* Online play (online.js): no New game while a friend is playing. */
body.is-online #btn-new { display: none; }
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online ~ #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }

/* The owner asked for the piece characters alone, no Roman letters (2026-09-12). The initial stays
   in the piece's aria-label, so a screen reader still names it. */
.pc .mark { display: none; }
.pc .ch { font-size: 58cqw; }
