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

:root {
  --felt: #1a5c2a;
  --felt-dark: #143f1e;
  --card-w: 72px;
  --card-h: 100px;
  --card-r: 8px;
  --gap: 8px;
}

body {
  background: var(--felt);
  color: #fff;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen { width: 100%; max-width: 900px; padding: 20px; }
.hidden { display: none !important; }

/* ---------- Landing ---------- */
#screen-landing { text-align: center; }
#screen-landing h1 { font-size: 3rem; margin-bottom: 24px; }

.form-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 340px;
  margin: 0 auto;
}

input[type="text"] {
  padding: 10px 14px;
  border-radius: 8px;
  border: 2px solid #3a7d4b;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}
input[type="text"]::placeholder { color: rgba(255,255,255,.45); }
input[type="text"]:focus { border-color: #6fcf97; }

.divider { color: rgba(255,255,255,.4); font-size: .85rem; text-align: center; }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 2px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover { background: rgba(255,255,255,.2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: #27ae60; border-color: #2ecc71; }
.btn.primary:hover { background: #2ecc71; }
.btn.danger { background: #c0392b; border-color: #e74c3c; }
.btn.danger:hover { background: #e74c3c; }

/* ---------- Error ---------- */
.err-msg { color: #e74c3c; font-size: .85rem; min-height: 1em; text-align: center; }

/* ---------- Lobby ---------- */
#screen-lobby { text-align: center; }
#screen-lobby h2 { font-size: 1.8rem; margin-bottom: 16px; }

.code-badge {
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px;
  padding: 2px 10px;
  font-family: monospace;
  font-size: 1.1em;
  letter-spacing: 3px;
}

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 16px 0;
}
.player-chip {
  background: rgba(255,255,255,.12);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: .95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-chip .ready-dot { width: 8px; height: 8px; border-radius: 50%; background: #e74c3c; }
.player-chip .ready-dot.yes { background: #2ecc71; }
.player-chip .chip-action {
  border: 0;
  border-radius: 999px;
  background: rgba(0,0,0,.32);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1;
  padding: 4px 7px;
  cursor: pointer;
}
.player-chip .chip-action:hover {
  background: rgba(0,0,0,.5);
}

.screen-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.hint { color: rgba(255,255,255,.55); font-size: .9rem; margin: 8px 0; }

/* ---------- Swap ---------- */
#screen-swap { text-align: center; }
#screen-swap h2 { font-size: 1.6rem; margin-bottom: 6px; }
.swap-section { margin: 16px 0; }
.swap-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 16px; }

/* ---------- Cards ---------- */
.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  justify-content: center;
  padding: 4px;
}

#your-hand {
  align-items: flex-end;
  min-height: calc(var(--card-h) + 28px);
  gap: 0;
  padding: 10px 18px 0;
}

#your-hand .card {
  margin-left: -18px;
}

#your-hand .card:first-child {
  margin-left: 0;
}

#your-hand .card.hand-fan-card {
  transform: var(--hand-transform, none);
  transform-origin: center 145%;
}

#your-hand .card.hand-fan-card.clickable:hover {
  transform: var(--hand-transform, none) translateY(-10px);
}

#your-hand .card.hand-fan-card.selected {
  transform: var(--hand-transform, none) translateY(-12px);
}

.label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.5);
  margin-bottom: 4px;
}

.label-with-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .62rem;
  color: rgba(255,255,255,.72);
  letter-spacing: .8px;
}

.sort-control select {
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: rgba(0,0,0,.24);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 5px 10px;
  cursor: pointer;
}

.sort-control select:focus {
  outline: 2px solid rgba(111,207,151,.55);
  outline-offset: 1px;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-r);
  background: #fff;
  border: 2px solid #ddd;
  position: relative;
  cursor: default;
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  flex-shrink: 0;
  pointer-events: auto; /* Allow clicks on individual cards */
}

.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-6px); box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.card.selected {
  border-color: #f39c12;
  box-shadow: 0 0 0 3px #f39c12, 0 8px 20px rgba(0,0,0,.4);
  transform: translateY(-8px);
}

.card.swap-hand-selected {
  border-color: #3498db;
  box-shadow: 0 0 0 3px #3498db;
  transform: translateY(-6px);
}

/* Card text colours */
.card.red .corner { color: #c0392b; }
.card.red .center-suit { color: #c0392b; }
.card.black .corner { color: #1a1a1a; }
.card.black .center-suit { color: #1a1a1a; }

/* Joker */
.card.joker-card { background: linear-gradient(135deg, #2c003e, #6a0572); border-color: #9b59b6; }
.card.joker-card .corner, .card.joker-card .center-suit { color: #f1c40f; }

/* Special badges */
.card.special-2 { background: #eaf4ff; border-color: #3498db; }
.card.special-3 { background: #fff5e6; border-color: #e67e22; }
.card.special-10 { background: #fffde6; border-color: #f1c40f; }
.card.special-j { background: #f0fff4; border-color: #27ae60; }

.card .corner {
  font-size: .7rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card .corner.br {
  align-self: flex-end;
  transform: rotate(180deg);
}
.card .center-suit {
  font-size: 1.6rem;
  text-align: center;
  line-height: 1;
  align-self: center;
}
.card .center-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  align-self: center;
  padding: 0 4px;
}
.card .center-stack-compact {
  justify-content: center;
  min-height: 28px;
}
.card .center-stack .center-suit {
  align-self: center;
}
.card .card-flavor {
  display: inline-block;
  max-width: 62px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(0,0,0,.78);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 4px 12px rgba(0,0,0,.22);
  font-size: .57rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: .35px;
  text-transform: uppercase;
  text-align: center;
  color: #fffaf0;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.card .yoki-actions {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 26px;
  display: flex;
  gap: 4px;
  justify-content: center;
  z-index: 2;
}
.card .yoki-action {
  border: 0;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: .55rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .3px;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.28);
}
.card .yoki-action.stir {
  background: #2980b9;
}
.card .yoki-action.clear {
  background: #c0392b;
}
/* Back of card */
.card.face-down {
  background: repeating-linear-gradient(
    45deg, #1a237e, #1a237e 5px, #283593 5px, #283593 10px
  );
  border-color: #3949ab;
}
.card.face-down .back-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: rgba(255,255,255,.3);
}

/* ---------- Game ---------- */
#screen-game {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px;
  min-height: 100vh;
  justify-content: space-between;
}

#game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.dir-badge {
  background: rgba(0,0,0,.3);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: .85rem;
}

.battle-badge {
  background: #c0392b;
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
  padding: 4px 14px;
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.65} }

.deck-badge {
  margin-left: auto;
  color: rgba(255,255,255,.6);
  font-size: .85rem;
}

.sound-toggle {
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.22);
  color: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
}

/* Opponents row */
#opponents {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.opponent-slot {
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: center;
  min-width: 160px;
  transition: border-color .2s;
}
.opponent-slot.current { border-color: #f39c12; box-shadow: 0 0 10px rgba(243,156,18,.4); }
.opponent-slot.finished { opacity: .45; }
.opponent-slot .opp-name { font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.opp-section { margin-top: 8px; }
.opp-label {
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.45);
  margin-bottom: 4px;
}
.opponent-slot .opp-cards { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.opp-hand-cards {
  min-height: 38px;
  flex-wrap: nowrap !important;
  gap: 0 !important;
  overflow: hidden;
  justify-content: center;
  max-width: 132px;
  margin: 0 auto;
  padding: 0 4px;
}
.opp-hand-cards .opp-mini-card {
  margin-left: -18px;
  box-shadow: 0 4px 10px rgba(0,0,0,.18);
}
.opp-hand-cards .opp-mini-card:first-child {
  margin-left: 0;
}
.opp-tableau-stack {
  position: relative;
  min-height: 50px;
}
.opp-tableau-row {
  position: absolute;
  inset: 0;
}
.opp-tableau-row-top {
  inset: 10px 0 0;
}
.opp-mini-card {
  width: 28px; height: 38px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.2);
  font-size: .55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.opp-mini-card.face-down {
  background: repeating-linear-gradient(
    45deg, #1a237e, #1a237e 3px, #283593 3px, #283593 6px
  );
}
.opp-mini-card.red { background: #fff; color: #c0392b; }
.opp-mini-card.black { background: #fff; color: #111; }
.opp-mini-card.joker { background: #6a0572; color: #f1c40f; }

/* Pile */
#pile-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
  position: relative;
}

#pile-area.fx-play #pile-display {
  animation: pile-pop .28s ease;
}

#pile-area.fx-clear #pile-display,
#pile-area.fx-burn #pile-display {
  animation: pile-clear .48s ease;
}

#pile-area.fx-pickup #pile-display {
  animation: pile-pickup .34s ease;
}

#pile-area.fx-battle #pile-display,
#pile-area.fx-skip #pile-display,
#pile-area.fx-stir #pile-display {
  animation: pile-shake .34s ease;
}

.pile-announcement {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: rgba(0,0,0,.82);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 8px 16px;
  color: #fff6c7;
  font-size: .95rem;
  font-weight: 800;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0,0,0,.34);
  opacity: 0;
  transition: opacity .45s ease, transform .45s ease;
  pointer-events: none;
}

.pile-announcement.visible {
  opacity: 1;
  transform: translate(-50%, -118%);
}

.pile-announcement.fade-out {
  opacity: 0;
  transform: translate(-50%, -135%);
}

.pile-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#pile-display {
  width: calc(var(--card-w) + 150px);
  min-height: calc(var(--card-h) + 46px);
  position: relative;
}
#pile-display .card {
  position: absolute;
  left: 50%;
  top: 6px;
  margin-left: calc(var(--card-w) / -2);
  transform-origin: center center;
  box-shadow: 0 12px 26px rgba(0,0,0,.3);
}

.card.flight-clone {
  position: fixed;
  margin: 0;
  z-index: 1000;
  pointer-events: none;
  transition: transform .38s cubic-bezier(.2,.8,.2,1), opacity .38s ease;
}

/* Your area */
#your-area {
  background: rgba(0,0,0,.2);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
}

.player-section {
  margin: 8px 0 14px;
}

.player-section:last-of-type {
  margin-bottom: 12px;
}

.tableau-stack {
  position: relative;
  min-height: calc(var(--card-h) + 22px);
  width: 100%;
}

.tableau-row {
  display: flex;
  justify-content: center;
  width: 100%;
  pointer-events: none; /* Don't block clicks to rows underneath */
}

.tableau-row-top {
  position: absolute;
  inset: 18px 0 0;
}

#your-facedown .card {
  box-shadow: 0 8px 18px rgba(0,0,0,.2);
  cursor: pointer;
}

#your-facedown .card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 22px rgba(0,0,0,.3);
}

#your-faceup .card {
  box-shadow: 0 12px 28px rgba(0,0,0,.38);
}

.turn-msg {
  font-weight: 700;
  font-size: 1rem;
  min-height: 1.4em;
  margin-bottom: 6px;
  color: #f39c12;
}

@keyframes pile-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes pile-clear {
  0% { transform: scale(1); opacity: 1; }
  35% { transform: scale(1.08) translateY(-6px); opacity: 1; }
  100% { transform: scale(.88) translateY(-18px); opacity: .3; }
}

@keyframes pile-pickup {
  0% { transform: translateY(0); }
  40% { transform: translateY(8px) scale(.96); }
  100% { transform: translateY(0); }
}

@keyframes pile-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-1deg); }
  50% { transform: translateX(5px) rotate(1deg); }
  75% { transform: translateX(-3px) rotate(-.5deg); }
}

/* Game over */
#screen-over {
  display: flex;
  align-items: center;
  justify-content: center;
}
.over-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}
.poop { font-size: 5rem; }
#over-msg { font-size: 1.5rem; }
