/* --- General Styling --- */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Prevent scrolling */
}

body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background-color: #013220; /* Dark green background */
  color: #fff;
  -webkit-user-select: none; /* Safari */
  -ms-user-select: none; /* IE 10+ */
  user-select: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-table {
  width: 100%;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  background-color: #006400; /* Classic green felt */
  border-radius: 15px;
  border: 3px solid #b38b00;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* --- Area Distribution --- */
#info-area {
  flex-shrink: 0; /* Don't shrink */
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 222, 122, 0.4);
}

#computer-area,
#player-area {
  flex: 1; /* Grow and shrink to fill available space */
  min-height: 0; /* Allow shrinking below content size */
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#play-area {
  flex-shrink: 0; /* Don't shrink */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
}

/* --- Info Area (Redesigned for Horizontal Layout) --- */
.title {
  margin: 0;
  font-size: 1.8em;
  font-weight: bold;
  color: #ffde7a;
  text-shadow: 2px 2px 4px #000;
}

#score-board {
  margin: 0 10px;
  font-size: 1em;
  flex-shrink: 0;
}
#score-board p {
  margin: 0 10px;
  display: inline;
}

#message-area {
  flex-grow: 1;
  text-align: center;
  min-height: 24px;
  font-size: 1.1em;
  font-style: italic;
  margin: 0 10px;
  color: #fafad2;
}

/* --- Hand & Card Styling --- */
.hand {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 5px;
  flex-wrap: wrap;
}

.card {
  width: 70px;
  height: 105px;
  border: 1px solid #222;
  border-radius: 6px;
  background-color: #fff;
  margin: 0 -30px; /* Overlap cards more */
  padding: 5px;
  box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.3);
  position: relative;
  font-size: 18px;
  font-weight: bold;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: default;
}

.card.red {
  color: #d90000;
}
.card.black {
  color: #000;
}

.card .rank {
  position: absolute;
  top: 5px;
  left: 8px;
}

.card .suit {
  position: absolute;
  bottom: 5px;
  right: 8px;
  font-size: 24px;
}

.card .suit-left {
  position: absolute;
  bottom: 5px;
  left: 8px;
  font-size: 24px;
}

/* Player Hand Interactions */
#player-hand .card {
  cursor: pointer;
}
#player-hand .card:hover {
  transform: translateY(-12px) scale(1.05);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

/* Card Back */
.card.back {
  background-color: #4a6da7;
  background-image: radial-gradient(circle, #5e84c4 20%, transparent 20%),
    radial-gradient(circle, #5e84c4 20%, transparent 20%);
  background-size: 15px 15px;
  background-position: 0 0, 7.5px 7.5px;
  border: 2px solid #fff;
}

/* --- Play Area (Redesigned for Horizontal Labels) --- */
#stock-pile-container,
#discard-pile-container {
  display: flex;
  align-items: center;
  margin: 0 15px;
}

.pile-label {
  margin: 0 15px 0 0;
  font-weight: bold;
  font-size: 1.1em;
}

.card-pile {
  width: 80px;
  height: 115px;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#stock-pile .card,
#discard-pile .card {
  margin: 0;
  cursor: pointer;
}

#stock-pile .card:hover,
#discard-pile .card:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
}

/* --- Action Buttons --- */
.actions {
  text-align: center;
  padding-top: 10px;
}

#info-area .actions {
  padding-top: 0;
}

button {
  background-color: #ffde7a;
  color: #333;
  border: 2px solid #b38b00;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
  margin: 5px;
}

button:hover:not(:disabled) {
  background-color: #fffacd;
  transform: translateY(-2px);
}

button:disabled {
  background-color: #999;
  color: #666;
  border-color: #555;
  cursor: not-allowed;
}

/* --- End of Hand Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-content {
  background: #006400;
  padding: 20px;
  border-radius: 10px;
  border: 2px solid #b38b00;
  text-align: center;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

#end-hand-title {
  color: #ffde7a;
}
#end-hand-details {
  margin: 20px 0;
}

.hand-reveal {
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  padding-top: 10px;
  margin-top: 10px;
}
.hand-reveal h3 {
  margin: 5px 0;
}
.hand-reveal .card {
  margin: 2px;
}

.melds,
.deadwood {
  border: 1px solid #b38b00;
  border-radius: 5px;
  padding: 5px;
  margin: 5px 0;
  min-height: 110px; /* Adjust for smaller cards */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.melds .meld-group {
  display: inline-flex;
  padding: 5px;
  margin: 5px;
  border: 1px solid white;
  border-radius: 5px;
}

/* --- Responsive Design Fallbacks --- */
@media (max-width: 768px) {
  #info-area {
    flex-wrap: wrap;
    justify-content: center;
    padding-bottom: 5px;
  }
  #info-area > * {
    margin-bottom: 5px;
  }
  .title {
    font-size: 1.5em;
    width: 100%;
    text-align: center;
  }
  #message-area {
    width: 100%;
    order: 3;
  }
  #score-board {
    order: 2;
  }
  #info-area .actions {
    order: 4;
  }

  .card {
    width: 60px;
    height: 90px;
    margin: 0 -25px;
    font-size: 16px;
  }
  .card .suit,
  .card .suit-left {
    font-size: 22px;
  }
  .card-pile {
    width: 70px;
    height: 100px;
  }
  #player-hand .card:hover {
    transform: translateY(-10px) scale(1.05);
  }
  .melds,
  .deadwood {
    min-height: 105px;
  }
}

@media (max-width: 480px) {
  body {
    position: fixed;
    width: 100%;
    height: 100%;
  }
  #game-table {
    padding: 5px;
    border-radius: 0;
    border: none;
    height: 100vh;
    width: 100vw;
  }

  #play-area {
    padding: 5px 0;
  }
  #stock-pile-container,
  #discard-pile-container {
    margin: 0 5px;
  }
  .pile-label {
    font-size: 0.9em;
    margin-right: 5px;
  }

  /* Use viewport units for fluid scaling */
  .card {
    width: 9vmin;
    height: 13.5vmin;
    margin: 0 -4.5vmin;
    font-size: 2.2vmin;
    border-radius: 3px;
    /* Set max sizes to prevent getting too big on weird aspect ratios */
    max-width: 50px;
    max-height: 75px;
  }

  .card .rank {
    top: 3px;
    left: 4px;
  }
  .card .suit,
  .card .suit-left {
    font-size: 3vmin;
    bottom: 2px;
    right: 4px;
  }

  .card-pile {
    width: 10vmin;
    height: 14.5vmin;
    max-width: 55px;
    max-height: 80px;
  }

  button {
    padding: 8px 12px;
    font-size: 0.9em;
  }
  #player-hand .card:hover {
    transform: translateY(-8px) scale(1.05);
  }

  .melds,
  .deadwood {
    min-height: 80px;
  }
  .melds .card,
  .deadwood .card {
    margin: 1px;
  }
}
/* Placeholder (shows where the card will be dropped) */
.card.placeholder {
  background: transparent;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  box-shadow: none;
  margin: 0 -30px; /* match .card overlap */
  min-width: 60px;
  min-height: 90px;
  pointer-events: none;
}

/* Floating clone that follows the pointer */
.dragging-clone {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: rotate(1deg);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);
  transition: none !important;
}
