/* ========== GAME TABLE LAYOUT ========== */
.game-table {
  display: grid;
  grid-template-areas:
    ".    top    ."
    "left center right"
    ".    bottom .";
  grid-template-columns: 180px 1fr 180px;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
  flex: 1;
  padding: 0.5rem;
  min-height: 0;
}

.player-zone {
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.player-zone.current-player {
  border-color: var(--gold);
  background: rgba(218, 165, 32, 0.18);
  box-shadow: 0 0 16px rgba(218, 165, 32, 0.6), inset 0 0 8px rgba(218, 165, 32, 0.2);
  animation: current-turn-glow 1.8s infinite alternate ease-in-out;
}

@keyframes current-turn-glow {
  0% { box-shadow: 0 0 8px rgba(218, 165, 32, 0.4); border-color: rgba(218, 165, 32, 0.7); }
  100% { box-shadow: 0 0 22px rgba(218, 165, 32, 0.85), inset 0 0 10px rgba(218, 165, 32, 0.3); border-color: #ffd700; }
}

.player-zone .player-name {
  font-weight: bold;
  font-size: 0.95rem;
  text-align: center;
  letter-spacing: 0.2px;
}

.player-zone .player-tricks {
  font-size: 0.8rem;
  opacity: 0.75;
}

/* Teammate indicator */
.player-zone.teammate {
  border-left: 3px solid var(--gold);
  background: rgba(218, 165, 32, 0.12);
}

.teammate-badge {
  font-size: 0.72rem;
  color: var(--gold);
  opacity: 0.95;
  font-weight: 600;
}

.player-top { grid-area: top; }
.player-left { grid-area: left; }
.player-right { grid-area: right; }
.player-bottom { grid-area: bottom; }

/* Belt-and-braces fallback for spectator/undefined seats (F-P1):
   mirror the seat-0 layout if a player-undefined class ever slips through. */
.player-undefined { grid-area: bottom; }

/* Hand area at bottom of viewport */
.hand-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* Edge affordance for the horizontally-scrolling hand: edge fades (local
     attachment, scroll with the content) cover pinned scroll shadows. The
     right shadow shows until you reach the end of the hand; the left one
     appears once you have scrolled. */
  background:
    linear-gradient(to right, rgba(20, 56, 33, 0.98), rgba(20, 56, 33, 0) 28px) left center / 28px 100% no-repeat,
    linear-gradient(to left, rgba(20, 56, 33, 0.98), rgba(20, 56, 33, 0) 28px) right center / 28px 100% no-repeat,
    linear-gradient(to right, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 28px) left center / 28px 100% no-repeat,
    linear-gradient(to left, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 28px) right center / 28px 100% no-repeat,
    linear-gradient(to top, rgba(14, 38, 22, 0.98) 0%, rgba(20, 56, 33, 0.94) 100%);
  background-attachment: local, local, scroll, scroll, scroll;
  backdrop-filter: blur(8px);
  padding: 8px 12px;
  /* Keep the bar clear of the home indicator: the bar's background extends
     behind the safe area and its content is padded up out of it. */
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  overflow-x: auto;
  overscroll-behavior: contain;
  display: flex;
  justify-content: flex-start;
  border-top: 1.5px solid rgba(218, 165, 32, 0.45);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45);
}

.center-zone {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  min-height: 0;
}

/* Compact play button inside player zone (bottom zone, your turn) */
.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.player-play-btn {
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: bold;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: var(--gold);
  color: var(--bg);
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}

.player-play-btn:hover {
  background: #c4941d;
}

.player-play-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Turn indicator inside player zone */
.player-turn-indicator {
  font-size: 0.7rem;
  color: var(--gold);
  opacity: 0.8;
  white-space: nowrap;
  flex-shrink: 0;
  animation: prompt-pulse 1.5s ease-in-out infinite;
}

/* Shared pulse (also consumed by lobby.css's .table-swap-hint) */
@keyframes prompt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Trick history toggle */
.trick-history-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  margin-left: 6px;
}
.trick-history-toggle.active {
  background: var(--gold);
  color: var(--bg);
}

/* ========== TRICK AREA ========== */
.trick-area {
  position: relative;
  width: 300px;
  height: 300px;
  z-index: 200; /* above fixed hand-area (z-index: 100) so bottom card isn't hidden */
}

.trick-card {
  position: absolute;
}

.trick-card-0 { bottom: 0; left: 50%; transform: translateX(-50%); }
.trick-card-1 { left: 0; top: 50%; transform: translateY(-50%); }
.trick-card-2 { top: 0; left: 50%; transform: translateX(-50%); }
.trick-card-3 { right: 0; top: 50%; transform: translateY(-50%); }

/* Belt-and-braces fallback for spectator/undefined positions (F-P1). */
.trick-card-undefined { bottom: 0; left: 50%; transform: translateX(-50%); }

.trump-badge {
  background: var(--gold);
  color: var(--bg);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: bold;
  white-space: nowrap;
}

.trick-info {
  text-align: center;
  font-size: 0.9rem;
}

/* Fix #2: Running score during trick play */
.running-score {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  padding: 4px 0;
  font-size: 0.85rem;
  font-weight: bold;
}

.running-score .score-ns,
.running-score .score-ew {
  display: inline;
}

/* Fix #3: Trick history (accumulated completed tricks) */
.trick-history {
  max-height: 200px;
  overflow-y: auto;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.trick-history-title {
  text-align: center;
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 4px;
}

.trick-history-entry {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
  padding: 2px 4px;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.trick-history-entry .trick-number {
  min-width: 28px;
  color: var(--gold);
  font-weight: bold;
  font-size: 0.7rem;
}

.trick-history-winner {
  font-size: 0.7rem;
  opacity: 0.7;
  min-width: 60px;
}

.trick-history-entry .trick-cards {
  display: flex;
  gap: 0;
}

/* Trick lead & high-card badges inside the trick area */
.trick-lead-badge {
  display: block;
  font-size: 0.6rem;
  color: #5bcec8;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  margin-top: 1px;
}

/* ========== WAITING ========== */
.waiting-message {
  text-align: center;
  opacity: 0.7;
  font-style: italic;
  padding: 1rem;
}

.dealing-message {
  text-align: center;
  font-size: 1.2rem;
  padding: 2rem;
}

/* ========== FIX #2: TRICK ANIMATION ========== */
@keyframes fly-to-winner {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  50% { opacity: 1; }
  100% { transform: translate(var(--fly-x), var(--fly-y)) scale(0.6); opacity: 0.8; }
}

.trick-animation-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  pointer-events: none;
}

.trick-animation-card {
  position: absolute;
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 8px;
  background: #fff;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.4);
  z-index: 301;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backface-visibility: hidden;
}

.trick-animation-card .rank {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
}

.trick-animation-card .suit {
  font-size: 40px;
  line-height: 1;
}

.trick-animation-card.red { color: var(--red); }
.trick-animation-card.black { color: var(--black); }

/* ========== SCORES ========== */
.scores-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  flex: 1;
  justify-content: center;
}

.set-indicator {
  color: #e44;
  font-weight: bold;
}

/* ========== SUB BOT / RECLAIM BUTTONS ========== */
.btn-sub-bot {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid #ffb74d;
  background: rgba(255, 183, 77, 0.2);
  color: #ffb74d;
  cursor: pointer;
  margin-top: 4px;
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
  transition: background 0.2s;
}

.btn-sub-bot:hover {
  background: rgba(255, 183, 77, 0.4);
}

/* ========== MOBILE RESPONSIVE (extracted per-component from the style.css mega-block) ========== */
@media (max-width: 768px), (min-width: 769px) and (max-width: 1024px) and (pointer: coarse) {
  .game-table {
    grid-template-areas:
      "top"
      "center"
      "left"
      "right"
      "bottom";
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0.25rem;
    padding: 0.25rem;
  }

  .player-zone {
    flex-direction: row;
    justify-content: flex-start;
    padding: 0.35rem 0.5rem;
    gap: 0.5rem;
  }

  .player-bottom {
    /* Fix #1: Hand is now in fixed .hand-area, no sticky needed */
  }

  .trick-area {
    width: 220px;
    height: 220px;
  }

  /* Fix #3: Trick history scrollable and compact */
  .trick-history {
    max-height: 120px;
    font-size: 0.7rem;
    overflow-y: auto;
  }

  .trick-history-entry {
    padding: 1px 2px;
  }

  .trick-cards .card {
    width: 32px;
    height: 46px;
    font-size: 0.6rem;
  }

  .trick-cards .card .rank {
    font-size: 8px;
  }

  .trick-cards .card .suit {
    font-size: 14px;
  }

  /* Fix #5: Hand area takes minimal vertical space */
  .hand-area {
    padding: 4px 8px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    min-height: 60px;
  }

  .hand-area .hand {
    gap: 0;
  }

  /* Fix #8: Center zone compact and centered */
  .center-zone {
    min-height: 120px;
    padding: 8px;
  }
}
