/* Chess board and controls. Page colors (paper, ink, accent, highlight) come from assets/site.css. */

.chess {
  --sq-light: #e7ebf1;
  --sq-dark: #9eafc6;
  --dot: rgba(29, 36, 51, 0.3);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 20px 32px;
  margin: 0 0 40px;
}

.chess-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* The board is a square that fits the screen height on laptops and the screen width on phones. */
.chess-board-wrap {
  position: relative;
  flex: 0 1 560px;
  width: 100%;
  max-width: 560px;
  max-width: clamp(288px, calc(100vh - 215px), 560px);
}

.chess-board-wrap::before {
  content: "";
  display: block;
  padding-top: 100%;
}

.chess-board {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--line);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--sq-light);
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

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

/* Last move: a highlighter stroke over both squares. */
.sq.last::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--highlight);
}

/* A king in check glows red. */
.sq.check {
  background-image: radial-gradient(circle, rgba(207, 58, 46, 0.9) 0, rgba(207, 58, 46, 0.5) 38%, rgba(207, 58, 46, 0) 70%);
}

.sq.sel {
  box-shadow: inset 0 0 0 3px var(--accent);
}

/* Where the selected piece can go: a dot, or a ring around a piece it can capture. */
.sq.target::after {
  content: "";
  position: absolute;
  z-index: 2;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--dot);
  pointer-events: none;
}

.sq.target.capture::after {
  width: 88%;
  height: 88%;
  background: transparent;
  box-shadow: inset 0 0 0 4px var(--dot);
}

.sq:focus {
  z-index: 3;
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.sq:focus:not(:focus-visible) {
  outline: none;
}

.is-thinking .sq {
  cursor: default;
}

.chess .pc {
  position: relative;
  z-index: 1;
  width: 90%;
  height: 90%;
  overflow: visible;
  pointer-events: none;
  stroke-width: 3.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.pc-w {
  fill: #fbfbf9;
  stroke: #1d2433;
  color: #1d2433;
}

.pc-b {
  fill: #232b3b;
  stroke: #232b3b;
  color: #eef1f5;
}

/* File letters and rank numbers along the edges. */
.co {
  position: absolute;
  z-index: 1;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.co-r {
  top: 4px;
  left: 4px;
}

.co-f {
  right: 4px;
  bottom: 3px;
}

.sq.light .co {
  color: #6b7d98;
}

.sq.dark .co {
  color: #eef1f6;
}

/* Side panel: status, buttons and the scoresheet. */
.chess-panel {
  display: flex;
  flex: 1 1 240px;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  max-width: 360px;
}

.chess-status {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.chess-sub {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.chess-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chess-sheet {
  max-height: 300px;
  margin: 4px 0 0;
  padding: 0;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  list-style: none;
  font-variant-numeric: tabular-nums;
}

.chess-sheet li {
  display: grid;
  grid-template-columns: 2.75em 1fr 1fr;
  gap: 4px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}

.chess-sheet .n {
  color: var(--muted);
}

.chess-sheet .cur {
  justify-self: start;
  margin-left: -4px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--highlight);
}

.chess-sheet .sheet-empty {
  display: block;
  color: var(--muted);
}

.chess-noscript {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* Dialogs: new game options and pawn promotion. */
.chess-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(13, 18, 28, 0.5);
}

.chess-overlay[hidden] {
  display: none;
}

.chess-dialog {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 16px 48px rgba(13, 18, 28, 0.28);
}

.chess-dialog h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.chess-dialog fieldset {
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.chess-dialog legend {
  margin: 0 0 6px;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.setup-friend .needs-computer {
  display: none;
}

.seg {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.seg label {
  position: relative;
  flex: 1 1 0;
}

.seg input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.seg span {
  display: block;
  padding: 9px 6px;
  border-left: 1px solid var(--line);
  text-align: center;
  cursor: pointer;
}

.seg label:first-child span {
  border-left: 0;
}

.seg input:checked + span {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.seg input:focus + span {
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 4px var(--ink);
}

.seg input:focus:not(:focus-visible) + span {
  box-shadow: none;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.promo-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.promo-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 72px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--sq-light);
  cursor: pointer;
}

.promo-choice:hover {
  border-color: var(--accent);
}

.promo-choice:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.promo-choice .pc {
  width: 52px;
  height: 52px;
}

@media (max-width: 640px) {
  .chess {
    gap: 16px;
  }

  .chess-panel {
    max-width: none;
  }

  .chess-actions .btn {
    flex: 1 1 auto;
  }

  .chess-sheet {
    max-height: 9.5em;
  }

  .co {
    font-size: 9px;
  }
}
