:root {
  color-scheme: dark;
}

body {
  letter-spacing: -0.01em;
}

.game-frame {
  min-height: 520px;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  row-gap: 0.75rem;
  justify-content: center;
  padding: 0.85rem 0.6rem;
}

.hand .card {
  width: 52px;
  height: 72px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(15, 23, 42, 0.65));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: #f8fafc;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.hand .card .rank-corner {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.hand .card .rank-corner-bottom {
  top: auto;
  left: auto;
  bottom: 4px;
  right: 6px;
  transform: rotate(180deg);
}

.hand .card .suit-corner {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
  line-height: 1;
}

.hand .card .suit-corner-bottom {
  top: auto;
  right: auto;
  bottom: 4px;
  left: 6px;
  transform: rotate(180deg);
}

.hand .card .suit-center {
  font-size: 1.6rem;
  line-height: 1;
  margin-top: 0.25rem;
}

.hand .card.hearts,
.hand .card.diamonds {
  color: #ef4444;
}

.hand .card.hearts .suit-center,
.hand .card.hearts .suit-corner {
  color: #fca5a5;
}

.hand .card.diamonds .suit-center,
.hand .card.diamonds .suit-corner {
  color: #f97316;
  text-shadow: 0 0 5px rgba(249, 115, 22, 0.9), 0 2px 3px rgba(0, 0, 0, 0.4);
  position: relative;
  font-weight: 700;
}

.hand .card.diamonds .suit-center {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.25), rgba(251, 146, 60, 0.1));
  border-radius: 3px;
  padding: 0.15rem;
  position: relative;
  box-shadow: inset 0 0 3px rgba(249, 115, 22, 0.3);
}

.hand .card.diamonds .suit-center::before {
  content: "♦";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.35) rotate(45deg);
  opacity: 0.25;
  color: #f97316;
  font-weight: 900;
}

.hand .card.clubs,
.hand .card.spades {
  color: #f8fafc;
}

.hand .card.clubs .suit-center,
.hand .card.spades .suit-center {
  color: #e2e8f0;
}

.hand .card:hover:not(.disabled) {
  transform: translateY(-4px);
  box-shadow: 0 10px 20px rgba(16, 185, 129, 0.35);
}

.hand .card.disabled {
  opacity: 0.35;
  filter: grayscale(1) brightness(0.3);
  cursor: not-allowed;
  pointer-events: auto;
  border-color: rgba(239, 68, 68, 0.3);
  background: linear-gradient(135deg, rgba(71, 85, 105, 0.15), rgba(15, 23, 42, 0.8));
  position: relative;
}

.hand .card.disabled::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 2px;
  height: 100%;
  background: rgba(239, 68, 68, 0.5);
  z-index: 1;
}

.hand .card.disabled:hover {
  transform: none;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
  opacity: 0.5;
  border-color: rgba(239, 68, 68, 0.5);
}

.hand .card.selected {
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
  transform: translateY(-2px);
}

.hand.hidden-cards .card {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.8), rgba(15, 23, 42, 0.9));
  border-style: dashed;
  cursor: default;
}

/* Opponent card count - single card showing number */
.opponent-card-count {
  width: 52px !important;
  height: 72px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 2rem !important;
  font-weight: 700 !important;
  color: #ffffff !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  border-style: solid !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.9), rgba(15, 23, 42, 0.95)) !important;
  margin: 0 auto !important;
}

.player-label {
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(16, 185, 129, 0.9);
}

.makker-text {
  font-size: 0.68rem; /* 20% smaller than 0.85rem */
  text-transform: uppercase;
  letter-spacing: normal;
  color: rgba(16, 185, 129, 0.9);
}

.player-label.active {
  color: #fbbf24;
}

.player-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid transparent;
  border-radius: 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.player-slot.active {
  border-color: rgba(16, 185, 129, 0.8);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.35);
}

.current-trick-section {
  margin-top: -30px;
}

.trick-info-bottom {
  margin-bottom: 10px;
}

.current-trick {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  min-height: 120px;
}

.turn-badge {
  padding: 0.3rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(16, 185, 129, 0.6);
  background: rgba(15, 23, 42, 0.8);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(248, 250, 252, 0.9);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.current-trick .trick-card {
  width: 72px;
  height: 96px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.2rem;
}

.current-trick .trick-card .player {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: rgba(148, 163, 184, 0.9);
}

.current-trick .trick-card.winner {
  border-color: rgba(16, 185, 129, 0.9);
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.55);
  animation: winnerPulse 0.6s ease-in-out;
}

@keyframes winnerPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.4), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(16, 185, 129, 0.5);
  border-radius: 24px;
  padding: 2.5rem;
  text-align: center;
  max-width: 420px;
}

.suit-icon {
  font-size: 1.2rem;
}

.tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(16, 185, 129, 0.5);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
}

.tooltip.visible {
  opacity: 1;
}

.hover-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(239, 68, 68, 0.6);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s;
  color: #fca5a5;
}

.hover-tooltip.visible {
  opacity: 1;
}

.sort-btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.7rem;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: rgba(248, 250, 252, 0.9);
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  white-space: nowrap;
  min-width: 90px;
}

.sort-btn:hover,
.sort-btn:focus {
  background: rgba(16, 185, 129, 0.3);
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

.sort-btn.active {
  background: rgba(16, 185, 129, 0.4);
  border-color: rgba(16, 185, 129, 0.7);
  color: #fbbf24;
  font-weight: 600;
}

.last-trick-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.75rem;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: rgba(248, 250, 252, 0.9);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  outline: none;
}

.last-trick-btn:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.6);
}

.last-trick-btn:focus {
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.trick-history-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
}

.trick-history-nav button {
  padding: 0.3rem 0.6rem;
  font-size: 0.7rem;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: rgba(248, 250, 252, 0.9);
  cursor: pointer;
}

.trick-history-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.trick-preview {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 8px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.7rem;
  text-align: center;
  max-width: 200px;
}

.trick-preview.hidden {
  display: none;
}

.player-slot[data-player="South"] {
  margin-top: -2.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
  /* South's cards - slightly smaller but still playable */
  .hand:not(.hidden-cards) .card {
    width: 44px;
    height: 62px;
    font-size: 0.8rem;
  }
  .hand:not(.hidden-cards) .card .suit-center {
    font-size: 1.3rem;
  }
  .hand:not(.hidden-cards) .card .rank-corner {
    font-size: 0.65rem;
  }
  
  /* North/East/West cards - single card with count */
  .hand.hidden-cards {
    gap: 0 !important;
    padding: 0.25rem !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  /* Opponent card count on mobile */
  .opponent-card-count {
    width: 40px !important;
    height: 56px !important;
    font-size: 1.5rem !important;
  }
  
  .current-trick {
    display: flex;
    flex-direction: row;
    gap: 0.3rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    min-height: 80px;
  }
  .current-trick .trick-card {
    width: 50px;
    height: 70px;
  }
  .current-trick .trick-card .player {
    font-size: 0.55rem;
  }
  .current-trick .trick-card .text-lg {
    font-size: 0.7rem;
  }
  
  .player-slot {
    padding: 0.5rem;
    gap: 0.4rem;
  }
  
  .player-label {
    font-size: 0.7rem;
  }
  
  .makker-text {
    font-size: 0.56rem; /* 20% smaller than 0.7rem */
  }
  
  .turn-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.75rem;
  }
  
  .game-frame {
    padding: 0.5rem !important;
  }
  
  .table-grid {
    gap: 0.5rem !important;
  }
}

/* Tablet styling - applies from mobile up to tablet */
@media (max-width: 1024px) {
  /* Opponent card count on tablet */
  .opponent-card-count {
    width: 46px !important;
    height: 64px !important;
    font-size: 1.75rem !important;
  }
  
  /* Match status - tablet: slightly larger fonts but still one row */
  .match-status-row {
    gap: 0.6rem !important;
  }
  
  .match-status-item {
    padding: 0.6rem 0.9rem !important;
    border-radius: 10px !important;
  }
  
  .match-status-row span.text-sm {
    font-size: 0.7rem !important;
  }
  
  .match-status-row span.text-2xl {
    font-size: 1.1rem !important;
  }
  
  .match-status-row span.text-xl {
    font-size: 0.95rem !important;
  }
}

/* Desktop styling for match status */
@media (min-width: 1025px) {
  .match-status-row {
    gap: 0.75rem !important;
  }
  
  .match-status-item {
    padding: 0.75rem 1rem !important;
    border-radius: 12px !important;
  }
}

@media (min-width: 1500px) {
  .hand .card {
    width: 58px;
    height: 80px;
  }
  .hand .card .suit-center {
    font-size: 1.8rem;
  }
  
  /* Opponent card count on large desktop */
  .opponent-card-count {
    width: 58px !important;
    height: 80px !important;
    font-size: 2.5rem !important;
  }
  
  .match-status-row {
    gap: 1rem !important;
  }
  
  .match-status-item {
    padding: 0.875rem 1.25rem !important;
    border-radius: 14px !important;
  }
}

@media (min-width: 125%) {
  .sort-btn,
  .last-trick-btn {
    margin: 0.25rem 0;
    padding: 0.35rem 0.7rem;
    font-size: 0.7rem;
  }
  .hand {
    gap: 0.5rem;
  }
}

@media (min-width: 100%) and (max-width: 150%) {
  .sort-btn {
    margin-bottom: 0.3rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.68rem;
    min-width: 85px;
  }
  .last-trick-btn {
    margin: 0.2rem 0;
    padding: 0.35rem 0.75rem;
    font-size: 0.7rem;
  }
  .hand {
    gap: 0.5rem;
    row-gap: 0.65rem;
    padding: 0.7rem 0.5rem;
  }
  .hand .card {
    width: 50px;
    height: 70px;
  }
}

@media (min-width: 75%) and (max-width: 100%) {
  .sort-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
    min-width: 80px;
    margin-bottom: 0.25rem;
  }
  .last-trick-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
    margin: 0.15rem 0;
  }
  .hand .card {
    width: 46px;
    height: 64px;
  }
  .hand .card .suit-center {
    font-size: 1.4rem;
  }
  .player-slot {
    gap: 0.4rem;
  }
}

@media (max-width: 640px) {
  .sort-btn {
    width: auto;
    min-width: auto;
    margin: 0;
    padding: 0.3rem 0.5rem;
    font-size: 0.65rem;
  }
  .last-trick-btn {
    width: 100%;
    max-width: 200px;
    margin: 0.2rem auto;
  }
  
  /* Keep sort/shuffle buttons side by side on mobile */
  .player-slot[data-player="South"] .flex {
    flex-wrap: nowrap !important;
  }
  
  /* Further optimize for very small screens */
  .game-frame {
    border-width: 2px !important;
    border-radius: 16px !important;
  }
  
  /* Three column layout for North/East/West */
  .grid.grid-cols-3 {
    gap: 0.5rem !important;
  }
  
  .player-slot[data-player="North"],
  .player-slot[data-player="West"],
  .player-slot[data-player="East"] {
    padding: 0.4rem !important;
    gap: 0.3rem !important;
  }
  
  .player-label {
    font-size: 0.65rem !important;
  }
  
  .makker-text {
    font-size: 0.52rem !important; /* 20% smaller than 0.65rem */
  }
  
  /* Match status section */
  .relative.px-4 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
  
  /* Control buttons above match status - always one row, centered */
  .flex.gap-2.items-center.justify-center.flex-nowrap.mb-2 {
    flex-wrap: nowrap !important;
    gap: 0.5rem !important;
  }
  
  .flex.gap-2.items-center.justify-center.flex-nowrap.mb-2 button,
  .flex.gap-2.items-center.justify-center.flex-nowrap.mb-2 select {
    font-size: 0.65rem !important;
    padding: 0.35rem 0.7rem !important;
  }
  
  /* Match status - always one row, centered */
  .match-status-row {
    flex-wrap: nowrap !important;
    justify-content: center !important;
    gap: 0.4rem !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .match-status-item {
    background: rgba(16, 185, 129, 0.25) !important;
    border: 1px solid rgba(16, 185, 129, 0.5) !important;
    border-radius: 6px !important;
    padding: 0.35rem 0.5rem !important;
    min-width: auto !important;
    flex-shrink: 0 !important;
    text-align: center !important;
  }
  
  .match-status-row span.text-sm {
    font-size: 0.55rem !important;
  }
  
  .match-status-row span.text-2xl {
    font-size: 0.85rem !important;
  }
  
  .match-status-row span.text-xl {
    font-size: 0.7rem !important;
  }
  
  /* Header text */
  h1 {
    font-size: 1.5rem !important;
  }
  
  /* Phase indicator inherits styling from parent */
  #phase-indicator {
    display: inline;
  }
  
  /* Buttons */
  #new-deal-btn,
  #new-match-btn {
    font-size: 0.65rem !important;
    padding: 0.35rem 0.7rem !important;
  }
  
  /* Style match length dropdown on mobile */
  #point-target-select {
    font-size: 0.65rem !important;
    padding: 0.3rem 0.5rem !important;
  }
  
  label[for="point-target-select"] {
    font-size: 0.6rem !important;
  }
  
  /* Ensure buttons stay visible on mobile - stack vertically */
  .game-frame .flex.justify-between.items-center {
    flex-direction: column !important;
    align-items: center !important;
    gap: 0.75rem !important;
  }
  
  .game-frame .flex.justify-between.items-center > div:first-child {
    width: 100%;
  }
  
  .game-frame .flex.justify-between.items-center > div:last-child {
    width: 100%;
    justify-content: center;
    align-items: center;
  }
  
  /* Header navigation */
  nav.flex.gap-3 {
    gap: 0.5rem !important;
  }
  
  nav.flex.gap-3 a,
  nav.flex.gap-3 button {
    font-size: 0.7rem !important;
    padding: 0.35rem 0.7rem !important;
  }
  
  /* Modals responsive */
  .overlay-card {
    max-width: 95% !important;
    padding: 1.5rem !important;
    margin: 1rem !important;
  }
  
  .overlay-card h2 {
    font-size: 1.25rem !important;
  }
  
  .overlay-card p,
  .overlay-card li {
    font-size: 0.85rem !important;
  }
  
  /* Trick history modal */
  .trick-card {
    width: 60px !important;
    height: 80px !important;
  }
  
  .trick-card .player {
    font-size: 0.6rem !important;
  }
  
  .trick-card .text-lg {
    font-size: 0.75rem !important;
  }
}
