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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  height: 100dvh;
}

.chat-container {
  max-width: 800px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e0e0e0;
  background: #fff;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
}

.subtitle {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.2rem;
}

#clear-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid #d0d0d0;
  border-radius: 0.5rem;
  background: #fff;
  color: #555;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

#clear-btn:hover {
  background: #f5f5f5;
  border-color: #999;
  color: #1a1a1a;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
  animation: fadeIn 0.2s ease-in;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-content {
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  line-height: 1.5;
  font-size: 0.95rem;
  word-break: break-word;
}

.message.assistant .message-content {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 1rem 1rem 1rem 0.25rem;
  transition: box-shadow 0.3s ease;
}

.message.assistant.streaming .message-content {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
  animation: pulseGlow 2s ease-in-out infinite;
}

.streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #2563eb;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

.message.user .message-content {
  background: #2563eb;
  color: #fff;
  border-radius: 1rem 1rem 0.25rem 1rem;
}

.message-content ul {
  margin: 0.5rem 0 0 1.2rem;
}

.message-content li {
  margin-bottom: 0.25rem;
}

.message-content p {
  margin-bottom: 0.5rem;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content strong {
  font-weight: 600;
}

.message-content code {
  background: #f0f0f0;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
}

.message-content pre {
  background: #f0f0f0;
  padding: 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 0.75rem 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.input-area {
  padding: 1rem;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #d0d0d0;
  border-radius: 1.5rem;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  max-height: 150px;
  outline: none;
  transition: border-color 0.2s;
}

#user-input:focus {
  border-color: #2563eb;
}

#send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

#send-btn:hover {
  background: #1d4ed8;
}

#send-btn:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 0.5rem 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

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

.token-fade {
  animation: tokenReveal 0.35s ease-out both;
}

@keyframes tokenReveal {
  from {
    opacity: 0;
    filter: blur(2px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

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

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1); }
  50% { box-shadow: 0 0 8px 2px rgba(37, 99, 235, 0.2); }
}

@media (max-width: 600px) {
  .message { max-width: 92%; }
  header { padding: 0.75rem 1rem; }
  .messages { padding: 0.75rem; }
}
