/* Card tables — Palace and Spit (server/web/cardTable.js), and their bubbles in a chat (chatGames.js).
 * The cards are inline SVG from server/web/cards/art.mjs; everything is placed by cards/layout.mjs.
 * Motion: a sprite's place is its transform, eased with a little overshoot; pops, flips and
 * wiggles use the separate scale / rotate / translate properties so they never fight the place. */

html.ct-open, html.ct-open body { overflow: hidden; }

.ct-layer {
  position: fixed; inset: 0; z-index: 2400;
  display: flex; flex-direction: column;
  padding: calc(var(--sa-t, env(safe-area-inset-top, 0px)) + 4px) calc(var(--sa-r, env(safe-area-inset-right, 0px)) + 0px) calc(var(--sa-b, env(safe-area-inset-bottom, 0px)) + 6px) calc(var(--sa-l, env(safe-area-inset-left, 0px)) + 0px);
  background:
    radial-gradient(ellipse 90% 55% at 50% 46%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 72%),
    radial-gradient(circle at 12% 8%, color-mix(in srgb, #FF5D8F 12%, transparent), transparent 40%),
    radial-gradient(circle at 92% 96%, color-mix(in srgb, #4D8DFF 12%, transparent), transparent 42%),
    var(--bg);
  color: var(--ink);
  opacity: 0; transform: translateY(14px);
  transition: opacity .2s ease, transform .26s cubic-bezier(.2, 1.2, .4, 1);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
.ct-layer.in { opacity: 1; transform: none; }

.ct-head { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; flex: none; max-width: 640px; width: 100%; margin: 0 auto; box-sizing: border-box; }
.ct-close {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  background: var(--surface-solid, var(--surface)); color: var(--ink); font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: 0 1px 0 var(--border), 0 4px 14px rgba(20, 10, 40, .1);
}
.ct-close:active { scale: .92; }
.ct-title { font-family: var(--font-display, inherit); font-size: 19px; font-weight: 800; letter-spacing: -.3px; flex: 1; min-width: auto; display: flex; align-items: center; gap: 8px; line-height: 1.15; }
/* A narrow phone: the live light keeps its dot and drops its word, so it never lands on the game's name. */
@media (max-width: 359px) { .ct-head { gap: 8px; padding: 0 10px; } .ct-live { font-size: 0; gap: 0; } .ct-title .match-ico, .ct-title .match-ico svg { width: 26px; height: 26px; } }
.ct-live { flex: none; font-size: 11.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; display: inline-flex; align-items: center; gap: 5px; color: var(--ink-muted); }
.ct-live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); }
.ct-live.on { color: var(--success, #1F9D63); }
.ct-live.on::before { background: var(--success, #1F9D63); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success, #1F9D63) 25%, transparent); animation: ct-breathe 2s ease-in-out infinite; }
.ct-live.wait::before { background: #F0A020; }
.ct-end { flex: none; border: 1px solid var(--border); background: transparent; color: var(--ink-muted); border-radius: 999px; padding: 0 13px; height: 32px; font-size: 13px; font-weight: 700; cursor: pointer; }
.ct-end[hidden] { display: none; }
.ct-chat { flex: none; width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border-radius: 14px; border: 1px solid var(--border); border-bottom-width: 3px; background: var(--surface-solid, var(--surface)); color: var(--ink); cursor: pointer; }
.ct-chat:active { transform: translateY(2px); border-bottom-width: 1px; }
.ct-chat svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 32; }

.ct-powers { display: flex; justify-content: center; gap: 6px; flex: none; padding: 0 10px 2px; flex-wrap: nowrap; }
@media (max-width: 359px) {
  .ct-powers { gap: 4px; }
  .ct-power { font-size: 10.5px; padding: 3px 7px; }
  .ct-power::before { content: none !important; }
}
.ct-powers[hidden] { display: none; }
.ct-power { font-size: 11.5px; font-weight: 800; padding: 3px 9px; white-space: nowrap; border-radius: 999px; background: var(--surface-solid, var(--surface)); color: var(--ink-muted); box-shadow: inset 0 0 0 1px var(--border); }
.ct-power.p-2::before { content: '↺ '; color: #4D8DFF; }
.ct-power.p-10::before { content: '🔥 '; }
.ct-power.p-four::before { content: '✦ '; color: #FF5D8F; }

.ct-table { position: relative; flex: 1; min-height: 0; width: 100%; max-width: 560px; margin: 0 auto; }
.ct-sprites, .ct-chrome { position: absolute; inset: 0; }
.ct-chrome { pointer-events: none; }
.ct-chrome > * { pointer-events: auto; }
.ct-chrome .ct-chip, .ct-chrome .ct-badge, .ct-chrome .ct-count, .ct-chrome .ct-burned, .ct-chrome .ct-slot { pointer-events: none; }
.ct-chrome { z-index: 1; }
.ct-sprites { z-index: 2; pointer-events: none; }

/* ---- a card */
.ct-card {
  position: absolute; left: 0; top: 0; pointer-events: auto;
  border-radius: 11% / 7.86%;
  transition: transform .44s cubic-bezier(.2, 1.28, .36, 1), opacity .3s ease, box-shadow .2s ease, filter .2s ease;
  filter: drop-shadow(0 2px 3px rgba(26, 16, 48, .22));
  will-change: transform;
}
.ct-card svg { display: block; width: 100%; height: 100%; }
.ct-card.tap { cursor: pointer; }
.ct-card.lit { box-shadow: 0 0 0 2.5px #FFC93C, 0 0 14px rgba(255, 186, 40, .55); }
.ct-card.up { filter: drop-shadow(0 10px 14px rgba(26, 16, 48, .3)); }
.ct-card.dim { filter: drop-shadow(0 2px 3px rgba(26, 16, 48, .18)) saturate(.55) brightness(.9); }
.ct-card.dragging { cursor: grabbing; filter: drop-shadow(0 16px 22px rgba(26, 16, 48, .35)); transition: none; }
.ct-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.ct-card.pop { animation: ct-pop .42s cubic-bezier(.2, 1.5, .4, 1); }
.ct-card.flip { animation: ct-flip .34s ease-out; }
.ct-card.nope { animation: ct-nope .42s ease; }
.ct-card.leaving { opacity: 0; }
.ct-card.burning { opacity: 0; scale: .5; filter: drop-shadow(0 0 12px #FF7A1A) saturate(1.6); transition: transform .5s ease-in, opacity .5s ease-in, scale .5s ease-in; }

/* ---- names, counts, places */
.ct-chip { position: absolute; height: 30px; display: flex; align-items: center; justify-content: center; }
.ct-chip.left { justify-content: flex-start; }
.ct-chip-in {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; box-sizing: border-box;
  height: 30px; padding: 0 11px 0 3px; border-radius: 999px;
  background: var(--surface-solid, var(--surface)); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--seat) 55%, var(--border)), 0 3px 10px rgba(26, 16, 48, .08);
  font-size: 13px; white-space: nowrap; overflow: hidden;
}
.ct-chip-in > span:first-child { flex: none; }
.ct-chip-in b { font-weight: 800; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ct-chip.narrow .ct-chip-in { padding-right: 8px; gap: 5px; }
.ct-chip.tiny .ct-chip-in { padding-left: 9px; }
.ct-chip.narrow .ct-chip-n { background: var(--ink); color: var(--bg); border-radius: 999px; padding: 0 6px; line-height: 18px; font-size: 11px; }
.ct-chip-n { color: var(--ink-muted); font-weight: 700; font-size: 12px; flex: none; font-variant-numeric: tabular-nums; }
.ct-chip.turn .ct-chip-in { box-shadow: inset 0 0 0 2.5px var(--seat), 0 0 0 4px color-mix(in srgb, var(--seat) 22%, transparent); animation: ct-turn 1.6s ease-in-out infinite; }
.ct-chip.won .ct-chip-in { box-shadow: inset 0 0 0 2.5px #F5B400, 0 0 0 4px rgba(245, 180, 0, .25); }
.ct-here { width: 7px; height: 7px; border-radius: 50%; background: var(--success, #1F9D63); flex: none; }

.ct-badge {
  position: absolute; translate: -50% 5px; min-width: 22px; height: 20px; padding: 0 7px; box-sizing: border-box; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-size: 11.5px; font-weight: 800; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.ct-count { position: absolute; text-align: center; font-size: 12.5px; font-weight: 800; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.ct-count.big { font-size: 16px; color: var(--ink); translate: 0 12px; }
.ct-burned { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 0; font-size: 18px; line-height: 1; }
.ct-burned b { font-size: 12px; font-weight: 800; color: var(--ink-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.ct-slot { position: absolute; box-sizing: border-box; border-radius: 11% / 7.86%; border: 2px dashed color-mix(in srgb, var(--ink) 22%, transparent); }
.ct-target { position: absolute; background: transparent; border: 0; padding: 0; border-radius: 18px; cursor: default; }
.ct-target.slap { cursor: pointer; z-index: 5; box-shadow: 0 0 0 3px #FF5D8F, 0 0 0 9px rgba(255, 93, 143, .22); animation: ct-slap 0.9s ease-in-out infinite; }
.ct-target.slap span { position: absolute; left: 50%; top: -14px; translate: -50% 0; background: #FF5D8F; color: #fff; font-weight: 900; font-size: 13px; letter-spacing: 1px; padding: 3px 10px; border-radius: 999px; }

/* ---- the line, and its button — my buddy says it */
.ct-status { position: absolute; display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 3; }
.ct-me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ct-me > span:first-child { flex: none; }
.ct-status-text { font-size: 16px; line-height: 1.2; font-weight: 800; letter-spacing: -.2px; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.ct-status-text.mine { color: var(--accent); }
@media (max-width: 359px) { .ct-status-text { font-size: 15px; } .ct-btn { padding: 0 16px; } }
.ct-status-text.wait { color: var(--ink-muted); }
.ct-actions { display: flex; gap: 8px; flex: none; }
.ct-btn {
  height: 42px; padding: 0 20px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent, #fff); font-size: 15px; font-weight: 800;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: scale .15s cubic-bezier(.2, 1.5, .4, 1);
}
.ct-btn:active { scale: .94; }
.ct-btn:disabled { opacity: .45; box-shadow: none; cursor: default; }
.ct-btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--border); }

/* ---- the flash: Burn!, Reset, Spit!, Too slow! */
.ct-flash { position: absolute; z-index: 6; display: flex; justify-content: center; pointer-events: none; opacity: 0; --fl: var(--accent); --fl-ink: #fff; }
.ct-flash.show { opacity: 1; animation: ct-flash 1.5s cubic-bezier(.2, 1.4, .4, 1) both; }
.ct-flash span {
  background: var(--fl); color: var(--fl-ink); padding: 9px 18px; border-radius: 999px; white-space: nowrap;
  font-size: 19px; font-weight: 900; letter-spacing: -.2px; line-height: 1.2;
  box-shadow: 0 10px 24px rgba(26, 16, 48, .25);
}
.ct-flash.k-burn { --fl: linear-gradient(135deg, #FF7A1A, #FF3D6E); }
.ct-flash.k-reset { --fl: #4D8DFF; }
.ct-flash.k-pickup, .ct-flash.k-out, .ct-flash.k-begin { --fl: var(--ink); --fl-ink: var(--bg); }
.ct-flash.k-spit { --fl: linear-gradient(135deg, #8A5CFF, #FF5D8F); }
.ct-flash.k-slap, .ct-flash.k-slapnow { --fl: #FF5D8F; }
.ct-flash.k-nope { --fl: var(--danger, #E5484D); animation-duration: .9s; }
.ct-flash.k-nope span { font-size: 15px; padding: 7px 14px; }

/* ---- Spit's countdown */
.ct-countdown { position: absolute; z-index: 7; display: none; align-items: center; justify-content: center; pointer-events: none; font-family: var(--font-display, inherit); font-size: 104px; font-weight: 900; color: var(--accent); text-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 30%, transparent), 0 14px 30px rgba(26, 16, 48, .25); }
.ct-countdown.show { display: flex; }
.ct-countdown.beat { animation: ct-beat .9s cubic-bezier(.2, 1.5, .4, 1); }

@keyframes ct-pop { 0% { scale: .6; opacity: 0; } 100% { scale: 1; opacity: 1; } }
@keyframes ct-flip { 0% { rotate: y 90deg; } 100% { rotate: y 0deg; } }
@keyframes ct-nope { 0%, 100% { translate: 0 0; } 18% { translate: -9px 0; } 36% { translate: 8px 0; } 54% { translate: -6px 0; } 72% { translate: 4px 0; } }
@keyframes ct-flash { 0% { scale: .5; opacity: 0; } 14% { scale: 1.08; opacity: 1; } 24% { scale: 1; } 80% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: .96; translate: 0 -10px; } }
@keyframes ct-beat { 0% { scale: 1.7; opacity: 0; } 30% { scale: 1; opacity: 1; } 100% { scale: .92; opacity: .9; } }
@keyframes ct-turn { 0%, 100% { scale: 1; } 50% { scale: 1.035; } }
@keyframes ct-slap { 0%, 100% { scale: 1; } 50% { scale: 1.04; } }
@keyframes ct-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

@media (prefers-reduced-motion: reduce) {
  .ct-card, .ct-layer { transition: none; }
  .ct-card.pop, .ct-card.flip, .ct-card.nope, .ct-chip.turn .ct-chip-in, .ct-target.slap, .ct-live.on::before, .ct-countdown.beat { animation: none; }
}

/* ---- the bubble in a chat: a card game is a tile you open */
.cg-bubble { display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 0; }
.cg-top { display: flex; align-items: center; gap: 12px; }
.cg-art { position: relative; width: 96px; height: 72px; flex: none; margin-left: 6px; }
.cg-art .cg-c { position: absolute; top: 4px; width: 44px; height: 62px; transform-origin: 50% 110%; filter: drop-shadow(0 2px 3px rgba(26, 16, 48, .22)); }
.cg-art .cg-c svg { display: block; width: 100%; height: 100%; }
.cg-art .cg-c:nth-child(1) { left: 6px; rotate: -14deg; }
.cg-art .cg-c:nth-child(2) { left: 24px; rotate: 0deg; top: 1px; }
.cg-art .cg-c:nth-child(3) { left: 42px; rotate: 14deg; }
.cg-who { display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; flex: 1; }
.cg-who span { color: var(--ink); font-size: 12.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--seat, var(--accent)) 14%, var(--surface-solid, var(--surface))); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--seat, var(--accent)) 50%, transparent); max-width: 100%; overflow-wrap: anywhere; }
.cg-who span.turn { box-shadow: inset 0 0 0 2.5px var(--seat, var(--accent)); }
.cg-open { align-self: stretch; height: 42px; border: 0; border-radius: 14px; background: var(--accent); color: var(--on-accent, #fff); font-size: 15px; font-weight: 800; cursor: pointer; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 30%, transparent); }
.cg-open:active { scale: .97; }
.cg-open.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--border); }

/* the games rail's mini art for the card games */
.mini-cards { position: relative; width: 96px; height: 72px; }
.mini-cards .cg-c { position: absolute; top: 6px; width: 42px; height: 59px; transform-origin: 50% 110%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .3)); }
.mini-cards .cg-c svg { display: block; width: 100%; height: 100%; }
.mini-cards .cg-c:nth-child(1) { left: 8px; rotate: -16deg; }
.mini-cards .cg-c:nth-child(2) { left: 27px; top: 2px; }
.mini-cards .cg-c:nth-child(3) { left: 46px; rotate: 16deg; }

/* ---- the end of a game: the buddy, who won, Play again */
.ct-endcard {
  position: absolute; z-index: 8; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 16px 16px 14px; border-radius: 22px; background: var(--surface-solid, var(--surface));
  box-shadow: 0 0 0 1px var(--border), 0 18px 40px rgba(26, 16, 48, .28);
}
.ct-endcard[hidden] { display: none; }
.ct-endcard.in { animation: ct-endin .55s cubic-bezier(.2, 1.4, .4, 1) both; }
.ct-endcard.won { box-shadow: 0 0 0 2.5px #FFC93C, 0 18px 40px rgba(255, 170, 30, .3); }
.ct-end-title { font-family: var(--font-display, inherit); font-size: 22px; font-weight: 900; letter-spacing: -.4px; margin-top: 4px; max-width: 100%; overflow-wrap: anywhere; }
.ct-end-line { font-size: 14px; font-weight: 600; color: var(--ink-muted); max-width: 100%; overflow-wrap: anywhere; }
.ct-end-btns { display: flex; gap: 8px; margin-top: 10px; width: 100%; }
.ct-end-btns .ct-btn { flex: 1; padding: 0 12px; }
@keyframes ct-endin { 0% { scale: .6; opacity: 0; } 100% { scale: 1; opacity: 1; } }

/* the finished tile: its two buttons side by side */
.cg-btns { display: flex; gap: 8px; }
.cg-btns .cg-open { flex: 1; }
/* the rail's cards hold their picture across the whole card (a button left-aligns its content) */
.game-cardlet { align-items: stretch; }
