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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a5c2e;
  color: #fff;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Lobby */
#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  gap: 16px;
  padding: 20px;
}

#lobby h1 {
  font-size: 3rem;
}

#lobby p {
  opacity: 0.8;
  font-size: 1.1rem;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 300px;
  margin-top: 20px;
}

.lobby-form input {
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  text-align: center;
  text-transform: uppercase;
}

.lobby-form button {
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: #f0c040;
  color: #1a3c0e;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.lobby-form button:hover {
  background: #ffd060;
}

#botBtn {
  background: #4a90d9;
  color: #fff;
}

#botBtn:hover {
  background: #5aa0e9;
}

.lobby-divider {
  text-align: center;
  opacity: 0.5;
  font-size: 0.9rem;
  padding: 4px 0;
}

#lobbyStatus {
  margin-top: 10px;
  font-weight: 600;
}

/* Game — desktop: game left, chat right */
#game {
  display: flex;
  flex-direction: row;
  height: 100dvh;
  overflow: hidden;
}

#gameMain {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
  overflow-y: auto;
}

/* Chat panel — right sidebar on desktop */
#chatPanel {
  width: 280px;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.2);
  border-left: 1px solid rgba(255,255,255,0.1);
  order: 2;
  min-height: 0;
}

#chatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  opacity: 0.7;
}

#chatCloseBtn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.6;
  padding: 2px 6px;
}

#chatCloseBtn:hover {
  opacity: 1;
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

.chat-msg {
  font-size: 0.8rem;
  line-height: 1.3;
  word-break: break-word;
}

.chat-system {
  color: rgba(255,255,255,0.4);
  font-style: italic;
}

.chat-player {
  color: rgba(255,255,255,0.9);
}

.chat-name {
  font-weight: 700;
  color: #f0c040;
}

#chatInputArea {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

#chatInput {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.8rem;
  outline: none;
}

#chatInput::placeholder {
  color: rgba(255,255,255,0.3);
}

#chatInput:focus {
  border-color: rgba(255,255,255,0.35);
}

#chatSendBtn {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

#chatSendBtn:hover {
  background: rgba(255,255,255,0.22);
}

/* Chat toggle — hidden on desktop */
#chatToggle {
  display: none;
}

/* Top bar with stats */
#topBar {
  text-align: center;
  padding: 2px 0;
  min-height: 20px;
}

#statsBar {
  font-size: 0.85rem;
  font-weight: 700;
  color: #f0c040;
  letter-spacing: 0.5px;
}

/* Opponent area */
#opponentArea {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.opponent-name {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.8;
}

.opponent-cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
}

.card-back {
  width: 70px;
  height: 100px;
  background: linear-gradient(135deg, #1a3a6e 0%, #2a5298 50%, #1a3a6e 100%);
  border-radius: 8px;
  border: 2px solid #4a7ad4;
  margin-left: -30px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-back::after {
  content: '✦';
  color: rgba(255,255,255,0.3);
  font-size: 1.4rem;
}

.card-back:first-child {
  margin-left: 0;
}

/* Table */
#tableArea {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  min-height: 160px;
}

#pile {
  display: flex;
  align-items: center;
  justify-content: center;
}

#deckArea {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#deck {
  font-size: 5rem;
  cursor: pointer;
  transition: transform 0.15s;
  user-select: none;
  line-height: 1;
}

#deck:hover {
  transform: scale(1.08);
}

#deckCount {
  font-size: 0.8rem;
  opacity: 0.6;
}

/* Cards */
.card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 100px;
  background: #fff;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  position: relative;
  flex-shrink: 0;
}

.card:hover {
  transform: translateY(-8px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.card.playable {
  border: 2px solid #f0c040;
}

.card.not-playable {
  opacity: 0.5;
  cursor: default;
}

.card.not-playable:hover {
  transform: none;
}

.card .rank {
  font-size: 1.3rem;
  line-height: 1;
}

.card .suit-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.card.red { color: #d32f2f; }
.card.black { color: #222; }

.card.pile-card {
  width: 90px;
  height: 130px;
  cursor: default;
  font-size: 1.5rem;
}

.card.pile-card .rank { font-size: 1.6rem; }
.card.pile-card .suit-icon { font-size: 2rem; }

/* Hand */
#myHand {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 0 6px;
  min-height: 110px;
}

/* Info panel */
#infoPanel {
  text-align: center;
  padding: 2px 8px;
}

#turnInfo {
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 22px;
}

.turn-mine {
  color: #f0c040;
}

.turn-opponent {
  color: rgba(255,255,255,0.7);
}

#requestInfo {
  text-align: center;
  font-size: 0.95rem;
  min-height: 20px;
  padding: 1px 4px;
  font-weight: 600;
  color: #f0c040;
}

#hintBar {
  text-align: center;
  font-size: 0.85rem;
  min-height: 18px;
  padding: 1px 8px;
}

.hint-warning {
  color: #ff9800;
}

.hint-ok {
  color: rgba(255,255,255,0.6);
}

/* Action bar */
#actionBar {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 4px 0 8px;
  min-height: 32px;
}

.action-btn {
  padding: 8px 20px;
  border: 2px solid #fff;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: rgba(255,255,255,0.15);
}

.makao-btn {
  border-color: #f0c040;
  color: #f0c040;
  font-size: 1.1rem;
  animation: pulse 1s infinite;
}

.stop-btn {
  border-color: #ff6b6b;
  color: #ff6b6b;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Overlay (for J/A selection) */
#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;
}

#overlayContent {
  background: #1a5c2e;
  border: 2px solid #f0c040;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  max-width: 350px;
  width: 90%;
}

#overlayContent h3 {
  margin-bottom: 16px;
  font-size: 1.2rem;
}

.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.choice-btn {
  padding: 12px 18px;
  border: 2px solid #fff;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s;
  min-width: 60px;
}

.choice-btn:hover {
  background: rgba(255,255,255,0.15);
}

.choice-btn.suit-hearts, .choice-btn.suit-diamonds { color: #ff6b6b; border-color: #ff6b6b; }
.choice-btn.suit-clubs, .choice-btn.suit-spades { color: #ddd; border-color: #ddd; }

/* Winner banner */
.winner-banner {
  text-align: center;
}

.winner-banner h2 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.winner-banner button {
  padding: 12px 30px;
  border: none;
  border-radius: 8px;
  background: #f0c040;
  color: #1a3c0e;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 12px;
}

/* Drawn card highlight */
.card.drawn-highlight {
  border: 2px solid #4fc3f7;
  box-shadow: 0 0 12px rgba(79, 195, 247, 0.6);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: transform 0.3s;
  z-index: 200;
  pointer-events: none;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Mobile */
@media (max-width: 768px) {
  #game {
    flex-direction: column;
  }

  #gameMain {
    min-height: 0;
    height: 100dvh;
  }

  /* Chat panel — slide-up from bottom on mobile */
  #chatPanel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 55dvh;
    z-index: 50;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.15);
    background: rgba(15, 50, 25, 0.97);
    border-radius: 16px 16px 0 0;
  }

  #chatPanel.open {
    transform: translateY(0);
  }

  #chatCloseBtn {
    display: block;
  }

  /* Floating toggle button */
  #chatToggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 14px;
    right: 14px;
    z-index: 40;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.5);
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    transition: background 0.2s;
  }

  #chatToggle:hover {
    background: rgba(0,0,0,0.65);
  }

  #chatBadge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #ff4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }

  .card {
    width: 56px;
    height: 82px;
    font-size: 1rem;
  }
  .card .rank { font-size: 1.1rem; }
  .card .suit-icon { font-size: 1.3rem; }
  .card.pile-card {
    width: 76px;
    height: 110px;
  }
  .card-back {
    width: 70px;
    height: 100px;
    margin-left: -30px;
  }
  .card-back::after { font-size: 1.1rem; }
  #deck { font-size: 4rem; }
}
