:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #020617 0%, var(--bg) 100%);
  color: var(--text);
  min-height: 100vh;
}

.page {
  width: min(980px, calc(100% - 32px));
  margin: 40px auto;
}

.hero {
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.6;
  max-width: 740px;
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.form-card {
  padding: 22px;
}

.label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 138px;
  resize: vertical;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.15);
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  flex-wrap: wrap;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s ease, background 0.2s ease;
}

button:hover { transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: 0.6; transform: none; }

.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #062033;
}

.secondary {
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
}

.status {
  margin-top: 16px;
  min-height: 24px;
  font-size: 0.95rem;
  color: var(--muted);
}

.status.error { color: var(--danger); }
.status.success { color: var(--success); }

.results {
  margin-top: 24px;
  display: grid;
  gap: 18px;
}

.answer-card,
.sources-card {
  padding: 22px;
}

.section-title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.answer {
  white-space: pre-wrap;
  line-height: 1.75;
  color: var(--text);
}

.sources {
  display: grid;
  gap: 14px;
}

.source-item {
  padding: 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.source-item h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.source-meta {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 8px;
  word-break: break-word;
}

.source-preview {
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.footer-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .page { width: min(100% - 20px, 980px); margin: 20px auto; }
  .form-card, .answer-card, .sources-card { padding: 16px; }
  .actions { align-items: stretch; }
}