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

:root {
  --primary: #1a1a2e;
  --accent: #e94560;
  --bg: #0f0f23;
  --surface: #16213e;
  --text: #eaeaea;
  --text-muted: #a0a0b0;
  --user-bubble: #e94560;
  --assistant-bubble: #1e2a45;
  --input-bg: #1a1a2e;
  --border: #2a2a4a;
  --radius: 12px;
}

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

#app {
  height: 100%;
  height: 100dvh; /* handles iOS keyboard collapsing viewport */
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

.accent {
  color: var(--accent);
}

/* Auth Screen */
.auth-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  gap: 2rem;
}

.brand h1 {
  font-size: 2.5rem;
  font-weight: 800;
  text-align: center;
}

.tagline {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 0.25rem;
}

#auth-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#auth-form input {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#auth-form input:focus {
  border-color: var(--accent);
}

#input-code {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  font-weight: 700;
}

.code-prompt {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error {
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
}

/* Chat Screen */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.user-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

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

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message a {
  color: var(--accent);
  text-decoration: underline;
}

/* Typing Indicator */
.typing {
  padding: 0.5rem 1.25rem;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

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

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

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

/* Chat Input */
.chat-input-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input-bar input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--accent);
}

.btn-send {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  opacity: 0.9;
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Mobile responsive */
@media (max-width: 640px) {
  #app {
    max-width: 100%;
  }

  .brand h1 {
    font-size: 2rem;
  }

  .message {
    max-width: 90%;
  }

  /* Prevent font scaling on iOS */
  input, button {
    font-size: 16px;
  }
}
