:root {
  --bg: #f7fffd;
  --panel: #ffffff;
  --panel-2: #f0fdfa;
  --border: #d7eee9;
  --text: #0f2e2a;
  --muted: #5b7a74;
  --teal: #14b8a6;
  --cyan: #06b6d4;
  --blue: #3b82f6;
  --green: #10b981;
  --accent: #0ea5a5;
  --accent-2: #22d3c5;
  --radius: 16px;
  --maxw: 760px;
  --shadow: 0 18px 50px rgba(13, 148, 136, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* --- Uplifting aurora bloom rising from the bottom --- */
.horizon {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 62vh;
  background:
    radial-gradient(62% 90% at 28% 125%, rgba(45, 212, 191, 0.40), transparent 62%),
    radial-gradient(62% 90% at 72% 125%, rgba(56, 189, 248, 0.34), transparent 62%),
    radial-gradient(54% 80% at 50% 135%, rgba(52, 211, 153, 0.36), transparent 62%);
  filter: blur(8px);
  z-index: 0;
  pointer-events: none;
}
/* a soft bright crest where the bloom meets the page */
.horizon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 30vh;
  transform: translateX(-50%);
  width: 80vw;
  height: 16vw;
  background: radial-gradient(ellipse at center bottom, rgba(255, 255, 255, 0.7), transparent 70%);
  filter: blur(24px);
}

/* --- Top bar --- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 16px 0;
}
.badge {
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.06);
}
.badge::first-letter { color: var(--green); }  /* the live dot */
.icon-btn {
  position: absolute;
  right: 18px;
  top: 18px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 34px; height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* --- Hero --- */
.hero {
  position: relative;
  z-index: 2;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16vh 20px 6vh;
  text-align: center;
}
.headline {
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  color: #0c2b27;
}
.headline em {
  font-style: italic;
  background: linear-gradient(90deg, var(--teal), var(--cyan) 45%, var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subhead {
  color: var(--muted);
  font-size: 15.5px;
  margin: 0 auto 26px;
  max-width: 540px;
}

/* --- Ask box --- */
.ask {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}
.ask:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 4px rgba(34, 211, 197, 0.15), var(--shadow); }
.ask-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 15.5px;
  padding: 8px 4px;
}
.ask-input::placeholder { color: #9bb5b0; }
.ticker-input {
  width: 78px;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 2px 8px 4px;
}
.ticker-input::placeholder { color: #9bb5b0; font-weight: 600; letter-spacing: 0; text-transform: none; }
.form-select {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 2px;
}
.ask-divider { width: 1px; align-self: stretch; background: var(--border); margin: 4px 2px; }
.ask-hint { color: var(--muted); font-size: 12.5px; margin: 10px auto 0; max-width: 560px; }
.ask-hint b { color: var(--accent); font-weight: 600; }
.status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--accent);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
}
.ask-btn {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: white;
  border: 0;
  border-radius: 11px;
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(14, 165, 165, 0.3);
}
.ask-btn:hover { filter: brightness(1.05); }
.ask-btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

/* --- Quick links --- */
.quicklinks {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 18px 0 26px;
}
.ghost-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent-2); }

/* --- Suggestion chips --- */
.chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.chip {
  text-align: left;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  color: #2f5651;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.35;
}
.chip:hover { border-color: var(--accent-2); color: var(--text); background: var(--panel-2); }

/* --- Result panel --- */
.result {
  position: relative;
  z-index: 2;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px 12vh;
}
.result-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.result-head { display: flex; align-items: center; justify-content: space-between; }
.result-head h2 { margin: 0; font-size: 18px; color: #0c2b27; }
.faith-badge {
  font-size: 12px;
  color: var(--accent);
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 4px 10px;
}
.answer {
  margin: 14px 0 8px;
  line-height: 1.6;
  font-size: 15px;
  white-space: pre-wrap;
}
.answer .cite { color: var(--blue); font-weight: 600; }
.error { color: #dc2626; font-size: 14px; margin-top: 8px; }

.sources-title { font-size: 14px; color: var(--muted); margin: 18px 0 8px; }
.sources { display: flex; flex-direction: column; gap: 8px; }
.source {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
}
.source .tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 8px;
}
.tag.cited { background: rgba(20, 184, 166, 0.16); color: #0d9488; }
.tag.retr { background: rgba(15, 46, 42, 0.06); color: var(--muted); }
.source .doc { font-weight: 600; font-size: 13.5px; }
.source .meta { color: var(--muted); font-size: 12px; }
.source .excerpt { color: #466b65; font-size: 12.5px; margin-top: 6px; line-height: 1.45; }

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
}
.metrics b { color: var(--text); font-weight: 600; }

/* --- Modal --- */
/* The [hidden] attribute must win over .modal's display:flex, or the modal shows
   on every load (this was the "API settings popup keeps coming up" bug). */
[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 40, 36, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; color: #0c2b27; }
.modal-note { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 0 0 16px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.modal-card input {
  width: 100%;
  margin-top: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }

.build {
  position: fixed;
  right: 10px;
  bottom: 8px;
  z-index: 5;
  font-size: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
}

@media (max-width: 560px) {
  .chips { grid-template-columns: 1fr; }
  .hero { padding-top: 12vh; }
}
