/* Chess (member request, Elsa_Cline: "Add chess"). public/chess.js. The overlay borrows gin's (.gin: felt, letterboard
   header, the boards list) and backgammon's player chips. The board sits in a grooved felt frame with the files and ranks
   in board letters; squares are indigo and pale slate. Pieces are flat toy shapes with an ink edge, ivory and raspberry
   like backgammon's checkers. Periwinkle marks the last move, your pick and where it can go; red rings a king in check.
   The one showpiece: a checkmated king topples over. No yellow. */
.chv, .ch-invite, .ch-turn {
  --sq-l: #c3c7dc;
  --sq-d: #3340a0;
  --ivory: #f5f5f2; --ivory-edge: #1d2140;
  --rasp: #d63a62;  --rasp-edge: #5a0f26;
  --pick: #9aa4ff;
}
.chv [data-s="x"], .ch-invite [data-s="x"] { --ck: transparent; --ck-edge: #f5f5f266; }
.ch-invite [data-s="x"] { --ck-edge: #1d214066; }

/* ---------- pieces (in the board, the trays, the chips, the card) ---------- */
.pc path, .pc circle { stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; }
.pc.w path, .pc.w circle { fill: var(--ivory); stroke: var(--ivory-edge); }
.pc.b path, .pc.b circle { fill: var(--rasp); stroke: var(--rasp-edge); }
.pc .d { fill: none !important; stroke-width: 3.5; }
.pc.w .d { stroke: #1d214066; }
.pc.b .d { stroke: #ffffff80; }
.pc .e { stroke: none !important; }
.pc.w .e { fill: var(--ivory-edge) !important; }
.pc.b .e { fill: var(--rasp-edge) !important; }
.ch-mini { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: -.25em; overflow: visible; }

/* ---------- the board ---------- */
.ch-table { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 4px 0 calc(10px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.ch-board { position: relative; flex: none; width: min(100% - 12px, 560px, var(--app-h) - 330px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-width: min(100% - 12px, 290px); }
.ch-board svg { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.ch-board .frame { fill: var(--felt-groove); }
.ch-board .sl { fill: var(--sq-l); }
.ch-board .sd { fill: var(--sq-d); }
.ch-board .lastmv { fill: #9aa4ff; opacity: .42; }
.ch-board .selsq { fill: #9aa4ff; opacity: .8; }
.ch-board .chk { fill: none; stroke: #ff4f5e; stroke-width: 4.5; }
.ch-board .coord { font: 600 11px var(--board); letter-spacing: .06em; text-transform: uppercase; fill: var(--letter); opacity: .72; text-anchor: middle; }
.ch-board .tgt { fill: var(--pick); stroke: #fff; stroke-width: 1.6; pointer-events: none; }
.ch-board .tgt.cap { fill: none; stroke: var(--pick); stroke-width: 4; }
.ch-board .pc { pointer-events: none; }
.ch-board .pc.lift .pc-in { filter: drop-shadow(0 3px 0 #0000004d); }
#chDrag, [id^="chFly"] { pointer-events: none; }

/* checkmate: the beaten king tips over and rolls a little */
.ch-board .pc.fallen .pc-in { transform-box: fill-box; transform-origin: 85% 95%; transform: rotate(80deg) translate(6%, 4%); animation: ch-topple 1.1s cubic-bezier(.5, 0, .7, 1) both; }
@keyframes ch-topple {
  0% { transform: none; }
  35% { transform: rotate(-8deg); }
  70% { transform: rotate(88deg) translate(6%, 4%); }
  82% { transform: rotate(74deg) translate(6%, 4%); }
  100% { transform: rotate(80deg) translate(6%, 4%); }
}

/* a pawn on the last rank: what does it become? */
.ch-promo { position: absolute; inset: 0; display: grid; place-items: center; background: #1d214080; border-radius: 8px; }
.ch-promo[hidden] { display: none; }
.ch-promo-in { display: flex; gap: 6px; padding: 8px; background: var(--felt); border-radius: 12px; box-shadow: 0 0 0 2px var(--letter), 0 4px 0 #0000004d; }
.ch-pp { width: 56px; height: 56px; padding: 6px; border: 0; border-radius: 10px; background: var(--sq-l); display: grid; place-items: center; }
.ch-pp .ch-mini { width: 100%; height: 100%; }
.ch-pp:active { background: var(--pick); }
.ch-pp.no { background: none; color: var(--letter); width: 44px; }
.ch-pp.no svg { width: 22px; height: 22px; }

/* ---------- players above and below (backgammon's .bp chips) ---------- */
.ch-p { flex: none; width: min(100% - 12px, 560px); padding: 5px 2px; }
.chv [data-s="0"] { --ck: var(--ivory); --ck-edge: var(--ivory-edge); }
.chv [data-s="1"] { --ck: var(--rasp); --ck-edge: var(--rasp-edge); }
.ch-tray { display: flex; align-items: center; flex-wrap: wrap; min-height: 18px; }
.ch-tray .ch-mini { width: 17px; height: 17px; margin-right: -4px; }
.ch-tray em { font-style: normal; font-size: 13.5px; color: var(--letter-2); margin-left: 9px; }
.ch-offer { flex: none; font-size: 13.5px; font-weight: 700; padding: 4px 9px; border-radius: 10px; border: 1.5px solid var(--pick); color: var(--letter); }

/* the moves so far, one strip that scrolls sideways (newest on the right) */
.ch-moves { flex: none; width: min(100% - 24px, 548px); margin: 2px 0 0; padding: 4px 0; list-style: none; display: flex; gap: 12px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; font-size: 14.5px; color: var(--letter-2); }
.ch-moves::-webkit-scrollbar { display: none; }
.ch-moves[hidden] { display: none; }
.ch-moves li { display: flex; gap: 5px; }
.ch-moves .no { opacity: .7; }
.ch-moves .now { color: var(--letter); font-weight: 700; }

.ch-bar { flex: none; width: min(100% - 24px, 548px); padding-top: 4px; }
.ch-bar .g-sort + .g-sort { margin-left: 10px; }
.ch-result { background: var(--card); color: var(--card-ink); border-radius: 4px; padding: 12px 16px; }
.ch-res-head { font-size: 21px; font-weight: 700; line-height: 1.2; }
.ch-res-sub { font-size: 14.5px; color: #5b6079; margin-top: 3px; }

/* ---------- all boards ---------- */
.ch-side { display: inline-flex; align-items: center; gap: 6px; }
.ch-side .ch-mini { width: 22px; height: 22px; }

/* ---------- the card in the chat: a mini letterboard with a corner of a board ---------- */
.ch-invite { margin: 16px 0 8px; }
.ci-card { display: block; width: min(100%, 330px); padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--paper); color: var(--ink); text-align: left; box-shadow: 0 1px 0 #1d214020; }
.ci-card:disabled { opacity: .6; cursor: default; }
.ci-card:active { transform: translateY(1px); }
.ci-board { position: relative; display: block; padding: 14px 16px 13px; min-height: 76px; }
.ci-board .row1 { display: block; font-size: 30px; }
.ci-board .row2 { display: block; margin-top: 6px; padding-right: 96px; }
.ci-art { position: absolute; right: 12px; top: 8px; width: 88px; height: 60px; overflow: visible; }
.ci-art .sl { fill: var(--sq-l); } .ci-art .sd { fill: var(--sq-d); }
.ci-seat { white-space: nowrap; }
.ci-seat b { color: var(--ink); }
.ci-seat i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; border-radius: 50%; background: var(--ck); box-shadow: 0 0 0 1.5px var(--ck-edge); }
.ch-invite [data-s="0"] { --ck: var(--ivory); --ck-edge: var(--ivory-edge); }
.ch-invite [data-s="1"] { --ck: var(--rasp); --ck-edge: var(--rasp-edge); }
.ci-len { flex: none; font-size: 14px; color: var(--ink-2); }
.ci-card.turn .gi-cta { background: var(--indigo); color: var(--indigo-ink); padding: 6px 12px; border-radius: 10px; }

/* ---------- "your move" slip: gin's letterboard slip, with a knight on a square ---------- */
.gt-knight { position: absolute; right: 18px; top: 50%; width: 42px; height: 42px; margin-top: -21px; padding: 4px; background: var(--sq-l); border-radius: 6px; transform: rotate(8deg); }
.gt-knight .ch-mini { width: 100%; height: 100%; }
.gin-turn.shake .gt-knight { animation: gt-tap .42s .3s ease-out 1; }

@media (prefers-reduced-motion: reduce) {
  .ch-board .pc.fallen .pc-in { animation: none; }
  .gin-turn.shake .gt-knight { animation: none; }
}
