:root {
  --cho: #28536d;
  --han: #8b4038;
  --piece-face: #f4ecd8;
  --last-player: #36705a;
  --last-ai: #a76520;
  --board-inner-inset: 5%;
  --piece-cell-ratio: .78;
  --piece-size: 78%;
}

/*
 * 보드 선과 기물은 반드시 같은 board-inner 좌표계를 사용한다.
 * board-inner는 가로 8칸, 세로 9칸 비율이고 각 점은 x/8, y/9 위치다.
 */
.janggi-board {
  background-color: #e3c58c;
  background-image:
    linear-gradient(100deg, rgba(255,255,255,.07), transparent 35%, rgba(104,68,22,.02) 72%, transparent),
    repeating-linear-gradient(0deg, rgba(91,59,20,.01) 0 1px, transparent 1px 9px);
  box-shadow: 0 16px 38px rgba(57,38,13,.18), inset 0 0 22px rgba(111,72,19,.08);
}

.board-inner {
  position: absolute;
  z-index: 2;
  inset: var(--board-inner-inset);
  overflow: visible;
}

.board-lines {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.board-lines line {
  stroke: #65471f;
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
}

.palace-lines line { stroke-width: 1.35; }

.board-lines text {
  fill: rgba(73,47,17,.46);
  font-family: "Noto Serif CJK KR", "Noto Serif KR", "Nanum Myeongjo", Batang, serif;
}

/* 한 교차점 간격 전체를 클릭 영역으로 사용하고, SVG 말은 그 안의 78%로 그린다. */
.board-point {
  position: absolute;
  z-index: 4;
  width: 12.5%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

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

/* 모든 실제 장기말은 동일한 SVG 팔각형을 사용한다. */
.piece-svg {
  --piece-color: #6b5533;
  display: block;
  width: var(--piece-size);
  height: var(--piece-size);
  overflow: visible;
  color: var(--piece-color);
  filter: drop-shadow(0 1px 1.5px rgba(57,37,13,.22));
  transform: translateZ(0);
  transition: filter .14s ease, opacity .14s ease;
}

.piece-svg.cho,
.board-point.cho .piece-svg,
.moving-piece.cho .piece-svg,
.captured-piece.cho .piece-svg {
  --piece-color: var(--cho);
}

.piece-svg.han,
.board-point.han .piece-svg,
.moving-piece.han .piece-svg,
.captured-piece.han .piece-svg {
  --piece-color: var(--han);
}

.piece-face {
  fill: var(--piece-face);
  stroke: var(--piece-color);
  stroke-width: 4.8;
  stroke-linejoin: round;
}

.piece-inner-line {
  fill: none;
  stroke: var(--piece-color);
  stroke-width: 1.2;
  stroke-opacity: .3;
  stroke-linejoin: round;
}

.piece-label {
  fill: var(--piece-color);
  font-family: "Noto Serif CJK KR", "Noto Serif KR", "Nanum Myeongjo", "Malgun Gothic", "Apple SD Gothic Neo", Batang, serif;
  font-size: 48px;
  font-weight: 900;
  paint-order: stroke fill;
  stroke: rgba(244,236,216,.38);
  stroke-width: .7px;
}

/* 선택은 SVG 형태를 바꾸지 않고 외곽선과 약한 그림자로만 표현한다. */
.board-point.selected .piece-face {
  stroke-width: 7;
}

.board-point.selected .piece-svg {
  filter:
    drop-shadow(0 0 2px rgba(255,248,216,.98))
    drop-shadow(0 0 4px rgba(154,120,47,.9))
    drop-shadow(0 2px 2px rgba(57,37,13,.2));
}

/* 빈 교차점 이동 가능 표시 */
.board-point.move-target:not(.has-piece)::after {
  content: "";
  position: absolute;
  z-index: 6;
  width: 18%;
  aspect-ratio: 1;
  border: 2px solid rgba(255,255,255,.82);
  border-radius: 50%;
  background: rgba(43,104,73,.8);
  box-shadow: 0 0 0 4px rgba(43,104,73,.16);
}

/* 포획 가능 표시는 교차점 중심의 링으로 표현 */
.board-point.capture-target::after {
  content: "";
  position: absolute;
  z-index: 6;
  width: 86%;
  aspect-ratio: 1;
  border: 3px solid #a94437;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 2px rgba(255,245,224,.7);
}

/* 마지막 수는 말이 아니라 교차점 중심 주변을 강조한다. */
.board-point.last-from::before,
.board-point.last-to::before,
.board-point.ai-animation-destination::before {
  content: "";
  position: absolute;
  z-index: 2;
  width: 88%;
  aspect-ratio: 1;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: rgba(54,112,90,.12);
  pointer-events: none;
}

.board-point.last-from::before { border-style: dashed; }
.board-point.last-to::before { border-width: 3px; }
.board-point.last-player::before { color: var(--last-player); background: rgba(54,112,90,.12); }
.board-point.last-ai::before,
.board-point.ai-animation-destination::before { color: var(--last-ai); background: rgba(167,101,32,.14); }
.board-point.ai-animation-destination::before { animation: destinationPulse .58s ease-in-out infinite alternate; }

.board-point.ai-animation-source .piece-svg { opacity: 0; }
.board-point.ai-capture-destination .piece-svg { animation: capturedPieceFade var(--ai-move-duration, 280ms) ease-in forwards; }

/* 이동 오버레이도 board-inner 좌표계와 동일한 좌표를 사용한다. */
.moving-piece {
  position: absolute;
  z-index: 11;
  width: 9.75%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition-property: left, top;
  transition-duration: var(--ai-move-duration, 280ms);
  transition-timing-function: cubic-bezier(.2,.72,.25,1);
  will-change: left, top;
}

.moving-piece .piece-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 2px rgba(57,37,13,.25));
}

/* 장군은 궁 기물의 팔각형 외곽선과 교차점 링을 함께 경고색으로 표시한다. */
.board-point.check-king::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 91%;
  aspect-ratio: 1;
  border: 3px solid rgba(168,48,38,.78);
  border-radius: 50%;
  animation: checkPulse .9s ease-in-out infinite alternate;
}

.board-point.check-king .piece-face {
  stroke: #a83026;
}

@keyframes checkPulse { to { opacity: .48; transform: scale(1.06); } }
@keyframes destinationPulse { to { opacity: .55; transform: scale(1.04); } }
@keyframes capturedPieceFade { to { opacity: .1; transform: scale(.76); } }

.turn-panel.ai-thinking,
.turn-panel.aiThinking { background: #4d4a42; }
.turn-panel.ai-animating,
.turn-panel.aiAnimating { background: #625033; }
.turn-panel.ai-reviewing,
.turn-panel.aiReviewing { background: #4b5d4f; }
.turn-panel.danger.ai-reviewing,
.turn-panel.danger.aiReviewing { background: #7e2924; }

.recent-ai-move {
  min-height: 58px;
  margin: -4px 0 14px;
  padding: 9px 12px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(116,93,46,.2);
  border-left: 4px solid #8c7350;
  border-radius: 11px;
  background: rgba(255,253,248,.76);
  color: #4e493f;
}

.recent-ai-move.active {
  border-left-color: var(--last-ai);
  background: #fff7e9;
  box-shadow: 0 5px 15px rgba(94,60,16,.08);
}

.recent-ai-badge {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #3b3933;
  color: white;
  font-size: .68rem;
  font-weight: 900;
}

.recent-ai-move div { min-width: 0; }
.recent-ai-move strong,
.recent-ai-move span { display: block; }
.recent-ai-move strong { margin-bottom: 2px; font-size: .78rem; }
.recent-ai-move div span { overflow-wrap: anywhere; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.recent-ai-move em { padding: 5px 7px; border-radius: 999px; background: #f2ddd7; color: #7c3029; font-size: .68rem; font-style: normal; font-weight: 850; white-space: nowrap; }

.board-lock { z-index: 20; background: rgba(244,239,226,.2); backdrop-filter: blur(.6px); }
.spinner { position: relative; width: 48px; height: 48px; background: rgba(255,250,237,.84); box-shadow: 0 5px 14px rgba(48,33,13,.18); }
.spinner::after { content: none; }
.spinner b { animation: counterSpin .8s linear infinite; font-size: .62rem; }
@keyframes counterSpin { to { transform: rotate(-360deg); } }

/* 잡힌 말과 홈 장식 말도 같은 SVG 팔각형을 사용한다. */
.captured-piece {
  width: 30px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0 !important;
  border-radius: 0 !important;
  clip-path: none !important;
  background: transparent !important;
}
.captured-piece .piece-svg { width: 100%; height: 100%; }

.mini-piece {
  border: 0 !important;
  border-radius: 0 !important;
  clip-path: none !important;
  background: transparent !important;
  box-shadow: none !important;
}
.mini-piece .piece-svg { width: 100%; height: 100%; }

@media (max-width: 620px) {
  .recent-ai-move { grid-template-columns: 34px minmax(0,1fr); }
  .recent-ai-move em { grid-column: 2; justify-self: start; }
  .piece-label { font-size: 50px; }
}

@media (max-width: 360px) {
  .game-shell { padding-left: 4px; padding-right: 4px; }
  .recent-ai-move { padding: 8px; gap: 8px; }
  .piece-label { font-size: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .moving-piece { transition-duration: .01ms !important; }
  .board-point.ai-capture-destination .piece-svg { animation-duration: .01ms !important; }
}
