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

/* Toggled by chat.js on a 403 from the Lambda's own resource policy — see
   app.html. Same warning tone as the landing page's banner. */
.maintenance-banner {
  background: #7c332c;
  color: #f2ede4;
  text-align: center;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 20px;
}
.maintenance-banner[hidden] { display: none; }

* { box-sizing: border-box; }

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

.app {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback for browsers without dvh */
  /* 100vh on phones is the height with the address bar hidden, so while
     the bar shows, the app overflowed and the top bar or the footer got
     pushed off-screen. dvh tracks the bar as it shows and hides. */
  height: 100dvh;
  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;
  white-space: nowrap;
  min-width: 0;
}

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

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

.new-chat,
.auth-link {
  white-space: nowrap;
}

.new-chat[hidden] {
  display: none;
}

/* Phones: keep the brand and buttons on one line. */
@media (max-width: 480px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar-actions { gap: 6px; }
  .new-chat { padding: 7px 12px; }
  .auth-link { padding: 7px 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: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.profile-btn:hover {
  opacity: 0.85;
}

.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: linear-gradient(165deg, var(--bg-elevated), var(--bg));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}

.modal::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  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);
}

.modal-icon {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
  margin: 4px auto 20px;
}

.profile-signed-in {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

.profile-signed-in strong {
  color: var(--text);
  font-weight: 600;
  word-break: break-all;
}

.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

/* Each row only draws its own top rule, so two stacked rows share a
   single line between them instead of each contributing one (which left
   a double line with a 20px gap). The last row closes the block with its
   own bottom rule and the margin down to "Signed in as...". */
.profile-row:last-of-type {
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

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

.plan-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}

.plan-option {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 3px 10px;
  border-radius: 999px;
  /* Free/Pro are <span>s (no reset needed); the translation toggle uses
     real <button>s (see app.html) so keyboard/click activation is
     reliable across browsers — this undoes the UA button chrome so both
     render identically. */
  margin: 0;
  border: none;
  background: none;
  font-family: inherit;
  line-height: normal;
  appearance: none;
  -webkit-appearance: none;
}

.plan-option.active {
  background: var(--accent);
  color: #1b1a17;
}

/* Free/Pro is stubbed (no Stripe billing yet — see app.html), so it
   deliberately gets no pointer/hover affordance. The translation toggle
   is real, so it needs to visibly read as clickable, unlike its sibling. */
#translation-toggle .plan-option {
  cursor: pointer;
  transition: color 0.15s ease;
}

#translation-toggle .plan-option:hover:not(.active) {
  color: var(--text);
}

.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;
  text-align: center;
  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%;
}

/* A 3rd suggestion is a lone leftover in the 2-column grid above — spans
   both columns instead of sitting alone next to an empty gap. */
.suggestions-grid .suggestion:nth-child(3):last-child {
  grid-column: 1 / -1;
}

.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;
}

.bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 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; }
.bubble .answer-heading { font-weight: 700; font-size: 1.15em; line-height: 1.35; margin-bottom: 6px; }

.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: 4px 0 10px;
  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;
  /* .bubble sets white-space: pre-wrap (needed for the AI's raw answer
     text) and this panel inherits it — without resetting, any literal
     newline/indentation in markup built here (template literals) renders
     as real blank space instead of being collapsed like normal HTML. */
  white-space: normal;
}

.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-version {
  margin-left: 4px;
  font-weight: 600;
  color: var(--text-dim);
  opacity: 0.55;
}

.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;
}

/* Click (tap on mobile) any one verse to find passages similar to just
   that verse — never the whole displayed range, see formatCitationDetail. */
.verse-line {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 2px;
  margin: -1px -2px;
  transition: background 0.12s ease;
}

.verse-line:hover {
  background: rgba(201, 162, 75, 0.12);
}

.verse-line.active {
  background: rgba(201, 162, 75, 0.18);
}

.citation-hint {
  margin: 8px 0 0;
  font-size: 11px;
  font-style: italic;
  color: var(--text-dim);
  opacity: 0.8;
}

.commentary-offer-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.commentary-offer-btn:hover {
  background: rgba(201, 162, 75, 0.08);
  border-color: var(--accent);
  color: var(--text);
}

.commentary-offer-hint {
  display: inline-block;
  margin-top: 4px;
  opacity: 0.8;
}

.similar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.similar-btn:hover:not(:disabled) {
  background: rgba(201, 162, 75, 0.1);
}

.similar-btn:disabled {
  color: var(--text-dim);
  border-color: var(--border);
  cursor: default;
}

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

/* A nested list under the root passage above, not a separate widget —
   the left branch-line is the only thing marking it as a child of the
   citation, same tree level as the citation itself, not a boxed-off
   component in a different color. */
.similar-results:not(:empty) {
  margin-top: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Same tree-branch language as .similar-results above, so historical
   commentary reads as another child of the citation rather than an
   unrelated boxed-in widget dropped into the panel. */
.commentary-content:not(:empty) {
  margin-top: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  font-size: 13.5px;
  line-height: 1.65;
  max-height: 420px;
  overflow-y: auto;
}

.commentary-content[hidden] {
  display: none;
}

.similar-item {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.similar-item:first-child {
  padding-top: 0;
  border-top: none;
}

.similar-ref {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 3px;
}

/* Reset the .similar-ref styling above — the gloss is descriptive prose,
   not a heading label, so it shouldn't inherit uppercase/bold/tracking. */
.similar-gloss {
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
  font-style: italic;
  color: var(--text-dim);
}

.similar-text {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.similar-empty {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* Arbitrary-phrase similarity search is shelved (see chat.js) — kept
   commented out rather than deleted for easy revival.
.selection-tooltip {
  position: fixed;
  z-index: 150;
  max-width: 320px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 16px 40px -10px rgba(0, 0, 0, 0.6);
}

.selection-tooltip[hidden] {
  display: none;
}

.selection-tooltip .similar-btn {
  margin-top: 0;
  width: 100%;
  justify-content: center;
}

.selection-tooltip .similar-results:not(:empty) {
  max-height: 280px;
  overflow-y: auto;
}
*/

.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; }
}

/* > and last-of-type, so the cursor stays on the answer's last paragraph
   even when an open citation panel sits after it. */
.stream-text.streaming > p:last-of-type::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 {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--accent);
  color: #1b1a17;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

#send svg {
  width: 19px;
  height: 19px;
}

#send:hover:not(:disabled) {
  background: var(--accent-dim);
}

#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; }
  /* Avatar on its own line above the answer, so the answer gets the
     full width instead of losing a column to the avatar. */
  .message.assistant { flex-direction: column; gap: 6px; }
  .chat > .composer { padding-left: 16px; padding-right: 16px; }
  .welcome { padding: 16px; }
  .disclaimer { padding-left: 16px; padding-right: 16px; }
}
