:root {
  --felt: #0b5d3b;
  --felt-dark: #084027;
  --panel: #ffffff;
  --ink: #1b1b1f;
  --muted: #6b7280;
  --red: #de1d52;
  --yellow: #f7b23c;
  --green: #5fa331;
  --blue: #3f69dc;
  --radius: 14px;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--felt), var(--felt-dark));
  color: var(--ink);
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Home / Lobby shared card ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.home-card {
  background: var(--panel);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
}

.logo {
  font-size: 48px;
  font-weight: 900;
  color: var(--red);
  margin: 0 0 4px;
  letter-spacing: 2px;
}
.logo-dot { color: var(--yellow); }

.tagline {
  color: var(--muted);
  margin: 0 0 24px;
}

.panel h2 {
  font-size: 16px;
  margin: 0 0 12px;
  color: var(--ink);
}

.panel input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid #e5e7eb;
  font-size: 15px;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.15s;
}
.panel input:focus { border-color: var(--blue); }

.divider {
  display: flex;
  align-items: center;
  color: var(--muted);
  margin: 20px 0;
  font-size: 13px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}
.divider span { padding: 0 12px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  width: 100%;
  transition: transform 0.08s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--red); color: white; }
.btn-secondary { background: #eef0f4; color: var(--ink); }
.btn-small { width: auto; padding: 8px 14px; background: rgba(255,255,255,0.15); color: white; }
.btn-uno {
  background: var(--yellow);
  color: #3a2600;
  border-radius: 999px;
  width: auto;
  padding: 14px 30px;
  font-size: 18px;
  box-shadow: 0 6px 0 #b3791f;
}
.btn-uno:active { box-shadow: 0 2px 0 #b3791f; transform: translateY(4px); }

.error-text { color: var(--red); font-size: 14px; margin-top: 14px; }

/* ---------- Music toggle ---------- */
.music-toggle {
  border: none;
  background: rgba(255,255,255,0.15);
  color: white;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.music-toggle:active { transform: scale(0.9); }
.music-toggle-home {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0,0,0,0.12);
  color: var(--ink);
}

/* ---------- Lobby ---------- */
.room-code-label { margin: 10px 0 2px; color: var(--muted); font-size: 13px; }
.room-code {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--ink);
  margin-bottom: 16px;
}
.invite-row { display: flex; gap: 8px; margin-bottom: 4px; }
.invite-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #e5e7eb;
  font-size: 13px;
  color: var(--muted);
}
.invite-row .btn { width: auto; white-space: nowrap; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 18px; }

.player-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  text-align: left;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f7f7f9;
  border-radius: 10px;
  margin-bottom: 6px;
  font-weight: 600;
}
.player-list .badge {
  font-size: 10px;
  background: var(--blue);
  color: white;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
}
.player-list .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e; margin-left: auto;
}
.player-list .dot.off { background: #d1d5db; }

/* ---------- Game screen ---------- */
#screen-game { padding: 12px; align-items: stretch; }
.table {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 24px);
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  padding: 8px 4px;
}
.room-pill {
  background: rgba(255,255,255,0.15);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.last-action {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #d7f5e5;
  min-height: 18px;
}

.opponents {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 10px 0;
}
.opponent {
  background: rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 8px 12px;
  color: white;
  text-align: center;
  min-width: 90px;
  position: relative;
  border: 2px solid transparent;
}
.opponent.active-turn { border-color: var(--yellow); box-shadow: 0 0 12px rgba(247,178,60,0.6); }
.opponent .opp-name { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.opponent .opp-count { font-size: 20px; font-weight: 900; }
.opponent .opp-status { font-size: 10px; opacity: 0.75; }
.opponent .opp-uno { color: var(--yellow); font-weight: 800; font-size: 11px; }
.opponent .catch-btn {
  margin-top: 4px;
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 8px;
  border: none;
  background: var(--red);
  color: white;
  font-weight: 700;
}
.opponent.disconnected { opacity: 0.45; }
.opponent.count-changed { animation: opponent-flash 0.5s ease; }

@keyframes opponent-flash {
  0% { background: rgba(247,178,60,0.5); }
  100% { background: rgba(255,255,255,0.12); }
}

.center-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 20px 0;
}
.pile-wrap { text-align: center; position: relative; }
.pile-label { color: rgba(255,255,255,0.7); font-size: 11px; margin-bottom: 6px; letter-spacing: 1px; text-transform: uppercase; }
.direction-indicator { font-size: 28px; display: inline-block; }
.direction-indicator.spin-pulse { animation: spin-pulse 0.5s ease; }

@keyframes spin-pulse {
  0% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.4) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

.card {
  width: 90px;
  height: 132px;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}
.card-back-slot {
  background-image: url('cards/back.png');
  cursor: pointer;
  transition: transform 0.1s;
}
.card-back-slot:hover { transform: translateY(-4px); }
.card-back-slot.disabled { cursor: default; filter: grayscale(0.6) brightness(0.8); }
.discard-slot { background-color: rgba(255,255,255,0.1); }
.discard-slot.card-played { animation: card-played 0.42s cubic-bezier(.34,1.56,.64,1); }

@keyframes card-played {
  0% { transform: scale(0.4) rotate(-25deg); opacity: 0.3; }
  60% { transform: scale(1.12) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}
.deck-count { color: white; font-size: 12px; margin-top: 4px; opacity: 0.8; }
.color-dot {
  width: 18px; height: 18px; border-radius: 50%;
  margin: 6px auto 0;
  border: 2px solid white;
}
.color-dot.red { background: var(--red); }
.color-dot.yellow { background: var(--yellow); }
.color-dot.green { background: var(--green); }
.color-dot.blue { background: var(--blue); }

.turn-banner {
  text-align: center;
  color: white;
  font-weight: 800;
  font-size: 16px;
  min-height: 24px;
  margin-bottom: 4px;
}
.turn-banner.your-turn { color: var(--yellow); }
.turn-banner.banner-pulse { animation: banner-pulse 0.5s ease; }

@keyframes banner-pulse {
  0% { transform: scale(0.85); opacity: 0.4; }
  50% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}

.action-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
}
.action-row .btn-secondary { width: auto; padding: 12px 20px; }

.hand {
  display: flex;
  gap: -10px;
  padding: 14px 10px 20px;
  overflow-x: auto;
  justify-content: center;
  min-height: 150px;
}
.hand .card {
  flex: 0 0 auto;
  margin-left: -22px;
  cursor: pointer;
  transition: transform 0.12s, margin 0.12s;
}
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-14px); }
.hand .card.unplayable { filter: grayscale(0.7) brightness(0.65); cursor: default; }
.hand .card.unplayable:hover { transform: none; }
.hand .card.card-drawn { animation: card-drawn 0.35s ease; }

@keyframes card-drawn {
  0% { transform: translateY(40px) scale(0.7); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-box {
  background: white;
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  min-width: 280px;
  position: relative;
  z-index: 2;
}
.color-choices { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }
.color-choice {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 3px solid white;
  outline: 2px solid #e5e7eb;
}
.color-choice.red { background: var(--red); }
.color-choice.yellow { background: var(--yellow); }
.color-choice.green { background: var(--green); }
.color-choice.blue { background: var(--blue); }
.color-choice:hover { outline-color: var(--ink); }

#gameover-modal .btn { margin-top: 10px; }

#confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}
.confetti-piece {
  position: absolute;
  top: -40px;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0.9; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

@media (max-width: 640px) {
  .card { width: 66px; height: 98px; }
  .logo { font-size: 38px; }
  .room-code { font-size: 30px; letter-spacing: 5px; }
}
