:root {
  --bg: #07110f;
  --panel: rgba(12, 24, 22, 0.72);
  --panel-border: rgba(120, 255, 210, 0.12);
  --text: #e8fff8;
  --muted: #8eb5aa;
  --accent: #2ee6a8;
  --accent-2: #1aa6ff;
  --user: rgba(46, 230, 168, 0.14);
  --assistant: rgba(255, 255, 255, 0.05);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(46, 230, 168, 0.12), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(26, 166, 255, 0.12), transparent 30%),
    linear-gradient(180deg, #06100e 0%, #040807 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  animation: float 14s ease-in-out infinite;
}

.orb-1 {
  width: 320px;
  height: 320px;
  background: #2ee6a8;
  top: 8%;
  left: -4%;
}

.orb-2 {
  width: 280px;
  height: 280px;
  background: #1aa6ff;
  top: 55%;
  right: -6%;
  animation-delay: -4s;
}

.orb-3 {
  width: 220px;
  height: 220px;
  background: #7c5cff;
  bottom: 8%;
  left: 35%;
  animation-delay: -8s;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 80%);
  animation: drift 20s linear infinite;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 1040px;
  margin: 0 auto;
  padding: 36px 16px 22px;
}

.hero {
  text-align: center;
  margin-bottom: 28px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

h1 {
  margin: 18px 0 10px;
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.gradient-text {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

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

.chat-card {
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 150px);
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.14);
}

.chat-toolbar-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.toolbar-btn {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.toolbar-btn:hover:not(:disabled) {
  background: rgba(46, 230, 168, 0.08);
  border-color: rgba(46, 230, 168, 0.28);
}

.toolbar-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.messages {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 20px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  flex: 1;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.message.user {
  justify-content: flex-end;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #042018;
  flex-shrink: 0;
}

.bubble {
  max-width: min(100%, 680px);
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.55;
}

.message.assistant .bubble {
  background: var(--assistant);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.message.user .bubble {
  background: var(--user);
  border: 1px solid rgba(46, 230, 168, 0.18);
  color: #d8fff2;
}

.bubble p {
  margin: 0;
}

.answer.markdown {
  white-space: normal;
  font-size: 0.9rem;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown p {
  margin: 0 0 0.85em;
  color: #dff7ef;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 1.1em 0 0.55em;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--text);
}

.markdown h1 { font-size: 1.35rem; }
.markdown h2 { font-size: 1.15rem; }
.markdown h3 { font-size: 1.02rem; color: #c9f5e6; }
.markdown h4 { font-size: 0.95rem; color: #b8e8d8; }

.markdown strong {
  color: #f2fff9;
  font-weight: 700;
}

.markdown em {
  color: #c8e8de;
}

.markdown a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(46, 230, 168, 0.35);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.markdown a:hover {
  color: #7dffd0;
  border-bottom-color: rgba(125, 255, 208, 0.6);
}

.markdown ul,
.markdown ol {
  margin: 0.4em 0 0.9em;
  padding-left: 1.35rem;
}

.markdown li {
  margin: 0.35em 0;
  color: #d9f5ec;
}

.markdown li::marker {
  color: var(--accent);
}

.markdown ul ul,
.markdown ol ol,
.markdown ul ol,
.markdown ol ul {
  margin-top: 0.35em;
  margin-bottom: 0.35em;
}

.markdown blockquote {
  margin: 0.85em 0;
  padding: 0.7em 0.9em;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: rgba(46, 230, 168, 0.06);
  color: #c6e8dc;
}

.markdown blockquote p:last-child {
  margin-bottom: 0;
}

.markdown code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.86em;
  padding: 0.15em 0.4em;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #9ef5d4;
}

.markdown pre {
  margin: 0.9em 0;
  padding: 12px 14px;
  border-radius: 12px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.markdown pre code {
  padding: 0;
  border: none;
  background: transparent;
  color: #d7ffef;
  font-size: 0.84rem;
  line-height: 1.55;
}

.markdown hr {
  border: none;
  height: 1px;
  margin: 1.1em 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(46, 230, 168, 0.35),
    transparent
  );
}

.markdown table {
  width: 100%;
  margin: 0.9em 0;
  border-collapse: collapse;
  font-size: 0.9rem;
  overflow: hidden;
  border-radius: 10px;
}

.markdown th,
.markdown td {
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.markdown th {
  background: rgba(46, 230, 168, 0.1);
  color: #ecfff7;
  font-weight: 600;
}

.markdown td {
  background: rgba(0, 0, 0, 0.18);
}

.markdown img {
  max-width: 100%;
  border-radius: 10px;
  margin: 0.6em 0;
}

.sources {
  margin-top: 14px;
}

.sources-wrap {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 12px;
}

.sources-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sources-toggle:hover {
  background: rgba(46, 230, 168, 0.06);
  border-color: rgba(46, 230, 168, 0.22);
  color: #c5e8dc;
}

.sources-toggle.is-open {
  border-color: rgba(46, 230, 168, 0.28);
  background: rgba(46, 230, 168, 0.08);
  color: var(--accent);
}

.sources-chevron {
  display: inline-block;
  font-size: 0.7rem;
  transition: transform 0.25s ease;
  opacity: 0.8;
}

.sources-chevron::before {
  content: "▼";
}

.sources-toggle.is-open .sources-chevron {
  transform: rotate(180deg);
}

.sources-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  animation: sources-expand 0.3s ease;
}

.sources-panel[hidden] {
  display: none;
}

@keyframes sources-expand {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.source-card {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  animation: card-in 0.45s ease both;
}

.source-card:hover {
  transform: translateY(-2px);
  border-color: rgba(46, 230, 168, 0.28);
  background: rgba(46, 230, 168, 0.06);
}

.source-card a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.source-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.source-excerpt {
  margin-top: 8px;
  color: #c7ddd7;
  font-size: 0.9rem;
}

.source-excerpt.markdown {
  font-size: 0.86rem;
}

.source-excerpt.markdown p {
  margin: 0 0 0.5em;
  color: #b8d4cb;
}

.source-excerpt.markdown h1,
.source-excerpt.markdown h2,
.source-excerpt.markdown h3,
.source-excerpt.markdown h4 {
  margin: 0 0 0.35em;
  font-size: 0.92rem;
  color: #d2ebe3;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 18px 12px;
}

.chip {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font: inherit;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: rgba(46, 230, 168, 0.35);
  background: rgba(46, 230, 168, 0.08);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.18);
}

textarea {
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 16px;
  padding: 12px 14px;
  font: inherit;
  min-height: 52px;
  max-height: 160px;
  line-height: 1.45;
}

textarea:focus {
  outline: none;
  border-color: rgba(46, 230, 168, 0.45);
  box-shadow: 0 0 0 4px rgba(46, 230, 168, 0.08);
}

button[type="submit"] {
  border: none;
  border-radius: 16px;
  padding: 0 20px;
  min-width: 96px;
  background: linear-gradient(135deg, var(--accent), #18c98d);
  color: #042018;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

button[type="submit"]:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(46, 230, 168, 0.25);
}

button[type="submit"]:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-width: 56px;
}

.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  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; }

.footer {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

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

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

.fade-in {
  animation: fade-in 0.8s ease both;
}

.delay-1 { animation-delay: 0.12s; }
.delay-2 { animation-delay: 0.24s; }

.slide-up {
  animation: slide-up 0.45s ease both;
}

.pulse {
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(-24px) translateX(12px); }
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(48px); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-6px); opacity: 1; }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(46, 230, 168, 0); }
  50% { box-shadow: 0 0 24px rgba(46, 230, 168, 0.18); }
}

@media (max-width: 640px) {
  .shell { padding-top: 22px; padding-left: 12px; padding-right: 12px; }
  .chat-card { height: calc(100vh - 110px); border-radius: 22px; }
  .messages { padding: 16px 14px 12px; gap: 12px; }
  .composer { grid-template-columns: 1fr; }
  button[type="submit"] { min-height: 48px; }
}
