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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 500px;
  padding: 20px;
}

.username-box,
.lobby-box {
  background: white;
  padding: 30px;
  border-radius: 5px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
}

h1 {
  color: #667eea;
  margin-bottom: 20px;
  font-size: 2em;
}

p {
  color: #666;
  margin-bottom: 20px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 15px;
  border: 2px solid #e0e0e0;
  border-radius: 5px;
  font-size: 16px;
  margin-bottom: 15px;
  transition: border 0.3s;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: #667eea;
}

button {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

button:active {
  transform: translateY(0);
}

.error {
  color: #e74c3c;
  margin-top: 10px;
  min-height: 20px;
}

.waiting-text {
  margin-top: 30px;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.cancel-btn {
  background: #e74c3c;
}

.cancel-btn:hover {
  box-shadow: 0 5px 20px rgba(231, 76, 60, 0.4);
}

.logout-btn {
  background: #95a5a6;
  margin-top: 10px;
}

.logout-btn:hover {
  box-shadow: 0 5px 20px rgba(149, 165, 166, 0.4);
}

/* 방 나가기 버튼 */
.leave-game-btn {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 15px 30px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 5px rgba(231, 76, 60, 0.3);
  width: 100%;
}

.leave-game-btn:hover {
  background: #c0392b;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(231, 76, 60, 0.4);
}

/* 위험 버튼 */
.danger-btn {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
}

.danger-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

/* 취소 버튼 */
.cancel-btn {
  background: #95a5a6;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
}

.cancel-btn:hover {
  background: #7f8c8d;
  transform: translateY(-2px);
}

.success {
  color: #2ecc71;
  margin-top: 10px;
  min-height: 20px;
}

/* 사용자 통계 */
.user-stats {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 5px;
  padding: 20px;
  margin: 20px 0;
  color: white;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.user-stats h3 {
  margin: 0 0 15px 0;
  font-size: 20px;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 15px;
}

.stat-item {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  padding: 15px;
  text-align: center;
  backdrop-filter: blur(10px);
  transition: all 0.3s;
}

.stat-item:hover {
  transform: translateY(-3px);
  background: rgba(255, 255, 255, 0.3);
}

.stat-label {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.stat-win {
  color: #2ecc71;
  text-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.stat-loss {
  color: #e74c3c;
  text-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.stat-rate {
  color: #f1c40f;
  text-shadow: 0 0 10px rgba(241, 196, 15, 0.5);
}

/* 반응형: 작은 화면 - 아래 모바일 미디어 쿼리로 통합됨 */

/* 게임 화면 스타일 */
.game-container {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.game-header {
  background: white;
  border-radius: 5px;
  padding: 20px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.player-info {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.player-info h3 {
  color: #667eea;
  margin-bottom: 10px;
}

.round-wins {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

/* 기존 헤더의 round-info는 더 이상 사용하지 않음 */

.game-main {
  flex: 1;
  display: flex;
  gap: 20px;
  overflow: hidden;
}

.game-board-area {
  flex: 3; /* 게임 영역이 채팅보다 3배 더 큰 비율 */
  background: white;
  border-radius: 5px;
  padding: 20px;
  overflow-x: hidden; /* 좌우 스크롤 방지 */
  overflow-y: visible; /* 세로 스크롤 허용 */
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  max-width: 100%; /* 부모 너비를 넘지 않도록 */
}

/* 메인 컨텐츠 영역 (카드보드/핸드) */
.main-content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: visible; /* 스크롤 허용 */
  height: 100%; /* 높이 제한 */
}

/* 카드 선택 안내 */
.card-selection-guide {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 15px;
  border-radius: 5px;
  margin: 10px;
  flex-shrink: 0; /* 안내 박스는 고정 크기 유지 */
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
  gap: 30px;
}

.player-selection-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* min-width: 150px; */
}

.player-id {
  font-size: 18px;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.15);
  padding: 6px 16px;
  border-radius: 5px;
  border: 2px solid rgba(255, 215, 0, 0.3);
}

.selection-count {
  font-size: 24px;
  font-weight: bold;
  color: white;
  background: rgba(255, 255, 255, 0.2);
  padding: 8px 20px;
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  min-width: 80px;
  text-align: center;
}

.selection-center {
  flex: 1;
  text-align: center;
}

.selection-center h3 {
  margin: 0 0 10px 0;
  font-size: 24px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.selection-center p {
  margin: 0;
  font-size: 18px;
  color: white;
  opacity: 0.95;
  min-height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 카드 보드 */
.card-board {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(100px, 1fr)
  ); /* 카드 너비에 맞춰 자동 열 조정 */
  gap: 10px;
  justify-content: center;
  overflow-y: auto; /* 세로 스크롤 활성화 */
  overflow-x: hidden; /* 좌우 스크롤 방지 */
  padding: 0;
  margin: 10px;
  flex: 1; /* 남은 공간 차지 */
  max-height: 100%; /* 최대 높이 제한 */
}

/* 카드 보드 스크롤바 스타일 */
.card-board::-webkit-scrollbar {
  width: 8px;
}

.card-board::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
}

.card-board::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 5px;
}

.card-board::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

.card {
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2em;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  position: relative;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.card.back {
  background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%);
}

.card.back::after {
  content: "🂠";
  font-size: 2em;
}

.card.selected-p1 {
  border: 6px solid #2ecc71;
  box-shadow: 0 0 20px rgba(46, 204, 113, 0.8), 0 0 40px rgba(46, 204, 113, 0.5);
  transform: scale(1.05);
}

.card.selected-p2 {
  position: relative;
  border: 6px solid #f1c40f;
  box-shadow: 0 0 20px rgba(241, 196, 15, 0.8), 0 0 40px rgba(241, 196, 15, 0.5);
  transform: scale(1.05);
}

.card.selected-p2::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(128, 128, 128, 0.6);
  border-radius: 5px;
  pointer-events: none;
  z-index: 1;
}

.card.revealed {
  background: white;
  border: 2px solid #e0e0e0;
}

.card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 공개된 카드 영역 */
.revealed-cards-area {
  flex: 1;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.revealed-cards-area h4 {
  color: white;
  margin-bottom: 15px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.revealed-cards {
  width: 100%;
}

.revealed-cards > div {
  padding: 20px;
  background: white;
  border-radius: 5px;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.revealed-cards > div > div {
  font-size: 28px;
  font-weight: bold;
  color: #333;
  padding: 8px 15px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 5px;
  min-width: 120px;
  text-align: center;
}

/* 공개된 카드 요약 - PC에서는 세로 방향 */
.revealed-cards-summary {
  display: flex;
  flex-direction: column;
  gap: 20px;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  font-weight: bold;
  padding: 20px;
}

.revealed-cards-summary > div {
  color: white;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* 플레이어 핸드 */
.hand-area {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 30px;
}

/* 점수 + 공개된 카드 컨테이너 */
.score-and-revealed {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

.score-display {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 5px;
  padding: 20px 30px;
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.6);
  animation: scoreGlow 2s ease-in-out infinite;
  gap: 20px;
}

.player-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.player-name {
  font-size: 16px;
  font-weight: bold;
  color: #ffd700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 12px;
  border-radius: 5px;
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.round-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

@keyframes scoreGlow {
  0%,
  100% {
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.6);
  }
  50% {
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.9),
      0 0 50px rgba(102, 126, 234, 0.4);
  }
}

.score-left,
.score-right {
  font-size: 48px;
  font-weight: bold;
  color: white;
  text-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  display: inline-block;
  animation: scoreScale 0.3s ease-in-out;
  min-width: 60px;
  text-align: center;
}

.round-info {
  font-size: 24px !important;
  font-weight: bold !important;
  color: #ffd700 !important;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5) !important;
  background: rgba(255, 255, 255, 0.2) !important;
  padding: 8px 16px !important;
  border-radius: 5px !important;
  border: 2px solid rgba(255, 215, 0, 0.3) !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

@keyframes scoreScale {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

/* 현재 상태 표시 */
.phase-status {
  text-align: center;
  padding: 12px 24px;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  border-radius: 5px;
  box-shadow: 0 3px 15px rgba(46, 204, 113, 0.4);
  margin: 15px auto;
  max-width: 500px;
  transition: all 0.3s ease;
}

.phase-status.win {
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  box-shadow: 0 3px 15px rgba(46, 204, 113, 0.6);
}

.phase-status.lose {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  box-shadow: 0 3px 15px rgba(231, 76, 60, 0.6);
}

.phase-status.draw {
  background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
  box-shadow: 0 3px 15px rgba(149, 165, 166, 0.6);
}

.phase-status p {
  margin: 0;
  color: white !important;
  font-size: 18px;
  font-weight: bold;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.hands-wrapper {
  display: flex;
  justify-content: space-around;
  gap: 30px;
  overflow-y: auto; /* 카드 선택 시 스크롤 생성 */
  flex: 1; /* 남은 공간을 모두 사용 */
}

.player-hand {
  flex: 1;
  text-align: center;
}

.player-hand h4 {
  color: #667eea;
  margin-bottom: 10px;
}

.hand-cards {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  /* min-height: 400px; */
}

/* 카드 선택 비활성화 상태 */
.hand-cards.disabled {
  pointer-events: none;
  opacity: 0.5;
  filter: grayscale(30%);
}

.hand-cards.disabled::before {
  content: "라운드 결과 확인 중...";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 24px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* 카드 래퍼 */
.hand-card-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  /* gap: 12px; */
  transition: all 0.5s ease;
}

/* 내 카드 영역의 카드들 - 반시계 방향 90도 회전 (오른쪽 향함) */
#myHand .hand-card {
  transform: rotate(-90deg);
}

/* 상대방 카드 영역의 카드들 - 시계 방향 90도 회전 (왼쪽 향함) */
#opponentHand .hand-card {
  transform: rotate(90deg);
}

/* 사용된 카드 래퍼는 안쪽(중앙)으로 이동 */
/* 내 카드는 오른쪽에 있으므로 왼쪽으로 이동 */
#myHand .hand-card-wrapper.used-card {
  transform: translateX(-50px);
}

/* 상대방 카드는 왼쪽에 있으므로 오른쪽으로 이동 */
#opponentHand .hand-card-wrapper.used-card {
  transform: translateX(50px);
}

/* 사용된 카드의 회전 유지 */
#myHand .hand-card-wrapper.used-card .hand-card {
  transform: rotate(-90deg);
}

#opponentHand .hand-card-wrapper.used-card .hand-card {
  transform: rotate(90deg);
}

/* 라운드 라벨 위치 조정 - 내 카드는 오른쪽, 상대방 카드는 왼쪽 */
#myHand .hand-card-wrapper {
  flex-direction: row;
}

#opponentHand .hand-card-wrapper {
  flex-direction: row-reverse;
}

/* 라운드 결과별 테두리 */
.hand-card-wrapper.result-win .hand-card {
  border: 4px solid #2ecc71;
  box-shadow: 0 0 15px rgba(46, 204, 113, 0.6);
}

.hand-card-wrapper.result-lose .hand-card {
  border: 4px solid #e74c3c;
  box-shadow: 0 0 15px rgba(231, 76, 60, 0.6);
}

.hand-card-wrapper.result-draw .hand-card {
  border: 4px solid #95a5a6;
  box-shadow: 0 0 15px rgba(149, 165, 166, 0.6);
}

/* 라운드 번호 라벨 */
.round-label {
  font-size: 12px;
  font-weight: bold;
  color: #667eea;
  background: white;
  padding: 4px 10px;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  border: 2px solid #667eea;
  min-width: 40px;
  text-align: center;
}

/* 내 카드의 라운드 라벨 - 카드 오른쪽에 위치 */
#myHand .round-label {
  margin-left: 40px;
}

/* 상대방 카드의 라운드 라벨 - 카드 왼쪽에 위치 */
#opponentHand .round-label {
  margin-right: 40px;
}

.hand-card {
  width: 80px;
  height: 120px;
  background: white;
  border: 3px solid #e0e0e0;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 3em;
  cursor: pointer;
  transition: all 0.5s ease;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  transform-style: preserve-3d;
  position: relative;
}

/* flipping 애니메이션 - 내 카드 */
#myHand .hand-card.flipping {
  animation: cardFlipMyHand 0.6s ease-in-out;
}

/* flipping 애니메이션 - 상대방 카드 */
#opponentHand .hand-card.flipping {
  animation: cardFlipOpponentHand 0.6s ease-in-out;
}

@keyframes cardFlipMyHand {
  0% {
    transform: rotate(-90deg) rotateY(0deg) scale(1);
  }
  50% {
    transform: rotate(-90deg) rotateY(90deg) scale(1.1);
  }
  100% {
    transform: rotate(-90deg) rotateY(0deg) scale(1);
  }
}

@keyframes cardFlipOpponentHand {
  0% {
    transform: rotate(90deg) rotateY(0deg) scale(1);
  }
  50% {
    transform: rotate(90deg) rotateY(90deg) scale(1.1);
  }
  100% {
    transform: rotate(90deg) rotateY(0deg) scale(1);
  }
}

/* hover 효과 - 내 카드 */
#myHand .hand-card:not(.used):hover {
  transform: rotate(-90deg) translateY(-10px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  border-color: #667eea;
}

/* hover 효과 - 상대방 카드 */
#opponentHand .hand-card:hover {
  transform: rotate(90deg) scale(1.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.hand-card.back {
  background: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%);
  font-size: 2em;
}

.hand-card.played {
  opacity: 0.3;
  cursor: not-allowed;
}

.hand-card.used {
  opacity: 0.8;
  cursor: not-allowed;
  border-color: #95a5a6;
  border-width: 2px;
}

/* 선택된 카드 - 내 카드 */
#myHand .hand-card.selected {
  border-color: #2ecc71;
  border-width: 6px;
  box-shadow: 0 0 25px rgba(46, 204, 113, 0.9), 0 0 50px rgba(46, 204, 113, 0.6);
  transform: rotate(-90deg) translateY(-10px) scale(1.05);
}

/* 선택된 카드 - 상대방 카드 */
#opponentHand .hand-card.selected {
  border-color: #ffd700;
  border-width: 6px;
  box-shadow: 0 0 25px rgba(255, 215, 0, 0.9), 0 0 50px rgba(255, 215, 0, 0.6);
  transform: rotate(90deg) scale(1.05);
}

/* 상대방이 선택한 카드 (내 화면에서 보이는 상대방 카드) */
#opponentHand .hand-card.opponent-selected {
  border: 4px solid #f39c12;
  box-shadow: 0 0 20px rgba(243, 156, 18, 0.8), 0 0 40px rgba(243, 156, 18, 0.5);
  animation: opponentSelectPulse 1s ease-in-out infinite;
  transform: rotate(90deg) scale(1.05);
}

@keyframes opponentSelectPulse {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(243, 156, 18, 0.8),
      0 0 40px rgba(243, 156, 18, 0.5);
  }
  50% {
    box-shadow: 0 0 30px rgba(243, 156, 18, 1), 0 0 60px rgba(243, 156, 18, 0.7);
  }
}

/* 레디 버튼 */
.ready-btn {
  margin-top: 20px;
  padding: 15px 40px;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 5px 15px rgba(46, 204, 113, 0.4);
  animation: readyPulse 1.5s ease-in-out infinite;
}

.ready-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(46, 204, 113, 0.6);
  background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
}

.ready-btn:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(46, 204, 113, 0.4);
}

@keyframes readyPulse {
  0%,
  100% {
    box-shadow: 0 5px 15px rgba(46, 204, 113, 0.4);
  }
  50% {
    box-shadow: 0 8px 30px rgba(46, 204, 113, 0.8),
      0 0 40px rgba(46, 204, 113, 0.4);
  }
}

/* 라운드 결과 */
.round-result-area {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 40px;
  border-radius: 5px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  text-align: center;
}

.result-cards {
  display: flex;
  align-items: center;
  gap: 30px;
  margin-bottom: 20px;
}

.result-card {
  text-align: center;
}

.result-card p {
  color: #667eea;
  font-weight: bold;
  margin-bottom: 10px;
}

.result-card-display {
  width: 100px;
  height: 150px;
  background: white;
  border: 3px solid #e0e0e0;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 4em;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.result-vs {
  font-size: 2em;
  font-weight: bold;
  color: #667eea;
}

#roundWinnerText {
  color: #2ecc71;
  font-size: 1.5em;
  margin-top: 10px;
}

/* 채팅 컨테이너 */
.chat-container {
  flex: 1; /* 유연한 크기 */
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-width: 300px;
  max-width: 25%; /* 최대 25%로 제한 */
}

/* 채팅 토글 버튼 - PC에서는 숨김 */
.chat-toggle-btn {
  display: none;
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  padding: 15px 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
  z-index: 1000;
}

.chat-toggle-btn:hover {
  transform: translateX(-50%) translateY(-3px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* 채팅 뱃지 */
.chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #e74c3c;
  color: white;
  font-size: 12px;
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(231, 76, 60, 0.6);
  animation: badgePulse 1s ease infinite;
}

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

/* 채팅 오버레이 - PC에서는 숨김 */
.chat-overlay {
  display: none !important;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1500;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 채팅 패널 */
.chat-panel {
  background: white;
  border-radius: 5px;
  width: 90%;
  max-width: 500px;
  height: 80%;
  max-height: 600px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 채팅 패널 헤더 */
.chat-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 2px solid #f0f0f0;
  flex-shrink: 0; /* 헤더 크기 고정 */
}

.chat-panel-header h3 {
  margin: 0;
  color: #667eea;
  font-size: 20px;
}

.chat-close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: #95a5a6;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.chat-close-btn:hover {
  background: #f0f0f0;
  color: #e74c3c;
}

/* 채팅 영역 */
.chat-area {
  flex: 1;
  background: white;
  border-radius: 5px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
  max-height: calc(100vh - 100px); /* 화면 높이에 맞춰 최대 높이 설정 */
  overflow: hidden; /* 전체 영역은 overflow 숨김 */
}

.chat-area h3 {
  color: #667eea;
  margin-bottom: 15px;
  text-align: center;
  font-size: 18px;
  flex-shrink: 0; /* 제목 크기 고정 */
}

/* 채팅 패널 안의 메시지 영역 */
.chat-panel .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 300px); /* 화면 높이에서 여유 공간 제외 */
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  padding: 15px;
  margin-bottom: 15px;
  background: #b2c7d9;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 150px;
}

/* 채팅 메시지 스크롤바 스타일링 */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.6);
  border-radius: 5px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.8);
}

/* 메시지 래퍼 */
.chat-message-wrapper {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
  animation: messageSlide 0.3s ease-out;
}

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

/* 내 메시지 (오른쪽) */
.chat-message-wrapper.my-message {
  align-items: flex-end;
}

/* 상대방 메시지 (왼쪽) */
.chat-message-wrapper.other-message {
  align-items: flex-start;
}

/* 이름 표시 */
.chat-username {
  font-size: 12px;
  color: #333;
  margin-bottom: 4px;
  margin-left: 8px;
  font-weight: 500;
}

/* 말풍선 */
.chat-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 5px;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  line-height: 1.4;
  font-size: 14px;
}

/* 내 메시지 말풍선 (노란색) */
.my-message .chat-bubble {
  background: #fee500;
  color: #000;
  border-bottom-right-radius: 4px;
}

/* 상대방 메시지 말풍선 (흰색) */
.other-message .chat-bubble {
  background: white;
  color: #000;
  border-bottom-left-radius: 4px;
}

/* 채팅 패널 안의 입력 영역 */
.chat-panel .chat-input-area {
  padding: 20px;
  background: white;
  border-top: 2px solid #f0f0f0;
  display: flex;
  gap: 10px;
  border-radius: 5px;
  border: none;
  border-top: 2px solid #f0f0f0;
  flex-shrink: 0; /* 입력창 크기 고정 (줄어들지 않음) */
}

.chat-panel .chat-input-area input {
  flex: 1;
  padding: 12px 15px;
  border: 2px solid #e0e0e0;
  border-radius: 5px;
  font-size: 14px;
  outline: none;
}

.chat-panel .chat-input-area input:focus {
  border-color: #667eea;
}

.chat-panel .chat-input-area button {
  padding: 12px 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 5px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-panel .chat-input-area button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.chat-input-area {
  display: flex;
  gap: 10px;
  background: white;
  padding: 10px;
  border-radius: 5px;
  border: 2px solid #e0e0e0;
  flex-shrink: 0; /* 입력창 크기 고정 (줄어들지 않음) */
}

.chat-input-area input {
  flex: 1;
  margin-bottom: 0;
  border: none;
  padding: 10px 15px;
  font-size: 14px;
}

.chat-input-area input:focus {
  outline: none;
  border: none;
}

.chat-input-area button {
  width: auto;
  padding: 10px 25px;
  background: #fee500;
  color: #000;
  border-radius: 5px;
  font-weight: bold;
  font-size: 14px;
}

.chat-input-area button:hover {
  background: #fada0a;
}

/* 모달 */
/* 토스트 알림 */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 16px 32px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  cursor: pointer;
  max-width: 400px;
  text-align: center;
}

.toast.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-content {
  background: white;
  padding: 40px;
  border-radius: 5px;
  text-align: center;
  max-width: 500px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  color: #667eea;
  margin-bottom: 20px;
}

.modal-content p {
  font-size: 1.2em;
  color: #333;
  margin-bottom: 30px;
}

/* 반응형 */
/* 세로 화면 대응 */
@media (max-height: 900px) and (orientation: portrait) {
  .game-container {
    height: 100vh;
    overflow: hidden;
    padding: 10px; /* 패딩 줄임 */
  }

  .game-main {
    flex-direction: column;
    height: calc(100vh - 20px); /* 패딩 줄인 만큼 높이 증가 */
  }

  .game-board-area {
    flex: 1; /* 남은 공간 모두 사용 */
    overflow: visible; /* 스크롤 허용 */
  }

  .chat-container {
    display: none; /* 모바일에서 채팅 컨테이너 숨김 */
  }

  .chat-area {
    flex: 1;
    min-height: 200px;
    max-height: 35vh;
  }

  .chat-messages {
    flex: 1;
    min-height: 120px;
    max-height: 25vh;
    overflow-y: auto;
  }
}

/* 모바일 버튼 컨테이너 - 기본적으로 숨김 */
.mobile-button-container {
  display: none;
  gap: 10px;
  padding: 10px;
}

/* 모바일 모드 (800px 이하) */
@media (max-width: 1024px) {
  /* 게임 컨테이너 패딩 줄임 */
  .game-container {
    padding: 10px;
  }

  /* 게임 메인 높이 조정 */
  .game-main {
    height: calc(100vh - 20px);
    flex-direction: column;
  }

  /* 화면이 좁을 때 카드 이동 거리 줄임 */
  #myHand .hand-card-wrapper.used-card {
    transform: translateX(-25px);
  }

  #opponentHand .hand-card-wrapper.used-card {
    transform: translateX(25px);
  }

  /* 모바일 버튼 컨테이너 표시 */
  .mobile-button-container {
    display: flex !important;
  }

  /* 모바일 방 나가기 버튼 */
  .mobile-leave-btn {
    flex: 1;
    background: #e74c3c;
    color: white;
    border: none;
    padding: 15px;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(231, 76, 60, 0.3);
    transition: all 0.3s;
  }

  .mobile-leave-btn:hover {
    background: #c0392b;
    transform: translateY(-2px);
  }

  /* 모바일 채팅 토글 버튼 */
  .mobile-chat-toggle-btn {
    flex: 1;
    position: relative;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
  }

  .mobile-chat-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
  }

  /* 게임 보드 영역 스크롤 허용 */

  /* 카드 보드 스크롤 활성화 */
  .card-board {
    grid-template-columns: repeat(
      auto-fit,
      minmax(80px, 1fr)
    ); /* 모바일에서 더 작은 카드 */
    overflow-x: hidden; /* 좌우 스크롤 방지 */
    overflow-y: auto; /* 세로 스크롤만 허용 */
  }

  /* 점수와 공개된 카드 세로 배치 */
  .score-and-revealed {
    flex-direction: column;
  }

  /* 채팅 컨테이너 숨김 */
  .chat-container {
    display: none !important;
  }

  /* 채팅 영역 숨기기 */
  .chat-area {
    display: none !important;
  }

  /* 채팅 오버레이 활성화 */
  .chat-overlay {
    display: none;
  }

  .chat-overlay[style*="display: flex"] {
    display: flex !important;
  }

  .game-header {
    flex-direction: column;
    gap: 15px;
  }

  .revealed-cards-area {
    position: relative;
    width: 100%;
    margin-top: 20px;
  }

  /* 공개된 카드 요약을 가로 방향으로 */
  .revealed-cards-summary {
    flex-direction: row !important;
    gap: 15px;
  }
}

/* 매우 작은 화면 (600px 이하) */
@media (max-width: 600px) {
  /* 카드 이동 거리 더 줄임 */
  #myHand .hand-card-wrapper.used-card {
    transform: translateX(-15px);
  }

  #opponentHand .hand-card-wrapper.used-card {
    transform: translateX(15px);
  }
}

/* 초소형 화면 (400px 이하) */
@media (max-width: 400px) {
  /* 카드 이동 거리 최소화 */
  #myHand .hand-card-wrapper.used-card {
    transform: translateX(-10px);
  }

  #opponentHand .hand-card-wrapper.used-card {
    transform: translateX(10px);
  }
}
