* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #1a6b3c url('background.png') no-repeat center center;
  background-size: cover;
  color: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden { display: none !important; }

/* ── Lobby ── */
#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 24px;
}

#lobby h1 {
  font-size: 48px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.lobby-buttons {
  display: flex;
  gap: 16px;
}

button {
  font-size: 20px;
  padding: 14px 32px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.1s, box-shadow 0.1s;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

button:active {
  transform: translateY(0);
}

#btnCreate {
  background: #f5c542;
  color: #333;
}

#linkBox {
  background: rgba(0,0,0,0.3);
  padding: 20px 28px;
  border-radius: 16px;
  text-align: center;
}

#linkBox p { margin-bottom: 12px; font-size: 18px; }

.link-row {
  display: flex;
  gap: 8px;
}

#shareLink {
  font-size: 16px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  width: 360px;
  background: #fff;
  color: #333;
}

#btnCopy {
  background: #4caf50;
  color: #fff;
  font-size: 16px;
  padding: 10px 20px;
}

#waiting {
  color: #f5c542;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.error {
  background: #c0392b;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 18px;
}

/* ── Game ── */
#game {
  width: 100%;
  max-width: 900px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  padding-bottom: 60px;
}

/* ── Status bar (bottom) ── */
#statusBar {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  padding: 10px 8px;
  background: rgba(0,0,0,0.35);
  border-radius: 10px 10px 0 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
}

/* ── Opponent hand (overlapping) ── */
#opponentArea {
  display: flex;
  justify-content: center;
  min-height: 70px;
  margin-bottom: 8px;
}

#opponentHand {
  display: flex;
  justify-content: center;
}

.card-back {
  width: 50px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  margin-right: -12px;
  box-shadow: 0 2px 7px rgba(80,30,120,0.55);
}

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

.card-back img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
}

/* ── Deck row: deck left, discard right ── */
#deckRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 4px 0;
  margin-bottom: 8px;
}

#deckArea {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

#trumpDisplay {
  position: relative;
  width: 100px;
  height: 96px;
}

#trumpDisplay .trump-card {
  position: absolute;
  top: 50%;
  right: -10px;
  transform: translateY(-50%) rotate(90deg);
  transform-origin: center center;
}

#trumpDisplay .deck-back {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 66px;
  height: 96px;
  border-radius: 6px;
  overflow: hidden;
  z-index: 1;
}

#trumpDisplay .deck-back img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
}

#deckCount {
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  margin-top: 2px;
}

/* ── Discard pile ── */
#discardPile {
  min-width: 50px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#discardPile:empty::after {
  content: '';
  display: block;
  width: 50px;
  height: 72px;
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: 6px;
}

#discardPile .discard-card {
  width: 50px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  position: absolute;
}

#discardPile .discard-card img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
}

/* ── Table: 3-column grid ── */
#table {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  justify-items: center;
  align-items: flex-start;
  width: 100%;
  min-height: 140px;
  flex: 1;
}

.table-pair {
  position: relative;
  width: 80px;
  height: 130px;
}

.table-pair .card:first-child {
  position: absolute;
  top: 0;
  left: 0;
}

.table-pair .card:nth-child(2) {
  position: absolute;
  top: 20px;
  left: 14px;
}

/* ── Controls (wide, centered) ── */
#controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
}

#controls button {
  width: 80%;
  max-width: 320px;
}

#btnBeaten {
  background: #4caf50;
  color: #fff;
}

#btnTake {
  background: #e67e22;
  color: #fff;
}

#btnDoneThrow {
  background: #3498db;
  color: #fff;
}

/* ── Player hand (overlapping) ── */
#playerArea {
  display: flex;
  justify-content: center;
  padding: 8px 0 16px;
}

#playerHand {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

#playerHand .card {
  margin-right: -8px;
}

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

/* ── Card ── */
.card {
  width: 72px;
  height: 104px;
  border-radius: 8px;
  cursor: default;
  user-select: none;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
  box-shadow: 0 2px 7px rgba(80,30,120,0.55);
}

.card img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
}

.card.playable {
  cursor: pointer;
  box-shadow: 0 0 12px 4px #4caf50, 0 0 24px 8px rgba(76,175,80,0.4);
  border-color: #4caf50;
}

.card.playable:hover {
  transform: translateY(-8px);
  box-shadow: 0 0 18px 6px #4caf50, 0 0 32px 12px rgba(76,175,80,0.5);
}

.table-pair .card {
  width: 66px;
  height: 96px;
  cursor: default;
}

/* Unbeaten attack card - highlight */
.table-pair .card.unbeaten {
  border-color: #e67e22;
  box-shadow: 0 0 8px rgba(230, 126, 34, 0.5);
}

/* Trump card in deck area */
#trumpDisplay .trump-card {
  width: 66px;
  height: 96px;
}

/* ── My turn: yellow glow around player cards ── */
#playerHand.my-turn {
  filter: drop-shadow(0 0 12px rgba(255, 215, 0, 0.7)) drop-shadow(0 0 30px rgba(255, 215, 0, 0.4));
}

/* ── Waiting for opponent overlay ── */
#waitingOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 45;
}

.waiting-message {
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.7), 0 2px 4px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.45);
  padding: 16px 36px;
  border-radius: 16px;
  animation: pulse 1.5s infinite;
}

/* Game over overlay */
#gameOver {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 100;
}

#gameOverText {
  font-size: 42px;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#btnRematch {
  background: #f5c542;
  color: #333;
  font-size: 24px;
  padding: 16px 40px;
}

/* ── Card movement animations ── */
#table .card {
  will-change: transform, opacity;
}

.card.flip-animating {
  -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-back.flip-animating {
  -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.table-clear-anim {
  -webkit-transition: -webkit-transform 0.4s ease-in, opacity 0.4s ease-in;
  transition: transform 0.4s ease-in, opacity 0.4s ease-in;
  opacity: 0;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  #lobby h1 { font-size: 32px; }
  #shareLink { width: 220px; font-size: 13px; }
  .card { width: 58px; height: 84px; }
  .table-pair .card { width: 54px; height: 78px; }
  .table-pair { width: 68px; height: 110px; }
  .card-back { width: 40px; height: 58px; }
  #discardPile:empty::after { width: 40px; height: 58px; }
  #discardPile .discard-card { width: 40px; height: 58px; }
  #gameOverText { font-size: 28px; }
  button { font-size: 16px; padding: 10px 20px; }
  #statusBar { font-size: 16px; }
}
