/* Backgammon (member request, henry: "Add backgammon with doubling cube"). public/backgammon.js. The overlay borrows gin's
   (.gin: felt, letterboard header, the boards list). The board is itself a letterboard: grooved felt, with long indigo and
   pale-slate points. Checkers are ivory and raspberry (by seat, never by name colour); each player's dice match their
   checkers. The one showpiece is the doubling cube: a real white 3D cube that tumbles to its new face. Periwinkle marks
   what you can move and where it can go (as picks do at the gin table). No yellow. */
.bgv, .bg-invite {
  --pt-a: #3340a0;
  --pt-b: #a9adc2;
  --ivory: #f5f5f2; --ivory-edge: #1d2140;
  --rasp: #d63a62;  --rasp-edge: #6e1430;
  --pick: #9aa4ff;
}
[data-s="0"] { --ck: var(--ivory); --ck-edge: var(--ivory-edge); }
[data-s="1"] { --ck: var(--rasp); --ck-edge: var(--rasp-edge); }

/* ---------- the board ---------- */
.bg-table { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 6px 0 calc(10px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.bg-board { position: relative; flex: none; container-type: inline-size; width: min(100% - 12px, 640px, (var(--app-h) - 360px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.266); min-width: min(100% - 12px, 300px); }
.bg-board svg { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.bg-board .frame, .bg-board .bar { fill: var(--felt-groove); }
.bg-board .fld { fill: var(--felt); }
.bg-board .grv { fill: var(--felt-groove); }
.bg-board .tray { fill: #f5f5f20d; }
.bg-board .tray.tgt { fill: #9aa4ff33; stroke: var(--pick); stroke-width: 2; }
.bg-board .pa { fill: var(--pt-a); }
.bg-board .pb { fill: var(--pt-b); }
.bg-board .pt.tgt { stroke: var(--pick); stroke-width: 2.4; stroke-linejoin: round; }
.bg-board .hit { fill: transparent; cursor: pointer; }

.bg-board .ck circle { stroke-width: 1.5; }
.bg-board .ck.s0 circle { fill: var(--ivory); stroke: var(--ivory-edge); }
.bg-board .ck.s1 circle { fill: var(--rasp); stroke: var(--rasp-edge); }
.bg-board .ck .in { fill: none !important; stroke-width: 1; }
.bg-board .ck.s0 .in { stroke: #1d214038; }
.bg-board .ck.s1 .in { stroke: #ffffff4d; }
.bg-board .ck text { font: 700 11px var(--font); text-anchor: middle; pointer-events: none; }
.bg-board .ck.s0 text { fill: var(--ivory-edge); }
.bg-board .ck.s1 text { fill: #fff; }
.bg-board .ck.can circle:first-child { stroke: var(--pick); stroke-width: 2.6; }
.bg-board .ck.sel circle:first-child { stroke: var(--pick); stroke-width: 4; }
.bg-board .ghost { fill: var(--pick); stroke: #fff; stroke-width: 1.6; stroke-dasharray: 3 2.4; pointer-events: none; }
.bg-board .slab { stroke-width: 1; }
.bg-board .slab.s0 { fill: var(--ivory); stroke: var(--ivory-edge); }
.bg-board .slab.s1 { fill: var(--rasp); stroke: var(--rasp-edge); }
.bg-board .die rect { stroke-width: 1.2; }
.bg-board .die.s0 rect { fill: var(--ivory); stroke: var(--ivory-edge); }
.bg-board .die.s0 circle { fill: var(--ivory-edge); }
.bg-board .die.s1 rect { fill: var(--rasp); stroke: var(--rasp-edge); }
.bg-board .die.s1 circle { fill: #fff; }
.bg-board .die.used { opacity: .3; }
.bg-board .die, .bg-board .ck, .bg-board .slab, .bg-board .ghost { pointer-events: none; }

/* ---------- the doubling cube ---------- */
.bg-cube { position: absolute; z-index: 2; width: 6.4cqw; height: 6.4cqw; left: 44.5%; top: 50%; translate: -50% -50%; perspective: 30cqw; pointer-events: none;
  transition: left .45s cubic-bezier(.3, 1.2, .5, 1), top .45s cubic-bezier(.3, 1.2, .5, 1), scale .45s cubic-bezier(.3, 1.4, .5, 1), opacity .3s; }
.bg-cube[data-at="near"] { left: 93.5%; top: 62%; }
.bg-cube[data-at="far"] { left: 93.5%; top: 38%; }
.bg-cube[data-at="offer"] { scale: 2.6; }
.bg-cube.dead { opacity: .4; }
.cb-in { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .8s cubic-bezier(.3, 1.35, .45, 1); }
.cf { position: absolute; inset: 0; display: grid; place-items: center; background: #fff; color: #1d2140; border-radius: 16%; box-shadow: inset 0 0 0 .25cqw #1d214059; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  font: 600 3.6cqw/1 var(--board); letter-spacing: 0; text-shadow: none; }
.cf.f0 { transform: translateZ(3.2cqw); }
.cf.f1 { transform: rotateY(90deg) translateZ(3.2cqw); }
.cf.f2 { transform: rotateX(90deg) translateZ(3.2cqw); }
.cf.f3 { transform: rotateY(180deg) translateZ(3.2cqw); }
.cf.f4 { transform: rotateX(-90deg) translateZ(3.2cqw); }
.cf.f5 { transform: rotateY(-90deg) translateZ(3.2cqw); }
.cf.f1, .cf.f5 { background: #e8eaf3; }
.cf.f2, .cf.f4 { background: #f4f5fa; }

/* ---------- players, above and below the board ---------- */
.bg-p { flex: none; width: min(100% - 12px, 640px); padding: 6px 2px; }
.bp { display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px; border-radius: 12px; border: 1.5px solid transparent; }
.bp.act { border-color: var(--letter); background: #f5f5f214; }
.bp .mface { flex: none; width: 38px; height: 38px; }
.bp.empty .mface:empty { border-radius: 50%; border: 1.5px dashed #f5f5f240; }
.bp .mface img, .bp .mface svg { width: 100%; height: 100%; display: block; }
.bp-t { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.bp-t b { display: flex; align-items: center; gap: 6px; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-t > span { font-size: 13.5px; color: var(--letter-2); }
.bp-ck, .bh-n i, .bi-seat i { flex: none; display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--ck); box-shadow: 0 0 0 1.5px var(--ck-edge); }
.bh-n i, .bi-seat i { width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; }
.bp-sc { flex: none; font-size: 14px; color: var(--letter-2); }
.bp-sc b { font-size: 22px; color: var(--letter); margin-right: 2px; }
.bg-last { flex: none; width: min(100% - 24px, 628px); min-height: 1.4em; font-size: 14px; color: var(--letter-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bg-bar { flex: none; width: min(100% - 24px, 628px); padding-top: 6px; }
.bg-bar .g-hint { min-height: 2.7em; }
.bg-foot { margin: 8px 0 0; font-size: 13.5px; color: var(--letter-2); }
.bg-result { background: var(--card); color: var(--card-ink); border-radius: 4px; padding: 12px 16px; }
.bg-res-head { font-size: 21px; font-weight: 700; line-height: 1.2; }
.bg-res-sub { font-size: 14.5px; color: #5b6079; margin-top: 3px; }

/* ---------- all boards ---------- */
.bh-new { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.bh-q { font-size: 15px; color: var(--letter-2); margin-top: 4px; }
.bh-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.bh-chip { min-height: 40px; padding: 7px 13px; border-radius: 10px; border: 1.5px solid #f5f5f266; background: none; color: var(--letter); font-size: 15.5px; }
.bh-chip.on { background: var(--letter); border-color: var(--letter); color: var(--felt); font-weight: 700; }
.bh-new .btn { margin-top: 6px; }
.bh-n { color: var(--letter); }
.bh-n b { font-weight: 400; color: var(--letter-2); }

/* ---------- the card in the chat: a mini letterboard with a corner of a board and the cube ---------- */
.bg-invite { margin: 16px 0 8px; }
.bi-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; }
.bi-card:disabled { opacity: .6; cursor: default; }
.bi-card:active { transform: translateY(1px); }
.bi-board { position: relative; display: block; padding: 14px 16px 13px; min-height: 76px; }
.bi-board .row1 { display: block; font-size: 28px; }
.bi-board .row2 { display: block; margin-top: 6px; padding-right: 96px; }
.bi-art { position: absolute; right: 12px; top: 8px; width: 88px; height: 60px; }
.bi-art .pa { fill: var(--pt-a); } .bi-art .pb { fill: var(--pt-b); }
.bi-art .k0 { fill: var(--ivory); stroke: var(--ivory-edge); stroke-width: 1.3; }
.bi-art .k1 { fill: var(--rasp); stroke: var(--rasp-edge); stroke-width: 1.3; }
.bi-art .cb { fill: #fff; stroke: #1d214059; }
.bi-art text { font: 600 12px var(--board); fill: #1d2140; text-anchor: middle; letter-spacing: 0; text-shadow: none; }
.bi-seat { white-space: nowrap; }
.bi-seat span { color: var(--ink-2); }
.bi-len { flex: none; font-size: 14px; color: var(--ink-2); }
.bi-card.turn .gi-cta { background: var(--indigo); color: var(--indigo-ink); padding: 6px 12px; border-radius: 10px; }

/* ---------- "your turn" slip: gin's letterboard slip, with the cube instead of a card ---------- */
.gt-cube { position: absolute; right: 20px; top: 50%; width: 34px; height: 34px; margin-top: -17px; display: grid; place-items: center; background: #fff; color: #1d2140; border-radius: 6px; box-shadow: inset 0 0 0 1px #1d214059; transform: rotate(9deg); font: 600 17px/1 var(--board); letter-spacing: 0; text-shadow: none; }
.gin-turn.shake .gt-cube { animation: gt-tap .42s .3s ease-out 1; }

@media (prefers-reduced-motion: reduce) {
  .bg-cube, .cb-in { transition: none; }
  .gin-turn.shake .gt-cube { animation: none; }
}
