:root {
  color-scheme: light;
  --bg: #f3eadc;
  --ink: #20242b;
  --muted: #71665b;
  --line: #d5bd95;
  --panel: #fff8ec;
  --panel-strong: #fff0d8;
  --board: #dc9e4b;
  --board-dark: #7a431c;
  --red: #bf202f;
  --black: #26292f;
  --accent: #087b74;
  --accent-dark: #07554f;
  --shadow: 0 18px 45px rgba(61, 40, 18, 0.17);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 250, 241, 0.76), rgba(245, 241, 232, 0.98)),
    radial-gradient(circle at 20% 20%, rgba(12, 108, 115, 0.12), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid rgba(32, 36, 43, 0.15);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(12, 108, 115, 0.4);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 0.94rem;
  letter-spacing: 0;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.board-area,
.control-panel {
  border: 1px solid rgba(72, 46, 18, 0.16);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.78);
  box-shadow: var(--shadow);
}

.board-area {
  padding: clamp(12px, 2vw, 22px);
}

.board-frame {
  display: grid;
  place-items: center;
}

.board {
  position: relative;
  width: min(100%, 680px);
  aspect-ratio: 9 / 10;
  --piece-size: 54px;
  --hit-size: 66px;
  --piece-font: 27px;
  --line-size: 2px;
  --hint-size: 12px;
  border: 6px solid var(--board-dark);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(100, 50, 12, 0.08) 0 1px, transparent 1px 9px),
    linear-gradient(0deg, rgba(255, 242, 204, 0.18), rgba(111, 55, 16, 0.08)),
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 28%),
    var(--board);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  box-shadow:
    inset 0 0 0 4px rgba(255, 230, 168, 0.42),
    inset 0 0 24px rgba(79, 39, 10, 0.23),
    0 10px 20px rgba(72, 44, 14, 0.18);
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 13%, rgba(255, 255, 255, 0.08) 14%, transparent 15%),
    linear-gradient(0deg, rgba(114, 61, 19, 0.06), transparent 38%, rgba(255, 242, 211, 0.07));
  pointer-events: none;
  z-index: 0;
}

.river {
  position: absolute;
  left: 7.5%;
  right: 7.5%;
  top: calc(6% + 4 * (88% / 9));
  height: calc(88% / 9);
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: rgba(80, 42, 10, 0.42);
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(1.4rem, 4vw, 2.8rem);
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
}

.board-line {
  position: absolute;
  background: rgba(92, 48, 16, 0.76);
  pointer-events: none;
  z-index: 1;
}

.board-line.h {
  left: 6%;
  width: 88%;
  height: var(--line-size);
}

.board-line.v {
  top: 6%;
  width: var(--line-size);
}

.board-line.diag {
  height: var(--line-size);
  transform-origin: left center;
}

.point {
  position: absolute;
  display: grid;
  place-items: center;
  width: var(--hit-size);
  height: var(--hit-size);
  min-height: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  transform: translate(-50%, -50%);
  transform-origin: center;
  padding: 0;
  z-index: 3;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.point:hover:not(:disabled) {
  border-color: transparent;
  transform: translate(-50%, -50%);
}

.point::before {
  content: "";
  position: absolute;
  width: calc(var(--piece-size) + 9px);
  height: calc(var(--piece-size) + 9px);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 110ms ease;
}

.point::after {
  content: "";
  position: absolute;
  width: var(--hint-size);
  height: var(--hint-size);
  border-radius: 999px;
  background: transparent;
  pointer-events: none;
  transition:
    transform 110ms ease,
    opacity 110ms ease,
    background 110ms ease;
}

.point.hint::after {
  background: rgba(8, 123, 116, 0.88);
  box-shadow: 0 0 0 7px rgba(8, 123, 116, 0.14);
}

.point.capture-hint::after {
  width: calc(var(--piece-size) + 7px);
  height: calc(var(--piece-size) + 7px);
  border: 3px solid rgba(8, 123, 116, 0.65);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.piece {
  position: relative;
  z-index: 4;
  display: grid;
  place-items: center;
  width: var(--piece-size);
  height: var(--piece-size);
  border: 2px solid currentColor;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.98), rgba(255, 242, 213, 0.92) 43%, rgba(229, 201, 153, 0.96)),
    #f5dcaa;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.42),
    inset 0 -5px 10px rgba(128, 80, 28, 0.12),
    0 5px 10px rgba(40, 24, 8, 0.26);
  font-family: "Songti SC", "STSong", "PingFang SC", serif;
  font-size: var(--piece-font);
  font-weight: 900;
  line-height: 1;
  transform: translateZ(0);
  transition:
    transform 110ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
}

.piece.red {
  color: var(--red);
}

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

.point.selected .piece {
  filter: saturate(1.08);
}

.point.selected::before {
  opacity: 1;
  border: 3px solid rgba(8, 123, 116, 0.88);
  box-shadow:
    0 0 0 4px rgba(255, 247, 219, 0.72),
    0 0 0 8px rgba(8, 123, 116, 0.18);
}

.point.last-from .piece,
.point.last-to .piece {
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.5),
    inset 0 -5px 10px rgba(128, 80, 28, 0.12),
    0 0 0 5px rgba(250, 196, 76, 0.48),
    0 5px 10px rgba(39, 24, 9, 0.22);
}

.point.pressed .piece {
  transform: scale(0.93);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.4),
    inset 0 4px 10px rgba(91, 48, 12, 0.18),
    0 2px 6px rgba(39, 24, 9, 0.24);
}

.under-board {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-top: 14px;
  color: var(--muted);
}

.under-board strong {
  color: var(--ink);
}

.label {
  margin-right: 7px;
  font-size: 0.82rem;
}

.control-panel {
  padding: 16px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid rgba(32, 36, 43, 0.1);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.segmented,
.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.segmented.two {
  grid-template-columns: repeat(2, 1fr);
}

.policy-label {
  margin-top: 14px;
  margin-bottom: 8px;
}

.wide-toggle {
  width: 100%;
  margin-top: 10px;
  background: var(--panel-strong);
  border-color: rgba(122, 67, 28, 0.22);
  color: var(--board-dark);
  font-weight: 800;
}

.wide-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.actions {
  grid-template-columns: repeat(2, 1fr);
}

.actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

label,
output {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="number"] {
  width: 86px;
  min-height: 36px;
  border: 1px solid rgba(32, 36, 43, 0.16);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
}

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid rgba(32, 36, 43, 0.16);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  line-height: 1.4;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.engine-output {
  min-height: 98px;
  margin-top: 10px;
  border-radius: 8px;
  background: #20242b;
  color: #f8ead0;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.moves-section {
  max-height: 190px;
  overflow: auto;
}

#move-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.88rem;
}

#move-list .move-entry {
  display: grid;
  grid-template-columns: 2.4em minmax(5.4em, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 26px;
}

.move-index {
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.move-notation {
  color: var(--ink);
  font-weight: 750;
}

.move-side,
.move-source {
  font-size: 0.78rem;
  font-weight: 800;
}

.move-side.red {
  color: var(--red);
}

.move-side.black {
  color: var(--black);
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding: 16px 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar > div:first-child {
    width: 100%;
    min-width: 0;
  }

  h1 {
    white-space: nowrap;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 2;
  }

  .board-area,
  .control-panel {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .board-area {
    padding: 8px;
  }

  .under-board {
    flex-direction: column;
    gap: 6px;
  }
}
