:root {
  --navy: #1a2744;
  --navy-deep: #121b30;
  --ink: #1c2434;
  --muted: #5c677a;
  --paper: #f3f1ec;
  --panel: #faf9f7;
  --line: rgba(26, 39, 68, 0.12);
  --teal: #2a7a7b;
  --user-bg: #e4e9f2;
  --assistant-bg: #ffffff;
  --shadow: 0 12px 40px rgba(18, 27, 48, 0.08);
  --font-display: "Newsreader", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --radius: 12px;
  --max: 1120px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(42, 122, 123, 0.12), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(26, 39, 68, 0.1), transparent 55%),
    linear-gradient(180deg, #e9e6df 0%, var(--paper) 40%, #ebe8e2 100%);
  background-attachment: fixed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.topbar {
  background: linear-gradient(180deg, var(--navy-deep), var(--navy));
  color: #f4f6fb;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 0.75rem;
  flex: 1;
}

.nav-link {
  color: rgba(244, 246, 251, 0.72);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.2rem 0.15rem;
  border-bottom: 2px solid transparent;
}

.nav-link.active {
  color: #fff;
  border-bottom-color: var(--teal);
}

.nav-link.muted {
  opacity: 0.55;
  cursor: default;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status {
  font-size: 0.8rem;
  color: rgba(244, 246, 251, 0.65);
  white-space: nowrap;
}

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1rem;
  min-height: calc(100vh - 9rem);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.msg {
  max-width: min(720px, 92%);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 1.02rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
  border: 1px solid rgba(26, 39, 68, 0.08);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--line);
}

.msg.assistant .role-label,
.msg.user .role-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.msg.streaming::after {
  content: "▍
  display: inline-block;
  width: 0.5ch;
  animation: blink 1s step-end infinite;
  color: var(--teal);
}

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

.welcome {
  margin: auto 0;
  padding: 2rem 1.5rem 3rem;
  text-align: left;
  max-width: 36rem;
}

.welcome h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.85rem;
  margin: 0 0 0.6rem;
  color: var(--navy);
}

.welcome p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.05rem;
}

.composer {
  display: flex;
  gap: 0.65rem;
  padding: 0.9rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  min-height: 2.8rem;
  max-height: 9rem;
  background: #fff;
  color: var(--ink);
}

.composer textarea:focus {
  outline: 2px solid rgba(42, 122, 123, 0.35);
  border-color: var(--teal);
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 0.65rem 1rem;
  white-space: nowrap;
}

.btn.primary {
  background: var(--navy);
  color: #fff;
}

.btn.primary:hover {
  background: var(--navy-deep);
}

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

.btn.ghost {
  background: transparent;
  color: rgba(244, 246, 251, 0.9);
  border-color: rgba(255, 255, 255, 0.2);
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sources-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  height: fit-content;
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 6rem);
  overflow: auto;
}

.sources-header h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0 0 0.25rem;
  color: var(--teal);
  font-weight: 600;
}

.sources-hint {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.source-group {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.source-group-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.source-group.tradition-urantia .source-group-label {
  color: var(--teal);
}

.source-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  background: #fff;
}

.source-card .ref {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.source-card .title {
  font-size: 0.78rem;
  color: var(--teal);
  margin-bottom: 0.35rem;
}

.source-card .excerpt {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.4;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.about-strip {
  max-width: var(--max);
  margin: 0 auto 1.5rem;
  padding: 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.about-strip p {
  margin: 0;
  max-width: 46rem;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sources-panel {
    position: static;
    max-height: none;
  }

  .topbar-inner {
    flex-wrap: wrap;
  }

  .nav {
    order: 3;
    width: 100%;
  }
}
