/* —— 私信 / 自由对话 —— */
.chat-fab-wrap {
  position: fixed;
  left: max(0.65rem, env(safe-area-inset-left));
  bottom: max(0.85rem, env(safe-area-inset-bottom));
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

.chat-fab {
  background: linear-gradient(135deg, #1e4d8c, #2563eb);
  color: #e8f4ff;
  border: 2px solid rgba(77, 166, 255, 0.55);
  border-radius: 999px;
  padding: 0.72rem 1.15rem;
  font-size: clamp(0.95rem, 4vw, 1.12rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  max-width: calc(100vw - 1.5rem);
  line-height: 1.35;
}

.chat-fab-menu {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: rgba(10, 18, 32, 0.96);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 0.45rem;
  min-width: 11rem;
}

.chat-fab-menu button {
  background: #152238;
  color: #e8f0ff;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
}

.chat-fab-menu button:hover {
  background: #1a2d4d;
}

#screen-chat {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  background: #0a1220;
  padding: 0;
}

#screen-chat.active {
  display: flex;
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  padding-top: max(0.65rem, env(safe-area-inset-top));
  border-bottom: 1px solid #334155;
  background: #0f172a;
}

.chat-header-avatar-btn {
  background: linear-gradient(135deg, #2563eb, #4da6ff);
  border: 2px solid #93c5fd;
  color: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(77, 166, 255, 0.25), 0 4px 14px rgba(37, 99, 235, 0.45);
  animation: avatar-btn-pulse 2.4s ease-in-out infinite;
}

@keyframes avatar-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(77, 166, 255, 0.25), 0 4px 14px rgba(37, 99, 235, 0.45); }
  50% { box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.35), 0 4px 18px rgba(37, 99, 235, 0.55); }
}

.chat-header-back,
.chat-header-refresh-btn {
  background: transparent;
  border: 1px solid #4da6ff55;
  color: #e8f0ff;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.chat-header-refresh-btn {
  margin-left: auto;
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  min-width: 0;
}

.chat-header-title {
  font-weight: 600;
  font-size: 1rem;
}

.chat-peer-name {
  font-size: 0.88rem;
  color: #94a3b8;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(77, 166, 255, 0.45);
  flex-shrink: 0;
}

.chat-avatar.lg {
  width: 42px;
  height: 42px;
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.85rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: 100%;
}

.chat-msg-row.is-user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.chat-msg-row.is-admin {
  align-self: flex-start;
}

.chat-bubble {
  max-width: min(82vw, 520px);
  padding: 0.6rem 0.75rem;
  border-radius: 14px;
  font-size: clamp(0.95rem, 3.8vw, 1.05rem);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg-row.is-user .chat-bubble {
  background: #1e3a5f;
  border: 1px solid rgba(77, 166, 255, 0.35);
  border-bottom-right-radius: 4px;
}

.chat-msg-row.is-admin .chat-bubble {
  background: #152238;
  border: 1px solid #334155;
  border-bottom-left-radius: 4px;
}

.chat-msg-time {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 0.2rem;
}

.chat-msg-row.is-user .chat-msg-time {
  text-align: right;
}

.chat-msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.chat-msg-images img {
  max-width: 140px;
  max-height: 140px;
  border-radius: 8px;
  object-fit: cover;
  cursor: zoom-in;
  border: 1px solid #334155;
}

.chat-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 1rem;
}

.chat-image-lightbox.hidden {
  display: none;
}

.chat-lightbox-close {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.85);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.chat-lightbox-img {
  max-width: min(96vw, 1200px);
  max-height: min(88vh, 1200px);
  object-fit: contain;
  border-radius: 8px;
}

.chat-compose {
  flex-shrink: 0;
  border-top: 1px solid #334155;
  background: #0f172a;
  padding: 0.65rem 0.75rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
}

.chat-compose textarea {
  width: 100%;
  min-height: 72px;
  max-height: 140px;
  resize: vertical;
  background: #111827;
  color: #e8f0ff;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-family: inherit;
  font-size: clamp(0.95rem, 3.8vw, 1.05rem);
}

.chat-compose-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.chat-compose-tools label {
  cursor: pointer;
  font-size: 0.85rem;
  color: #94a3b8;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
}

.chat-compose-tools input[type="file"] {
  display: none;
}

.chat-pending-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.chat-pending-images .thumb {
  position: relative;
  width: 64px;
  height: 64px;
}

.chat-pending-images img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}

.chat-pending-images button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #7f1d1d;
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
}

.chat-send-btn {
  margin-left: auto;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-hint {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 0.35rem;
}

.chat-welcome-note {
  text-align: center;
  font-size: 0.82rem;
  color: #64748b;
  padding: 0.5rem;
}

.chat-avatar-overlay {
  position: fixed;
  inset: 0;
  z-index: 220;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.chat-avatar-overlay.open {
  display: flex;
}

.chat-avatar-card {
  background: #111827;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.chat-avatar-preview {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0.75rem auto;
  border: 2px solid rgba(77, 166, 255, 0.45);
}

#chat-avatar-file {
  display: none;
}

body.chat-open .chat-fab-wrap,
body.chat-open .site-footer,
body.chat-open .app {
  visibility: hidden;
}

body.is-locked .chat-fab-wrap {
  display: none !important;
}

body.quiz-session-active .chat-fab-wrap {
  display: none !important;
}
