:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-light: #1e2d4d;
  --accent: #e2b04a;
  --accent-soft: rgba(226, 176, 74, 0.15);
  --text: #e8e6e3;
  --text-muted: #8b8d93;
  --user-bubble: #2a3a5c;
  --nick-bubble: #2c2c3e;
  --radius: 18px;
  --max-width: 680px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--surface-light);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.header-info h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.header-info .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.visitor-select {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.visitor-select label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.visitor-select select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-light);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.visitor-select select:focus {
  border-color: var(--accent);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.message {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 6px;
  color: var(--text);
}

.message.nick {
  align-self: flex-start;
  background: var(--nick-bubble);
  border-bottom-left-radius: 6px;
  color: var(--text);
  position: relative;
}

/* TTS play button */
.tts-btn {
  position: absolute;
  bottom: 6px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
  opacity: 0.4;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
}

.message.nick:hover .tts-btn {
  opacity: 0.7;
}

.tts-btn:hover {
  opacity: 1;
  color: var(--accent);
  background: var(--accent-soft);
}

.tts-btn.loading {
  opacity: 1;
  color: var(--accent);
  animation: ttsPulse 1.2s ease-in-out infinite;
}

.tts-btn.playing {
  opacity: 1;
  color: var(--accent);
}

@keyframes ttsPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--nick-bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
  display: none;
}

.typing.visible {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Date separator */
.date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 12px 0 4px;
  letter-spacing: 0.04em;
}

/* Input */
.input-area {
  padding: 12px 16px 24px;
  border-top: 1px solid var(--surface-light);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-area textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface-light);
  border-radius: 22px;
  padding: 11px 18px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.input-area textarea:focus {
  border-color: var(--accent);
}

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

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover { opacity: 0.85; }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.3; cursor: default; }

/* Welcome */
.welcome {
  text-align: center;
  padding: 48px 32px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.7;
}

.welcome .name {
  font-size: 22px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 6px;
}

/* Scrollbar */
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--surface-light); border-radius: 4px; }

/* Mobile */
@media (max-width: 600px) {
  .header { padding: 16px; }
  .messages { padding: 16px 12px; }
  .input-area { padding: 10px 12px 20px; }
  .message { max-width: 88%; }
}
