/* ==========================================================
   Chat & Emote System Styles (Desktop & Mobile Unified Input)
   Path: public/css/chat.css
   ========================================================== */

/* 1. Chat Log Overlay (Left Side) */
#chat-panel {
  position: absolute;
  bottom: 84px;
  left: 16px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 190px;
  background: rgba(11, 15, 23, 0.85);
  border: 1.5px solid rgba(223, 183, 67, 0.4);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(12px);
  z-index: 45;
  transition: all 0.25s ease;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

#chat-panel.collapsed {
  height: 36px;
  opacity: 0.6;
}
#chat-panel.collapsed #chat-messages {
  display: none;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(18, 24, 36, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 11px 11px 0 0;
}

.chat-tabs {
  display: flex;
  gap: 6px;
}

.chat-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.chat-tab.active {
  background: rgba(197, 155, 39, 0.25);
  color: var(--accent-gold-light);
  font-weight: 600;
}

.chat-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  line-height: 1.4;
}

#chat-messages::-webkit-scrollbar {
  width: 5px;
}
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(223, 183, 67, 0.3);
  border-radius: 3px;
}

.chat-msg {
  word-break: break-word;
}
.chat-msg .sender {
  font-weight: 600;
  color: var(--accent-gold-light);
  margin-right: 6px;
}
.chat-msg.system {
  color: #38bdf8;
  font-weight: 500;
  font-size: 0.8rem;
  background: rgba(14, 165, 233, 0.1);
  padding: 3px 6px;
  border-radius: 4px;
}

/* 2. Bottom Action Bar (PC & Mobile Unified Always-Visible Input) */
#bottom-bar {
  position: absolute;
  bottom: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

#chat-input-wrapper {
  flex: 1;
  max-width: 520px;
  position: relative;
  pointer-events: auto;
}

#chat-input {
  width: 100%;
  background: rgba(11, 15, 23, 0.92);
  border: 1.5px solid var(--border-gold);
  padding: 12px 48px 12px 16px;
  border-radius: 24px;
  color: #fff;
  font-size: 16px !important; /* iOS自動ズーム防止 */
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 18px rgba(0,0,0,0.6);
  transition: all 0.2s ease;
  user-select: text !important;
  -webkit-user-select: text !important;
  touch-action: manipulation !important;
}
#chat-input:focus {
  outline: none;
  border-color: var(--accent-gold-light);
  background: rgba(18, 24, 36, 0.98);
  box-shadow: 0 0 16px rgba(197, 155, 39, 0.5);
}

.chat-send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, var(--accent-gold) 0%, #8c6b12 100%);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #070a0f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.chat-send-btn:active {
  transform: translateY(-50%) scale(0.92);
}

/* 3. Emote & Quick Phrases Bar */
#emote-bar {
  display: flex;
  gap: 6px;
  background: rgba(11, 15, 23, 0.88);
  border: 1.5px solid rgba(223, 183, 67, 0.4);
  padding: 6px 10px;
  border-radius: 24px;
  backdrop-filter: blur(10px);
  pointer-events: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.emote-btn {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  touch-action: manipulation !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emote-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.2);
}
.emote-btn:active {
  transform: scale(0.92);
}

/* 4. Comic Chat Bubble & Floating Emotes */
.speech-bubble {
  position: absolute;
  background: #ffffff;
  color: #0f172a;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  font-weight: 700;
  white-space: pre-wrap;
  max-width: 260px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 0 2px #c59b27;
  pointer-events: none;
  transform: translate(-50%, -100%);
  z-index: 90;
  animation: bubblePop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 7px 7px 0;
  border-style: solid;
  border-color: #ffffff transparent;
  display: block;
  width: 0;
}

@keyframes bubblePop {
  0% { transform: translate(-50%, -70%) scale(0.4); opacity: 0; }
  100% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}

.floating-emote {
  position: absolute;
  font-size: 2.2rem;
  pointer-events: none;
  transform: translate(-50%, -100%);
  z-index: 95;
  animation: floatUp 1.8s ease-out forwards;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(0.5); }
  20% { opacity: 1; transform: translate(-50%, -100%) scale(1.4); }
  75% { opacity: 1; transform: translate(-50%, -150%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(0.8); }
}

/* ==========================================================
   Mobile Responsive Adjustments (スマホ向け最適化)
   ========================================================== */
@media (max-width: 900px), (pointer: coarse) {
  /* 💬 チャットパネルを左上にコンパクト配置（中央フィールドを完全に開放！） */
  #chat-panel {
    width: 210px;
    height: 85px;
    top: max(44px, calc(env(safe-area-inset-top) + 38px));
    bottom: auto;
    left: 8px;
    background: rgba(11, 15, 23, 0.75);
    border: 1px solid rgba(223, 183, 67, 0.3);
    border-radius: 8px;
    z-index: 25;
    pointer-events: none; /* スマホではタップ透過で邪魔にならない */
  }

  #chat-panel .chat-header {
    padding: 2px 6px;
    pointer-events: auto;
  }
  .chat-tab {
    font-size: 0.7rem;
    padding: 2px 5px;
  }

  #chat-messages {
    font-size: 0.72rem;
    padding: 3px 6px;
    gap: 2px;
  }

  /* PC用下部チャット入力バーは非表示（スマホは右下💬ボタンからモーダルで入力） */
  #bottom-bar {
    display: none !important;
  }
}
