:root {
  --bg-start: #f6ebd7;
  --bg-end: #e7d0a3;
  --card: rgba(255, 248, 235, 0.88);
  --ink: #493425;
  --muted: #856852;
  --accent: #8f3b2e;
  --accent-strong: #6f261b;
  --board: #e9c891;
  --grid: rgba(79, 54, 30, 0.62);
  --selected: #f2a65a;
  --legal: rgba(78, 144, 112, 0.24);
  --danger: rgba(160, 45, 45, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.5), transparent 36%),
    linear-gradient(180deg, var(--bg-start), var(--bg-end));
}

.app {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 10px 10px 14px;
}

.board-card,
.side-panel {
  background: var(--card);
  border: 1px solid rgba(116, 82, 55, 0.15);
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(101, 67, 37, 0.12);
}

.game-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
  align-items: start;
  min-height: calc(100vh - 24px);
}

.board-card {
  display: grid;
  justify-items: center;
  padding: 12px 8px 12px;
}

.board-legend {
  display: flex;
  justify-content: space-between;
  margin: 0 6px 8px;
  color: var(--muted);
  font-size: 16px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
}

.side-panel {
  display: grid;
  gap: 10px;
  justify-items: stretch;
  padding: 14px 10px;
}

.side-button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
  color: #fffaf2;
  background: linear-gradient(180deg, #b85f40, var(--accent));
}

.side-control {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
  font-size: 16px;
  text-align: center;
}

.side-title {
  font-size: 18px;
  font-weight: 700;
}

.vertical-range {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 220px;
  accent-color: var(--accent);
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(113, 81, 52, 0.45);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(241, 214, 161, 0.8), rgba(228, 192, 132, 0.88));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.cell.river {
  background: linear-gradient(180deg, rgba(203, 226, 232, 0.95), rgba(171, 206, 216, 0.95));
}

.cell.selected {
  outline: 4px solid #e29c38;
  outline-offset: 1px;
}

.cell.legal {
  background: linear-gradient(180deg, rgba(207, 236, 224, 0.98), rgba(187, 223, 210, 0.98));
}

.cell.capture {
  background: linear-gradient(180deg, rgba(244, 214, 214, 0.96), rgba(232, 185, 185, 0.96));
}

.piece {
  width: 94%;
  height: 94%;
  border-radius: 999px;
  border: 3px solid #764d2f;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.18) 28%, transparent 30%),
    radial-gradient(circle at 50% 48%, #fff8ea, #f3dec0 64%, #d8b787 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(26px, 6.8vw, 42px);
  font-weight: 800;
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.72),
    inset 0 -2px 3px rgba(117, 74, 40, 0.22);
}

.piece.red {
  color: #a62d28;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.piece.black {
  color: #28231f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.36);
}

.piece.empty {
  display: none;
}

@media (max-width: 760px) {
  .app {
    width: min(100%, 760px);
    padding: 8px 8px 10px;
  }

  .game-screen {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 8px;
  }

  .side-panel {
    grid-template-columns: 1.05fr 1.95fr;
    align-items: stretch;
    gap: 8px;
    padding: 4px 2px 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .side-control {
    min-height: auto;
  }

  .vertical-range {
    writing-mode: horizontal-tb;
    direction: ltr;
    width: 100%;
    height: auto;
  }
}

@media (max-width: 520px) {
  body {
    overflow-x: hidden;
  }

  .app {
    padding: 6px 6px 8px;
  }

  .game-screen {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: auto;
  }

  .board-legend,
  .side-control,
  .side-button {
    font-size: 14px;
  }

  .board-card {
    padding: 8px 6px 10px;
    border-radius: 18px;
  }

  .board {
    gap: 4px;
    width: 100%;
  }

  .piece {
    width: 92%;
    height: 92%;
    border-width: 2px;
    font-size: clamp(30px, 9.4vw, 46px);
  }

  .cell {
    border-radius: 8px;
  }

  .board-legend {
    width: 100%;
    margin: 0 2px 8px;
    font-size: 15px;
  }

  .side-panel {
    grid-template-columns: 0.95fr 1.85fr;
    gap: 6px;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }

  .side-panel > * {
    min-width: 0;
  }

  .side-button {
    min-height: 44px;
    padding: 6px 10px;
    border-radius: 12px;
    line-height: 1.1;
  }

  .side-control {
    gap: 4px;
    padding: 8px 10px;
    border-radius: 12px;
  }

  .side-title {
    font-size: 14px;
  }

  .vertical-range {
    width: 100%;
    height: auto;
  }

  #difficultyLabel {
    font-size: 11px;
    line-height: 1.1;
  }
}
