/* Retro Messenger Window & Chat Styles */

.messenger-container {
  display: flex;
  height: 100%;
  width: 100%;
  background: var(--retro-gray);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* Sidebar Contacts */
.messenger-sidebar {
  width: 220px;
  background-color: #f0f0f0;
  border-right: 2px solid #808080;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messenger-user-profile {
  padding: 10px;
  background: linear-gradient(180deg, #e4e7eb 0%, #cbd2d9 100%);
  border-bottom: 2px solid #808080;
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-avatar {
  width: 40px;
  height: 40px;
  background: #ffffff;
  border: 2px solid #808080;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.profile-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.profile-name {
  font-weight: bold;
  font-size: 16px;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-status {
  font-size: 13px;
  color: #2ed573;
}

.contacts-header {
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font-pixel);
  background: #dcdde1;
  color: #2f3640;
  border-bottom: 1px solid #bcbec2;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #ececec;
  position: relative;
  transition: background 0.1s;
}

.contact-item:hover {
  background-color: #e2e8f0;
}

.contact-item.active {
  background-color: #000080;
  color: #ffffff;
}

.contact-item.active .contact-status-text {
  color: #d1d8e0;
}

.contact-avatar {
  width: 32px;
  height: 32px;
  background: #ffffff;
  border: 1px solid #808080;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  position: relative;
  flex-shrink: 0;
}

.contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-header-user .contact-avatar {
  width: 38px;
  height: 38px;
  font-size: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  position: absolute;
  bottom: -2px;
  right: -2px;
  border: 1px solid #fff;
}

.status-dot.online {
  background-color: #2ed573;
}

.status-dot.offline {
  background-color: #a4b0be;
}

.contact-details {
  flex: 1;
  overflow: hidden;
}

.contact-name {
  font-size: 15px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-status-text {
  font-size: 12px;
  color: #718093;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background-color: #ff4757;
  color: #ffffff;
  font-size: 11px;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 10px;
}

/* Right Chat Area */
.messenger-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.chat-header {
  padding: 8px 14px;
  background: #f1f2f6;
  border-bottom: 2px solid #808080;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-name {
  font-size: 17px;
  font-weight: bold;
  color: #2f3542;
}

.chat-header-status {
  font-size: 13px;
  color: #747d8c;
}

/* Chat Messages Stream */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f7f9fa;
  min-height: 120px;
}

.chat-system-message {
  align-self: center;
  font-size: 13px;
  color: #57606f;
  background: #e4e7eb;
  padding: 3px 12px;
  border-radius: 4px;
  border: 1px solid #ced6e0;
  margin: 4px 0;
  text-align: center;
}

.chat-bubble-row {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: bubble-pop 0.15s ease-out;
}

@keyframes bubble-pop {
  from { transform: translateY(4px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.chat-bubble-row.incoming {
  align-self: flex-start;
}

.chat-bubble-row.outgoing {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble-sender {
  font-size: 12px;
  color: #747d8c;
  margin-bottom: 2px;
  padding: 0 4px;
}

.bubble-content {
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.incoming .bubble-content {
  background-color: #e4e7eb;
  color: #2f3542;
  border: 1px solid #ced6e0;
}

.outgoing .bubble-content {
  background: linear-gradient(135deg, #1084d0 0%, #000080 100%);
  color: #ffffff;
  border: 1px solid #000066;
}

.bubble-time {
  font-size: 11px;
  color: #a4b0be;
  margin-top: 2px;
  padding: 0 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #747d8c;
  font-style: italic;
  align-self: flex-start;
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dot {
  width: 4px;
  height: 4px;
  background-color: #747d8c;
  border-radius: 50%;
  animation: typing-bounce 1s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Choices Panel inside Chat (Polished Response Bubbles) */
.chat-choices-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  background: #eef2f7;
  border-top: 2px solid #ced6e0;
  max-height: 190px;
  overflow-y: auto;
}

.choice-bubble-btn {
  padding: 9px 14px;
  text-align: left;
  background-color: #ffffff;
  border: 2px solid #000080;
  border-radius: 6px;
  color: #000080;
  font-family: var(--font-retro);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.12);
  transition: all 0.12s ease-in-out;
}

.choice-bubble-btn:hover {
  background-color: #000080;
  color: #ffffff;
  transform: translateX(3px);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.25);
}

.choice-bubble-btn:active {
  transform: translate(2px, 1px);
}

.choice-arrow {
  opacity: 0.7;
  font-size: 14px;
}

.choice-bubble-btn:hover .choice-arrow {
  opacity: 1;
}

/* Playful runaway choice button */
.runaway-choice-btn {
  background-color: #fff0f3 !important;
  border-color: #ff4757 !important;
  color: #ff4757 !important;
  box-shadow: 2px 2px 0 rgba(255, 71, 87, 0.25) !important;
  cursor: not-allowed !important;
}

.runaway-choice-btn:hover,
.runaway-choice-btn:active {
  background-color: #ff4757 !important;
  color: #ffffff !important;
}

.runaway-choice-btn .choice-arrow {
  display: none !important;
}

.choice-btn {
  padding: 8px 12px;
  text-align: left;
  background-color: #ffffff;
  border: 1px solid #000080;
  color: #000080;
  font-family: var(--font-retro);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.1s;
}

.choice-btn:hover {
  background-color: #000080;
  color: #ffffff;
}

/* Blocked Banner */
.blocked-banner {
  background: #ffeaa7;
  border: 1px solid #fdcb6e;
  color: #d63031;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px;
}

/* Chat Input Bar */
.chat-input-bar {
  display: flex;
  align-items: center;
  padding: 8px;
  background-color: var(--retro-gray);
  border-top: 2px solid #808080;
  gap: 6px;
}

.chat-input-field {
  flex: 1;
  padding: 6px 10px;
  font-size: 16px;
  outline: none;
  background-color: #ffffff;
  border-top: 1px solid #808080;
  border-left: 1px solid #808080;
  border-right: 1px solid #ffffff;
  border-bottom: 1px solid #ffffff;
}

/* Window Shake for NUDGE */
@keyframes window-nudge-shake {
  0% { transform: translate(0, 0); }
  15% { transform: translate(-10px, -8px); }
  30% { transform: translate(10px, 8px); }
  45% { transform: translate(-8px, 6px); }
  60% { transform: translate(8px, -6px); }
  75% { transform: translate(-4px, 3px); }
  90% { transform: translate(4px, -3px); }
  100% { transform: translate(0, 0); }
}

.retro-window.window-shake {
  animation: window-nudge-shake 0.5s ease-in-out !important;
}

/* Chat Toolbar */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: #e4e7eb;
  border-top: 1px solid #ced6e0;
}

.chat-quick-emojis {
  display: flex;
  gap: 4px;
  align-items: center;
}

.emoji-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 16px;
  padding: 3px 5px;
  border-radius: 3px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn:hover {
  background: #cbd2d9;
  border-color: #808080;
}

.pixel-art-icon {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  display: block;
}

.nudge-btn {
  font-family: var(--font-pixel);
  font-size: 11px;
  font-weight: bold;
  padding: 3px 8px;
  color: #b00020;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Mobile Landscape & Touchscreen Messenger Layout */
@media (max-width: 900px), (max-height: 560px), (pointer: coarse) {
  .messenger-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex !important;
    flex-direction: row !important;
  }

  /* In landscape (min-width: 540px), show sidebar and chat area side-by-side */
  @media (min-width: 540px) {
    .messenger-sidebar {
      width: 180px !important;
      min-width: 180px !important;
      display: flex !important;
      border-right: 2px solid #808080 !important;
    }
    .messenger-chat-area {
      flex: 1 !important;
      display: flex !important;
      min-width: 0 !important;
    }
    #chat-mobile-back-btn {
      display: none !important;
    }
  }

  /* Narrow portrait fallback */
  @media (max-width: 539px) {
    .messenger-container.view-chat .messenger-sidebar {
      display: none !important;
    }
    .messenger-container.view-chat .messenger-chat-area {
      display: flex !important;
      width: 100% !important;
      height: 100% !important;
    }
    .messenger-container.view-chat #chat-mobile-back-btn {
      display: inline-flex !important;
    }
    .messenger-container.view-contacts .messenger-sidebar {
      display: flex !important;
      width: 100% !important;
      height: 100% !important;
      border-right: none !important;
    }
    .messenger-container.view-contacts .messenger-chat-area {
      display: none !important;
    }
  }

  .messenger-user-profile {
    padding: 6px 8px !important;
    gap: 8px !important;
  }

  .profile-avatar {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
  }

  .profile-name {
    font-size: 14px !important;
  }

  .profile-status {
    font-size: 11px !important;
  }

  .contacts-header {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }

  .contact-item {
    padding: 6px 8px !important;
    gap: 6px !important;
    touch-action: manipulation;
  }

  .contact-avatar {
    width: 32px !important;
    height: 32px !important;
  }

  .contact-name {
    font-size: 13px !important;
  }

  .contact-status-text {
    font-size: 11px !important;
  }

  .chat-header {
    padding: 4px 8px !important;
    min-height: 36px !important;
  }

  #chat-mobile-back-btn {
    height: 28px;
    padding: 2px 8px;
    font-size: 12px;
  }

  #current-chat-avatar {
    width: 28px !important;
    height: 28px !important;
    font-size: 14px !important;
  }

  .chat-header-name {
    font-size: 14px !important;
  }

  #header-puzzle-btn {
    font-size: 11px !important;
    padding: 3px 6px !important;
  }

  #chat-objective-banner {
    padding: 3px 8px !important;
    font-size: 11px !important;
  }

  .chat-messages {
    padding: 8px 10px !important;
    gap: 8px !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  .chat-bubble-row {
    max-width: 90% !important;
  }

  .bubble-content {
    font-size: 15px !important;
    padding: 8px 12px !important;
    line-height: 1.4 !important;
    border-radius: 6px !important;
    word-break: break-word !important;
  }

  .chat-choices-panel {
    padding: 8px 10px !important;
    max-height: 220px !important;
    max-height: 38vh !important;
    gap: 8px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    background: #e4e9f2 !important;
    border-top: 2px solid #000080 !important;
    box-shadow: 0 -3px 8px rgba(0, 0, 0, 0.08) !important;
    flex-shrink: 0 !important;
  }

  .choice-bubble-btn {
    padding: 10px 12px !important;
    font-size: 14px !important;
    line-height: 1.35 !important;
    min-height: 46px !important;
    border-radius: 6px !important;
    border: 2px solid #000080 !important;
    background-color: #ffffff !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    cursor: pointer !important;
  }

  .choice-bubble-btn:active {
    background-color: #000080 !important;
    color: #ffffff !important;
    transform: scale(0.98) !important;
  }

  .chat-toolbar {
    padding: 2px 6px !important;
  }

  .emoji-btn {
    padding: 4px 8px !important;
    font-size: 18px !important;
    touch-action: manipulation;
  }

  .nudge-btn {
    padding: 4px 10px !important;
    font-size: 12px !important;
    touch-action: manipulation;
  }

  .chat-input-bar {
    padding: 6px 8px !important;
  }

  .chat-input-field {
    font-size: 15px !important;
    padding: 6px 8px !important;
  }

  #chat-send-btn {
    padding: 6px 16px !important;
    font-size: 14px !important;
    min-height: 36px !important;
    touch-action: manipulation;
  }
}

