:root {
  color-scheme: light;
  --ink: #1d2528;
  --muted: #687379;
  --paper: #f3f3f1;
  --panel: #fffdfa;
  --line: #d6d0c4;
  --dark-square: #779954;
  --light-square: #eeeed2;
  --dark-active: #baca44;
  --light-active: #f6f669;
  --target: #cc4a4f;
  --white-piece: #f9f9f6;
  --black-piece: #171717;
  --piece-edge: #292724;
  --shadow: 0 18px 42px rgba(49, 46, 43, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 720px) minmax(270px, 360px);
  align-items: center;
  gap: 28px;
  padding: 28px 0;
}

.play-area {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow,
.panel-label,
.turn-badge {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  min-height: 2.1rem;
  margin: 2px 0 0;
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0;
  transition: color 140ms ease, text-shadow 140ms ease;
}

.status-check {
  color: #b73446;
  text-shadow: 0 5px 18px rgba(183, 52, 70, 0.2);
}

.status-mate {
  color: #fff8ec;
  width: fit-content;
  max-width: 100%;
  padding: 5px 10px 7px;
  border-radius: 8px;
  background: #a21f34;
  box-shadow: 0 12px 28px rgba(162, 31, 52, 0.28);
}

.status-draw {
  color: #365f75;
}

.status-thinking {
  color: #5d6570;
}

.controls {
  display: flex;
  gap: 8px;
}

.controls button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(47, 42, 34, 0.09);
  text-decoration: none;
}

.rules-link {
  min-width: 52px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #376f88;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.rules-link:hover {
  text-decoration: underline;
}

.controls button:disabled {
  cursor: default;
  opacity: 0.42;
}

.controls span {
  display: block;
  font-size: 1.34rem;
  line-height: 1;
}

.board {
  width: min(100%, calc(100vh - 132px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 8px solid #312e2b;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #312e2b;
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: filter 130ms ease, background-color 130ms ease;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.square.selected.light {
  background: var(--light-active);
}

.square.selected.dark {
  background: var(--dark-active);
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(186, 63, 85, 0.76);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.18);
}

.square.capture::after {
  width: 72%;
  background: transparent;
  border: 5px solid rgba(186, 63, 85, 0.78);
  box-shadow: none;
}

.square.king-check {
  background: #cb4459;
}

.square.king-check::before {
  content: "";
  position: absolute;
  inset: 7%;
  z-index: 1;
  border: 5px solid rgba(255, 248, 236, 0.92);
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(162, 31, 52, 0.25), inset 0 0 22px rgba(162, 31, 52, 0.34);
  pointer-events: none;
}

.square.king-checkmate {
  background: #94192c;
}

.square.king-checkmate::before {
  inset: 5%;
  border-width: 6px;
  box-shadow: 0 0 0 8px rgba(255, 248, 236, 0.22), inset 0 0 28px rgba(0, 0, 0, 0.22);
}

.square:hover {
  filter: brightness(1.04);
}

.square:disabled,
.board.locked .square {
  cursor: default;
}

.square:disabled:hover {
  filter: none;
}

.piece {
  position: relative;
  z-index: 3;
  display: block;
  width: 86%;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.28));
  pointer-events: none;
  user-select: none;
}

.piece.white {
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.26));
}

.piece.type-p {
  width: 88%;
}

.coord {
  position: absolute;
  left: 6px;
  bottom: 4px;
  z-index: 2;
  color: rgba(29, 37, 40, 0.64);
  font-size: clamp(0.56rem, 1.35vw, 0.78rem);
  font-weight: 800;
  pointer-events: none;
}

.square.has-piece .coord {
  display: none;
}

.dark .coord {
  color: rgba(255, 248, 236, 0.74);
}

.side-panel {
  align-self: stretch;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  padding: 28px 0;
}

.settings-panel,
.progression,
.move-log-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  box-shadow: 0 16px 30px rgba(47, 42, 34, 0.08);
}

.settings-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.progression {
  padding: 18px;
}

.setting-block {
  display: grid;
  gap: 7px;
}

.setting-label {
  color: #3f484c;
  font-size: 0.82rem;
  font-weight: 750;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(247, 244, 237, 0.72);
}

.segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 750;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button[aria-pressed="true"] {
  background: #365f75;
  color: #fffdf8;
}

.segmented button:disabled {
  cursor: default;
  opacity: 0.45;
}

.cycle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 10px;
  color: var(--ink);
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Arial Unicode MS", serif;
  font-size: clamp(1.08rem, 2.3vw, 1.55rem);
  white-space: nowrap;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.move-log-section {
  min-height: 260px;
  overflow: hidden;
}

.move-log {
  max-height: min(58vh, 560px);
  margin: 0;
  padding: 8px 18px 18px 42px;
  overflow: auto;
}

.move-log li {
  padding: 9px 0;
  color: #30393d;
  font-size: 0.95rem;
  line-height: 1.25;
  border-bottom: 1px solid rgba(216, 209, 194, 0.58);
}

.move-log li:last-child {
  border-bottom: 0;
}

@media (max-width: 860px) {
  .shell {
    min-height: auto;
    grid-template-columns: 1fr;
    align-items: start;
    padding: 18px 0 24px;
  }

  .board {
    width: min(100%, calc(100vh - 170px));
    margin: 0 auto;
    border-width: 7px;
  }

  .side-panel {
    padding: 0;
  }

  .move-log {
    max-height: 220px;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100vw - 18px, 520px);
    gap: 18px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .controls button {
    width: 42px;
    height: 42px;
  }

  .cycle {
    font-size: 1rem;
  }
}
