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

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: #1a1a2e;
  color: #fff;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== 로비 ===== */
#lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

.lobby-card {
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 24px;
  padding: 40px 36px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.lobby-card h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 28px;
}

.emoji-picker p {
  font-size: 13px;
  opacity: 0.7;
  margin-bottom: 10px;
}

.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.emoji-option {
  font-size: 32px;
  width: 52px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.08);
  transition: all 0.2s;
  image-rendering: pixelated;
}

.emoji-option:hover {
  background: rgba(255,255,255,0.2);
}

.emoji-option.selected {
  border-color: #fff;
  background: rgba(255,255,255,0.25);
  transform: scale(1.1);
}

#nicknameInput {
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 16px;
  outline: none;
  margin-bottom: 14px;
}

#nicknameInput::placeholder {
  color: rgba(255,255,255,0.5);
}

#joinBtn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#joinBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(240,147,251,0.4);
}

.online-count {
  margin-top: 16px;
  font-size: 13px;
  opacity: 0.6;
}

/* ===== 게임 ===== */
#game {
  position: relative;
  width: 100vw;
  height: 100dvh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #2d2d44;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 100%);
  pointer-events: none;
}

.hud-left, .hud-right {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

.hud-left span {
  font-size: 13px;
  background: rgba(0,0,0,0.4);
  padding: 6px 12px;
  border-radius: 20px;
}

.hud-right button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.4);
  font-size: 20px;
  cursor: pointer;
  color: #fff;
}

/* ===== 조이스틱 ===== */
#joystick {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 140px;
  height: 140px;
  display: none;
}

.joy-btn {
  position: absolute;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.joy-btn:active {
  background: rgba(255,255,255,0.35);
}

.joy-up { top: 0; left: 50%; transform: translateX(-50%); }
.joy-down { bottom: 0; left: 50%; transform: translateX(-50%); }
.joy-left { top: 50%; left: 0; transform: translateY(-50%); }
.joy-right { top: 50%; right: 0; transform: translateY(-50%); }

/* ===== 채팅박스 ===== */
#chatBox {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 280px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  border-radius: 16px 16px 0 0;
}

#chatBox.chat-hidden {
  transform: translateY(100%);
}

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  max-height: 200px;
}

.chat-msg {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

.chat-msg .sender {
  font-weight: 700;
  margin-right: 6px;
}

.chat-msg.mine .sender {
  color: #f093fb;
}

.chat-msg.system {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  text-align: center;
}

.chat-input-wrap {
  display: flex;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

.chat-input-wrap input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 14px;
  outline: none;
}

.chat-input-wrap button {
  padding: 10px 18px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ===== 프로필 팝업 ===== */
#profilePopup {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}

.profile-card {
  background: rgba(40,40,70,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  padding: 32px 28px;
  text-align: center;
  min-width: 260px;
  position: relative;
}

.profile-close {
  position: absolute;
  top: 12px;
  right: 16px;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.6;
}

.profile-emoji {
  font-size: 64px;
  margin-bottom: 12px;
}

.profile-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-btn {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* ===== 1:1 채팅 ===== */
#privateChat {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 380px;
  max-height: 70vh;
  background: rgba(30,30,55,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
}

.private-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.private-header span {
  font-weight: 700;
}

.private-header button {
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

#privateMessages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  min-height: 200px;
  max-height: 50vh;
}

/* ===== 대화 요청 팝업 ===== */
#chatRequestPopup {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
}

.request-card {
  background: rgba(40,40,70,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(240,147,251,0.4);
  border-radius: 16px;
  padding: 18px 24px;
  text-align: center;
  min-width: 260px;
  animation: slideDown 0.3s ease;
}

.request-card p {
  margin-bottom: 14px;
  font-size: 15px;
}

.request-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.request-actions button {
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

#requestAccept {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
}

#requestDecline {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ===== 리액션 알림 ===== */
#reactionNotify {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40,40,70,0.9);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 14px 24px;
  font-size: 15px;
  z-index: 250;
  animation: slideDown 0.3s ease;
}

/* ===== 말풍선 (캔버스 위 오버레이) ===== */
.speech-bubble {
  position: absolute;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 180px;
  word-break: break-word;
  pointer-events: none;
  animation: bubbleFade 4s ease forwards;
  z-index: 50;
}

/* ===== 드래그 앤 드롭 ===== */
#game.drag-over::after {
  content: '📷 이미지를 놓으세요';
  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;
  font-size: 24px;
  color: #fff;
  z-index: 999;
  pointer-events: none;
  border: 4px dashed rgba(255,255,255,0.4);
}

/* ===== 이미지 전송 ===== */
.img-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.img-btn:active {
  background: rgba(255,255,255,0.35);
  transform: scale(0.95);
}

#chatImagePreview,
#privateImagePreview {
  padding: 8px 12px;
  position: relative;
}

#chatImagePreview img,
#privateImagePreview img {
  max-width: 160px;
  max-height: 120px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
}

#chatPreviewCancel,
#privatePreviewCancel {
  position: absolute;
  top: 4px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.chat-msg img.chat-image {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
}

/* ===== 이미지 뷰어 ===== */
#imageViewer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  cursor: pointer;
}

#imageViewer img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
}

/* ===== 애니메이션 ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes bubbleFade {
  0% { opacity: 0; transform: translateY(4px); }
  10% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}

/* ===== 모바일 ===== */
@media (pointer: coarse) {
  #joystick {
    display: block !important;
  }
}

@media (max-width: 480px) {
  .lobby-card {
    padding: 28px 20px;
  }
  .lobby-card h1 {
    font-size: 22px;
  }
  #chatBox {
    max-height: 240px;
  }
}
