*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@600;700&display=swap');

:root {
  --bg: #0f1117;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.08);
  --glass: rgba(255,255,255,0.06);
  --glass-border: rgba(255,255,255,0.08);
  --glass-strong: rgba(255,255,255,0.1);
  --accent: #6c5ce7;
  --accent-glow: rgba(108,92,231,0.3);
  --accent-light: #a29bfe;
  --gold: #ffd32a;
  --red-suit: #ff6b6b;
  --black-suit: #dfe6e9;
  --text: #f1f2f6;
  --text-dim: rgba(255,255,255,0.5);
  --text-dimmer: rgba(255,255,255,0.3);
  --felt: #0d2818;
  --felt-dark: #091f12;
  --danger: #ff4757;
  --success: #2ed573;
  --card-bg: #fff;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { display: none; min-height: 100vh; padding-top: 48px; }
.screen.active { display: flex; align-items: center; justify-content: center; }
#screen-home { padding-top: 0; }

/* --- Top bar --- */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 900;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.top-bar-room {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-light);
  letter-spacing: 0.08em;
  background: rgba(108,92,231,0.15);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(108,92,231,0.2);
}
.top-bar-name {
  color: var(--text-dim);
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-leave-global {
  background: none;
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-leave-global:hover {
  color: var(--danger);
  border-color: rgba(255,68,87,0.3);
  background: rgba(255,68,87,0.08);
}

/* --- Spectator bar --- */
.spectator-bar {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  z-index: 850;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.25rem 1rem;
  background: rgba(15,17,23,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.75rem;
}
.spectator-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-weight: 500;
}
.seat-spectator-eye {
  font-size: 0.7rem;
  line-height: 1;
}
body.has-spectators .screen {
  padding-top: 76px;
}

/* Spectator seat switcher */
.spectator-seat-switcher {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
  font-size: 0.8rem;
  overflow-x: auto;
}
.switcher-label {
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.switcher-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: nowrap;
}
.switcher-buttons button {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  white-space: nowrap;
  flex-shrink: 0;
}
.switcher-buttons button:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  color: var(--text);
}
.switcher-buttons button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

@media (max-width: 480px) {
  .spectator-seat-switcher {
    flex-direction: column;
    align-items: stretch;
    overflow-x: unset;
  }
  .switcher-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex-wrap: unset;
  }
  .switcher-buttons button:last-child {
    grid-column: 1 / -1;
  }
}

/* Full board hands grid */
.fullboard-hands {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}

.fullboard-row {
  padding: 0.5rem 0.75rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.fullboard-row.active-turn {
  background: rgba(108,92,231,0.15);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(108,92,231,0.3);
}

.fullboard-name {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.fullboard-hand {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
}


/* --- Overlay --- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.overlay-content {
  text-align: center; color: #fff; font-size: 1.1rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 2rem 3rem;
  border-radius: var(--radius-lg);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.75rem 1.5rem;
  border: none; border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 600; font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  color: #fff;
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover {
  background: #7c6ff0;
  box-shadow: 0 6px 20px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-1px);
}
.btn-pass {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim);
}
.btn-pass:hover { background: rgba(255,255,255,0.12); color: var(--text); }
.btn-small {
  padding: 0.3rem 0.75rem; font-size: 0.75rem; font-weight: 600;
  background: rgba(255,255,255,0.08); color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition);
  font-family: var(--font);
}
.btn-small:hover { background: rgba(255,255,255,0.15); color: var(--text); }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.08);
}
.btn-ghost:hover {
  color: var(--danger);
  border-color: rgba(255,68,87,0.3);
  background: rgba(255,68,87,0.08);
}
.btn:disabled, .btn-small:disabled { opacity: 0.35; cursor: not-allowed; transform: none !important; }

/* --- Home --- */
.home-container {
  text-align: center;
  padding: 2.5rem 2rem;
  max-width: 400px;
  width: 100%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
}
.home-container h1 {
  font-size: 1.75rem; font-weight: 700;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, #fff 0%, var(--accent-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { color: var(--text-dim); margin-bottom: 2rem; font-size: 0.9rem; }
.form-group { margin-bottom: 1.25rem; text-align: left; }
.form-group label {
  display: block; margin-bottom: 0.4rem;
  font-size: 0.8rem; font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-group input {
  width: 100%; padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: #fff; font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.form-group input:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group input::placeholder { color: rgba(255,255,255,0.25); }
.form-group input.input-readonly {
  color: var(--text-dim);
  cursor: default;
  border-color: transparent;
  background: rgba(255,255,255,0.03);
}
.form-group input.input-readonly:focus {
  border-color: transparent;
  background: rgba(255,255,255,0.03);
  box-shadow: none;
}
.divider {
  display: flex; align-items: center; gap: 1rem;
  margin: 1.75rem 0; color: var(--text-dimmer);
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}
.home-container .btn { width: 100%; }
.fc-back-link {
  display: block; width: fit-content; margin: -0.75rem 0 0.75rem;
  color: var(--text-dim); font-size: 0.8rem; font-weight: 600; text-decoration: none;
}
.fc-back-link:hover { color: var(--accent-light); }
#btn-create { margin-bottom: 0.75rem; }
#btn-create-group { margin-bottom: 0; }
#btn-join { margin-bottom: 0.75rem; }
.role-choice-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}
.role-choice-buttons .btn {
  padding: 1rem;
  font-size: 1rem;
}

/* --- Lobby --- */
.lobby-container {
  text-align: center; padding: 2.5rem 2rem;
  max-width: 420px; width: 100%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
}
.lobby-container h2 {
  margin-bottom: 1.5rem;
  font-size: 1.4rem; font-weight: 700;
  color: var(--text);
}
.room-code-display {
  background: rgba(0,0,0,0.3); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  border: 1px solid rgba(255,255,255,0.06);
}
.lobby-invite-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.75rem;
}
.lobby-invite-row .btn {
  width: 100%;
  font-size: 0.9rem;
}
.room-code-display .label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.room-code-display .code {
  font-size: 2.2rem; font-weight: 700; letter-spacing: 0.25em;
  color: var(--accent-light);
  font-family: var(--mono);
}
.player-list { margin-bottom: 1.25rem; text-align: left; }
.player-list .player-item {
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  display: grid;
  grid-template-columns: 32px 7px minmax(0, 1fr) 9.5rem 36px;
  align-items: center; column-gap: 0.5rem; row-gap: 0.2rem;
  transition: background var(--transition);
}
.player-item { display: flex; align-items: center; gap: 0.5rem; }
.player-item:hover { background: rgba(255,255,255,0.06); }
.lobby-identity { min-width: 0; display: flex; align-items: baseline; gap: 0.25rem; }
.lobby-player-name { min-width: 0; text-align: left; overflow-wrap: anywhere; }
.lobby-meta { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem; }
.lobby-meta .not-ranked-badge { margin-left: 0; }
.lobby-action { grid-column: 5; width: 36px; display: flex; justify-content: flex-end; }
.player-item .lobby-action .kick-btn { width: 36px; min-height: 36px; margin: 0; padding: 0; }
.lobby-stats {
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 600px) {
  .player-list .player-item { grid-template-columns: 32px 7px minmax(0, 1fr) 36px; padding: 0.75rem; }
  .lobby-meta { grid-column: 3; grid-row: 2; }
  .lobby-action { grid-column: 4; grid-row: 1 / span 2; }
  .player-item .seat-num, .player-item > .status-dot { grid-row: 1; }
}
.player-item .seat-num {
  color: var(--accent-light); font-weight: 700;
  min-width: 1.5rem; font-size: 0.85rem;
  font-family: var(--mono);
}
.lobby-container [id^="lobby-add-"][id$="-bot"] {
  margin-bottom: 0.5rem;
}
#lobby-status,
#lobby-countdown {
  margin: 0.75rem 0;
}
.status-text {
  color: var(--text-dim); font-style: normal;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.status-text::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--accent-light);
  border-radius: 50%;
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* --- Status dots --- */
.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online {
  background: #4ade80;
  box-shadow: 0 0 4px rgba(74,222,128,0.5);
}
.status-dot.offline {
  background: #f87171;
  box-shadow: 0 0 4px rgba(248,113,113,0.4);
}

.player-status-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.player-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* --- Bidding --- */
.bidding-container {
  padding: 1.25rem; max-width: 500px; width: 100%; text-align: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
}
.bidding-container h2 {
  font-size: 1.3rem; font-weight: 700;
  color: var(--text); margin-bottom: 0.5rem;
}
.bid-info { margin-bottom: 1rem; }
#bid-status { font-size: 0.9rem; color: var(--text-dim); }
#bid-current {
  font-size: 0.85rem; color: var(--accent-light);
  margin-top: 0.3rem; font-weight: 500;
}
#bid-history {
  margin-top: 0.5rem;
  max-height: 9rem;
  overflow-y: auto;
}
.bid-table {
  width: 100%;
  border-collapse: collapse;
}
.bid-table thead th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 4px 2px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  letter-spacing: 0.02em;
}
.bid-table tbody td {
  text-align: center;
  padding: 4px 2px;
  font-size: 0.8rem;
  font-weight: 500;
}
.bt-pass { color: var(--text-dimmer); }
.bt-bid.suit-clubs, .bt-bid.suit-spades { color: var(--black-suit); font-weight: 600; }
.bt-bid.suit-diamonds, .bt-bid.suit-hearts { color: var(--red-suit); font-weight: 600; }
.bt-bid.suit-notrump { color: var(--gold); font-weight: 600; }
.bt-current {
  background: rgba(108,92,231,0.2);
  border: 1px solid var(--accent);
  border-radius: 5px;
  box-shadow: 0 0 8px var(--accent-glow);
}
.bid-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.04);
}
.bid-btn {
  padding: 0.55rem 0.25rem;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: clamp(0.7rem, 2.5vw, 0.85rem);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font);
}
.bid-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}
.bid-btn:disabled { opacity: 0.2; cursor: not-allowed; }
.bid-btn.suit-clubs, .bid-btn.suit-spades { color: var(--black-suit); }
.bid-btn.suit-diamonds, .bid-btn.suit-hearts { color: var(--red-suit); }
.bid-btn.suit-notrump { color: var(--gold); }
#btn-pass { width: 100%; margin-bottom: 1rem; }

/* --- Partner --- */
.partner-container {
  padding: 1.25rem; max-width: 560px; width: 100%; text-align: center;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
}
.partner-container h2 { color: var(--text); font-size: 1.3rem; margin-bottom: 0.5rem; }
#partner-status { color: var(--text-dim); margin-bottom: 1rem; font-size: 0.9rem; }
.partner-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.04);
}
.partner-card-btn {
  padding: 0.45rem;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: var(--black-suit);
  font-size: clamp(0.7rem, 2.5vw, 0.85rem);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}
.partner-card-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}
.partner-card-btn.red { color: var(--red-suit); }

/* --- Play screen --- */
.play-container { padding: 0.5rem; width: 100%; max-width: 600px; }
.game-info-bar {
  display: flex; flex-wrap: wrap; gap: 0.6rem;
  justify-content: center;
  padding: 0.85rem 1.25rem; margin-bottom: 0.5rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.game-info-bar span {
  white-space: nowrap;
  padding: 0.3rem 0.75rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.01em;
}
.practice-badge {
  background: rgba(167, 139, 250, 0.18) !important;
  border-color: rgba(167, 139, 250, 0.4) !important;
  color: #c4b5fd !important;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.practice-notice {
  font-size: 0.8rem;
  font-weight: 600;
  color: #c4b5fd;
  background: rgba(167, 139, 250, 0.12);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  margin-bottom: 0.75rem;
  text-align: center;
  letter-spacing: 0.04em;
}

.table {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  max-height: 45vh;
  background: radial-gradient(ellipse at center, #0f3520 0%, #091a10 100%);
  border-radius: var(--radius-lg);
  border: 2px solid rgba(255,255,255,0.06);
  margin-bottom: 0.5rem;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.3), 0 8px 32px rgba(0,0,0,0.4);
  overflow: hidden;
  transition: background 0.4s ease, border-color 0.4s ease;
}
.table.practice {
  background: radial-gradient(ellipse at center, #1e0a3c 0%, #110520 100%);
  border-color: rgba(167, 139, 250, 0.2);
}
.table::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.35s ease, background 0.35s ease;
}
.table.active-seat-bottom::before {
  opacity: 1;
  background: linear-gradient(to top, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.04) 45%, transparent 70%);
}
.table.active-seat-top::before {
  opacity: 1;
  background: linear-gradient(to bottom, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.04) 45%, transparent 70%);
}
.table.active-seat-left::before {
  opacity: 1;
  background: linear-gradient(to right, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.04) 45%, transparent 70%);
}
.table.active-seat-right::before {
  opacity: 1;
  background: linear-gradient(to left, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.04) 45%, transparent 70%);
}

.seat {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
  z-index: 1;
}
.seat-label {
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 0.7rem; font-weight: 500;
  color: var(--text-dim);
  background: rgba(0,0,0,0.5);
  padding: 4px 10px; border-radius: 12px;
  max-width: 110px;
  border: 1px solid rgba(255,255,255,0.06);
  transition: all var(--transition);
}
.seat-label.active-turn {
  color: #fff;
  font-weight: 700;
  background: rgba(108,92,231,0.25);
  border-color: var(--accent-light);
  box-shadow: 0 0 0 2px var(--accent), 0 0 20px rgba(108,92,231,0.7), 0 0 40px rgba(108,92,231,0.3);
}
.seat-label.disconnected { opacity: 0.5; }
.disconnect-countdown { font-size: 0.65em; color: #f87171; display: block; white-space: nowrap; }
.seat-name-row {
  display: flex; align-items: center; gap: 4px;
  max-width: 90px;
  overflow: hidden;
}
.seat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bidder-star {
  color: #ffd700;
  font-size: 1.1rem;
  margin-right: 0.3rem;
  line-height: 1;
}
.partner-star {
  color: #c0c0c0;
  font-size: 0.85rem;
  margin-right: 0.3rem;
  line-height: 1;
}
.seat-sets {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
}

.seat-top    { top: 4%;   left: 50%; transform: translateX(-50%); }
.seat-left   { top: 50%;  left: 4%;  transform: translateY(-50%); }
.seat-right  { top: 50%;  right: 4%; transform: translateY(-50%); }
.seat-bottom { bottom: 4%; left: 50%; transform: translateX(-50%); flex-direction: column-reverse; }

.seat-card { min-height: 30px; }

.trick-area {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 1;
  display: grid;
  grid-template-areas:
    ".    top  ."
    "left .    right"
    ".    bot  .";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2px;
  width: 55%; height: 65%;
}
.trick-card {
  display: flex; align-items: center; justify-content: center;
}
.trick-card-top   { grid-area: top; }
.trick-card-left  { grid-area: left; }
.trick-card-right { grid-area: right; }
.trick-card-bot   { grid-area: bot; }
.trick-card .card-mini { width: clamp(37px, 7.9vw, 55px); font-size: clamp(1.32rem, 4.75vw, 1.72rem); }

.trick-area.trick-complete .trick-card {
  opacity: 0.4;
  transition: opacity 0.3s ease;
}

.set-item {
  background: var(--glass); padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm); font-weight: 500;
  border: 1px solid rgba(255,255,255,0.06);
}
.set-item.is-me {
  border-color: var(--accent);
  background: rgba(108,92,231,0.15);
  color: var(--accent-light);
}

/* --- Cards --- */
.card-hand {
  position: relative;
  width: 100%;
  min-width: 0;
  overflow: visible;
  isolation: isolate;
  z-index: 2;
  touch-action: pan-y;
}
/* Ownership is fixed before contact, even while waiting for another player.
   The blank hand area and the rest of the page retain normal scrolling. */
.card-hand .hand-card { touch-action: none; }

.card {
  width: clamp(40px, 10vw, 60px);
  aspect-ratio: 5/7;
  border-radius: 8px;
  border: 1.5px solid rgba(0,0,0,0.1);
  background: var(--card-bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), margin-top var(--transition);
  font-weight: 700;
  font-size: clamp(1.2rem, 5vw, 1.7rem);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  user-select: none;
  position: relative;
  line-height: 1.1;
  margin-left: -6px;
  flex-shrink: 0;
}
.suit-group > .card:first-child { margin-left: 0; }

.card:hover:not(.disabled) {
  transform: translateY(-10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 10;
}
.card.disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
.card.red { color: var(--red-suit); }
.card.black { color: #2d3436; }
.card .card-value { font-size: 1em; }
.card .card-suit { font-size: 1.1em; }

/* Cards follow an arc, progressively rotated like a held hand. */
.card-hand .hand-card {
  position: absolute;
  top: 18px;
  width: var(--hand-card-width, 60px);
  height: calc(var(--hand-card-width, 60px) * 1.4);
  margin: 0;
  padding: 0;
  appearance: none;
  color: #2d3436;
  font-family: inherit;
  border-width: 1.5px;
  border-radius: 8px;
  z-index: var(--card-order);
  transform: rotate(var(--card-angle, 0deg)) translateY(0);
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.card-hand .hand-card.red { color: var(--red-suit); }
.card-hand.hand-initializing .hand-card { transition: none; }
.card-hand.hand-reflow .hand-card { transition: left 160ms ease-out, top 160ms ease-out, transform 160ms ease-out, box-shadow 120ms ease; }
.card-hand .hand-card:hover { z-index: var(--card-order); transform: rotate(var(--card-angle, 0deg)) translateY(0); box-shadow: var(--card-shadow); }
/* Slide along the card's own axis so its side edge keeps the neighboring
   indices exposed. Preserve the arc position, rotation and stacking order. */
.card-hand.hand-fan .hand-card.is-selected {
  transform: rotate(var(--card-angle, 0deg)) translateY(calc(-1 * var(--hand-lift, 8px)));
  box-shadow: 0 0 0 2px var(--accent-light), 0 4px 10px rgba(0,0,0,0.3);
}
.card-hand .hand-card.disabled { opacity: 0.45; pointer-events: auto; }
/* Preserve fan order during focus so neighboring indices stay exposed, even
   when another optional theme adds a generic raised-card focus treatment. */
.card-hand.hand-fan .hand-card:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px; z-index: var(--card-order);
}
.card-corner {
  position: absolute; top: var(--corner-inset, 2px); left: var(--corner-inset, 2px);
  display: flex; flex-direction: column; align-items: center;
  font-size: var(--corner-font, 16px);
  line-height: 1.1;
  font-weight: 700;
}
.hand-help {
  position: absolute; bottom: 2px; left: 0; right: 0;
  color: var(--text-dim); font-size: 0.72rem; text-align: center;
  pointer-events: none;
}
.card-hand.hand-fan .hand-card.is-drag-source { opacity: 0.18; transition: none; }
.drop-ready .hand-help { color: var(--success); }
/* One compositor-moved copy escapes the fan stacking context. The real card
   retains its place, original text and keyboard semantics in the hand. */
.card-hand.card-drag-layer {
  position: fixed; inset: 0; width: 100%; height: 100%; min-height: 0;
  z-index: 1200; overflow: clip; isolation: isolate;
}
.card-drag-layer, .card-drag-layer * { pointer-events: none !important; }
.card-hand.card-drag-layer .hand-card.drag-proxy {
  left: 0; top: 0; z-index: 1; transition: none; outline: none;
  box-shadow: 0 16px 28px #0006, 0 3px 8px #0004;
  will-change: transform;
}
.table-surface { position: absolute; inset: 0; border-radius: calc(var(--radius-lg) - 2px); pointer-events: none; }
.card-drop-zone {
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
}
.card-drop-label {
  display: none;
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  padding: 5px 10px; border-radius: 20px; background: #09251feb;
  color: #d8ffed; font: 600 12px var(--font); white-space: nowrap;
}
.card-drop-available .card-drop-zone { pointer-events: auto; box-shadow: inset 0 0 0 2px #b4e9cf88; background: #2ed5730c; }
.card-drop-available .card-drop-label { display: block; }
.card-drop-ready .card-drop-zone { background: #2ed57324; box-shadow: inset 0 0 0 2px #7cf3b2, inset 0 0 24px #2ed57325; }
@media (prefers-reduced-motion: reduce) {
  .card-hand.hand-fan .hand-card { transition: none; }
}

.card-mini {
  width: clamp(28px, 6vw, 42px);
  aspect-ratio: 5/7;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  background: var(--card-bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-weight: 700;
  font-size: clamp(1.0rem, 3.6vw, 1.3rem);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  line-height: 1.1;
}
.card-mini.red { color: var(--red-suit); }
.card-mini.black { color: #2d3436; }

/* Trump card fire aura (trick area + last-trick popup) */
/*
 * Glow tokens — single source of truth for both gameplay and gameover recap.
 * Tighter spread so po-* top borders remain readable when glows are co-applied.
 * No border-color override so sequence borders (po-1…po-4) are never hidden.
 */
:root {
  --glow-trump-min:
    0 0 3px 1px rgba(255, 200, 80, 0.5),
    0 0 7px 2px rgba(255, 100, 20, 0.4),
    0 0 11px 3px rgba(255, 60, 0, 0.22);
  --glow-trump-max:
    0 0 4px 1px rgba(255, 230, 120, 0.6),
    0 0 9px 3px rgba(255, 140, 40, 0.5),
    0 0 14px 4px rgba(255, 80, 0, 0.28);
  --glow-trump-filter-min: drop-shadow(0 0 2px rgba(255, 120, 0, 0.65));
  --glow-trump-filter-max: drop-shadow(0 0 3px rgba(255, 160, 40, 0.85));

  --glow-partner-min:
    0 0 3px 1px rgba(255, 60, 60, 0.5),
    0 0 7px 2px rgba(220, 20, 20, 0.4),
    0 0 11px 3px rgba(180, 0, 0, 0.22);
  --glow-partner-max:
    0 0 4px 1px rgba(255, 90, 90, 0.65),
    0 0 9px 3px rgba(230, 30, 30, 0.55),
    0 0 14px 4px rgba(200, 0, 0, 0.28);
  --glow-partner-filter-min: drop-shadow(0 0 2px rgba(210, 0, 0, 0.65));
  --glow-partner-filter-max: drop-shadow(0 0 3px rgba(230, 0, 0, 0.9));
}

@keyframes trump-fire-glow {
  0%, 100% {
    box-shadow: var(--glow-trump-min);
    filter: var(--glow-trump-filter-min);
  }
  50% {
    box-shadow: var(--glow-trump-max);
    filter: var(--glow-trump-filter-max);
  }
}
.card-trump-fire {
  position: relative;
  z-index: 2;
  animation: trump-fire-glow 0.75s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .card-trump-fire {
    animation: none;
    box-shadow: var(--glow-trump-min);
    filter: var(--glow-trump-filter-min);
  }
}

/* Partner card red glow (played trick area) */
@keyframes partner-card-glow {
  0%, 100% {
    box-shadow: var(--glow-partner-min);
    filter: var(--glow-partner-filter-min);
  }
  50% {
    box-shadow: var(--glow-partner-max);
    filter: var(--glow-partner-filter-max);
  }
}
.card-partner-glow {
  position: relative;
  z-index: 2;
  animation: partner-card-glow 0.75s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .card-partner-glow {
    animation: none;
    box-shadow: var(--glow-partner-min);
    filter: var(--glow-partner-filter-min);
  }
}

.card-back {
  width: clamp(28px, 6vw, 42px);
  aspect-ratio: 5/7;
  border-radius: 6px;
  background: linear-gradient(135deg, #6c5ce7 25%, #a29bfe 25%, #a29bfe 50%, #6c5ce7 50%, #6c5ce7 75%, #a29bfe 75%);
  background-size: 8px 8px;
  border: 1.5px solid rgba(255,255,255,0.1);
}

/* --- Hand display label --- */
.hand-display {
  margin-top: 0.25rem;
}
.hand-display h3 {
  text-align: center; font-size: 0.75rem;
  color: var(--text-dimmer);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.hcp-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(99, 179, 237, 0.12);
  border: 1px solid rgba(99, 179, 237, 0.25);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  letter-spacing: 0.03em;
  vertical-align: middle;
  text-transform: none;
}

/* --- Game Over --- */
.gameover-container {
  text-align: center; padding: 2.5rem 2rem;
  max-width: 420px; width: 100%;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  transition: background 0.4s, border-color 0.4s, box-shadow 0.4s;
}
.gameover-container.outcome-win {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.15);
}
.gameover-container.outcome-loss {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  box-shadow: 0 0 40px rgba(239, 68, 68, 0.15);
}
.gameover-container h2 {
  font-size: 1.8rem; margin-bottom: 0.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.gameover-container.outcome-win h2 {
  background: linear-gradient(135deg, #fff, #4ade80);
  -webkit-background-clip: text;
  background-clip: text;
}
.gameover-container.outcome-loss h2 {
  background: linear-gradient(135deg, #fff, #f87171);
  -webkit-background-clip: text;
  background-clip: text;
}
#gameover-detail { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; line-height: 1.5; }
.play-time-section {
  padding: 0.5rem 1rem; margin-bottom: 1rem;
  font-size: 0.8rem; color: var(--text-dimmer);
  background: rgba(255,255,255,0.03); border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.05);
}
.play-time-header {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dimmer); margin-bottom: 0.4rem;
}
.play-time-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.25rem 0;
}
.play-time-name { color: var(--text-dim); }
.play-time-value { font-weight: 600; color: var(--text-dim); }
.elo-delta-section { margin-bottom: 1.25rem; }
.elo-delta-section .section-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dimmer);
  margin-bottom: 0.5rem;
}
.elo-delta-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.45rem 1rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}
.elo-delta-row .elo-name { font-weight: 500; }
.elo-delta-row .elo-change { font-weight: 700; font-family: var(--mono); }
.elo-delta-row .elo-change.positive { color: #4ade80; }
.elo-delta-row .elo-change.negative { color: #f87171; }
.elo-delta-row .elo-change.zero { color: var(--text-dimmer); }
.scores { margin-bottom: 1.5rem; }
.score-item {
  display: flex; justify-content: space-between;
  padding: 0.65rem 1rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  transition: background var(--transition);
}
.score-item:hover { background: rgba(255,255,255,0.06); }
.score-item .name { font-weight: 600; }
.score-item .sets-won { color: var(--accent-light); font-weight: 600; font-family: var(--mono); }
.score-item.team-bidder {
  background: rgba(255,200,60,0.1);
  border-color: rgba(255,200,60,0.25);
}
.score-item.team-bidder .name { color: var(--gold); }
.score-item.team-bidder .sets-won { color: var(--gold); }
.score-item .role-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255,200,60,0.7);
  background: rgba(255,200,60,0.12);
  border: 1px solid rgba(255,200,60,0.25);
  border-radius: 8px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.gameover-actions {
  display: flex; flex-direction: column; gap: 0.5rem;
}
.gameover-actions .btn-ghost {
  font-size: 0.85rem; padding: 0.6rem;
}
.gameover-hands {
  width: 100%;
  margin: 1rem 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.gameover-hand-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.gameover-hand-row .hand-label {
  font-size: 0.7rem;
  color: var(--text-dimmer);
  text-align: left;
}
.gameover-hand-cards {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  width: 100%;
}
.gameover-hand-cards .card-win-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
  padding-bottom: calc(0.6rem + 1px);
}
.gameover-hand-cards .card-win-wrap .card-mini {
  width: 100%;
  font-size: clamp(0.5rem, 2.6vw, 0.75rem);
  padding: 0;
}
.gameover-hand-cards .card-win-wrap .card-mini.played {
  opacity: 0.3;
}
.gameover-hand-cards .card-win-wrap .card-mini.po-1 { border-top: 3px solid #4ade80; }
.gameover-hand-cards .card-win-wrap .card-mini.po-2 { border-top: 3px solid #facc15; }
.gameover-hand-cards .card-win-wrap .card-mini.po-3 { border-top: 3px solid #fb923c; }
.gameover-hand-cards .card-win-wrap .card-mini.po-4 { border-top: 3px solid #f87171; }
.trick-star {
  font-size: 0.5rem;
  color: rgba(250, 204, 21, 0.85);
  line-height: 1;
  height: 0.6rem;
  position: absolute;
  bottom: 1px;
}
.gameover-hand-row .hand-label .hand-pts {
  font-size: 0.6rem;
  color: var(--text-dimmer);
  margin-left: 0.35em;
}
.gameover-hand-row .hand-label .hand-role {
  font-size: 0.6rem;
  margin-left: 0.35em;
  font-weight: 600;
}
.gameover-hand-row .hand-label .hand-role.bidder { color: #ffd700; }
.gameover-hand-row .hand-label .hand-role.partner { color: #c0c0c0; }
.gameover-ready-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}
.gameover-ready-player {
  color: var(--text-dimmer);
}
.gameover-ready-player.ready {
  color: #4ade80;
  font-weight: 600;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .bidding-container, .partner-container { padding: 1rem 0.5rem; }
  .fullboard-hands { padding: 0; }
  .fullboard-row { padding: 0.5rem 0; }
}

@media (min-width: 768px) {
  /* Give a full hand room on desktop, including bidding and partner selection. */
  .bidding-container, .partner-container, .play-container { max-width: 860px; }

}

@media (max-width: 400px) {
  .bid-grid { gap: 4px; }
  .bid-btn { padding: 0.4rem 0.1rem; font-size: 0.65rem; }
  .game-info-bar { font-size: 0.8rem; gap: 0.4rem; padding: 0.65rem 0.75rem; }
  .table { max-height: 40vh; }
  .card { margin-left: -8px; }
}

/* --- Last Trick mini panel (bottom-right of table) --- */
.last-trick-panel {
  position: absolute;
  bottom: 3%;
  right: 3%;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 0.25rem 0.3rem;
  z-index: 2;
  backdrop-filter: blur(4px);
}
.ltp-label {
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dimmer);
  text-align: center;
  margin-bottom: 0.15rem;
}
.ltp-grid {
  display: grid;
  grid-template-areas:
    ". top ."
    "left . right"
    ". bot .";
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2px;
}
.ltp-item {
  display: flex;
  align-items: center;
  justify-content: center;
}
.ltp-top   { grid-area: top; }
.ltp-left  { grid-area: left; }
.ltp-right { grid-area: right; }
.ltp-bot   { grid-area: bot; }
.ltp-winner .card-mini {
  box-shadow: 0 0 0 2px var(--gold);
  border-radius: 4px;
}
.ltp-grid .card-mini {
  width: clamp(20px, 4vw, 30px);
  font-size: clamp(0.7rem, 2.4vw, 1rem);
}

/* --- Connection toast --- */
.connection-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.88);
  color: #ccc;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  z-index: 600;
  font-size: 0.8rem;
  pointer-events: none;
  animation: bannerIn 0.3s ease-out;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.connection-toast.fade-out {
  animation: bannerOut 0.4s ease-in forwards;
}
@keyframes bannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes bannerOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* --- Trick won banner (centered on play table) --- */
.trick-won-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.88);
  color: var(--gold);
  padding: 0.5rem 1.5rem;
  border-radius: 20px;
  z-index: 8;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
  max-width: min(92%, 280px);
  line-height: 1.25;
  animation: trickBannerIn 0.3s ease-out;
  border: 1px solid rgba(255,211,42,0.2);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.trick-won-banner.fade-out {
  animation: trickBannerOut 0.4s ease-in forwards;
}
@keyframes trickBannerIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% - 12px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}
@keyframes trickBannerOut {
  from { opacity: 1; transform: translate(-50%, -50%); }
  to { opacity: 0; transform: translate(-50%, calc(-50% - 12px)); }
}

/* --- Trick sweep animations --- */
.trick-card.trick-sweep-top {
  animation: sweepTop 0.6s ease-in forwards 0.6s;
}
.trick-card.trick-sweep-bot {
  animation: sweepBot 0.6s ease-in forwards 0.6s;
}
.trick-card.trick-sweep-left {
  animation: sweepLeft 0.6s ease-in forwards 0.6s;
}
.trick-card.trick-sweep-right {
  animation: sweepRight 0.6s ease-in forwards 0.6s;
}
@keyframes sweepTop {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-60px) scale(0.7); }
}
@keyframes sweepBot {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(60px) scale(0.7); }
}
@keyframes sweepLeft {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(-60px) scale(0.7); }
}
@keyframes sweepRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(60px) scale(0.7); }
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.screen.active > * {
  animation: fadeIn 0.3s ease-out;
}

/* Auth UI */
.auth-status {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 1.25rem;
  text-align: center;
}

.auth-status a {
  color: rgba(255, 255, 255, 0.5);
  text-decoration: underline;
  cursor: pointer;
}

#telegram-widget-container {
  display: flex;
  justify-content: center;
  margin-bottom: 0.5rem;
  min-height: 48px;
}

/* Leaderboard */
.lb-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.lb-footer {
  text-align: right;
  margin-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.5rem;
}

.lb-header {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d4a843;
  margin-bottom: 0.75rem;
  text-align: center;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}

.lb-rank {
  width: 2rem;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  color: rgba(255, 255, 255, 0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-stats {
  color: #d4a843;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.lb-elo {
  font-weight: 700;
  color: #d4a843;
  min-width: 3.5rem;
  text-align: right;
}

.lb-me .lb-name {
  font-weight: 600;
  color: #fff;
}

/* Bridge | Regicide switch on the shared leaderboard card (static/leaderboard.js). */
.lb-tabs { display: flex; justify-content: center; gap: 4px; margin: -0.25rem 0 0.6rem; }
.lb-tab {
  padding: 0.2rem 0.7rem; border-radius: 6px; cursor: pointer;
  background: transparent; border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-dim); font: 600 0.72rem var(--font);
}
.lb-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-empty { text-align: center; color: var(--text-dimmer); font-size: 0.8rem; padding: 0.4rem 0; }

.lb-divider {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 0.4rem 0;
}

/* Spectator seat-select */
.spectator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.spectator-player-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.spectator-player-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-light);
}

.spectator-seat-num {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.spectator-player-name {
  font-size: 1rem;
  font-weight: 600;
}

/* --- Bot lobby UI --- */
.bot-icon {
  font-size: 0.9rem;
  margin-right: 0.1rem;
}
.bot-remove-btn {
  background: none;
  border: 1px solid rgba(255, 68, 87, 0.3);
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  margin-left: auto;
  transition: background var(--transition);
}
.bot-remove-btn:hover {
  background: rgba(255, 68, 87, 0.15);
}
.kick-btn {
  background: none;
  border: 1px solid rgba(255, 68, 87, 0.3);
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  margin-left: auto;
  transition: background var(--transition);
}
.kick-btn:hover {
  background: rgba(255, 68, 87, 0.15);
}
.ping-btn {
  background: none;
  border: none;
  color: var(--accent-light);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font: inherit;
  transition: opacity var(--transition);
}
.ping-btn:hover {
  opacity: 0.7;
}
.ping-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  text-decoration: none;
}
#lobby-start-btn {
  width: 100%;
  margin-top: 0.75rem;
}
/* --- Inline chat (lobby + gameover) --- */
.inline-chat {
  margin-top: 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 1rem 0.75rem 0.75rem;
  text-align: left;
}
.inline-chat-log {
  min-height: 72px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 8px 8px 2px;
  margin-bottom: 0.75rem;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #667086 #17202c;
  color-scheme: dark;
  border-radius: 4px;
}
.inline-chat-log::-webkit-scrollbar { width: 7px; }
.inline-chat-log::-webkit-scrollbar-track { background: #17202c; border-radius: 8px; }
.inline-chat-log::-webkit-scrollbar-thumb { background: #667086; border: 2px solid #17202c; border-radius: 8px; }
.inline-chat-log:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.inline-chat-log:empty::before {
  content: 'No messages yet';
  color: #aeb5c4;
  font-size: 0.78rem;
  font-style: italic;
}
.chat-msg {
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  margin-bottom: 0.35rem;
  color: #d6d9e2;
}
.chat-msg:last-child { margin-bottom: 0; }
.chat-msg .chat-name {
  color: var(--accent-light);
  font-weight: 600;
  margin-right: 0.3rem;
}
.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.chat-input-row input {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font: 400 16px var(--font);
  outline: none;
}
.inline-chat .chat-send-btn { min-width: 64px; min-height: 44px; flex-shrink: 0; }
.inline-chat .chat-input-field:focus-visible,
.inline-chat .chat-send-btn:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.chat-input-row input:focus {
  border-color: rgba(139,92,246,0.5);
  background: rgba(255,255,255,0.1);
}

/* --- Chat bubbles (play screen) --- */
.chat-bubble {
  display: none;
  position: absolute;
  background: rgba(30,20,60,0.92);
  border: 1px solid rgba(139,92,246,0.4);
  border-radius: 10px;
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  color: var(--text);
  max-width: 300px;
  line-height: 1.3;
  white-space: normal;
  z-index: 10;
  animation: bubblePop 0.2s ease-out;
  pointer-events: none;
}
.chat-bubble.visible { display: block; }
.seat-top .chat-bubble    { left: 100%; top: 0; margin-left: 4px; transform: none; }
.seat-bottom .chat-bubble { right: auto; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 4px; margin-bottom: 0; }
.seat-left .chat-bubble   { left: 50%; top: auto; bottom: 100%; margin-left: 0; margin-bottom: 4px; transform: translateX(-50%); }
.seat-right .chat-bubble  { right: 50%; top: auto; bottom: 100%; margin-right: 0; margin-bottom: 4px; transform: translateX(50%); }
@keyframes bubblePopBottom {
  from { opacity: 0; transform: translateY(-50%) translateX(-8px) scale(0.85); }
  to   { opacity: 1; transform: translateY(-50%) scale(1); }
}
.seat-bottom .chat-bubble {
  animation: bubblePopBottom 0.2s ease-out;
}
@keyframes bubblePopTopBottom {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.85); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}
.seat-left .chat-bubble, .seat-right .chat-bubble {
  animation: bubblePopTopBottom 0.2s ease-out;
}
@keyframes bubblePopTop {
  from { opacity: 0; transform: translateX(-8px) scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
.seat-top .chat-bubble {
  animation: bubblePopTop 0.2s ease-out;
}

/* --- Not-ranked badge (group games) --- */
.not-ranked-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255, 180, 0, 0.8);
  background: rgba(255, 180, 0, 0.1);
  border: 1px solid rgba(255, 180, 0, 0.25);
  border-radius: 10px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.25rem;
  white-space: nowrap;
}

/* --- Stats page --- */
.btn-link {
  background: none;
  border: none;
  color: var(--accent-light);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0;
  text-decoration: none;
  transition: color var(--transition);
}
.btn-link:hover { color: #fff; }

.stats-container {
  width: 100%;
  max-width: 600px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  overflow: hidden;
}
.stats-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.stats-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-light);
}
.stats-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.stats-group-select {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: #ccc;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
}
.stats-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 0 1rem;
}
.stats-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #888;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.6rem 1rem;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.stats-tab.active {
  color: #fff;
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.stats-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.stats-filter-label {
  font-size: 0.68rem;
  color: #888;
}
.min-games-filter {
  display: flex;
  gap: 3px;
}
.min-games-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: #888;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.min-games-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.stats-table-wrap {
  overflow-x: auto;
  padding: 0 0 0.5rem;
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.73rem;
}
.stats-table thead tr {
  background: rgba(255,255,255,0.04);
}
.stats-table th {
  padding: 6px 8px;
  text-align: right;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: color var(--transition);
}
.stats-table th:hover { color: #ccc; }
.stats-table th.sorted { color: #fff; }
.stats-th-left { text-align: left !important; padding-left: 1rem !important; }
.stats-table td {
  padding: 6px 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
  color: #ccc;
}
.stats-td-name {
  text-align: left;
  padding-left: 1rem !important;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.stats-td-num {
  text-align: right;
  font-family: var(--mono);
  white-space: nowrap;
}
.stats-elo {
  color: #d4a843;
  font-weight: 600;
}
.sort-arrow { font-size: 0.6rem; margin-left: 2px; color: #555; }
.sort-arrow.active { color: var(--accent-light); }
.win-pct-high { color: #4ade80; font-weight: 700; }
.win-pct-mid  { color: #facc15; font-weight: 700; }
.win-pct-low  { color: #f87171; font-weight: 700; }
.stats-na { color: #555; }
.stats-empty {
  text-align: center;
  color: #666;
  font-size: 0.8rem;
  padding: 2rem 1rem;
}
.stats-footer {
  text-align: center;
  font-size: 0.62rem;
  color: #444;
  padding: 0.5rem 1rem 0.75rem;
  margin: 0;
}

/* --- Betting widget --- */
.betting-widget {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-top: 2px solid #7c3aed;
  padding: 10px 16px;
}
.betting-widget-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 600px;
  margin: 0 auto;
}
.betting-widget-label { font-size: 0.85rem; color: #a78bfa; white-space: nowrap; }
.betting-buttons { display: flex; gap: 8px; }
.btn-bet {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-bet:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-bet-win  { background: #16a34a; color: #fff; }
.btn-bet-win:hover:not(:disabled)  { background: #15803d; }
.btn-bet-lose { background: #dc2626; color: #fff; }
.btn-bet-lose:hover:not(:disabled) { background: #b91c1c; }
.betting-result { font-size: 0.85rem; }
.bet-placed-label { color: #e2e8f0; }
.bet-correct { color: #4ade80; font-weight: 600; }
.bet-wrong   { color: #f87171; font-weight: 600; }
.bet-pending { color: #94a3b8; }
body.has-betting-widget { padding-bottom: 60px; }
.betting-tab-desc { font-size: 0.85rem; color: #94a3b8; margin-bottom: 12px; }
.betting-empty { text-align: center; padding: 24px 0; }

/* --- Game history / replay --- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem;
  max-height: 70vh;
  overflow-y: auto;
}
.history-row {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-left: 3px solid #94a3b8;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.history-row:hover { background: rgba(255,255,255,0.08); }
.history-row-won  { border-left-color: #4ade80; }
.history-row-lost { border-left-color: #f87171; }
.history-row-main {
  display: flex;
  gap: 0.8rem;
  align-items: baseline;
  font-size: 0.9rem;
}
.history-row-main .history-bid {
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
}
.history-row-main .history-role { color: #cbd5e1; font-size: 0.8rem; }
.history-row-main .history-practice,
.replay-header-row .replay-practice {
  background: rgba(148,163,184,0.15);
  color: #cbd5e1;
  border: 1px solid rgba(148,163,184,0.35);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.history-row-main .history-result { margin-left: auto; color: #e2e8f0; font-size: 0.85rem; }
.history-row-sub {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: #94a3b8;
  flex-wrap: wrap;
}
.history-row-sub .history-date { margin-left: auto; }
.history-footer {
  text-align: center;
  padding: 0.5rem;
}

.replay-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.replay-header-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: #cbd5e1;
  margin-bottom: 0.25rem;
}
.replay-header-row .replay-bid {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--accent-light);
  font-size: 1rem;
}
.replay-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.6rem;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.replay-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.replay-progress {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e2e8f0;
  min-width: 10rem;
  text-align: center;
}
#replay-hands { padding: 0.5rem; max-height: 60vh; overflow-y: auto; }

.replay-summary {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding: 0.4rem 0 0.2rem 0;
}
.replay-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.2rem 0 0.4rem 0;
}
.replay-breakdown-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.35rem 0.5rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
}
.replay-breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.replay-breakdown-label {
  font-size: 0.72rem;
  color: var(--text-dimmer);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.replay-breakdown-role {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
}
.replay-breakdown-role.role-bidder { color: #ffd700; }
.replay-breakdown-role.role-partner { color: #c0c0c0; }
.replay-breakdown-role.role-opposition { color: #94a3b8; }
.replay-breakdown-pills {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.replay-breakdown-pills .rating-pill {
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
}
.rating-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: #cbd5e1;
}
.rating-pill .rating-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.rating-best     .rating-dot { background: #4ade80; }
.rating-good     .rating-dot { background: #60a5fa; }
.rating-inaccuracy .rating-dot { background: #facc15; }
.rating-mistake  .rating-dot { background: #fb923c; }
.rating-blunder  .rating-dot { background: #f87171; }

.rating-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  border-radius: 9px;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #0b1120;
  background: #94a3b8;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.45);
  pointer-events: auto;
  cursor: help;
  z-index: 3;
}
.card-win-wrap { position: relative; }
.rating-badge.rating-best     { background: #4ade80; }
.rating-badge.rating-good     { background: #60a5fa; }
.rating-badge.rating-inaccuracy { background: #facc15; }
.rating-badge.rating-mistake  { background: #fb923c; color: #0b1120; }
.rating-badge.rating-blunder  { background: #f87171; color: #0b1120; }


