/* ChessExpose Board — board.css
 * Own design. Themes are CSS variables; switch with data-theme on .cxb
 * (or override the variables in your own stylesheet). */

.cxb {
  /* ---- theme variables (default: green) ---- */
  --cxb-light: #ecefd6;
  --cxb-dark: #6f9a55;
  --cxb-coord-on-light: #6f9a55;
  --cxb-coord-on-dark: #ecefd6;
  --cxb-last: rgba(246, 234, 92, 0.55);
  --cxb-selected: rgba(246, 234, 92, 0.75);
  --cxb-dot: rgba(0, 0, 0, 0.16);
  --cxb-ring: rgba(0, 0, 0, 0.16);
  --cxb-hover: rgba(255, 255, 255, 0.75);
  --cxb-check: radial-gradient(ellipse at center, rgba(255, 0, 0, 1) 0%, rgba(231, 0, 0, 1) 25%, rgba(169, 0, 0, 0) 89%, rgba(158, 0, 0, 0) 100%);
  --cxb-radius: 4px;
  --cxb-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  --cxb-anim: 150ms;

  /* ---- sizing: ~90% of the available width, capped on desktop ---- */
  width: min(90%, var(--cxb-max, 520px));
  margin: 0 auto;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cxb[data-theme="chessexpose"] {
  --cxb-light: #eef3f8;
  --cxb-dark: #8fb4d8;
  --cxb-coord-on-light: #5a83ad;
  --cxb-coord-on-dark: #f4f8fc;
  --cxb-last: rgba(255, 214, 92, 0.72);
  --cxb-selected: rgba(255, 186, 40, 0.8);
  --cxb-dot: rgba(18, 52, 92, 0.38);
  --cxb-ring: rgba(18, 52, 92, 0.45);
  --cxb-hover: rgba(255, 255, 255, 0.9);
}
.cxb[data-theme="brown"] {
  --cxb-light: #f0dab5;
  --cxb-dark: #b48764;
  --cxb-coord-on-light: #b48764;
  --cxb-coord-on-dark: #f0dab5;
  --cxb-last: rgba(205, 210, 106, 0.6);
  --cxb-selected: rgba(20, 85, 30, 0.45);
  --cxb-dot: rgba(20, 85, 30, 0.45);
  --cxb-ring: rgba(20, 85, 30, 0.4);
}
.cxb[data-theme="blue"] {
  --cxb-light: #dfe4e8;
  --cxb-dark: #8aa1ae;
  --cxb-coord-on-light: #8aa1ae;
  --cxb-coord-on-dark: #dfe4e8;
  --cxb-last: rgba(155, 199, 0, 0.42);
  --cxb-selected: rgba(20, 85, 30, 0.45);
  --cxb-dot: rgba(20, 85, 30, 0.45);
  --cxb-ring: rgba(20, 85, 30, 0.4);
}

/* The board is a fixed square: aspect-ratio + overflow hidden = no layout shift ever. */
.cxb-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--cxb-radius);
  box-shadow: var(--cxb-shadow);
  touch-action: none;           /* no scrolling/zooming while dragging on touch */
  contain: layout paint;        /* board internals can never affect page layout */
  outline: none;
}
/* Read-only boards (movable: 'none') must not trap touch scrolling. */
.cxb-board:not(.can-grab) { touch-action: auto; }
@supports not (aspect-ratio: 1 / 1) {
  .cxb-board { height: 0; padding-bottom: 100%; }
}

.cxb-squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.cxb-sq {
  position: relative;
  background: var(--cxb-light);
  outline: none;
}
.cxb-sq.dark { background: var(--cxb-dark); }

/* highlight overlays (pseudo-element ::before), dots/rings (::after) */
.cxb-sq::before, .cxb-sq::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cxb-sq.last::before { background: var(--cxb-last); }
.cxb-sq.selected::before { background: var(--cxb-selected); }
.cxb-sq.check::before { background: var(--cxb-check); }
.cxb-sq.dest::after {
  background: radial-gradient(var(--cxb-dot) 22%, transparent 23%);
}
.cxb-sq.dest.capture::after {
  background: radial-gradient(transparent 0%, transparent 79%, var(--cxb-ring) 80%);
}
.cxb-sq.hover::after {
  box-shadow: inset 0 0 0 max(2px, 0.45vmin) var(--cxb-hover);
  background: none;
}
.cxb.kbd .cxb-sq:focus::after {
  box-shadow: inset 0 0 0 3px #3b82f6;
}

/* coordinates inside the edge squares */
.cxb-coord {
  position: absolute;
  font: 600 clamp(10px, 2.7cqw, 15px)/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
  z-index: 1;
}
.cxb-coord.rank { top: 4%; left: 5%; }
.cxb-coord.file { bottom: 4%; right: 6%; }
.cxb-sq.light .cxb-coord { color: var(--cxb-coord-on-light); }
.cxb-sq.dark .cxb-coord { color: var(--cxb-coord-on-dark); }
.cxb.no-coords .cxb-coord { display: none; }
.cxb-board { container-type: inline-size; }

/* pieces: absolutely positioned, moved only by transform (GPU, no layout) */
.cxb-pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cxb-piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  will-change: transform;
  transition: transform var(--cxb-anim) ease-out, opacity var(--cxb-anim) linear;
  z-index: 2;
}
.cxb-piece.moving { z-index: 3; }
.cxb-piece.dragging {
  transition: none;
  z-index: 5;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}
.cxb-piece.fading { opacity: 0; }
.cxb-board.can-grab { cursor: pointer; }
.cxb-board.is-dragging { cursor: grabbing; }

/* promotion picker — an overlay inside the board, never changes layout */
.cxb-promo {
  position: absolute;
  inset: 0;
  background: rgba(30, 30, 30, 0.55);
  z-index: 10;
  display: none;
}
.cxb-promo.open { display: block; }
.cxb-promo button {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: #e8e8e8;
  background-size: 80% 80%;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: border-radius 120ms, background-color 120ms;
}
.cxb-promo button:hover,
.cxb-promo button:focus-visible {
  border-radius: 6%;
  background-color: #f6b34a;
  outline: none;
}

.cxb-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- optional move list (fixed height, scrolls internally) ---- */
.cxb-moves {
  box-sizing: border-box;
  height: 7.5rem;
  overflow-y: auto;
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-columns: 2.6em 1fr 1fr;
  align-content: start;
  background: #f4f4f2;
  border-radius: 6px;
  padding: 4px 0;
  scrollbar-gutter: stable;
}
.cxb-moves .no { color: #888; text-align: right; padding-right: 0.6em; }
.cxb-moves .mv { padding: 0 0.5em; border-radius: 3px; }
.cxb-moves .mv.current { background: #d9e6c4; font-weight: 600; }
.cxb-moves .empty { grid-column: 1 / -1; color: #999; padding: 0 0.8em; }

@media (prefers-reduced-motion: reduce) {
  .cxb { --cxb-anim: 0ms; }
}
