:root {
  --bg: #1b1a17;
  --bg-elevated: #242220;
  --border: #34312c;
  --text: #f2ede4;
  --text-dim: #a8a196;
  --accent: #c9a24b;
  --accent-dim: #8c7639;
  --user-bubble: #2c2a26;
  --assistant-bubble: #201f1c;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
}

.topbar-brand .logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.new-chat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.new-chat:hover { border-color: var(--accent-dim); }

.auth-link {
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.auth-link:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

.auth-signup {
  background: var(--accent);
  color: #1b1a17;
  font-weight: 600;
}

.auth-signup:hover {
  background: var(--accent);
  color: #1b1a17;
  opacity: 0.9;
}

.auth-signup[hidden] {
  display: none;
}

.profile-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease;
}

.profile-btn:hover {
  border-color: var(--accent-dim);
}

.profile-btn[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.6);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.profile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 12px;
}

.profile-email {
  font-size: 14.5px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 18px;
  word-break: break-all;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.profile-label {
  font-size: 13px;
  color: var(--text-dim);
}

.profile-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(201, 162, 75, 0.1);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 3px 10px;
}

.btn-signout {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-signout:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

/* Chat column */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Empty state: composer + suggestions vertically centered in the page */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  min-height: 0;
  overflow-y: auto;
}

/* .welcome and .messages both set their own `display`, which — at equal
   CSS specificity — beats the browser's default `[hidden] { display: none }`
   rule (author styles win ties over UA styles). Without this, toggling the
   `hidden` attribute via JS silently does nothing and both stay visible
   at once. */
.welcome[hidden],
.messages[hidden],
.composer[hidden],
.suggestions-grid[hidden],
.auth-gate[hidden] {
  display: none;
}

.welcome-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin-bottom: 8px;
}

.welcome h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
}

.welcome > p {
  margin: 8px 0 24px;
  color: var(--text-dim);
  font-size: 14.5px;
  max-width: 480px;
}

.welcome .composer {
  max-width: 640px;
  margin-bottom: 20px;
}

.auth-gate {
  max-width: 420px;
  margin-bottom: 8px;
}

.auth-gate p {
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 14.5px;
}

.auth-gate-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.auth-gate-actions .auth-link {
  font-size: 14px;
  padding: 10px 20px;
  border: 1px solid var(--border);
}

.auth-gate-actions .auth-link:not(.auth-signup) {
  color: var(--text);
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr));
  gap: 10px;
  max-width: 640px;
  width: 100%;
}

.suggestion {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-align: left;
  font-size: 13px;
  line-height: 1.4;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.suggestion:hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.message {
  display: flex;
  gap: 14px;
  padding: 14px 32px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 15px;
}

.avatar img {
  width: 19px;
  height: 19px;
  object-fit: contain;
}

.message.user .avatar {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--user-bubble);
}

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }

.citation-chip {
  appearance: none;
  margin: 0;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  background: rgba(201, 162, 75, 0.1);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.inline-citation {
  margin: 0 2px;
  padding: 0.5px 8px;
  line-height: 1.3;
  vertical-align: baseline;
  white-space: nowrap;
}

.citation-chip:hover {
  background: rgba(201, 162, 75, 0.2);
  border-color: var(--accent);
}

.citation-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1b1a17;
}

.citation-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.citation-detail {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
  user-select: text;
}

.citation-detail .citation-title {
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.citation-detail .citation-verses {
  margin: 0;
}

.citation-detail .verse-num {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.7em;
  vertical-align: super;
  margin-right: 1px;
  line-height: 0;
}

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

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

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.stream-text.streaming p:last-child::after {
  content: "▍";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 0.9s step-start infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Composer — lives centered inside .welcome until the first message is
   sent, then gets moved (see chat.js) to be a direct child of .chat,
   which pins it to the bottom via normal flex flow. */
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

.chat > .composer {
  max-width: 820px;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14.5px;
  font-family: inherit;
  max-height: 160px;
}

#input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

#send {
  background: var(--accent);
  color: #1b1a17;
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

#send:disabled {
  background: var(--bg-elevated);
  color: var(--text-dim);
  cursor: not-allowed;
}

.disclaimer {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 24px 14px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .suggestions-grid { grid-template-columns: 1fr; }
  .message { padding-left: 16px; padding-right: 16px; }
  .chat > .composer { padding-left: 16px; padding-right: 16px; }
  .welcome { padding: 16px; }
  .disclaimer { padding-left: 16px; padding-right: 16px; }
}
