/*
 * 中国象棋棋盘样式。
 * 所有选择器与动画均使用 cc- 前缀；不依赖 src/styles/global.css 的类名或变量。
 * 只负责组件内部呈现，不修改全局元素（body / button / * 等）。
 */

.cc-board,
.cc-board *,
.cc-board *::before,
.cc-board *::after {
  box-sizing: border-box;
}

.cc-board {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 9 / 10;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(93, 68, 37, 0.28);
  border-radius: 16px;
  background-color: #ead9b9;
  background-image:
    radial-gradient(
      circle at 32% 20%,
      rgba(255, 255, 255, 0.42),
      transparent 48%
    ),
    repeating-linear-gradient(
      116deg,
      rgba(108, 77, 38, 0.035) 0,
      rgba(108, 77, 38, 0.035) 2px,
      transparent 2px,
      transparent 7px
    ),
    linear-gradient(135deg, #f2e6cd 0%, #e9d8b7 48%, #dec9a3 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.34),
    inset 0 0 70px rgba(103, 75, 34, 0.14),
    0 14px 34px rgba(57, 43, 22, 0.18);
  container-type: inline-size;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cc-board__surface {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cc-board__frame-outer {
  fill: none;
  stroke: #67502f;
  stroke-width: 6;
  opacity: 0.85;
}

.cc-board__frame-inner {
  fill: none;
  stroke: #8b6a3f;
  stroke-width: 2.5;
  opacity: 0.75;
}

.cc-board__river {
  fill: rgba(70, 116, 102, 0.09);
}

.cc-board__grid {
  stroke: #70502b;
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0.8;
}

.cc-board__palace {
  stroke: #7f5c32;
  stroke-width: 2.8;
  stroke-linecap: round;
  opacity: 0.78;
}

.cc-board__river-text {
  fill: #88643a;
  font-family:
    "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", serif;
  font-size: 38px;
  font-weight: 600;
  letter-spacing: 16px;
  opacity: 0.76;
}

/* -------------------------------------------------------------------------- */
/* 交叉点与棋子                                                                */
/* -------------------------------------------------------------------------- */

.cc-point {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 9.8%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: transparent;
  font: inherit;
  line-height: 1;
  transform: translate(-50%, -50%);
  cursor: default;
  opacity: 1;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
}

.cc-point:disabled {
  cursor: default;
  opacity: 1;
}

.cc-point[data-can-move="true"] {
  cursor: pointer;
}

.cc-point:focus-visible {
  z-index: 6;
  outline: 3px solid #1f6f5a;
  outline-offset: -4px;
}

.cc-point--last::before {
  position: absolute;
  inset: -3%;
  border: 2px solid rgba(173, 119, 34, 0.58);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.cc-piece {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid #ad8c5d;
  border-radius: 50%;
  background: radial-gradient(
    circle at 34% 27%,
    #fffdf7 0%,
    #f8efdc 36%,
    #e8d6b2 76%,
    #d5be93 100%
  );
  box-shadow:
    0 2px 4px rgba(55, 38, 15, 0.34),
    inset 0 0 0 3px rgba(255, 255, 255, 0.52),
    inset 0 -3px 5px rgba(119, 88, 43, 0.16);
  font-family:
    "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", serif;
  font-size: 18px;
  font-size: 5.3cqw;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  pointer-events: none;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

@supports not (font-size: 1cqw) {
  .cc-piece {
    font-size: 18px;
  }
}

.cc-piece::after {
  position: absolute;
  inset: 8%;
  border: 1px solid currentColor;
  border-radius: 50%;
  content: "";
  opacity: 0.28;
  pointer-events: none;
}

.cc-piece--red {
  border-color: #b4775e;
  color: #a52a22;
  background: radial-gradient(
    circle at 34% 27%,
    #fffaf2 0%,
    #faeedb 36%,
    #eed9b6 76%,
    #ddc39a 100%
  );
}

.cc-piece--black {
  border-color: #8d7a5d;
  color: #25231f;
}

.cc-point[data-can-move="true"]:hover .cc-piece {
  transform: translateY(-1px);
}

.cc-point--selected {
  z-index: 4;
}

.cc-point--selected .cc-piece {
  transform: translateY(-2%) scale(1.08);
  box-shadow:
    0 0 0 3px rgba(198, 148, 38, 0.88),
    0 8px 14px rgba(70, 48, 15, 0.32),
    inset 0 0 0 3px rgba(255, 255, 255, 0.55);
}

.cc-target-dot {
  position: absolute;
  z-index: 3;
  width: 28%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: #20705a;
  box-shadow: 0 0 0 3px rgba(32, 112, 90, 0.18);
  pointer-events: none;
}

.cc-target-ring {
  position: absolute;
  z-index: 3;
  inset: 0;
  border: 3px solid rgba(32, 112, 90, 0.84);
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.36),
    0 0 0 1px rgba(32, 112, 90, 0.2);
  pointer-events: none;
}

.cc-piece--check {
  box-shadow:
    0 0 0 3px rgba(155, 51, 44, 0.86),
    0 0 18px rgba(183, 50, 39, 0.62),
    inset 0 0 0 3px rgba(255, 255, 255, 0.5);
  animation: cc-check-pulse 1.5s ease-in-out infinite;
}

@keyframes cc-check-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 3px rgba(155, 51, 44, 0.86),
      0 0 12px rgba(183, 50, 39, 0.48),
      inset 0 0 0 3px rgba(255, 255, 255, 0.5);
  }

  50% {
    box-shadow:
      0 0 0 4px rgba(155, 51, 44, 0.94),
      0 0 24px rgba(183, 50, 39, 0.76),
      inset 0 0 0 3px rgba(255, 255, 255, 0.58);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cc-piece {
    transition: none;
  }

  .cc-piece--check {
    animation: none;
  }
}

/*
 * 390px 窄视口：共享层 board-slot 有 18px 内边距，且 board-surface 为
 * 1 / 1.08 的比例。组件自身再收 4% 宽度，避免竖向被裁切，同时确保
 * scrollWidth === clientWidth（无任何负 margin / 固定大宽度）。
 */
@media (max-width: 480px) {
  .cc-board {
    width: 96%;
    border-radius: 13px;
  }
}
