* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #150329 0%, #2c0a4a 34%, #5b1560 58%, #a8326e 76%, #1a0533 100%);
  background-attachment: fixed;
  color: #f2f2f2;
  min-height: 100vh;
  overflow-x: hidden;
}
button {
  cursor: pointer;
  border: 1px solid #7b5cf0;
  background: #2d1b5e;
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 1rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover { background: #3d2580; }
button:focus-visible { outline: 2px solid #ffd970; outline-offset: 2px; }
input[type="text"], select {
  background: #1e0f3d;
  color: #fff;
  border: 1px solid #7b5cf0;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 1rem;
}
input[type="range"] { flex: 1; }

#tableWrap { max-width: 1080px; margin: 0 auto; padding: 0 8px 16px; position: relative; z-index: 1; }

/* Top bar: corner icon buttons like the reference, meta in the middle. */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
}
.icons { display: flex; gap: 8px; }
.icons button {
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 1.4rem;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
}
.icons button:hover { background: rgba(0, 0, 0, 0.8); }
.icons button.on { outline: 2px solid #ffd970; background: rgba(255, 217, 112, 0.25); }
#matchMeta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.95rem;
  color: #d8ccf5;
}
#matchMeta b { color: #ffd970; }

/* The felt table. */
.table {
  display: grid;
  grid-template-areas:
    "top top top"
    "left center right"
    "bottom bottom bottom"
    "fan fan fan";
  grid-template-columns: 1fr 2fr 1fr;
  gap: 4px 8px;
  padding: 12px 16px 8px;
  position: relative;
  background:
    radial-gradient(rgba(0, 0, 0, 0.08) 1px, transparent 1.5px),
    radial-gradient(ellipse at center, #4169e1 0%, #2b4cb0 45%, #1d357e 75%, #14245c 100%);
  background-size: 5px 5px, auto;
  border: 20px solid #2a160e;
  border-radius: 32px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), inset 0 0 60px rgba(0, 0, 0, 0.45), 0 0 32px rgba(255, 217, 112, 0.25), inset 0 0 0 2px rgba(255, 215, 112, 0.85);
  transform: perspective(1600px) rotateX(1.5deg);
}
.table > * { position: relative; z-index: 1; }
.table::before {
  content: "";
  position: absolute;
  inset: 16px;
  border: 2px solid rgba(255, 215, 112, 0.55);
  border-radius: 20px;
  pointer-events: none;
  z-index: 0;
}
.table::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 220px;
  height: 220px;
  transform: translate(-50%, -50%);
  background-image: url('spades-logo.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.16;
  pointer-events: none;
  z-index: 0;
}
.player-panel { text-align: center; padding: 4px; border-radius: 12px; position: relative; }
.player-panel.top { grid-area: top; }
.player-panel.left { grid-area: left; align-self: center; }
.player-panel.right { grid-area: right; align-self: center; }
.player-panel.bottom { grid-area: bottom; }
.player-panel.active { outline: 2px solid #ffd970; background: rgba(255, 217, 112, 0.12); }
.player-info {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.turn-arrow { color: #ffd970; min-width: 1em; }
.pname { font-size: 1.05rem; }
.heart { color: #ff6a6a; }
.heart b { color: #fff; margin-left: 2px; }
.pbid { color: #ffd970; min-height: 1.2em; }

/* Fanned card backs for bots. */
.fan { position: relative; margin: 0 auto; }
.fan.backs-h { height: 185px; width: 320px; }
.fan.backs-v { width: 120px; height: 252px; }
.fan-back { position: absolute; left: 50%; top: 0; }

/* Your hand: a curved fan at the bottom of the table. */
.fan-hand {
  grid-area: fan;
  position: relative;
  height: 150px;
  --fan-step: 34px;
  margin-top: 2px;
}
.fan-card { position: absolute; left: 50%; bottom: 4px; perspective: 900px; }

/* Cards. */
.card {
  width: 76px;
  height: 108px;
  border-radius: 10px;
  border: 1px solid #888;
  background: linear-gradient(160deg, #ffffff 0%, #f2f2f2 100%);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
  font-family: Georgia, 'Times New Roman', serif;
}
.card.red { color: #c00; }
.card .pip { font-size: 2.4rem; line-height: 1; }
.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-size: 0.95rem;
}
.card .corner b { font-size: 1.05rem; }
.card .corner.tl { top: 7px; left: 8px; }
.card .corner.br { bottom: 7px; right: 8px; transform: rotate(180deg); }
.fan-hand .card { width: 92px; height: 128px; transform: rotateX(16deg); transform-origin: bottom center; }
.fan-hand .card .pip { font-size: 3rem; }
.fan-hand .card .corner { font-size: 1.05rem; }
.fan-hand .card .corner b { font-size: 1.2rem; }
.fan-hand .card.playable { cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.fan-hand .card.playable:hover { transform: translateY(-12px) rotateX(8deg); box-shadow: 0 12px 20px rgba(0, 0, 0, 0.55), 0 0 18px rgba(255, 217, 112, 0.6); }
.fan-hand .card.selected { transform: translateY(-18px) scale(1.03) rotateX(6deg); outline: 3px solid #ffd970; box-shadow: 0 14px 22px rgba(0, 0, 0, 0.6); }
.card.back {
  width: 104px;
  height: 144px;
  background: linear-gradient(160deg, #2b5cb8 0%, #1d3f80 55%, #142c5c 100%);
  color: #fff;
  font-size: 0.9rem;
  border-color: #dfe8ff;
}
.card.back img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 20px;
  display: block;
}
.card.disabled { opacity: 0.35; }

/* Center: played cards positioned by seat, like the reference. */
.center { grid-area: center; text-align: center; }
#trickArea { position: relative; min-height: 150px; }
.played { position: absolute; left: 50%; top: 50%; }
.played .card { animation: cardFlipIn 0.35s ease-out; }
.played.seat-0 { transform: translate(-50%, -8%); }
.played.seat-1 { transform: translate(18%, -50%) rotate(4deg); }
.played.seat-2 { transform: translate(-50%, -92%) rotate(-2deg); }
.played.seat-3 { transform: translate(-118%, -50%) rotate(-4deg); }
@keyframes cardFlipIn {
  from { transform: perspective(700px) rotateY(75deg) scale(0.85); opacity: 0; }
  to { transform: perspective(700px) rotateY(0deg) scale(1); opacity: 1; }
}
.played .card { width: 84px; height: 116px; }
.played-who { font-size: 0.85rem; color: #e6f4ea; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
#statusLine { margin-top: 6px; color: #e6f4ea; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
#captionBar {
  min-height: 1.5em;
  margin-top: 4px;
  font-style: italic;
  color: #ffd970;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

#readyBar {
  text-align: center;
  padding: 14px;
  background: #ffd970;
  color: #123524;
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: 12px;
  margin-top: 10px;
}
#readyBar button { background: #123524; border-color: #123524; margin-left: 14px; font-weight: 700; }
#readyBar button:hover { background: #1d4a2e; }
#bidBar { text-align: center; padding: 10px; background: rgba(0, 0, 0, 0.3); border-radius: 12px; margin-top: 10px; }
#bidButtons { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-left: 8px; }
#bidButtons button { min-width: 44px; min-height: 44px; }
#betButtons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
#dailyBox { margin: 10px 0; }
#betButtons button.bet-on { outline: 3px solid #ffd970; }
#betButtons button:disabled { opacity: 0.45; }
#hint { color: #d8ccf5; min-height: 1.2em; text-align: center; }
#bagsLine { color: #b9a8e8; text-align: center; font-size: 0.95rem; margin: 2px 0; }
#errorLine { color: #ff9a8a; text-align: center; min-height: 1.2em; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 12px;
  overflow-y: auto;
}
.panel {
  background: #22124a;
  border: 1px solid #7b5cf0;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}
.panel.settings { max-width: 560px; text-align: left; max-height: 92vh; overflow-y: auto; }
.panel.settings h2, .panel.settings h3 { text-align: center; }
.panel .row { display: flex; gap: 10px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.panel .note { color: #b9a8e8; font-size: 0.9rem; }
#devPreviewList { display: flex; flex-wrap: wrap; gap: 6px; }
#devPreviewList button { font-size: 0.85rem; padding: 6px 8px; }
#devPreviewList button:disabled { opacity: 0.45; cursor: default; }
.hidden { display: none !important; }

/* Lobby: seat rows and hand-count picker. */
#lobbySeats { margin: 12px 0; }
.lobby-seat { padding: 6px; font-size: 1.1rem; }
#handCountButtons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
#handCountButtons button.picked { outline: 3px solid #ffd970; }
#lobbyHub button, #spadesLobby button, #dominoesLobby button { margin: 4px; }

/* Dominoes table. */
#dominoWrap { max-width: 1080px; margin: 0 auto; padding: 12px; }
#dominoTopbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
#dominoTopbar h2 { flex: 1; text-align: center; margin: 0; }
#dominoScores { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.domino-score.active { outline: 2px solid #ffd970; border-radius: 6px; padding: 2px 6px; }
#dominoBoard { display: flex; flex-wrap: wrap; gap: 6px; min-height: 120px; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.25); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
#dominoHand { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
#dominoStatus { text-align: center; }
#dominoEndButtons { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.domino { display: flex; background: #fdf6e3; color: #111; border: 2px solid #333; border-radius: 8px; font-weight: bold; padding: 0; }
.domino .half { display: flex; align-items: center; justify-content: center; }
.domino.hand { flex-direction: column; width: 56px; cursor: pointer; }
.domino.hand .half { padding: 10px 4px; font-size: 1.4rem; }
.domino.hand .half + .half { border-top: 2px solid #333; }
.domino.board { flex-direction: row; }
.domino.board .half { padding: 8px 10px; font-size: 1.2rem; }
.domino.board .half + .half { border-left: 2px solid #333; }
.domino.selected { outline: 3px solid #ffd970; transform: translateY(-6px); }
footer { text-align: center; color: #b9a8e8; padding: 12px; font-size: 0.9rem; line-height: 1.5; position: relative; z-index: 1; }

@media (max-width: 640px) {
  .fan-hand { height: 112px; --fan-step: 24px; }
  .fan-hand .card { width: 64px; height: 90px; }
  .fan-hand .card .pip { font-size: 2rem; }
  .played .card { width: 62px; height: 88px; }
  .table { border-width: 14px; border-radius: 24px; }
  .table::before { inset: 10px; }
  .table::after { width: 150px; height: 150px; }
  #trickArea { min-height: 120px; }
  .table { border-width: 6px; border-radius: 18px; padding: 8px; }
  #matchMeta { font-size: 0.85rem; gap: 8px; }
  .icons button { width: 42px; height: 42px; }
}
@media (max-width: 420px) {
  .fan-hand { --fan-step: 19px; height: 102px; }
  .fan-hand .card { width: 56px; height: 80px; }
  .fan-hand .card .pip { font-size: 1.7rem; }
  .pname { font-size: 0.95rem; }
}

/* Chicago skyline photo behind the table (embedded in the bundle). */
#citySky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(10, 2, 30, 0.15), rgba(10, 2, 30, 0.45)),
    url('city-background.jpg');
  background-size: cover;
  background-position: center bottom;
}

/* Player avatars: emoji for every seat; your photo wins for your seat. */
.avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 2.4rem;
  color: #fff;
  border: 4px solid #ffd970;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Emoji avatar pickers in Settings. */
.emoji-pick { margin: 8px 0; }
.emoji-pick > span { display: block; margin-bottom: 4px; font-size: 0.9rem; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick-btn { font-size: 1.5rem; padding: 4px 6px; border-radius: 10px; border: 2px solid transparent; background: rgba(255, 255, 255, 0.08); cursor: pointer; line-height: 1; }
.emoji-pick-btn.on { border-color: #ffd970; background: rgba(255, 217, 112, 0.2); }

/* Cut/set effects: cartoon knife pop-up on cuts, gun blast on sets. */
.cut-pop {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: clamp(3.5rem, 14vw, 6.5rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
  z-index: 5;
  pointer-events: none;
  animation: cutPop 1.4s ease-out forwards;
}
@keyframes cutPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-20deg); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.3) rotate(8deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
/* Shooting overlay: a gun that actually fires across the screen on sets. */
.gun-shoot-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  overflow: hidden;
}
.gun-shoot-gun {
  position: absolute;
  left: 4%;
  top: 42%;
  width: auto;
  height: clamp(220px, 45vh, 360px);
  animation: gunKick 0.9s ease-out;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
}
.gun-shoot-gun img {
  display: block;
  height: 100%;
  width: auto;
}
@keyframes gunKick {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  10% { transform: translateX(-10px) rotate(-6deg); }
  25% { transform: translateX(0) rotate(0deg); }
  40% { transform: translateX(-10px) rotate(-6deg); }
  55% { transform: translateX(0) rotate(0deg); }
  70% { transform: translateX(-10px) rotate(-6deg); }
  85% { transform: translateX(0) rotate(0deg); }
}
.gun-bullet {
  position: absolute;
  width: 26px;
  height: 7px;
  border-radius: 4px;
  background: #ffd970;
  box-shadow: 0 0 12px 3px rgba(255, 217, 112, 0.9);
  animation: bulletFly 0.55s linear backwards;
}
@keyframes bulletFly {
  from { left: var(--muzzle, 18%); opacity: 1; }
  to { left: 96%; opacity: 0; }
}
.gun-impact {
  position: absolute;
  right: 2%;
  font-size: clamp(3rem, 12vw, 6rem);
  opacity: 0;
  animation: impactPop 0.5s ease-out forwards;
}
@keyframes impactPop {
  0% { opacity: 0; transform: scale(0.4); }
  20% { opacity: 1; transform: scale(1.3); }
  100% { opacity: 0; transform: scale(1); }
}
body.screen-shake { animation: gunShake 0.6s ease-in-out; }

/* Slam hand: a hand slamming the winning card down hard. */
.slam-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}
.slam-hand-wrap {
  position: absolute;
  left: 50%;
  top: 38%;
  text-align: center;
  animation: slamDown 0.5s cubic-bezier(0.15, 0.85, 0.35, 1) forwards;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.55));
}
@keyframes slamDown {
  0% { transform: translate(-50%, -70vh) rotate(-14deg) scale(1.15); opacity: 0; }
  10% { opacity: 1; }
  70% { transform: translate(-50%, 0) rotate(2deg) scale(1.04); }
  85% { transform: translate(-50%, -12px) rotate(0deg) scale(0.99); }
  100% { transform: translate(-50%, 0) rotate(0deg) scale(1); }
}
.slam-hand {
  font-size: clamp(4rem, 14vw, 7rem);
  line-height: 1;
  margin-bottom: -12px;
  position: relative;
  z-index: 1;
}
.slam-card .card { width: 92px; height: 128px; margin: 0 auto; }
.slam-impact {
  position: absolute;
  left: 50%;
  top: 52%;
  font-size: clamp(3rem, 12vw, 6rem);
  opacity: 0;
  animation: slamImpactPop 0.5s ease-out 0.32s forwards;
}
@keyframes slamImpactPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
/* Gold particle burst for very nice plays. */
.burst-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}
.burst-bit {
  position: absolute;
  left: 50%;
  top: 42%;
  font-size: 1.6rem;
  color: #ffd970;
  opacity: 0;
  animation: burstFloat 1s ease-out forwards;
}
@keyframes burstFloat {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -80px))) scale(1.2); }
}
@keyframes gunShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Card effects while playing: winner glow, slam glow, trick burst. */
.played.trick-winner .card {
  outline: 3px solid #ffd970;
  box-shadow: 0 0 22px 6px rgba(255, 217, 112, 0.75);
  animation: winPulse 0.7s ease-in-out infinite;
}
.played.slam-win .card {
  outline: 3px solid #ffe27a;
  box-shadow: 0 0 30px 10px rgba(255, 200, 60, 0.85);
}
@keyframes winPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}
.trick-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 130px;
  height: 130px;
  margin: -65px 0 0 -65px;
  border: 3px solid #ffd970;
  border-radius: 50%;
  animation: burstRing 0.65s ease-out forwards;
  pointer-events: none;
}
@keyframes burstRing {
  from { transform: scale(0.4); opacity: 0.9; }
  to { transform: scale(1.5); opacity: 0; }
}

/* Chat: emoji + phrase grids, speech bubbles over panels. */
#chatEmojis { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
#chatEmojis button { font-size: 1.6rem; width: 52px; height: 52px; padding: 0; }
#chatPhrases { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.chat-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #111;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  z-index: 5;
  animation: bubbleIn 0.2s ease-out;
}
.chat-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: #fff;
}
@keyframes bubbleIn {
  from { transform: translateX(-50%) scale(0.7); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Street Approved Spades badge on the bet panel. */
.bet-logo {
  width: 220px;
  max-width: 80%;
  height: auto;
  display: block;
  margin: 0 auto 8px;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
}

/* Thunderbolt: when a team is set, the hand summary shows the last
   played card of the hand with a lightning effect. */
.set-line { color: #ffd770; font-weight: 800; font-size: 1.1rem; }
.thunder-card { display: inline-block; text-align: center; margin-top: 10px; animation: thunderShake 0.4s ease-in-out 2; }
.thunder-card .card { box-shadow: 0 0 0 3px #ffd770, 0 0 24px rgba(120, 200, 255, 0.9), 0 0 48px rgba(255, 255, 255, 0.55); animation: thunderFlash 0.35s ease-in-out 4; }
.thunder-bolt { font-size: 2.4rem; line-height: 1; animation: boltFlicker 0.35s ease-in-out 4; }
.thunder-cap { margin-top: 6px; font-size: 0.9rem; color: #d7ccf5; }
@keyframes thunderFlash { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.9); } }
@keyframes thunderShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px) rotate(-1deg); } 75% { transform: translateX(3px) rotate(1deg); } }
@keyframes boltFlicker { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
