* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #1a472a; font-family: 'Nunito', sans-serif; min-height: 100vh; display: flex; flex-direction: column; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 1rem; background: rgba(0,0,0,0.4); border-bottom: 1px solid rgba(255,255,255,0.1); flex-wrap: wrap; gap: 0.5rem; }
.btn-back { color: rgba(255,255,255,0.7); text-decoration: none; font-weight: 700; font-size: 0.9rem; }
.btn-back:hover { color: #fff; }
.game-title { font-size: 1.1rem; font-weight: 800; color: #fff; }
.stats { display: flex; gap: 1rem; font-size: 0.82rem; font-weight: 700; color: rgba(255,255,255,0.7); }

/* Room Info */
.room-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
}

.room-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.room-badge.host {
  background: rgba(76, 175, 80, 0.3);
  color: #a5d6a7;
  border: 1px solid rgba(76, 175, 80, 0.5);
}

.room-badge.guest {
  background: rgba(33, 150, 243, 0.3);
  color: #90caf9;
  border: 1px solid rgba(33, 150, 243, 0.5);
}

.room-id {
  color: rgba(255,255,255,0.5);
  font-family: monospace;
}

/* Multiplayer Lobby */
.multiplayer-lobby {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.multiplayer-lobby.hidden {
  display: none;
}

.lobby-content {
  background: #1a2a1a;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  text-align: center;
}

.lobby-content h2 {
  color: #fff;
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.lobby-content h3 {
  color: #ffd700;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.lobby-content p {
  color: rgba(255,255,255,0.6);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.lobby-options {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.lobby-section {
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 1.5rem;
}

.lobby-divider {
  color: rgba(255,255,255,0.4);
  font-weight: 700;
  font-size: 0.9rem;
}

.lobby-section input {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
}

.lobby-section input:focus {
  outline: none;
  border-color: #ff6b35;
}

.lobby-share {
  background: rgba(76, 175, 80, 0.1);
  border: 2px solid rgba(76, 175, 80, 0.3);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 1rem;
}

.lobby-share.hidden {
  display: none;
}

.share-link {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.share-link input {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.8rem;
}

.waiting-text {
  color: #ffd700 !important;
  font-weight: 700;
  animation: pulse 1.5s infinite;
}

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

.game-wrapper { flex: 1; display: flex; flex-direction: column; padding: 0.8rem; max-width: 760px; margin: 0 auto; width: 100%; gap: 0.7rem; }

/* SCORE BAR */
.score-bar { display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,0.3); border-radius: 12px; padding: 0.5rem 1rem; }
.score-side { text-align: center; }
.score-name { font-size: 0.72rem; font-weight: 800; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 1px; }
.score-val { font-size: 1.2rem; font-weight: 800; color: #ffd700; }
.turn-badge { padding: 0.3rem 0.8rem; border-radius: 999px; font-size: 0.78rem; font-weight: 800; transition: all 0.3s ease; }
.turn-mine { background: rgba(255,107,53,0.2); color: #ff8f5e; border: 1.5px solid #ff6b35; box-shadow: 0 0 10px rgba(255,107,53,0.3); }
.turn-cpu  { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.5); border: 1.5px solid rgba(255,255,255,0.15); }
.turn-cpu.active { background: rgba(255,193,7,0.15); color: #ffd54f; border-color: #ffd54f; box-shadow: 0 0 10px rgba(255,193,7,0.3); }

/* Opponent area highlight during turn */
.cpu-area.active-turn {
  background: rgba(255,193,7,0.1);
  border: 1px solid rgba(255,193,7,0.3);
  box-shadow: 0 0 15px rgba(255,193,7,0.2);
}

/* Thinking animation */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  background: #ffd54f;
  border-radius: 50%;
  animation: thinking-bounce 0.6s infinite alternate;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  from { transform: translateY(0); opacity: 0.5; }
  to { transform: translateY(-6px); opacity: 1; }
}

/* Card animation for plays */
@keyframes card-enter {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.card-animated {
  animation: card-enter 0.3s ease-out;
}

/* Disabled state for actions */
.player-area.disabled {
  opacity: 0.7;
  pointer-events: none;
}

.player-area.disabled .card.playable {
  cursor: not-allowed;
}

/* CARD */
.card { width: 38px; height: 54px; background: #fff; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; font-size: 0.75rem; color: #222; box-shadow: 0 2px 5px rgba(0,0,0,0.4); line-height: 1.1; text-align: center; user-select: none; flex-shrink: 0; cursor: default; transition: transform 0.12s, box-shadow 0.12s; }
.card.red { color: #c0392b; }
.card.wild { background: linear-gradient(135deg, #ffd700, #ff8c00); color: #222; }
.card.back { background: linear-gradient(135deg, #1a237e, #283593); border: 2px solid rgba(255,255,255,0.15); }
.card.selected { box-shadow: 0 0 0 3px #ffd700, 0 2px 10px rgba(255,215,0,0.5); transform: translateY(-6px); }
.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-4px); box-shadow: 0 0 0 2px #ff6b35, 0 4px 10px rgba(0,0,0,0.4); }
.card.sm { width: 28px; height: 40px; font-size: 0.6rem; }

/* Opponent AREA */
.cpu-area { background: rgba(0,0,0,0.25); border-radius: 14px; padding: 0.7rem; }
.area-label { font-size: 0.68rem; font-weight: 800; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.5rem; }
.cpu-hand { display: flex; gap: 3px; flex-wrap: wrap; }
.cpu-melds { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }

/* TABLE */
.table-area { background: rgba(0,0,0,0.2); border-radius: 14px; padding: 0.7rem; display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.pile-group { display: flex; gap: 0.5rem; align-items: center; flex-direction: column; }
.pile-label { font-size: 0.65rem; font-weight: 800; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; text-align: center; margin-bottom: 0.3rem; }
.pile-stack { position: relative; width: 38px; height: 54px; cursor: pointer; }
.pile-stack .card { position: absolute; top: 0; left: 0; }
.pile-count { font-size: 0.65rem; font-weight: 800; color: rgba(255,255,255,0.5); text-align: center; margin-top: 0.3rem; }
.discard-top { cursor: pointer; }
.discard-top:hover { box-shadow: 0 0 0 2px #ff6b35; transform: scale(1.05); }
.discard-pile-wrap { display: flex; flex-direction: column; align-items: center; }
.empty-discard { width: 38px; height: 54px; border: 2px dashed rgba(255,255,255,0.2); border-radius: 6px; }
.morto-taken { opacity: 0.35; }
.draw-btn { padding: 0.5rem 1rem; border-radius: 999px; background: rgba(76,175,80,0.15); border: 2px solid rgba(76,175,80,0.4); color: #a5d6a7; font-family:'Nunito',sans-serif; font-weight:800; font-size:0.82rem; cursor:pointer; transition:all 0.15s; white-space:nowrap; }
.draw-btn:hover:not(:disabled) { background:rgba(76,175,80,0.3); }
.draw-btn:disabled { opacity:0.3; cursor:default; }

/* PLAYER AREA */
.player-area { background: rgba(0,0,0,0.25); border-radius: 14px; padding: 0.7rem; }
.player-hand { display: flex; gap: 4px; flex-wrap: wrap; min-height: 60px; align-items: flex-end; }
.player-melds { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.6rem; }
.meld-group { background: rgba(255,255,255,0.07); border: 1.5px solid rgba(255,255,255,0.15); border-radius: 10px; padding: 0.4rem; display: flex; gap: 3px; flex-wrap: wrap; cursor: pointer; transition: border-color 0.15s; position: relative; }
.meld-group:hover { border-color: #ff6b35; }
.meld-group.canasta-pure { border-color: #ffd700; background: rgba(255,215,0,0.1); }
.meld-group.canasta-dirty { border-color: #ff8c00; background: rgba(255,140,0,0.1); }
.meld-badge { position: absolute; top: -8px; right: 4px; font-size: 0.6rem; font-weight: 800; padding: 1px 5px; border-radius: 999px; background: #ffd700; color: #222; }

/* ACTIONS */
.action-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.6rem; align-items: center; }
.btn-action { padding: 0.45rem 1rem; border-radius: 999px; border: 2px solid; font-family:'Nunito',sans-serif; font-weight:800; font-size:0.8rem; cursor:pointer; transition:all 0.15s; }
.btn-meld { background:rgba(33,150,243,0.12); border-color:rgba(33,150,243,0.4); color:#90caf9; }
.btn-meld:hover { background:rgba(33,150,243,0.25); }
.btn-discard { background:rgba(239,83,80,0.12); border-color:rgba(239,83,80,0.4); color:#ef9a9a; }
.btn-discard:hover:not(:disabled) { background:rgba(239,83,80,0.25); }
.btn-discard:disabled { opacity:0.3; cursor:default; }
.btn-baixar { background:rgba(255,215,0,0.12); border-color:rgba(255,215,0,0.4); color:#ffd700; }
.btn-baixar:hover { background:rgba(255,215,0,0.25); }
.msg-bar { font-size:0.82rem; font-weight:700; color:rgba(255,255,255,0.6); text-align:center; min-height:22px; }

/* MODAL */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.78); display:flex; align-items:center; justify-content:center; z-index:100; padding:1rem; }
.modal-overlay.hidden { display:none; }
.modal-content { background:#1a2a1a; border:2px solid rgba(255,255,255,0.15); border-radius:20px; padding:2rem; text-align:center; max-width:380px; width:100%; }
.modal-icon { font-size:3rem; margin-bottom:0.5rem; }
.modal-title { font-size:1.4rem; font-weight:800; color:#fff; margin-bottom:0.4rem; }
.modal-msg { font-size:0.9rem; color:rgba(255,255,255,0.6); margin-bottom:1.2rem; line-height:1.6; }
.btn-orange { background:#ff6b35; color:#fff; border:none; border-radius:999px; padding:0.7rem 1.8rem; font-family:'Nunito',sans-serif; font-weight:800; font-size:1rem; cursor:pointer; }
.btn-orange:hover { background:#e85d2a; }

/* GAME INFO */
.game-info { max-width:760px; margin:0 auto; padding:2rem 1rem; width:100%; }
.game-info h2 { font-size:1.3rem; font-weight:800; margin-bottom:0.8rem; color:#333; }
.game-info h3 { font-size:1rem; font-weight:800; margin:1rem 0 0.4rem; color:#555; }
.game-info p, .game-info li { font-size:0.92rem; color:#555; line-height:1.7; }
.game-info ul { padding-left:1.2rem; }
.game-info code {
  background: rgba(0,0,0,0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
}

@media(max-width:480px){
  .card { width:32px; height:46px; font-size:0.65rem; }
  .card.sm { width:24px; height:34px; font-size:0.55rem; }

  .lobby-content {
    padding: 1.5rem 1rem;
  }

  .lobby-content h2 {
    font-size: 1.2rem;
  }

  .share-link {
    flex-direction: column;
  }

  .room-info {
    width: 100%;
    justify-content: center;
    margin-top: 0.3rem;
  }
}
