:root {
  color-scheme: dark;
  --page: #000000;
  --ink: #f5f5f5;
  --muted: #b8b8b8;
  --light-square: #c7c6c1;
  --dark-square: #3f474a;
  --selected: #f0bd48;
  --move: rgba(245, 199, 86, 0.36);
  --capture: rgba(230, 75, 59, 0.4);
  --panel: rgba(255, 255, 255, 0.08);
  --panel-border: rgba(255, 255, 255, 0.16);
  --material-panel-size: clamp(72px, 8.5vw, 108px);
  --board-size: min(calc(100vw - var(--material-panel-size) - var(--material-panel-size) - 72px), calc(100vh - 130px), 720px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  justify-items: center;
  align-items: center;
  gap: clamp(12px, 2.6vmin, 22px);
  padding: clamp(14px, 3vmin, 28px);
}

.game-topbar {
  width: var(--board-size);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 2.2vmin, 1.15rem);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.reset-button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.reset-button:hover,
.reset-button:focus-visible {
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.14);
}

.board {
  width: var(--board-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 22px 62px rgba(0, 0, 0, 0.76);
  user-select: none;
  touch-action: none;
}

.board-stage {
  width: min(100%, calc(var(--board-size) + var(--material-panel-size) + var(--material-panel-size) + 32px));
  display: grid;
  grid-template-columns: var(--material-panel-size) var(--board-size) var(--material-panel-size);
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.material-panel {
  min-width: 0;
  min-height: 132px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 14px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.055);
}

.material-side {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1;
  text-transform: uppercase;
}

.material-score {
  color: var(--ink);
  font-size: clamp(1.55rem, 3.2vmin, 2.15rem);
  font-weight: 700;
  line-height: 1;
}

.material-advantage {
  min-width: 44px;
  min-height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(240, 189, 72, 0.16);
  color: #f3d68a;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1;
}

.material-advantage.even {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  color: #111111;
  cursor: pointer;
  line-height: 1;
  overflow: hidden;
}

.square.light {
  background: var(--light-square) url("board-light.png") center / cover;
}

.square.dark {
  background: var(--dark-square) url("board-dark.png") center / cover;
}

.square.selected {
  outline: 4px solid var(--selected);
  outline-offset: -4px;
}

.square.drag-origin .piece {
  opacity: 0;
}

.square.drag-target {
  outline: 4px solid rgba(255, 255, 255, 0.75);
  outline-offset: -4px;
}

.square.legal::after {
  content: "";
  width: 27%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--move);
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 9%;
  border: max(4px, 0.7vmin) solid var(--capture);
  border-radius: 50%;
}

.piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.22));
  pointer-events: none;
}

.dragging-piece {
  position: fixed;
  z-index: 20;
  display: grid;
  place-items: center;
  object-fit: contain;
  filter: drop-shadow(0 7px 8px rgba(0, 0, 0, 0.32));
  pointer-events: none;
  transform: translate(-50%, -52%);
  user-select: none;
}

.coordinate {
  display: none;
  position: absolute;
  z-index: 2;
  color: rgba(0, 0, 0, 0.56);
  font-size: clamp(0.62rem, 1.6vmin, 0.88rem);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.dark .coordinate {
  color: rgba(255, 255, 255, 0.62);
}

.file-label {
  right: 7%;
  bottom: 7%;
}

.rank-label {
  left: 7%;
  top: 7%;
}

.play-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.14);
}

.play-overlay.hidden {
  display: none;
}

.play-button {
  width: clamp(72px, 9vmin, 104px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0 0 0 0.12em;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  cursor: pointer;
  font-size: clamp(2rem, 4.8vmin, 3.1rem);
  line-height: 1;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}

.play-button:hover,
.play-button:focus-visible {
  border-color: #f3d68a;
  color: #f3d68a;
}

.support-link {
  position: fixed;
  left: clamp(14px, 2.5vw, 28px);
  bottom: clamp(14px, 2.5vw, 28px);
  z-index: 30;
  display: inline-grid;
  gap: 4px;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.95);
}

.support-text {
  font-size: clamp(0.9rem, 1.8vw, 1.1rem);
}

.support-link:hover,
.support-link:focus-visible {
  color: #f3d68a;
}

@media (max-width: 520px) {
  .game-shell {
    align-content: center;
  }

  :root {
    --board-size: min(94vw, calc(100vh - 175px), 720px);
  }

  .board-stage {
    width: var(--board-size);
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .board {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .material-panel {
    min-height: 58px;
    grid-template-columns: auto auto auto;
    align-content: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .material-score {
    font-size: 1.1rem;
  }

  .support-link {
    left: 10px;
    bottom: 9px;
  }

  .support-text {
    font-size: 0.8rem;
  }
}
