/* ==========================================================================
   Playing Card Component & Animations
   Rich tactile cards with depth, shadows, hover/selection states, and deals.
   ========================================================================== */

.card {
  position: relative;
  width: 72px;
  height: 104px;
  background-color: var(--card-white);
  border-radius: 9px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.38),
    0 1px 3px rgba(0, 0, 0, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 8px;
  cursor: pointer;
  transition:
    transform 0.22s cubic-bezier(0.18, 0.89, 0.32, 1.28),
    box-shadow 0.22s ease,
    border-color 0.2s ease,
    filter 0.2s ease;
  flex-shrink: 0;
  touch-action: manipulation;
  user-select: none;
  background-image: linear-gradient(180deg, #ffffff 0%, #f7f7f2 100%);
}

/* Card color schemes */
.card.red {
  color: var(--card-red);
}

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

/* Card rank & suit corners */
.card-corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
  pointer-events: none;
}

.card-corner.top-left {
  align-self: flex-start;
}

.card-corner.bottom-right {
  align-self: flex-end;
  transform: rotate(180deg);
}

.card-rank {
  font-size: 1.15rem;
  font-weight: 800;
  font-family: 'Georgia', 'Times New Roman', serif, system-ui;
  letter-spacing: -0.5px;
}

.card-suit-sm {
  font-size: 0.88rem;
  line-height: 1;
}

/* Center suit symbol */
.card-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.1rem;
  opacity: 0.92;
  pointer-events: none;
  line-height: 1;
}

/* Interactive card states */
.card.playable {
  cursor: pointer;
}

.card.playable:hover {
  transform: translateY(-14px) scale(1.05);
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.55),
    0 0 14px var(--gold-glow);
  border-color: rgba(212, 175, 55, 0.7);
  z-index: 55;
}

.card.playable:active {
  transform: translateY(-10px) scale(1.02);
}

/* Selected card highlight */
.card.selected {
  transform: translateY(-22px) scale(1.08) !important;
  box-shadow:
    0 16px 30px rgba(0, 0, 0, 0.65),
    0 0 18px var(--gold) !important;
  border: 2px solid var(--gold) !important;
  z-index: 60;
}

/* Disabled card state (e.g. when must follow suit) */
.card.disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.6) brightness(0.85);
  transform: none !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Card Back (for opponents and deck) */
.card-back {
  background: linear-gradient(135deg, #1b3d6c 25%, #0f233f 100%);
  border: 2px solid #ffffff;
  border-radius: 9px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
  position: relative;
  overflow: hidden;
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  border-radius: 5px;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.25) 12%, transparent 12%);
  background-size: 8px 8px;
}

/* Card Dealing Entrance Animation */
.card.deal-animate {
  animation: dealCard 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
  animation-delay: calc(var(--deal-idx, 0) * 0.07s);
}

@keyframes dealCard {
  0% {
    opacity: 0;
    transform: translateY(60px) scale(0.6) rotate(-10deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

/* Trick Play Table Center Cards */
.trick-card-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  animation: throwCard 0.38s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
  transition: transform 0.4s ease, opacity 0.4s ease;
}

.trick-card-wrapper.winning-card .card {
  border: 2px solid var(--gold) !important;
  box-shadow:
    0 0 22px var(--gold),
    0 8px 20px rgba(0, 0, 0, 0.6) !important;
  animation: winningPulse 1.2s infinite alternate;
}

@keyframes winningPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 16px var(--gold-glow);
  }
  100% {
    transform: scale(1.08);
    box-shadow: 0 0 26px var(--gold);
  }
}

.trick-player-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(8, 20, 13, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 2px 10px;
  border-radius: 12px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

@keyframes throwCard {
  0% {
    opacity: 0;
    transform: scale(0.55) translateY(45px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Trick sweep away animation when trick ends */
.trick-card-wrapper.sweep-out {
  opacity: 0;
  transform: scale(0.6) translateY(-40px);
  transition: transform 0.45s ease-in, opacity 0.45s ease-in;
}

/* ==========================================================================
   Responsive Sizing & Overlapping Hand Logic
   ========================================================================== */

@media (max-width: 768px) {
  .card {
    width: 62px;
    height: 92px;
    padding: 5px 6px;
    border-radius: 8px;
  }
  .card-rank {
    font-size: 1.02rem;
  }
  .card-suit-sm {
    font-size: 0.78rem;
  }
  .card-center {
    font-size: 1.75rem;
  }
}

@media (max-width: 480px) {
  .card {
    width: 52px;
    height: 78px;
    padding: 3px 5px;
    border-radius: 7px;
  }
  .card-rank {
    font-size: 0.92rem;
  }
  .card-suit-sm {
    font-size: 0.7rem;
  }
  .card-center {
    font-size: 1.45rem;
  }

  /* When hand has more than 5 cards on small mobile, overlap slightly */
  .hand-cards-row.crowded .card {
    margin-left: -14px;
  }
  .hand-cards-row.crowded .card:first-child {
    margin-left: 0;
  }
  .hand-cards-row.crowded .card:hover,
  .hand-cards-row.crowded .card.selected {
    margin-left: 2px;
    margin-right: 6px;
    z-index: 70;
  }
}

/* ==========================================================================
   Reduced Motion Accessibility
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .card,
  .trick-card-wrapper,
  .card.deal-animate,
  .trick-card-wrapper.winning-card .card {
    animation: none !important;
    transition: none !important;
  }
}
