.chess-page {
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 208, 76, 0.18), transparent 24%),
    radial-gradient(circle at 82% 20%, rgba(88, 184, 255, 0.18), transparent 26%),
    linear-gradient(135deg, #101820 0%, #19302b 47%, #241820 100%);
}

.chess-layout {
  grid-template-columns: minmax(240px, 0.72fr) minmax(440px, 1.34fr) minmax(240px, 0.72fr);
}

.chess-side-panel .arcade-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  transition: box-shadow 160ms ease, transform 120ms ease;
}

.chess-side-panel .arcade-button:active {
  transform: translateY(1px) scale(0.99);
}

.chess-sound-toggle {
  overflow: hidden;
  position: relative;
}

.chess-sound-toggle::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.34), transparent);
  content: "";
  height: 100%;
  left: -70%;
  opacity: 0;
  position: absolute;
  top: 0;
  transform: skewX(-18deg);
  transition: left 260ms ease, opacity 160ms ease;
  width: 52%;
}

.chess-sound-toggle.sound-on {
  background: linear-gradient(180deg, #42d66f, #1f9b5a);
  border-color: rgba(255, 255, 255, 0.32);
  box-shadow: 0 10px 24px rgba(66, 214, 111, 0.22);
  color: #09130d;
}

.chess-sound-toggle.sound-on::after {
  left: 116%;
  opacity: 1;
}

.chess-sound-icon {
  font-size: 18px;
  line-height: 1;
}

.chess-difficulty-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chess-difficulty-row .arcade-choice {
  font-size: 13px;
  min-height: 40px;
  padding: 0 8px;
}

.chess-difficulty-row .arcade-choice.active {
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16), 0 8px 18px rgba(66, 214, 111, 0.16);
}

.chess-score-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chess-score-grid .arcade-stat strong {
  font-size: clamp(18px, 2.2vw, 26px);
}

.chess-stage {
  background:
    linear-gradient(180deg, rgba(250, 252, 247, 0.98), rgba(227, 238, 232, 0.98));
  min-width: 0;
}

.chess-table {
  align-items: center;
  display: grid;
  gap: 12px;
  justify-items: center;
  min-height: 100%;
}

.chess-board {
  aspect-ratio: 1 / 1;
  background: #151a20;
  border: 8px solid #151a20;
  border-radius: 8px;
  box-shadow: 0 22px 54px rgba(4, 9, 14, 0.34);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  max-width: min(72vh, 100%);
  overflow: hidden;
  place-items: stretch;
  position: relative;
  width: min(100%, 680px);
}

.chess-board::before {
  border-radius: 8px;
  content: "";
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  transition: opacity 160ms ease;
  z-index: 3;
}

.chess-board.is-check::before {
  animation: chessCheckPulse 900ms ease-in-out infinite alternate;
  box-shadow: inset 0 0 0 6px rgba(255, 75, 86, 0.7), inset 0 0 38px rgba(255, 75, 86, 0.3);
  opacity: 1;
}

.chess-square {
  align-items: center;
  border: 0;
  color: #101820;
  cursor: pointer;
  display: flex;
  height: 100%;
  justify-content: center;
  line-height: 1;
  min-height: 0;
  min-width: 0;
  padding: 0;
  position: relative;
  width: 100%;
}

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

.chess-square.dark {
  background: #5e8f6f;
}

.chess-square.selected {
  box-shadow: inset 0 0 0 5px #ffd04c;
}

.chess-square.last-move {
  background-image: linear-gradient(0deg, rgba(255, 208, 76, 0.36), rgba(255, 208, 76, 0.36));
}

.chess-square.move-origin::before,
.chess-square.move-arrive::before,
.chess-square.capture-burst::before,
.chess-square.promotion-burst::before {
  border-radius: 50%;
  content: "";
  inset: 16%;
  pointer-events: none;
  position: absolute;
}

.chess-square.move-origin::before {
  animation: chessOriginGlow 520ms ease-out both;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.34), transparent 68%);
}

.chess-square.move-arrive .chess-piece {
  animation: chessPieceArrive 230ms cubic-bezier(0.2, 0.9, 0.2, 1.18) both;
}

.chess-square.capture-burst::before {
  animation: chessCaptureBurst 460ms ease-out both;
  border: 4px solid rgba(255, 75, 86, 0.78);
  inset: 8%;
}

.chess-square.promotion-burst::before {
  animation: chessPromotionBurst 640ms ease-out both;
  background: radial-gradient(circle, rgba(255, 208, 76, 0.7), rgba(255, 208, 76, 0.14) 52%, transparent 72%);
}

.chess-square.legal::after,
.chess-square.capture::after {
  border-radius: 999px;
  content: "";
  height: 24%;
  position: absolute;
  width: 24%;
}

.chess-square.legal::after {
  background: rgba(17, 24, 33, 0.34);
}

.chess-square.capture::after {
  border: 5px solid rgba(255, 75, 86, 0.78);
  height: 76%;
  width: 76%;
}

.chess-square small {
  bottom: 4px;
  color: rgba(16, 24, 32, 0.7);
  font-family: Arial, sans-serif;
  font-size: 10px;
  font-weight: 900;
  left: 5px;
  position: absolute;
  text-transform: uppercase;
}

.chess-piece {
  align-items: center;
  display: flex;
  height: 92%;
  justify-content: center;
  pointer-events: none;
  position: relative;
  width: 92%;
  z-index: 1;
}

.chess-piece-svg {
  display: block;
  filter: drop-shadow(0 9px 7px rgba(0, 0, 0, 0.28));
  height: 100%;
  overflow: visible;
  width: 100%;
}

.chess-piece-white {
  --piece-main: #f8efe0;
  --piece-side: #d7c09a;
  --piece-highlight: rgba(255, 255, 255, 0.72);
  --piece-shade: rgba(124, 96, 60, 0.26);
  --piece-stroke: rgba(92, 68, 42, 0.72);
  --piece-ground: rgba(43, 28, 18, 0.28);
}

.chess-piece-black {
  --piece-main: #202733;
  --piece-side: #0d1219;
  --piece-highlight: rgba(130, 151, 173, 0.35);
  --piece-shade: rgba(0, 0, 0, 0.34);
  --piece-stroke: rgba(243, 225, 191, 0.32);
  --piece-ground: rgba(0, 0, 0, 0.34);
}

.piece-main,
.piece-side,
.piece-highlight,
.piece-shade,
.piece-cut,
.piece-stroke,
.piece-outline,
.piece-stroke-fill,
.piece-ground {
  vector-effect: non-scaling-stroke;
}

.piece-main {
  fill: var(--piece-main);
  stroke: var(--piece-stroke);
  stroke-linejoin: round;
  stroke-width: 2.6;
}

.piece-side {
  fill: var(--piece-side);
  stroke: var(--piece-stroke);
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.piece-highlight {
  fill: var(--piece-highlight);
}

.piece-shade {
  fill: var(--piece-shade);
}

.piece-cut,
.piece-stroke,
.piece-outline {
  fill: none;
  stroke: var(--piece-stroke);
  stroke-linecap: round;
}

.piece-cut {
  stroke-width: 5;
}

.piece-stroke {
  stroke-width: 4;
}

.piece-outline {
  stroke-width: 3.2;
}

.piece-stroke-fill {
  fill: var(--piece-stroke);
}

.piece-ground {
  fill: var(--piece-ground);
}

.captured-row {
  align-items: center;
  background: rgba(17, 24, 33, 0.08);
  border: 2px solid rgba(17, 24, 33, 0.1);
  border-radius: 8px;
  color: #151a20;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  min-height: 42px;
  padding: 5px 10px;
  width: min(100%, 680px);
}

.captured-piece {
  display: inline-flex;
  height: 30px;
  width: 26px;
}

.captured-piece .chess-piece-svg {
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.22));
}

.promotion-dialog {
  align-items: center;
  background: rgba(8, 12, 16, 0.54);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: absolute;
  z-index: 5;
}

.promotion-dialog.hidden {
  display: none;
}

.promotion-dialog > div {
  background: #fff;
  border: 4px solid #ffd04c;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  color: #172017;
  display: grid;
  gap: 14px;
  max-width: 340px;
  padding: 18px;
  text-align: center;
  width: min(100%, 340px);
}

.promotion-dialog strong {
  font-size: 24px;
}

.promotion-choices {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.promotion-choices button {
  align-items: center;
  aspect-ratio: 1;
  background: linear-gradient(180deg, #fff9ec, #e6f0e8);
  border: 2px solid #cddbd1;
  border-radius: 8px;
  color: #111821;
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding: 4px;
}

.promotion-choices button .chess-piece-svg {
  filter: drop-shadow(0 5px 4px rgba(0, 0, 0, 0.24));
}

.chess-result-dialog {
  align-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 208, 76, 0.2), transparent 24%),
    rgba(8, 12, 16, 0.62);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: absolute;
  z-index: 6;
}

.chess-result-dialog.hidden {
  display: none;
}

.chess-result-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(232, 242, 235, 0.98));
  border: 4px solid #ffd04c;
  border-radius: 8px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
  color: #111821;
  display: grid;
  gap: 14px;
  max-width: 430px;
  padding: 20px;
  text-align: center;
  transform-origin: center;
  width: min(100%, 430px);
  animation: chessResultIn 240ms cubic-bezier(0.2, 0.9, 0.2, 1.12) both;
}

.chess-result-badge {
  align-self: center;
  background: #14202a;
  border-radius: 999px;
  color: #ffd04c;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  justify-self: center;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  text-transform: uppercase;
}

.chess-result-card strong {
  font-size: clamp(28px, 4.5vw, 44px);
  line-height: 0.96;
}

.chess-result-card p {
  color: #52625c;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
  margin: 0;
}

.chess-result-stats {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chess-result-stats span {
  background: #14202a;
  border-radius: 8px;
  color: #fff;
  display: grid;
  gap: 2px;
  min-height: 62px;
  padding: 10px 8px;
}

.chess-result-stats b {
  color: #ffd04c;
  font-size: 24px;
  line-height: 1;
}

.chess-result-stats small {
  color: rgba(255, 255, 255, 0.7);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.chess-result-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chess-result-actions .arcade-button {
  min-height: 48px;
}

.result-win .chess-result-card {
  border-color: #42d66f;
}

.result-win .chess-result-badge {
  color: #42d66f;
}

.result-draw .chess-result-card {
  border-color: #72d9ff;
}

.result-draw .chess-result-badge {
  color: #72d9ff;
}

.result-mate .chess-result-card {
  border-color: #ff6b5b;
}

.result-mate .chess-result-badge {
  color: #ffb1a9;
}

@keyframes chessPieceArrive {
  0% {
    opacity: 0.72;
    transform: translateY(-8%) scale(0.88);
  }
  70% {
    opacity: 1;
    transform: translateY(2%) scale(1.05);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes chessOriginGlow {
  0% {
    opacity: 0.8;
    transform: scale(0.65);
  }
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

@keyframes chessCaptureBurst {
  0% {
    opacity: 0.95;
    transform: scale(0.58);
  }
  100% {
    opacity: 0;
    transform: scale(1.32);
  }
}

@keyframes chessPromotionBurst {
  0% {
    opacity: 0.94;
    transform: scale(0.55) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.5) rotate(24deg);
  }
}

@keyframes chessCheckPulse {
  0% {
    filter: saturate(1);
  }
  100% {
    filter: saturate(1.24);
  }
}

@keyframes chessResultIn {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chess-board.is-check::before,
  .chess-square.move-origin::before,
  .chess-square.move-arrive .chess-piece,
  .chess-square.capture-burst::before,
  .chess-square.promotion-burst::before,
  .chess-result-card {
    animation: none;
  }
}

.move-panel {
  background: #fff;
  border: 2px solid #dde7df;
  border-radius: 8px;
  overflow: hidden;
}

.move-panel-head {
  align-items: center;
  background: #14202a;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
}

.move-panel-head span {
  background: #ffd04c;
  border-radius: 999px;
  color: #172017;
  font-weight: 900;
  min-width: 34px;
  padding: 4px 8px;
  text-align: center;
}

.move-list {
  display: grid;
  gap: 4px;
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 12px 12px 12px 34px;
}

.move-list li {
  color: #172017;
  font-weight: 900;
  line-height: 1.35;
  padding-left: 4px;
}

.move-pair {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.move-pair span {
  background: #eef5ea;
  border-radius: 6px;
  min-height: 30px;
  padding: 6px 8px;
}

@media (max-width: 1040px) {
  .chess-layout {
    grid-template-columns: 1fr;
  }

  .chess-board {
    max-width: min(92vw, 680px);
  }
}

@media (max-width: 620px) {
  .chess-board {
    border-width: 5px;
    width: min(100%, 94vw);
  }

  .chess-square {
    min-height: 0;
  }

  .chess-square small {
    display: none;
  }

  .captured-row {
    width: min(100%, 94vw);
  }

  .chess-result-dialog {
    padding: 12px;
  }

  .chess-result-card {
    padding: 16px;
  }

  .chess-result-actions {
    grid-template-columns: 1fr;
  }

  .chess-difficulty-row {
    grid-template-columns: 1fr;
  }
}
