/*
We want to have the game div in the middle of the screen.

height&width 100vh makes the body take the full viewport.
[margin: 0] and [padding: 0]removes default margins&paddings.
Flexbox centers it both horizontally and vertically

It is possible to use instead:
[display: grid; place-items: center;]
The flexbox approach is probably more widely supported,
while the Grid approach with place-items: center is more concise.
*/
body {
  background-color: rgb(231, 216, 216);
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: fixed !important;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  border: 10px solid black;
}
/*
min(100vw, 100vh) ensures the square fits within both screen dimensions.
If your game isn't square, you can change the aspect ratio, see [aspect-ratio: 1].
We give it [position: relative] so that the inside elements can be [position:absolute].
*/
.game {
  width: min(100vw, 100vh);
  height: min(100vw, 100vh);
  aspect-ratio: 1;
  position: relative;
}

/* To prevent long-press that will bring up copy-paste dialog.
user-select: none prevents text selection
-webkit-touch-callout: none specifically prevents the iOS long-press callout
-webkit-tap-highlight-color: transparent removes tap highlights on mobile
*/
* {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -moz-touch-callout: none;
  -ms-touch-callout: none;
  outline: 0; /* To prevent blue-box outline after click: http://stackoverflow.com/questions/21719306/getting-rid-of-a-blue-box-around-button-when-pressed */
}
textarea,
input {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
}

.turn-indicator {
  position: absolute;
  top: 5%;
  left: 10%;
  transform: translateX(-50%);
  background-color: rgba(255, 255, 255, 0.9);
  padding: min(2vw, 2vh) min(4vw, 4vh);
  border-radius: min(1vw, 1vh);
  border: min(0.5vw, 0.5vh) solid black;
}


.turn-indicator h2 {
  margin: 0;
  font-size: 1.5em;
  text-align: center;
}

.hand {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  left: 0;
  right: 0;
  pointer-events: none;
}

.player_2, .player_4 {
  flex-direction: column;
  left: auto;
  right: auto;
  top: 50%;
  transform: translateY(-50%);
}

.card {
  width: calc(min(100vw, 100vh)/ 10);
  height: calc(min(100vw, 100vh)/ 10);
}


.card.hoverable {
  cursor: pointer;
  transition: transform 0.2s ease;
  pointer-events: auto;
}

.player_1 .card.hoverable:hover {
  transform: translateY(-20%);
}
.player_1 .card.hoverable.selected {
  transform: translateY(-120%);
}

.player_2 .card.hoverable:hover {
  transform: rotate(90deg) translateY(-20%);
}
.player_2 .card.hoverable.selected {
  transform: rotate(90deg) translateY(-120%);
}

.player_3 .card.hoverable:hover {
  transform: translateY(20%);
}
.player_3 .card.hoverable.selected {
  transform: translateY(120%);
}

.player_4 .card.hoverable:hover {
  transform: rotate(90deg) translateY(20%);
}
.player_4 .card.hoverable.selected {
  transform: rotate(90deg) translateY(120%);
}


.player_4 {
  position: absolute;
  right: 5%;
}

.player_3 {
  position: absolute;
  top: 5%;
}

.player_2 {
  position: absolute;
  left: 5%;
}

.player_1 {
  position: absolute;
  bottom: 17%;
}

.player_2 .card, .player_4 .card {
  margin-bottom: -30%;
  transform: rotate(90deg);
}

.trick {
  position: absolute;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.trick .card {
  margin-right: -7%;
}

.trick .card:last-child {
  margin-right: 0;
}


.deal-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  /* Make it large */
  font-size: 2em;
  padding: min(3vw, 3vh) min(6vw, 6vh);
  
  /* Styling */
  background-color: #4CAF50;
  color: white;
  border: min(0.5vw, 0.5vh) solid #45a049;
  border-radius: min(1vw, 1vh);
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 min(0.5vw, 0.5vh) min(1vw, 1vh) rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.deal-button:hover {
  background-color: #45a049;
  box-shadow: 0 min(0.8vw, 0.8vh) min(1.5vw, 1.5vh) rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%) scale(1.05);
}

.deal-button:active {
  transform: translate(-50%, -50%) scale(0.98);
  box-shadow: 0 min(0.2vw, 0.2vh) min(0.5vw, 0.5vh) rgba(0, 0, 0, 0.2);
}


/* Action button (PASS/PLAY) */
.action-button {
  position: absolute;
  bottom: 5%;
  right: 45%;
  
  font-size: 1.5em;
  padding: min(2vw, 2vh) min(4vw, 4vh);
  
  color: white;
  border: min(0.3vw, 0.3vh) solid rgba(0, 0, 0, 0.3);
  border-radius: min(0.8vw, 0.8vh);
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 min(0.4vw, 0.4vh) min(0.8vw, 0.8vh) rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  min-width: min(15vw, 15vh);
  text-align: center;
}

/* PASS button styling */
.pass-button {
  background-color: #f44336;
  border-color: #d32f2f;
}

.pass-button:hover {
  background-color: #d32f2f;
  box-shadow: 0 min(0.6vw, 0.6vh) min(1.2vw, 1.2vh) rgba(0, 0, 0, 0.4);
  transform: scale(1.05);
}

/* PLAY button styling */
.play-button {
  background-color: #2196F3;
  border-color: #1976D2;
}

.play-button:hover {
  background-color: #1976D2;
  box-shadow: 0 min(0.6vw, 0.6vh) min(1.2vw, 1.2vh) rgba(0, 0, 0, 0.4);
  transform: scale(1.05);
}

.action-button:active {
  transform: scale(0.95);
  box-shadow: 0 min(0.2vw, 0.2vh) min(0.4vw, 0.4vh) rgba(0, 0, 0, 0.2);
}

/* Error message */
.error-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  background-color: rgba(244, 67, 54, 0.95);
  color: white;
  font-size: 1.8em;
  font-weight: bold;
  padding: min(3vw, 3vh) min(6vw, 6vh);
  border-radius: min(1vw, 1vh);
  border: min(0.5vw, 0.5vh) solid #d32f2f;
  box-shadow: 0 min(1vw, 1vh) min(3vw, 3vh) rgba(0, 0, 0, 0.5);
  z-index: 1000;
  text-align: center;
  
  /* Auto-fade after 1 second */
  animation: shake 0.5s, fadeOut 0.5s 1s forwards;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; pointer-events: none; }
}

@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  10%, 30%, 50%, 70%, 90% { transform: translate(-50%, -50%) rotate(-2deg); }
  20%, 40%, 60%, 80% { transform: translate(-50%, -50%) rotate(2deg); }
}

.opponent-hand-display {
  display: flex;
  align-items: center;
  gap: min(2vw, 2vh);
}

.card-count {
  font-size: 2em;
  font-weight: bold;
  color: white;
  text-shadow: 
    -1px -1px 0 #000,  
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
  z-index: 10;
}

/* Adjust for rotated side players */
.player_2 .opponent-hand-display,
.player_4 .opponent-hand-display {
  flex-direction: column;
}

/* Round Over display */
.round-over {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  background-color: rgba(255, 255, 255, 0.95);
  padding: min(4vw, 4vh) min(6vw, 6vh);
  border-radius: min(2vw, 2vh);
  border: min(0.5vw, 0.5vh) solid #333;
  box-shadow: 0 min(1.5vw, 1.5vh) min(4vw, 4vh) rgba(0, 0, 0, 0.5);
  z-index: 1000;
  text-align: center;
  min-width: 40%;
}

.round-over-title {
  font-size: 3em;
  font-weight: bold;
  color: #4CAF50;
  margin-bottom: min(2vw, 2vh);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.round-ranking {
  font-size: 1.8em;
  color: #333;
  line-height: 1.6;
  margin-top: min(2vw, 2vh);
  padding: min(2vw, 2vh);
  background-color: rgba(240, 240, 240, 0.8);
  border-radius: min(1vw, 1vh);
}

/* Individual ranking entries if you use the vertical list version */
.ranking-entry {
  font-size: 1.8em;
  padding: min(1vw, 1vh);
  margin: min(0.5vw, 0.5vh) 0;
  color: #333;
  font-weight: 500;
}

.ranking-entry:first-child {
  color: #FFD700;
  font-weight: bold;
  font-size: 2em;
}

.ranking-entry:nth-child(2) {
  color: #C0C0C0;
  font-weight: bold;
}

.ranking-entry:nth-child(3) {
  color: #CD7F32;
  font-weight: bold;
}

@media (max-width: 768px) {
  .card {
    width: calc(min(100vw, 100vh) / 15);
    height: calc(min(100vw, 100vh) / 15);
  }
  
  .player_2 .card, .player_4 .card {
  margin-bottom: -10%;
  transform: rotate(90deg);
}
.trick .card {
  margin-right: -4%;
}
}

/* ========== LOBBY SCREENS ========== */

/* Main Menu */
.main-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(3vw, 3vh);
  padding: min(4vw, 4vh);
}

.main-menu h1 {
  font-size: 3em;
  color: #333;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.menu-button {
  font-size: 1.8em;
  padding: min(2vw, 2vh) min(6vw, 6vh);
  background-color: #4CAF50;
  color: white;
  border: min(0.3vw, 0.3vh) solid #45a049;
  border-radius: min(1vw, 1vh);
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 min(0.4vw, 0.4vh) min(0.8vw, 0.8vh) rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  min-width: min(30vw, 30vh);
}

.menu-button:hover {
  background-color: #45a049;
  transform: scale(1.05);
}

.menu-button:active {
  transform: scale(0.95);
}

/* Join Lobby Screen */
.join-lobby-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: min(2vw, 2vh);
  padding: min(4vw, 4vh);
}

.join-lobby-screen h2 {
  font-size: 2.5em;
  color: #333;
  margin: 0;
}

.input-container {
  display: flex;
  flex-direction: column;
  gap: min(1vw, 1vh);
  width: 80%;
  max-width: min(50vw, 50vh);
}

.input-container label {
  font-size: 1.5em;
  font-weight: bold;
  color: #333;
}

.game-id-input {
  font-size: 1.5em;
  padding: min(1.5vw, 1.5vh);
  border: min(0.3vw, 0.3vh) solid #ccc;
  border-radius: min(0.8vw, 0.8vh);
  text-align: center;
}

.button-group {
  display: flex;
  gap: min(2vw, 2vh);
  justify-content: center;
}

.back-button {
  background-color: #757575;
  border-color: #616161;
}

.back-button:hover {
  background-color: #616161;
}

/* Lobby Waiting Screen */
.lobby-waiting-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(2vw, 2vh);
  padding: min(4vw, 4vh);
}

.lobby-waiting-screen h2 {
  font-size: 2.5em;
  color: #333;
  margin: 0;
}

.game-id-display {
  font-size: 1.8em;
  background-color: rgba(255, 255, 255, 0.9);
  padding: min(2vw, 2vh) min(4vw, 4vh);
  border-radius: min(1vw, 1vh);
  border: min(0.3vw, 0.3vh) solid #333;
}

.game-id-value {
  font-family: monospace;
  font-weight: bold;
  color: #2196F3;
}

.players-section {
  width: 80%;
  max-width: min(50vw, 50vh);
  text-align: center;
}

.players-section h3 {
  font-size: 2em;
  margin: 0 0 min(1vw, 1vh) 0;
}

.players-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.player-item {
  font-size: 1.6em;
  padding: min(1vw, 1vh);
  background-color: rgba(255, 255, 255, 0.8);
  margin: min(0.5vw, 0.5vh) 0;
  border-radius: min(0.5vw, 0.5vh);
}

.player-count {
  font-size: 1.4em;
  color: #666;
  margin-top: min(1vw, 1vh);
}

.lobby-actions {
  display: flex;
  gap: min(2vw, 2vh);
  flex-wrap: wrap;
  justify-content: center;
}

.start-game-button {
  background-color: #4CAF50;
  border-color: #45a049;
}

.start-game-button:hover {
  background-color: #45a049;
}

.leave-button {
  background-color: #f44336;
  border-color: #d32f2f;
}

.leave-button:hover {
  background-color: #d32f2f;
}

.waiting-message {
  font-size: 1.6em;
  color: #666;
  font-style: italic;
}

/* Loading State */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5em;
  color: #333;
  font-weight: bold;
}