:root {
  --bg: #f6efe2;
  --panel: rgba(255, 252, 245, 0.85);
  --line: #7f4f24;
  --line-soft: rgba(127, 79, 36, 0.35);
  --ink: #2f2a24;
  --muted: #6f665d;
  --red: #b42318;
  --black: #1f2937;
  --gold: #d4a017;
  --accent: #1f6f64;
  --shadow: 0 14px 28px rgba(58, 36, 14, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: 'Noto Serif SC', 'Kaiti SC', 'STKaiti', serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(212, 160, 23, 0.14), transparent 35%),
    radial-gradient(circle at 90% 18%, rgba(31, 111, 100, 0.14), transparent 40%),
    linear-gradient(180deg, #f8f3e8, #efe3c8 60%, #e4d2aa);
}

.xiangqi-page {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 360px);
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(127, 79, 36, 0.18);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.panel-main {
  padding: 16px;
}

.panel-side {
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 12px;
}

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

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

h2 {
  margin: 0 0 10px;
  font-size: 1.02rem;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.back-link:hover {
  text-decoration: underline;
}

.board-wrap {
  position: relative;
  padding: 10px;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 248, 231, 0.96), rgba(242, 221, 178, 0.92));
  border: 1px solid rgba(127, 79, 36, 0.18);
}

.board-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0 4px;
}

.top-meta {
  margin-bottom: 8px;
}

.bottom-meta {
  margin-top: 8px;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, minmax(34px, 1fr));
  grid-template-rows: repeat(10, minmax(34px, 1fr));
  aspect-ratio: 9 / 10;
  gap: 0;
  background:
    linear-gradient(var(--line-soft), var(--line-soft)) 0 calc(50% - 1px) / 100% 2px no-repeat,
    linear-gradient(90deg, rgba(127, 79, 36, 0.07), rgba(127, 79, 36, 0.02));
  border: 2px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.cell {
  position: relative;
  border: 1px solid rgba(127, 79, 36, 0.45);
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.cell:disabled {
  cursor: default;
}

.cell::before,
.cell::after {
  content: '';
  position: absolute;
  background: rgba(127, 79, 36, 0.55);
  pointer-events: none;
}

.cell::before {
  width: 1px;
  height: 100%;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.cell::after {
  width: 100%;
  height: 1px;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.cell.is-selected {
  background: rgba(31, 111, 100, 0.14);
}

.cell.is-target::after {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: rgba(31, 111, 100, 0.85);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.is-capture::after {
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  border-radius: 10px;
  background: transparent;
  border: 2px solid rgba(212, 160, 23, 0.95);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cell.is-disabled {
  cursor: not-allowed;
}

.piece {
  position: relative;
  width: 74%;
  height: 74%;
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(127, 79, 36, 0.8);
  background:
    radial-gradient(circle at 30% 25%, #fffdf8, #f4e7ca 58%, #ecd4a4 100%);
  display: grid;
  place-items: center;
  font-size: clamp(0.95rem, 2vw, 1.25rem);
  line-height: 1;
  font-weight: 700;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 2px 6px rgba(58, 36, 14, 0.15);
}

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

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

.piece::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 999px;
  border: 1px solid rgba(127, 79, 36, 0.25);
}

.river-label {
  position: absolute;
  inset: auto 18px 50% 18px;
  transform: translateY(50%);
  display: flex;
  justify-content: space-between;
  padding: 0 14px;
  pointer-events: none;
  color: rgba(127, 79, 36, 0.6);
  font-weight: 700;
  letter-spacing: 0.3em;
  font-size: clamp(0.75rem, 1.8vw, 1rem);
}

.card {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(127, 79, 36, 0.12);
  border-radius: 16px;
  padding: 12px;
}

.card label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.card select,
.actions button {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(127, 79, 36, 0.2);
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.85);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(127, 79, 36, 0.14);
  font-size: 0.93rem;
}

.status-line:last-child {
  border-bottom: 0;
}

.status-line span {
  color: var(--muted);
}

.status-line strong {
  text-align: right;
}

.actions {
  display: grid;
  gap: 8px;
}

.actions button {
  cursor: pointer;
  font-weight: 700;
}

.actions button:hover {
  border-color: rgba(31, 111, 100, 0.45);
}

.actions button:disabled,
.card select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tips p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.tips p:last-child {
  margin-bottom: 0;
}

@media (max-width: 980px) {
  .xiangqi-page {
    grid-template-columns: 1fr;
  }

  .panel-side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .status-card,
  .tips {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .xiangqi-page {
    padding: 10px;
    gap: 12px;
  }

  .panel-main,
  .panel-side {
    padding: 10px;
  }

  .heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-side {
    grid-template-columns: 1fr;
  }

  .status-card,
  .tips {
    grid-column: auto;
  }

  .river-label {
    letter-spacing: 0.12em;
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
    transition: none !important;
    animation: none !important;
  }
}
