/* Gambit — the board, pieces, highlights, arrows, promotion chooser, eval bar. */
.board {
  position: relative; width: 100%; aspect-ratio: 1 / 1; user-select: none; -webkit-user-select: none; touch-action: none;
  border-radius: var(--board-radius, 6px); box-shadow: var(--board-frame); outline: none; background: var(--frame-bg, transparent);
  -webkit-tap-highlight-color: transparent;
}
.board:focus-visible { outline: 3px solid var(--focus); outline-offset: calc(var(--frame-w, 0px) + 4px); }
.squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: inherit; overflow: hidden; }
.sq { position: relative; min-width: 0; min-height: 0; }
.sq::before, .sq::after { content: ''; position: absolute; pointer-events: none; }
.sq::before { inset: 0; background: transparent; transition: background .18s; }
.sq.last::before { background: var(--hl-last); }
.sq.sel::before { background: var(--hl-sel); }
.sq.premove::before { background: var(--premove); }
.sq.check::before { background: radial-gradient(circle, var(--check) 0%, var(--check) 22%, transparent 72%); animation: checkPulse 1.3s ease-in-out infinite; }
.sq.hint::after { left: 50%; top: 50%; width: 28%; height: 28%; margin: -14% 0 0 -14%; border-radius: 50%; background: var(--hint); animation: pop .18s ease-out; }
.sq.hint-cap::after { inset: 0; background: radial-gradient(circle, transparent 0 57%, var(--hint) 58% 69%, transparent 70%); animation: pop .18s ease-out; }
.sq.pre-target.hint::after, .sq.pre-target.hint-cap::after { --hint: var(--premove-hint); }
.sq.drag-over::before { box-shadow: inset 0 0 0 4px var(--accent); }
.board.kbd-on .sq.cursor::before { box-shadow: inset 0 0 0 4px var(--focus); }
.sq.flash::before { animation: flash .7s ease-in-out 2; }
.coord { position: absolute; z-index: 1; font-size: clamp(8px, 1.5vw, 13px); font-weight: 800; line-height: 1; pointer-events: none; font-family: var(--font-body); }
.coord.cf { right: 5%; bottom: 4%; }
.coord.cr { left: 5%; top: 5%; }
.sq.light .coord { color: var(--coord-on-light); }
.sq.dark .coord { color: var(--coord-on-dark); }
.pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; padding: .5%; z-index: 1;
  transform: translate(calc(var(--c, 0) * 100%), calc(var(--r, 0) * 100%));
  transition: transform var(--move-ms, 230ms) cubic-bezier(.22, .8, .25, 1), opacity .22s, scale .22s;
}
.piece svg { width: 100%; height: 100%; display: block; overflow: visible; filter: var(--p-filter, none); }
.piece.dragging { transition: none; z-index: 10; cursor: grabbing; }
.piece.dragging svg { filter: drop-shadow(0 12px 10px rgba(0,0,0,.35)); }
.piece.no-anim { transition: none; }
.piece.appear { opacity: 0; scale: .6; }
.piece.vanish { opacity: 0; scale: .5; z-index: 0; }
.piece-static { display: inline-block; }
.piece-static svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* piece paint — every set reads the same colour tokens */
.piece.w, .piece-static.w { --f: var(--pw-fill); --s: var(--pw-stroke); --l: var(--pw-line); }
.piece.b, .piece-static.b { --f: var(--pb-fill); --s: var(--pb-stroke); --l: var(--pb-line); }
.pset-regal .bd, .pset-bauhaus .bd { fill: var(--f); stroke: var(--s); stroke-width: 3.2; stroke-linejoin: round; }
.pset-regal .ln, .pset-bauhaus .ln { fill: none; stroke: var(--l); stroke-width: 3; stroke-linecap: round; }
.pset-regal .dt, .pset-bauhaus .dt { fill: var(--l); }
.pset-bauhaus .ac { fill: var(--p-accent); stroke: var(--s); stroke-width: 3.2; stroke-linejoin: round; }
.pset-bauhaus .bd { stroke-width: 3.6; stroke-linejoin: miter; }
.pset-pixel .po { fill: var(--s); }
.pset-pixel .pb { fill: var(--f); }
.pset-pixel .pdt { fill: var(--l); }

/* arrows */
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
.arrow line { stroke-width: .17; stroke-linecap: round; }
.arrow { opacity: .82; animation: arrowIn .3s ease-out; }
.arrow.best line { stroke: var(--arrow-best); }
.arrow.best polygon { fill: var(--arrow-best); }
.arrow.hint line { stroke: var(--arrow-hint); stroke-dasharray: .3 .16; }
.arrow.hint polygon { fill: var(--arrow-hint); }

/* promotion chooser */
.promo { position: absolute; inset: 0; z-index: 20; background: rgba(0,0,0,.38); border-radius: inherit; animation: fadeIn .15s; }
.promo-box {
  position: absolute; left: calc(var(--c, 0) * 12.5%); width: 12.5%; display: flex; flex-direction: column; background: var(--panel-solid);
  box-shadow: 0 10px 30px rgba(0,0,0,.45); border-radius: 8px; overflow: hidden; animation: pop .18s ease-out; border: 2px solid var(--accent);
}
.promo-box.from-top { top: 0; }
.promo-box.from-bottom { bottom: 0; flex-direction: column-reverse; }
.promo-btn { aspect-ratio: 1 / 1; border: 0; background: transparent; cursor: pointer; padding: 8%; transition: background .15s, transform .15s; }
.promo-btn:hover, .promo-btn:focus-visible { background: var(--hover); transform: scale(1.06); outline: none; }
.promo-btn .piece-static { width: 100%; height: 100%; }

/* effects */
.board.shake { animation: shake .4s; }
.board-wrap.barrel { animation: barrel 1.3s cubic-bezier(.5, 0, .3, 1); }
.board-banner {
  position: absolute; left: 50%; top: 50%; z-index: 6; pointer-events: none; font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 3.2rem); padding: .15em .7em; border: 4px solid currentColor; color: var(--stamp); background: var(--stamp-bg);
  border-radius: 10px; white-space: nowrap; text-transform: uppercase; letter-spacing: .06em;
  animation: banner .55s cubic-bezier(.2, 1.6, .4, 1) both, bannerAway .7s ease-in 3s forwards;
}
.knightmare .piece svg { animation: wobble 1.4s ease-in-out infinite; }
.knightmare .piece:nth-child(2n) svg { animation-delay: -.7s; }

/* eval bar */
.evalbar { position: relative; width: 24px; flex: none; border-radius: 6px; overflow: hidden; background: var(--eval-black); border: 1px solid var(--line); }
.eval-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--eval-white); transition: height .6s cubic-bezier(.2, .8, .2, 1); }
.evalbar.flipped .eval-fill { bottom: auto; top: 0; }
.eval-label { position: absolute; left: 0; right: 0; bottom: 4px; font-size: 9px; font-weight: 800; text-align: center; letter-spacing: -.3px; color: var(--eval-black); font-family: var(--font-mono); z-index: 1; }
.evalbar.black-better .eval-label { bottom: auto; top: 4px; color: var(--eval-white); }
.evalbar.flipped .eval-label { bottom: auto; top: 4px; }
.evalbar.flipped.black-better .eval-label { top: auto; bottom: 4px; }
.evalbar::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--accent); opacity: .6; }

@keyframes checkPulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes flash { 0%, 100% { background: transparent; } 50% { background: var(--hl-sel); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes barrel { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes banner { from { transform: translate(-50%, -50%) rotate(-30deg) scale(2.2); opacity: 0; } to { transform: translate(-50%, -50%) rotate(-8deg) scale(1); opacity: .95; } }
@keyframes bannerAway { to { opacity: 0; } }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) translateY(-3%); } }
@keyframes arrowIn { from { opacity: 0; } to { opacity: .82; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
html[data-motion="off"] .piece { transition: none; }
@media (prefers-reduced-motion: reduce) { .piece { transition: none; } }
