:root {
  --felt: #0b5c3a;
  --felt-dark: #084a2e;
  --gold: #d4af37;
  --card-w: 116px;
  --card-h: 163px;
  --back-card-w: 74px;
  --back-card-h: 104px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  color: #f2f2f2;
  font-size: 18px;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: rgba(0, 0, 0, 0.25);
  flex-wrap: wrap;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 1px;
  color: var(--gold);
}

.games-played {
  padding: 4px 20px;
  font-size: 13px;
  color: #c9c9c9;
  text-align: left;
}

.scoreboard {
  display: flex;
  gap: 16px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 18px;
  border-radius: 10px;
  min-width: 90px;
}

.score-label {
  font-size: 14px;
  text-transform: uppercase;
  opacity: 0.75;
}

.score-value {
  font-size: 30px;
  font-weight: 700;
}

.topbar-actions button {
  margin-left: 8px;
}

button {
  background: var(--gold);
  color: #201800;
  border: none;
  border-radius: 10px;
  padding: 14px 24px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 20px;
  gap: 10px;
}

.opponent-area, .player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hand-label-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hand-label {
  font-size: 16px;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#sort-btn {
  padding: 6px 14px;
  font-size: 14px;
}

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: var(--card-h);
  flex-wrap: wrap;
  gap: 8px;
}

.hand-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.group-cards {
  display: flex;
  gap: 6px;
}

.group-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.deadwood-group .group-label {
  color: #e08a8a;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: #fdfdfd;
  color: #111;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 8px;
  font-weight: 700;
  cursor: default;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border 0.12s ease;
  border: 3px solid transparent;
  position: relative;
}

.hand-face-down {
  min-height: var(--back-card-h);
}

.hand-face-up .card {
  cursor: grab;
}

.hand-face-up .card:hover {
  transform: translateY(-8px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.5);
}

.card.dragging {
  opacity: 0.4;
}

.card.drag-over {
  border-color: #fff;
  transform: translateY(-8px) scale(1.04);
}

.card.selected {
  transform: translateY(-14px);
  border-color: #fff;
  box-shadow: 0 8px 16px rgba(0,0,0,0.55);
}

.card.meld-hint {
  border-color: var(--gold);
}

.card .rank-top {
  font-size: 27px;
  line-height: 1;
}

.card .suit-center {
  font-size: 47px;
  text-align: center;
  line-height: 1;
}

.card .rank-bottom {
  font-size: 27px;
  line-height: 1;
  align-self: flex-end;
  transform: rotate(180deg);
}

.card.red { color: #c0272d; }
.card.black { color: #111; }

.card-back {
  width: var(--back-card-w);
  height: var(--back-card-h);
  border-radius: 8px;
  background: repeating-linear-gradient(
    45deg,
    #1a3fae,
    #1a3fae 6px,
    #16368f 6px,
    #16368f 12px
  );
  border: 2px solid #0d2266;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
}

.middle-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
}

.pile-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pile-label {
  font-size: 14px;
  opacity: 0.75;
  text-transform: uppercase;
}

.pile {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 2px dashed rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.stock-pile {
  width: var(--back-card-w);
  height: var(--back-card-h);
}

.stock-pile:hover, .discard-pile:hover {
  border-color: var(--gold);
}

.pile-count {
  font-size: 16px;
  opacity: 0.8;
}

.message {
  min-width: 260px;
  max-width: 400px;
  text-align: center;
  font-size: 18px;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  padding: 12px 20px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.controls {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}

#deadwood-label {
  font-weight: 700;
  color: var(--gold);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #123d29;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.modal-content h2 {
  margin-top: 0;
  color: var(--gold);
}

.rules-text p {
  font-size: 17px;
  line-height: 1.5;
}

#result-body {
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 16px;
}

#result-body .final {
  margin-top: 10px;
  font-weight: 700;
  color: var(--gold);
}

@media (max-width: 640px) {
  :root {
    --card-w: 92px;
    --card-h: 130px;
  }
  .card .suit-center { font-size: 38px; }
  .card .rank-top, .card .rank-bottom { font-size: 22px; }
  .middle-area { gap: 20px; }
}
