@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap');

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

:root {
  --bg: #0a0e27;
  --bg2: #141833;
  --surface: #1c2142;
  --surface2: #252b52;
  --primary: #6c5ce7;
  --primary-glow: #a29bfe;
  --accent: #fd79a8;
  --green: #00b894;
  --red: #e17055;
  --gold: #fdcb6e;
  --text: #dfe6e9;
  --text-dim: #636e72;
  --card-bg: #f8f9fa;
  --card-border: #ddd;
  --radius: 12px;
}

body {
  font-family: 'Fredoka', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== LOBBY ===== */
#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.logo {
  font-size: 4rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-glow), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
  text-shadow: none;
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 40px;
}

.lobby-panel {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.lobby-panel h2 {
  text-align: center;
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 1.3rem;
}

.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 500;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-group input:focus {
  border-color: var(--primary);
}

.input-group input::placeholder {
  color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c6cf0);
  color: white;
  box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.5);
  transform: translateY(-1px);
}

.btn-green {
  background: linear-gradient(135deg, var(--green), #55efc4);
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(0, 184, 148, 0.3);
}

.btn-green:hover {
  box-shadow: 0 6px 20px rgba(0, 184, 148, 0.5);
}

.btn-red {
  background: linear-gradient(135deg, var(--red), #fab1a0);
  color: white;
  box-shadow: 0 4px 15px rgba(225, 112, 85, 0.3);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #ffeaa7);
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(253, 203, 110, 0.3);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.85rem;
  width: auto;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.divider {
  text-align: center;
  margin: 20px 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: '';
  display: inline-block;
  width: 60px;
  height: 1px;
  background: var(--surface2);
  vertical-align: middle;
  margin: 0 12px;
}

.error-msg {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 8px;
  text-align: center;
}

/* ===== WAITING ROOM ===== */
#waiting { display: none; }

.waiting-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.room-code-display {
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 20px 40px;
  text-align: center;
  margin-bottom: 30px;
}

.room-code-display .label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.room-code-display .code {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--primary-glow);
}

.player-list {
  list-style: none;
  width: 100%;
  max-width: 400px;
  margin-bottom: 24px;
}

.player-list li {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 12px 20px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

.player-list .host-badge {
  background: var(--gold);
  color: #1a1a2e;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.player-list .player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

/* ===== GAME BOARD ===== */
#game { display: none; }

.game-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
}

.game-header .round-info {
  font-weight: 600;
  font-size: 1.1rem;
}

.game-header .room-code-small {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.game-header .deck-count {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ===== SCOREBOARD ===== */
.scoreboard {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.score-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 2px solid var(--surface2);
  border-radius: 50px;
  padding: 8px 16px;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: all 0.3s;
  flex-shrink: 0;
}

.score-pill.active {
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(108, 92, 231, 0.3);
}

.score-pill.busted {
  border-color: var(--red);
  opacity: 0.6;
}

.score-pill.stayed {
  border-color: var(--green);
}

.score-pill.is-me {
  background: var(--surface2);
}

.score-pill .name {
  font-weight: 600;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-pill .points {
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.8rem;
}

.score-pill .status-icon {
  font-size: 0.9rem;
}

/* ===== PLAYER AREAS ===== */
.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.player-area {
  background: var(--surface);
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.3s;
}

.player-area.active {
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(108, 92, 231, 0.2);
}

.player-area.busted {
  border-color: var(--red);
  opacity: 0.7;
}

.player-area.stayed {
  border-color: var(--green);
}

.player-area.is-me {
  background: linear-gradient(135deg, var(--surface), var(--surface2));
}

.player-area-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.player-area-header .player-name {
  font-weight: 600;
  font-size: 1rem;
}

.player-area-header .player-status {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 50px;
  font-weight: 600;
}

.status-thinking { background: var(--primary); color: white; }
.status-stayed { background: var(--green); color: #1a1a2e; }
.status-busted { background: var(--red); color: white; }
.status-frozen { background: #74b9ff; color: #1a1a2e; }
.status-flip7 { background: var(--gold); color: #1a1a2e; }

/* ===== CARDS ===== */
.cards-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 60px;
}

.card {
  width: 50px;
  height: 70px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: cardDeal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.card:hover { transform: translateY(-4px); }

@keyframes cardDeal {
  from { opacity: 0; transform: scale(0.3) rotateY(90deg); }
  to { opacity: 1; transform: scale(1) rotateY(0); }
}

.card-number {
  background: linear-gradient(135deg, #fff, #f0f0f0);
  color: #2d3436;
  border: 2px solid #ddd;
}

.card-number.duplicate {
  border-color: var(--red);
  box-shadow: 0 0 12px rgba(225, 112, 85, 0.5);
  animation: cardDeal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(5px) rotate(2deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(3px) rotate(1deg); }
}

.card-modifier {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  border: 2px solid #a29bfe;
  font-size: 0.9rem;
}

.card-modifier.x2 {
  background: linear-gradient(135deg, #e17055, #fab1a0);
  border-color: #fab1a0;
}

.card-action {
  font-size: 0.55rem;
  text-align: center;
  line-height: 1.2;
  padding: 4px;
  border: 2px solid;
}

.card-action.second-chance {
  background: linear-gradient(135deg, #00b894, #55efc4);
  border-color: #55efc4;
  color: #1a1a2e;
}

.card-action.freeze {
  background: linear-gradient(135deg, #0984e3, #74b9ff);
  border-color: #74b9ff;
  color: white;
}

.card-action.target {
  background: linear-gradient(135deg, #d63031, #ff7675);
  border-color: #ff7675;
  color: white;
}

.card-action.flip-three {
  background: linear-gradient(135deg, #fdcb6e, #ffeaa7);
  border-color: #ffeaa7;
  color: #1a1a2e;
}

/* ===== CONTROLS ===== */
.controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0;
}

.controls .btn {
  width: auto;
  min-width: 140px;
  padding: 14px 32px;
  font-size: 1.1rem;
}

.turn-indicator {
  text-align: center;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  border-radius: 8px;
  animation: pulse 2s ease-in-out infinite;
}

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

.turn-indicator.my-turn {
  background: linear-gradient(135deg, var(--primary), #7c6cf0);
  color: white;
}

.turn-indicator.waiting {
  background: var(--surface);
  color: var(--text-dim);
  animation: none;
}

/* ===== TARGET SELECTION MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.modal h3 {
  margin-bottom: 16px;
  text-align: center;
}

.modal .target-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal .target-btn {
  padding: 12px 20px;
  background: var(--bg2);
  border: 2px solid var(--surface2);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.modal .target-btn:hover {
  border-color: var(--primary);
  background: var(--surface2);
}

/* ===== LOG ===== */
.game-log {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 12px;
}

.game-log h4 {
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.game-log .log-entry {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.game-log .log-entry:last-child {
  color: var(--text);
  font-weight: 500;
}

/* ===== ROUND END ===== */
.round-summary {
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 24px;
  margin: 20px auto;
  max-width: 500px;
}

.round-summary h2 {
  text-align: center;
  margin-bottom: 16px;
}

.round-scores {
  list-style: none;
}

.round-scores li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface2);
}

.round-scores li:last-child { border-bottom: none; }

.round-scores .rs-name { font-weight: 600; }
.round-scores .rs-round {
  font-size: 0.85rem;
}
.round-scores .rs-round.positive { color: var(--green); }
.round-scores .rs-round.zero { color: var(--text-dim); }
.round-scores .rs-total {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary-glow);
}

/* ===== GAME OVER ===== */
.game-over-banner {
  text-align: center;
  padding: 40px;
  animation: winPulse 1s ease-in-out infinite alternate;
}

@keyframes winPulse {
  from { transform: scale(1); }
  to { transform: scale(1.02); }
}

.game-over-banner h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.game-over-banner .winner-name {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.game-over-banner .winner-score {
  color: var(--text-dim);
  margin-bottom: 24px;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
  max-width: 320px;
}

.toast.bust { border-left: 4px solid var(--red); }
.toast.flip7 { border-left: 4px solid var(--gold); }
.toast.action { border-left: 4px solid var(--primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* ===== CONFETTI ===== */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  top: -10px;
  z-index: 300;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    top: 110vh;
    transform: rotate(720deg);
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .logo { font-size: 2.8rem; }
  .lobby-panel { padding: 24px 20px; }
  .game-container { padding: 8px; }
  .players-grid { grid-template-columns: 1fr; }
  .controls .btn { min-width: 110px; padding: 12px 20px; font-size: 1rem; }
  .card { width: 42px; height: 60px; font-size: 0.95rem; }
  .scoreboard { gap: 6px; }
  .score-pill { padding: 6px 12px; font-size: 0.8rem; }
}

/* ===== MUTE BUTTON ===== */
.mute-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 250;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.mute-btn:hover { border-color: var(--primary); background: var(--surface2); }

/* ===== LEADERBOARD MODAL ===== */
.leaderboard-modal {
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
}
.leaderboard-modal h3 { text-align: center; margin-bottom: 16px; font-size: 1.3rem; }
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.leaderboard-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--primary);
  color: var(--primary-glow);
  font-weight: 600;
  font-size: 0.8rem;
}
.leaderboard-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--surface2);
}
.leaderboard-table tr:first-child td { color: var(--gold); font-weight: 600; }
.leaderboard-table .rank { font-weight: 700; width: 40px; }
.leaderboard-empty { text-align: center; color: var(--text-dim); padding: 24px; }

.game-over-leaderboard {
  margin-top: 16px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }

/* ===== EFFECT BADGES ===== */
.player-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.effect-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 50px;
  font-weight: 600;
  animation: badgePulse 2s ease-in-out infinite;
}

.badge-second-chance {
  background: linear-gradient(135deg, #00b894, #55efc4);
  color: #1a1a2e;
  box-shadow: 0 0 8px rgba(0, 184, 148, 0.4);
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(0, 184, 148, 0.4); }
  50% { opacity: 0.8; box-shadow: 0 0 16px rgba(0, 184, 148, 0.6); }
}

.sc-dot {
  font-size: 0.75rem;
}
