/* Chat with a character — setup + chat room screens. */

/* The screens and the .message error field use display:flex, which would
   otherwise override the UA [hidden] rule; keep the hidden attribute
   authoritative for toggling. */
.chat-setup[hidden],
.chat-room[hidden],
.chat-suggestions[hidden],
#setupError[hidden] {
  display: none;
}

.chat-setup {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chat-setup h2 {
  font-size: 1.15rem;
  color: var(--gold-light);
  text-align: center;
}

.chat-setup form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chat-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-field label {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.chat-field input,
.chat-field select {
  width: 100%;
  padding: 0.85rem 1.2rem;
  font-size: 1.05rem;
  background: var(--bg-deep);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-field input:focus,
.chat-field select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

.chat-field input::placeholder {
  color: var(--text-muted);
}

/* Chat room */

.chat-room {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-partner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-avatar {
  font-size: 2.2rem;
  line-height: 1;
  flex-shrink: 0;
}

.chat-partner-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-partner-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold-light);
}

.chat-partner-title {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  height: 360px;
  overflow-y: auto;
  padding: 0.5rem;
  scroll-behavior: smooth;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 85%;
}

.chat-message--character {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message-author {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.4rem;
}

.chat-message-text {
  padding: 0.7rem 1rem;
  border-radius: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-message--character .chat-message-text {
  background: rgba(107, 63, 160, 0.25);
  border: 1px solid rgba(107, 63, 160, 0.4);
  color: #d9c4f5;
  border-top-left-radius: 4px;
}

.chat-message--user .chat-message-text {
  background: rgba(212, 168, 67, 0.14);
  border: 1px solid var(--border);
  color: var(--text);
  border-top-right-radius: 4px;
}

.chat-input {
  display: flex;
  gap: 0.75rem;
}

.chat-input input {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1.2rem;
  font-size: 1.05rem;
  background: var(--bg-deep);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

.chat-input input::placeholder {
  color: var(--text-muted);
}

/* Follow-up questions offered after each reply. Chips wrap and grow with their
   text so a long question never pushes the page sideways on a narrow screen. */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-suggestion {
  min-height: 44px;
  max-width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--purple-light);
  border-radius: 999px;
  background: rgba(107, 63, 160, 0.18);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.chat-suggestion:hover {
  background: rgba(107, 63, 160, 0.32);
}

.chat-suggestion:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}

@media (max-width: 480px) {
  .chat-log {
    height: 300px;
  }

  .chat-message {
    max-width: 92%;
  }

  .chat-input {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-input .btn {
    width: 100%;
  }

  /* Full-width chips: easier to hit, and long questions stay readable. */
  .chat-suggestions {
    flex-direction: column;
    align-items: stretch;
  }
}
