:root {
  color-scheme: light;
}

html {
  background-color: black;
}

body {
  margin: 0;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  overflow: hidden;
  user-select: none; /* 텍스트 선택 방지 */
  touch-action: none; /* 모바일 터치 제스처(확대/스크롤) 방지 */
}

#game-container {
  position: relative;
  width: 1400px;
  height: 900px;
  transform-origin: center center;
  flex-shrink: 0; /* 화면이 작아져도 레이아웃이 깨지지 않도록 고정 */
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* 말풍선 스타일 */
.speech-bubble {
  position: absolute;
  background: white;
  border: 2px solid #333;
  border-radius: 10px; /* 모서리 둥글기 약간 증가 */
  padding: 6px 10px; /* [크기 조절] 내부 여백: 첫번째 숫자(상하), 두번째 숫자(좌우)를 늘리면 말풍선이 커집니다 */
  font-family: "Noto Sans KR", sans-serif; /* 폰트 변경 */
  font-weight: bold;
  font-size: 14px; /* [크기 조절] 글자 크기 */
  color: black;
  opacity: 0;
  transform: translate(-50%, -50%); /* 중앙 정렬을 위해 추가 */
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap; /* 줄바꿈 방지 (위아래로 길어지는 것 막음) */
  text-align: center;
}

.speech-bubble.show {
  opacity: 1;
}

/* 이모티콘 전용 스타일 (크게) */
.speech-bubble.emoji-mode {
  font-size: 36px !important; /* 이모티콘 크기 더 키움 */
  padding: 8px 12px !important; /* 이모티콘에 맞춰 패딩 조정 */
  border-radius: 12px;
}

/* 플레이어별 말풍선 위치 */
#bubble-0 {
} /* East */
#bubble-1 {
} /* North */
#bubble-2 {
} /* West */
#bubble-3 {
} /* South */

/* 기존에 개별적으로 적용되던 위치 및 변형 속성은 JS에서 처리하거나,
   .speech-bubble의 transform: translate(-50%, -50%)으로 일관되게 처리 */

/* UI 레이어 스타일 */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* UI 아래 캔버스 클릭 가능하도록 */
}

/* 전체 화면 오버레이 (시작, 게임오버) */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  pointer-events: auto; /* 버튼 클릭 가능하도록 */
  z-index: 100;
}

.title {
  font-size: 80px;
  color: #c62828;
  margin-bottom: 40px;
  text-shadow: 0 0 10px rgba(198, 40, 40, 0.5);
}

#game-over-title {
  font-size: 80px;
  color: white;
  margin-bottom: 40px;
}

/* 버튼 공통 스타일 */
.btn {
  padding: 15px 25px;
  font-size: 24px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition:
    transform 0.1s,
    opacity 0.2s;
  pointer-events: auto;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.95);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.primary {
  background-color: #2e7d32;
  color: white;
}
.success {
  background-color: #2e7d32;
  color: white;
  border: 2px solid #81c784;
}
.danger {
  background-color: #c62828;
  color: white;
  border: 2px solid #ef5350;
}
.secondary {
  background-color: #424242;
  color: white;
  border: 2px solid #616161;
}
.secondary:hover {
  background-color: #616161;
}

/* 게임 HUD */
#game-hud {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#target-rank {
  position: absolute;
  top: 120px;
  left: 120px;
  bottom: auto;
  transform: none;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 10px 20px;
  border-radius: 15px;
  border: 2px solid #d4af37;
  font-size: 24px;
  font-weight: bold;
}

/* 목표 카드 팝업 (중앙 일시 표시) */
#target-popup {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 300;
  pointer-events: none;
}

#target-popup img {
  width: 180px;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
  margin-bottom: 15px;
}

#target-popup-text {
  font-size: 40px;
  font-weight: bold;
  color: #d4af37;
  text-shadow: 2px 2px 4px black;
}

#game-status {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 28px;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

#action-buttons {
  position: absolute;
  bottom: 50px;
  left: calc(50% + 240px); /* 카드 오른쪽으로 이동 */
  transform: none;
  display: flex;
  gap: 20px;
}

#message-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 60px;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 20px black;
  text-align: center;
  width: 100%;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

/* 전체 화면 버튼 */
#btn-fullscreen {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 8px 15px;
  font-size: 14px;
  background-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  z-index: 200; /* 오버레이보다 위에 표시 */
}

#btn-fullscreen:hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: rgba(255, 255, 255, 0.5);
}

/* 사운드 컨트롤 */
#sound-controls {
  position: absolute;
  top: 70px; /* 전체 화면 버튼 아래 */
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 200;
  pointer-events: auto;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 20px;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

#volume-slider {
  width: 100px;
  cursor: pointer;
  accent-color: #2e7d32;
}

/* AI BGM 안내 문구 */
#ai-bgm-notice {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 12px;
  pointer-events: none;
  z-index: 200;
}

/* 모달 배경 및 위치 설정 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  pointer-events: auto;
}

/* 게임 방법 모달 스타일 */
.modal-content {
  background-color: rgba(20, 20, 20, 0.95);
  border: 2px solid #d4af37;
  border-radius: 20px;
  padding: 40px;
  max-width: 600px;
  width: 80%;
  text-align: center;
  color: white;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

.modal-content h2 {
  font-size: 40px;
  color: #d4af37;
  margin-bottom: 30px;
  text-shadow: 2px 2px 4px black;
}

.rules-text {
  text-align: left;
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 30px;
  max-height: 400px;
  overflow-y: auto;
}

.rules-text p {
  margin-bottom: 15px;
}

.rules-text ul {
  margin-bottom: 15px;
  padding-left: 20px;
  color: #ccc;
}

.rule-block {
  margin-bottom: 25px;
}

.rule-block h3 {
  color: #d4af37;
  margin: 0 0 10px 0;
  font-size: 20px;
}

/* 페이드 아웃 효과 */
body.fade-out {
  opacity: 0;
  transition: opacity 1s ease-out;
}

/* --- 멀티플레이 로비 스타일 --- */
.lobby-container {
  display: flex;
  width: 80%; /* 부모 요소(lobby-screen)의 너비에 맞게 조정 */
  height: 750px;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid #555;
  border-radius: 20px;
  overflow: hidden;
}

.lobby-main {
  flex: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 2px solid #555;
  padding: 0px;
}

.lobby-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(20, 20, 20, 0.9);
}

.player-slots-container {
  display: flex;
  gap: 15px;
  margin-bottom: 30px;
  width: 100%;
  justify-content: center;
}

.player-slot {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid #555;
  border-radius: 10px;
  padding: 10px;
  width: 150px; /* 캔버스 최소 너비에서도 잘리지 않도록 너비 조정 */
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.btn-select {
  padding: 8px 15px;
  font-size: 16px;
  font-weight: bold;
  border: 2px solid #616161; /* secondary 버튼과 유사한 테두리 */
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 0.1s,
    background-color 0.2s,
    border-color 0.2s;
  pointer-events: auto;
  white-space: nowrap;
  background-color: #424242; /* secondary 버튼과 유사한 배경 */
  color: white;
  width: 100%; /* 슬롯 너비에 맞춤 */
  box-sizing: border-box; /* 패딩, 보더 포함 너비 계산 */
}

.btn-select:hover:not(:disabled) {
  background-color: #616161;
}

.btn-select.selected {
  border-color: #d4af37; /* 황금색 테두리로 선택 강조 */
  background-color: #555; /* 선택 시 약간 더 밝은 배경 */
}
.btn-select.disabled,
.btn-select[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  background-color: #333; /* 비활성화 시 더 어두운 배경 */
  border-color: #444;
}

.slot-header {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 5px;
}

.slot-char-area {
  position: relative;
  width: 140px;
  height: 196px;
  margin-bottom: 10px;
}

.slot-char-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
}

.char-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
}

.slot-char-area.empty {
  border: 2px dashed #555;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
}

.slot-name {
  font-size: 16px;
  font-weight: bold;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.room-info {
  text-align: center;
  margin-bottom: 30px;
}

.room-label {
  display: block;
  font-size: 14px;
  color: #aaa;
  margin-bottom: 5px;
}

.room-code {
  font-size: 48px;
  font-weight: bold;
  color: white;
  letter-spacing: 5px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.chat-header {
  padding: 15px;
  background: #333;
  color: white;
  font-weight: bold;
  text-align: center;
}

.chat-messages {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  color: #ddd;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input-area {
  padding: 10px;
  display: flex;
  gap: 5px;
  background: #222;
}

.input-field {
  padding: 12px;
  font-size: 16px;
  border-radius: 5px;
  border: 1px solid #444;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  outline: none;
  transition: all 0.3s ease;
}
.input-field:focus {
  border-color: #d4af37;
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.4);
  background: rgba(0, 0, 0, 0.8);
}

.btn-send {
  padding: 0 15px;
  background: #444;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
.btn-send:hover {
  background: #555;
}

.slot-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.6);
}

.btn-mini {
  background: none;
  border: none;
  color: white;
  font-weight: bold;
  cursor: pointer;
  padding: 5px 10px;
}
.btn-mini:hover {
  color: #d4af37;
}

/* 카운트다운 스타일 */
#countdown-overlay {
  font-size: 120px;
  font-weight: 900;
  color: #d4af37;
  text-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  animation: pulseCount 1s infinite;
}

@keyframes pulseCount {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
  }
}

/* 인게임 채팅 스타일 */
#ingame-chat {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 300px;
  height: 250px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  z-index: 150;
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

#ingame-chat:hover {
  opacity: 1;
}

#ingame-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  color: white;
  font-size: 14px;
  text-shadow: 1px 1px 2px black;
  scrollbar-width: none;
}

#ingame-messages::-webkit-scrollbar {
  display: none;
}

.chat-controls {
  display: flex;
  padding: 5px;
  gap: 5px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 0 0 10px 10px;
}

#ingame-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 8px;
  border-radius: 5px;
  outline: none;
  transition: all 0.3s ease;
}
#ingame-input:focus {
  border-color: #d4af37;
  background: rgba(0, 0, 0, 0.8);
  box-shadow: 0 0 5px rgba(212, 175, 55, 0.4);
}

/* 로비 채팅 입력창 스타일 추가 */
#chat-input {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  border-radius: 5px;
  border: 1px solid #444;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  outline: none;
  transition:
    border-color 0.3s,
    box-shadow 0.3s;
}
#chat-input:focus {
  border-color: #d4af37;
  box-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
}

#emoji-picker {
  position: absolute;
  bottom: 40px;
  left: 0;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid #555;
  border-radius: 5px;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.emoji-item {
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
}
.emoji-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
