/* One back per real card; crowded hands overlap without replacing cards by a count. */
.physical-hand { --back-width: 42px; position: relative; display: block; width: 100%; height: calc(var(--back-width) * 1.42 + 8px); }
.physical-hand > .card-back {
  position: absolute; display: block; top: 4px;
  left: calc(50% + (var(--back-position) - .5) * min(100% - var(--back-width) - 12px, (var(--back-count) - 1) * var(--back-width) * .72));
  width: var(--back-width); height: auto; aspect-ratio: 110 / 156; margin: 0;
  transform: translateX(-50%) rotate(var(--back-angle)); transform-origin: center;
  border-radius: 4px; box-shadow: 0 1px 0 #132c24;
}
/* Seats sit outside the playing surface. Only the inward tips need to fit. */
body[data-screen="game"] .table-game .game:has(> .opponents:not(:empty)) {
  --seat-reveal: 34px; --seat-fan: clamp(110px, 18cqw, 190px); --seat-depth: 68px;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  gap: 0; padding: 58px 44px 0;
}
body[data-screen="game"] .table-game .game > .opponents {
  display: block; position: absolute; inset: 0; height: auto; min-height: 0; padding: 0; margin: 0;
  overflow: hidden; pointer-events: none; z-index: 4;
}
body[data-screen="game"] .table-game .opponents .opponent {
  position: absolute; display: block; width: var(--seat-fan); height: var(--seat-depth);
  padding: 0; margin: 0; border: 0; opacity: 1; min-width: 0;
}
body[data-screen="game"] .table-game .opponent[data-edge="top"] { left: var(--seat-position); top: 0; transform: translateX(-50%); }
body[data-screen="game"] .table-game .opponent[data-edge="left"] { left: 0; top: var(--seat-position); transform: translateY(-50%); width: var(--seat-depth); height: var(--seat-fan); }
body[data-screen="game"] .table-game .opponent[data-edge="right"] { right: 0; top: var(--seat-position); transform: translateY(-50%); width: var(--seat-depth); height: var(--seat-fan); }
body[data-screen="game"] .table-game .opponents .mini-hand {
  display: block; position: absolute; width: var(--seat-fan); height: var(--seat-depth); margin: 0;
  --back-width: 42px;
}
body[data-screen="game"] .table-game .opponent[data-edge="top"] .mini-hand { left: 0; top: calc(var(--seat-reveal) - var(--seat-depth)); transform: rotate(180deg); }
body[data-screen="game"] .table-game .opponent[data-edge="left"] .mini-hand { left: var(--seat-reveal); top: 50%; transform: translate(-50%, -50%) rotate(90deg) translateY(50%); }
body[data-screen="game"] .table-game .opponent[data-edge="right"] .mini-hand { right: var(--seat-reveal); top: 50%; transform: translate(50%, -50%) rotate(-90deg) translateY(50%); }
body[data-screen="game"] .table-game .opponents .opponent .avatar {
  position: absolute; display: grid; place-items: center; width: 22px; height: 24px; font-size: 16px;
  border-width: 1px; box-shadow: none; z-index: 1;
}
body[data-screen="game"] .table-game .opponents .opponent-detail { position: absolute; display: block; font-size: 14px; line-height: 22px; color: var(--pop-paper); white-space: nowrap; max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
body[data-screen="game"] .table-game .opponent[data-edge="top"] .avatar { top: calc(var(--seat-reveal) + 3px); left: calc(50% - 32px); }
body[data-screen="game"] .table-game .opponent[data-edge="top"] .opponent-detail { top: calc(var(--seat-reveal) + 3px); left: calc(50% - 6px); }
body[data-screen="game"] .table-game .opponent[data-edge="left"] .avatar { left: 3px; top: -26px; }
body[data-screen="game"] .table-game .opponent[data-edge="left"] .opponent-detail { left: 29px; top: -26px; }
body[data-screen="game"] .table-game .opponent[data-edge="right"] .avatar { right: 3px; bottom: -26px; }
body[data-screen="game"] .table-game .opponent[data-edge="right"] .opponent-detail { right: 29px; bottom: -26px; }
body[data-screen="game"] .table-game .opponents .opponent:is([data-turn="true"], .moving) .opponent-detail { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
body[data-screen="game"] .table-game .opponent[data-turn="true"] .mini-hand { filter: drop-shadow(0 0 5px #f3d685); }
body[data-screen="game"] .table-game[data-viewer-turn="true"] :is(.controller .hand, [data-personal-stack]) { filter: drop-shadow(0 0 5px #f3d685); }
body[data-screen="game"] .table-game .game > #foundations { grid-row: 1; }
body[data-screen="game"] .table-game .game:has(> .opponents:not(:empty)):not(:has(.opponent[data-edge="top"])) { padding-top: 8px; }
/* Public melds and scoreboards are separate from the seated private hands. */
body[data-screen="game"] .table-game[data-visual-explained="true"] .table-announcement[data-kind="event"] { width: 1px; height: 1px; min-height: 0; padding: 0; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
.continental-player-count { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.continental-player-name .physical-hand { --back-width: 28px; width: 72px; height: 18px; flex: none; overflow: hidden; }
.continental-player[data-human="true"] .physical-hand { display: none; }
.burro-score { grid-template-rows: 18px 20px 18px 16px; }
.burro-score .physical-hand { --back-width: 22px; height: 16px; overflow: hidden; }
.table-game .burro-table { max-height: 365px; }
.motion-back { position: fixed; z-index: 1000; width: 44px; height: 62px; margin: 0; pointer-events: none; }
.game-mona .mona-fan.physical-hand { --back-width: 52px; width: min(220px, 100%); min-height: 84px; }
.game-mona .mona-fan.physical-hand > .card-back { position: absolute; width: var(--back-width); height: auto; margin: 0; transform: translateX(-50%) rotate(var(--back-angle)); }
@media (min-width: 1100px) and (min-height: 650px) {
  body[data-screen="game"] .table-game .game:has(> .opponents:not(:empty)) {
    --seat-reveal: 68px; padding: 96px 78px 0;
  }
  body[data-screen="game"] .table-game .game:has(> .opponents:not(:empty)):not(:has(.opponent[data-edge="top"])) { padding-top: 8px; }
}
@media (max-width: 700px), (max-height: 500px) {
  .continental-player-name .physical-hand { width: 46px; height: 14px; --back-width: 24px; }
  body[data-screen="game"] .table-game .game:has(> .opponents:not(:empty)) {
    --seat-reveal: 17px; --seat-fan: 112px; padding: 40px 19px 0;
  }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] { --seat-fan: 66px; }
  body[data-screen="game"] .table-game .opponent[data-edge="top"] { --seat-fan: min(112px, 27cqw); }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="top"] { --seat-fan: min(66px, 22cqw); }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .mini-hand { --back-width: 34px; }
  body[data-screen="game"] .table-game .opponents .opponent-detail { font-size: 12px; }
  body[data-screen="game"] .table-game .opponents .opponent .avatar { width: 18px; height: 21px; font-size: 14px; }
  body[data-screen="game"] .table-game .opponent[data-edge="left"] .opponent-detail { left: 24px; }
  body[data-screen="game"] .table-game .opponent[data-edge="right"] .opponent-detail { right: 24px; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="left"] :is(.avatar, .opponent-detail) { top: calc(50% - 11px); }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="right"] :is(.avatar, .opponent-detail) { bottom: calc(50% - 11px); }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="left"] .avatar { left: 19px; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="left"] .opponent-detail { left: 40px; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="right"] .avatar { right: 19px; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="right"] .opponent-detail { right: 40px; }
}
@media (max-height: 650px) {
  .burro-score { grid-template-rows: 14px 17px 12px 12px; }
  .burro-score .physical-hand { height: 12px; }
  .table-game .burro-table { grid-template-rows: 18px minmax(112px, 1fr) 48px 30px; }
}
@media (max-height: 500px) {
}

/* Offer the real seat fan; other games opt in through GameViewPresentation.handDraw. */
body[data-screen="game"] .table-game .opponents .mini-hand { transition: top 240ms ease, left 240ms ease, right 240ms ease; }
body[data-screen="game"] .table-game .opponents .opponent.hand-offered {
  --seat-reveal: 110px; --seat-depth: 110px; --seat-fan: min(240px, 66cqw, 72cqh); z-index: 10;
}
body[data-screen="game"] .table-game .opponents .hand-offered .mini-hand { --back-width: clamp(54px, 18cqw, 78px); }
body[data-screen="game"] .table-game .opponent.hand-offered[data-edge="top"] {
  left: clamp(calc(var(--seat-fan) / 2 + 5px), var(--seat-position), calc(100% - var(--seat-fan) / 2 - 5px));
}
body[data-screen="game"] .table-game .hand-offered .card-back {
  pointer-events: auto; padding: 0; border: 0; opacity: 1; cursor: pointer;
}
body[data-screen="game"] .table-game .hand-offered .card-back:disabled { cursor: default; }
body[data-screen="game"] .table-game .hand-offered .card-back:focus-visible { outline: 3px solid var(--pop-paper); outline-offset: 3px; }
body[data-screen="game"] .table-game #hand { transition: translate 240ms ease; }
body[data-screen="game"] .table-game #hand.hand-offered { translate: 0 -55px; }
@media (prefers-reduced-motion: reduce) {
  body[data-screen="game"] .table-game .opponents .mini-hand,
  body[data-screen="game"] .table-game #hand { transition: none; }
}


/* A blind personal stack still has one anonymous back per card. */
.physical-hand.physical-stack > .card-back {
  left: calc(50% + var(--back-position) * var(--stack-depth));
  top: calc(4px - var(--back-position) * var(--stack-depth));
  transform: translateX(-50%);
}
body[data-screen="game"] .table-game .opponent:has(.physical-stack) { --seat-fan: 76px; }
@media (max-width: 700px), (max-height: 500px) {
  body[data-screen="game"] .table-game .opponent:has(.physical-stack) { --seat-reveal: 32px; --seat-depth: 52px; --seat-fan: 66px; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent:is([data-edge="left"], [data-edge="right"]) .opponent-detail {
    max-width: 38px; font-size: 11px; line-height: 14px; top: calc(50% - 36px); bottom: auto;
  }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="left"] .opponent-detail { left: 0; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent[data-edge="right"] .opponent-detail { right: 0; }
  body[data-screen="game"] .table-game .opponents[data-crowded="true"] .opponent:is([data-edge="left"], [data-edge="right"]) .avatar { display: none; }
}
