/* 国际象棋棋盘：仅作用于 chess-* 命名空间。 */

.chess-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 680px;
  min-width: 0;
}

.chess-board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid #b6a98f;
  border-radius: 10px;
  background: #d9cbb5;
  box-shadow:
    0 14px 34px rgba(54, 42, 26, 0.18),
    inset 0 0 0 5px rgba(255, 252, 244, 0.26);
  transition: box-shadow 180ms ease;
}

.chess-board-frame--check {
  box-shadow:
    0 0 0 3px rgba(155, 62, 52, 0.62),
    0 14px 34px rgba(54, 42, 26, 0.18),
    inset 0 0 0 5px rgba(255, 252, 244, 0.26);
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.chess-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  line-height: 1;
  touch-action: manipulation;
  user-select: none;
}

.chess-square:disabled {
  cursor: not-allowed;
  opacity: 1;
}

.chess-square--light {
  background: #eee4d2;
}

.chess-square--dark {
  background: #7c8d77;
}

.chess-square::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  content: "";
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.chess-square--last::before {
  background: rgba(225, 184, 91, 0.3);
  opacity: 1;
}

.chess-square--selected::before {
  background: rgba(37, 109, 86, 0.34);
  opacity: 1;
}

.chess-square--selected {
  box-shadow: inset 0 0 0 3px rgba(23, 79, 65, 0.86);
}

.chess-square--check {
  box-shadow: inset 0 0 0 3px rgba(161, 54, 43, 0.9);
}

.chess-square--check::before {
  background: radial-gradient(
    circle at 50% 50%,
    rgba(198, 61, 45, 0.42),
    rgba(198, 61, 45, 0.05) 68%
  );
  opacity: 1;
}

.chess-square:hover:not(:disabled) {
  filter: brightness(1.045);
}

.chess-square:focus-visible {
  z-index: 4;
  outline: 2px solid #193f35;
  outline-offset: -3px;
}

.chess-piece {
  --piece-fill: #fffaf0;
  --piece-stroke: #2b261f;
  --piece-detail: #2b261f;
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 88%;
  aspect-ratio: 1 / 1;
  pointer-events: none;
  transform: translateY(-1%);
}

.chess-piece--white {
  --piece-fill: #fffaf0;
  --piece-stroke: #2b261f;
  --piece-detail: #2b261f;
}

.chess-piece--black {
  --piece-fill: #1b1a17;
  --piece-stroke: #f2eadb;
  --piece-detail: #f2eadb;
}

.chess-piece__svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: var(--piece-fill);
  stroke: var(--piece-stroke);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chess-piece--black .chess-piece__svg {
  stroke-width: 3;
}

.chess-piece__detail {
  fill: var(--piece-detail);
  stroke: none;
}

.chess-coord {
  position: absolute;
  z-index: 3;
  font-family: var(--mono, monospace);
  font-size: clamp(6px, 1.45vmin, 10px);
  font-weight: 650;
  line-height: 1;
  pointer-events: none;
  opacity: 0.65;
}

.chess-square--light .chess-coord {
  color: #5e584a;
}

.chess-square--dark .chess-coord {
  color: rgba(255, 252, 244, 0.82);
}

.chess-coord--rank {
  top: 4px;
  left: 4px;
}

.chess-coord--file {
  right: 4px;
  bottom: 4px;
}

.chess-target {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: rgba(20, 55, 43, 0.58);
  box-shadow: 0 0 0 2px rgba(255, 252, 244, 0.42);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.chess-square--dark .chess-target {
  background: rgba(255, 252, 244, 0.58);
  box-shadow: 0 0 0 2px rgba(20, 55, 43, 0.28);
}

.chess-target--capture {
  top: 6%;
  left: 6%;
  width: 88%;
  height: 88%;
  border: 3px solid rgba(24, 65, 51, 0.62);
  background: transparent;
  box-shadow: none;
  transform: none;
}

.chess-square--dark .chess-target--capture {
  border-color: rgba(255, 250, 240, 0.78);
}

.chess-check-indicator {
  position: absolute;
  z-index: 6;
  top: 6px;
  left: 50%;
  min-width: 42px;
  padding: 4px 9px;
  border: 1px solid rgba(255, 244, 236, 0.42);
  border-radius: 999px;
  color: #fff8f1;
  background: rgba(139, 44, 35, 0.9);
  box-shadow: 0 4px 12px rgba(63, 25, 20, 0.24);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  pointer-events: none;
  transform: translateX(-50%);
}

.chess-promotion-backdrop {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(27, 32, 25, 0.55);
  backdrop-filter: blur(3px);
}

.chess-promotion {
  width: min(100%, 330px);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 14px;
  background: var(--paper, #f7f3ea);
  box-shadow: 0 22px 55px rgba(26, 24, 19, 0.3);
  text-align: center;
}

.chess-promotion__eyebrow {
  color: var(--accent, #246b57);
  font-family: var(--mono, monospace);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.4;
}

.chess-promotion h3 {
  margin-top: 4px;
  color: var(--ink, #202720);
  font-family: var(--serif, Georgia, serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.chess-promotion__options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 13px;
}

.chess-promotion__option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 60px;
  padding: 6px 2px;
  border: 1px solid rgba(44, 48, 40, 0.16);
  border-radius: 8px;
  color: var(--ink, #202720);
  background: rgba(255, 255, 255, 0.48);
  font-size: 10px;
  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.chess-promotion__option .chess-piece {
  --piece-fill: #2c2a24;
  --piece-stroke: transparent;
  --piece-detail: #f6efe2;
  width: 34px;
  transform: none;
}

.chess-promotion__option:hover {
  border-color: var(--accent, #246b57);
  background: rgba(36, 107, 87, 0.1);
  transform: translateY(-1px);
}

.chess-promotion__option:focus-visible {
  outline: 2px solid var(--accent, #246b57);
  outline-offset: 2px;
}

.chess-promotion__cancel {
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px solid rgba(44, 48, 40, 0.16);
  border-radius: 999px;
  color: var(--muted, #706f66);
  background: transparent;
  font-size: 10px;
  line-height: 1.3;
}

.chess-promotion__cancel:hover {
  color: var(--ink, #202720);
  background: rgba(255, 255, 255, 0.6);
}

.chess-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .chess-coord--rank {
    top: 2px;
    left: 2px;
  }

  .chess-coord--file {
    right: 2px;
    bottom: 2px;
  }

  .chess-target--capture {
    top: 4%;
    left: 4%;
    width: 92%;
    height: 92%;
    border-width: 2px;
  }

  .chess-check-indicator {
    top: 4px;
    min-width: 36px;
    padding: 3px 7px;
    font-size: 9px;
  }

  .chess-promotion {
    padding: 14px;
  }

  .chess-promotion h3 {
    font-size: 18px;
  }

  .chess-promotion__options {
    gap: 5px;
  }

  .chess-promotion__option {
    min-height: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chess-square::before,
  .chess-board-frame,
  .chess-promotion__option {
    transition: none;
  }
}
