* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(74, 139, 255, 0.18), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(182, 120, 255, 0.16), transparent 26rem),
    #0f1220;
  color: #d9e1f4;
  font-family: Arial, sans-serif;
}

.layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  padding: 24px 24px 8px;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-area {
  display: flex;
  flex-direction: column;
  width: 280px;
}

.board-wrap {
  border: 2px solid #2e3557;
  background: #11172c;
  padding: 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(82vw, 560px);
  height: min(82vw, 560px);
  max-width: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  background: #0a0e1c;
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

.cell.light {
  background: #c9d5f6;
}

.cell.dark {
  background: #4d5b86;
}

.cell.dark:hover {
  box-shadow: inset 0 0 0 3px rgba(127, 176, 255, 0.28);
}

.cell.selected {
  box-shadow: inset 0 0 0 4px #ffd447;
}

.cell.move-target::after,
.cell.capture-target::after {
  content: "";
  width: 28%;
  height: 28%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.36);
}

.cell.capture-target::after {
  background: rgba(255, 107, 107, 0.72);
  box-shadow: 0 0 18px rgba(255, 107, 107, 0.54);
}

.piece {
  position: absolute;
  width: 76%;
  height: 76%;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.28);
  box-shadow:
    inset 0 5px 10px rgba(255, 255, 255, 0.18),
    inset 0 -8px 12px rgba(0, 0, 0, 0.22),
    0 8px 18px rgba(0, 0, 0, 0.34);
  pointer-events: none;
}

.piece.white {
  background: linear-gradient(145deg, #f7fbff, #bfcdf0);
  border-color: rgba(74, 94, 145, 0.38);
}

.piece.black {
  background: radial-gradient(circle at 35% 28%, #6076b8, #1d2b4d 48%, #060a14 100%);
  border-color: #9fb3ee;
  box-shadow:
    inset 0 6px 12px rgba(255, 255, 255, 0.2),
    inset 0 -8px 14px rgba(0, 0, 0, 0.42),
    0 0 0 2px rgba(127, 176, 255, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.34);
}

.piece.king::before {
  content: "K";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ffd447;
  font-weight: 800;
  font-size: clamp(18px, 4vw, 34px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.panel {
  width: 280px;
  background: rgba(22, 29, 56, 0.92);
  border: 1px solid #2e3557;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
  font-size: 14px;
  line-height: 1.35;
}

h1,
h2 {
  margin: 0 0 12px;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
  margin-top: 16px;
}

.stat {
  margin-bottom: 6px;
  line-height: 1.35;
}

.stat span {
  color: #e6ecfb;
  font-weight: 700;
}

.controls ul {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.35;
}

.controls li {
  margin-bottom: 4px;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  font-size: 13px;
}

select {
  width: 100%;
  border: 1px solid #45568f;
  border-radius: 8px;
  background: #10162b;
  color: #d9e1f4;
  padding: 10px 12px;
  font-size: 14px;
}

button {
  margin-top: 16px;
  width: 100%;
  border: none;
  border-radius: 8px;
  background: #4a8bff;
  color: #edf2ff;
  padding: 10px 12px;
  font-size: 15px;
  cursor: pointer;
}

button:hover {
  background: #6ca2ff;
}

.mobile-stats,
.mobile-info-toggle,
.mobile-info-panel {
  display: none;
}

.app-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 0 0;
  color: #7f8bb7;
  font-size: 13px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
}

.overlay-content {
  width: min(90vw, 360px);
  border: 1px solid #3d4772;
  border-radius: 10px;
  background: #1b2442;
  padding: 20px;
  text-align: center;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    padding: 28px 14px 12px;
    gap: 10px;
  }

  .board-wrap {
    padding: 6px;
  }

  .board {
    width: min(94vw, 520px);
    height: min(94vw, 520px);
    max-width: none;
    max-height: none;
  }

  .side-area {
    width: min(100%, 520px);
  }

  .panel {
    display: none;
  }

  .mobile-stats {
    display: flex;
    justify-content: space-between;
    width: min(100%, 520px);
    border: 1px solid #2e3557;
    border-radius: 8px;
    background: rgba(22, 29, 56, 0.92);
    padding: 8px 10px;
    font-size: 14px;
  }

  .mobile-info-toggle {
    display: block;
    width: min(100%, 520px);
    margin-top: 0;
    background: #2f3b64;
    padding: 4px 12px 7px;
    font-size: 18px;
    line-height: 1;
  }

  .mobile-info-panel {
    width: min(100%, 520px);
    border: 1px solid #2e3557;
    border-radius: 8px;
    background: rgba(22, 29, 56, 0.92);
    padding: 10px;
  }

  .mobile-info-panel.hidden {
    display: none;
  }

  .mobile-info-panel:not(.hidden) {
    display: block;
  }

  .app-footer {
    padding: 0 0 10px;
  }
}
