/* Chess – only what's specific to this game.
   Header, buttons and the rest come from /css/style.css. */

.ch-pickers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
}

.ch-holder {
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* As big as fits: never wider than the column, never taller than the window */
  width: min(100%, 600px, calc(100svh - 230px));
  min-width: min(100%, 300px);
  --ch-light: #f0dcb8;
  --ch-dark: #b98a5e;
}

/* ---------- The board ---------- */

.ch-board-wrap {
  position: relative;
}

.ch-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ch-dark) 70%, #2a1b0e), 0 10px 30px rgba(0, 0, 0, 0.25);
  user-select: none;
  -webkit-user-select: none;
}

.ch-sq {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: var(--ch-dark);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

.ch-sq.is-light {
  background: var(--ch-light);
}

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

.ch-sq.can-move,
.ch-sq.is-target,
.ch-sq.is-capture {
  cursor: pointer;
}

/* The last move, and the piece you've picked up */
.ch-sq.is-last::before,
.ch-sq.is-selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 214, 64, 0.42);
}

.ch-sq.is-selected::before {
  background: rgba(255, 214, 64, 0.7);
}

/* In check: the king glows red */
.ch-sq.is-check::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 40, 40, 0.85) 0 25%, rgba(255, 40, 40, 0.35) 55%, transparent 72%);
}

/* Where the picked-up piece can go: dots, and rings on captures */
.ch-sq.is-target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(30, 20, 10, 0.28);
}

.ch-sq.is-capture::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 5px solid rgba(30, 20, 10, 0.3);
}

.ch-piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 90%;
  height: 90%;
  pointer-events: none;
}

.ch-sq.can-move .ch-piece {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.ch-piece.is-dragging {
  z-index: 10;
  cursor: grabbing;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.35));
}

.ch-piece-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ch-piece-svg path,
.ch-piece-svg circle {
  stroke-width: 3.2;
  stroke-linejoin: round;
}

.ch-piece-svg.is-white path,
.ch-piece-svg.is-white circle {
  fill: #fffdf8;
  stroke: #1c1f26;
}

.ch-piece-svg.is-black path,
.ch-piece-svg.is-black circle {
  fill: #2f323b;
  stroke: #0d0f14;
}

.ch-piece-svg.is-white .detail {
  stroke: #1c1f26;
}

.ch-piece-svg.is-black .detail {
  stroke: #8f94a2;
}

.ch-piece-svg .eye {
  stroke: none !important;
}

.ch-piece-svg.is-white .eye {
  fill: #1c1f26 !important;
}

.ch-piece-svg.is-black .eye {
  fill: #c9ccd4 !important;
}

/* Little a–h and 1–8 labels in the corners */
.ch-rank,
.ch-file {
  position: absolute;
  z-index: 1;
  font-family: var(--font-body);
  font-size: clamp(8px, 1.6vw, 12px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.ch-rank {
  top: 4%;
  left: 5%;
}

.ch-file {
  right: 6%;
  bottom: 4%;
}

.ch-sq.is-light .ch-rank,
.ch-sq.is-light .ch-file {
  color: var(--ch-dark);
}

.ch-sq.is-dark .ch-rank,
.ch-sq.is-dark .ch-file {
  color: var(--ch-light);
}

/* ---------- Promotion ---------- */

.ch-promo {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 10px;
  background: var(--overlay);
}

.ch-promo[hidden] {
  display: none;
}

.ch-promo p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.ch-promo-row {
  display: flex;
  gap: 10px;
}

.ch-promo-btn {
  width: 72px;
  height: 72px;
  padding: 6px;
  border-radius: 14px;
  border: 2px solid var(--border-strong);
  background: var(--ch-light);
  cursor: pointer;
}

.ch-promo-btn:hover,
.ch-promo-btn:focus-visible {
  border-color: var(--accent);
  outline: none;
  transform: translateY(-2px);
}

.ch-promo-cancel {
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Captured pieces ---------- */

.ch-captured {
  display: flex;
  align-items: center;
  min-height: 22px;
  padding: 0 2px;
}

.ch-cap {
  width: 20px;
  height: 20px;
  margin-right: -6px;
}

.ch-lead {
  margin-left: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Moves ---------- */

.ch-moves-box {
  width: min(100%, 600px);
}

.ch-moves-box.is-empty {
  display: none;
}

.ch-moves-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.ch-moves {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  max-height: 120px;
  margin: 0;
  padding: 10px 12px 10px 34px;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-display);
  font-size: 14px;
}

.ch-moves li {
  padding-left: 2px;
  margin-right: 10px;
}

.ch-moves li::marker {
  color: var(--text-muted);
}

.ch-moves span + span {
  margin-left: 8px;
}

.ch-moves .is-last {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--accent-soft);
}

/* ---------- Online ---------- */

.ch-who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.ch-who .ch-captured {
  flex: 1;
  justify-content: flex-end;
}

.ch-who-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ch-who-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #1c1f26;
}

.ch-who-dot.is-w {
  background: #fffdf8;
}

.ch-who-dot.is-b {
  background: #2f323b;
  border-color: #8f94a2;
}

.ch-who.is-turn .ch-who-name::after {
  content: "to move";
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent-fill);
  color: var(--accent-text);
  font-size: 11px;
}

.ch-online-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.ch-online-actions .btn[hidden] {
  display: none;
}

/* ---------- Phone held sideways (see css/style.css) ---------- */

@media (orientation: landscape) and (max-height: 540px) {
  .ch-holder {
    width: min(var(--play-w), calc(var(--play-h) - 56px));
    min-width: 0;
    gap: 2px;
  }
  .ch-captured {
    min-height: 18px;
  }
  .ch-moves {
    max-height: 70px;
  }
}
