:root {
  color-scheme: dark;
  --ink: #f4f1e8;
  --muted: #aaa89f;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(19, 20, 22, 0.78);
  --accent: #b8ff69;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 15%, rgba(126, 70, 255, 0.22), transparent 32rem),
    radial-gradient(circle at 85% 80%, rgba(87, 255, 173, 0.13), transparent 30rem),
    #0b0c0e;
}

.shell {
  width: min(1100px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: clamp(32px, 7vw, 100px);
  align-items: center;
  padding: 48px 0;
}

.eyebrow {
  margin: 0 0 18px;
  color: var(--accent);
  font: 700 0.72rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.15em;
}

h1 {
  margin: 0;
  max-width: 7ch;
  font-size: clamp(4rem, 9vw, 8rem);
  font-weight: 650;
  line-height: 0.82;
  letter-spacing: -0.075em;
}

.lede {
  max-width: 32rem;
  margin: 32px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.chat {
  height: min(760px, calc(100vh - 64px));
  min-height: 620px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(20px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 14, 0.62);
}

.identity { display: flex; align-items: center; gap: 11px; }
.identity > span:last-child { display: grid; gap: 3px; }
.identity strong { font-size: 0.92rem; }
.identity small { color: var(--muted); font-size: 0.72rem; }
.identity i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(184, 255, 105, 0.7);
}

.avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(184, 255, 105, 0.35);
  border-radius: 12px;
  color: var(--accent);
  background: rgba(184, 255, 105, 0.08);
  font: 700 0.68rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.clear-button {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--muted);
  background: transparent;
  font-size: 0.75rem;
}

.messages {
  padding: 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.message {
  width: fit-content;
  max-width: 88%;
  margin: 0 0 18px;
  padding: 14px 17px;
  border: 1px solid var(--line);
  border-radius: 6px 18px 18px;
  background: rgba(255, 255, 255, 0.06);
  line-height: 1.55;
  white-space: pre-wrap;
}

.message p { margin: 0; }

.message.user {
  margin-left: auto;
  border-radius: 18px 6px 18px 18px;
  color: #111;
  background: var(--accent);
}

.message.error {
  border-color: rgba(255, 115, 115, 0.5);
  color: #ffb3b3;
}

.message.streaming {
  position: relative;
  border-color: rgba(184, 255, 105, 0.24);
  animation: stream-glow 2.2s ease-in-out infinite;
}

.message.streaming p::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 0.35em;
  vertical-align: -0.12em;
  border-radius: 2px;
  background: var(--accent);
  animation: stream-cursor 0.85s steps(1, end) infinite;
}

.message.streaming-status p {
  color: var(--muted);
  animation: stream-status 1.4s ease-in-out infinite;
}

.streamed-claim {
  display: block;
  margin-top: 0.75em;
  animation: claim-reveal 320ms ease-out both;
}

.streamed-claim:first-child { margin-top: 0; }

@keyframes stream-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(184, 255, 105, 0); }
  50% { box-shadow: 0 0 22px rgba(184, 255, 105, 0.09); }
}

@keyframes stream-cursor {
  0%, 48% { opacity: 1; }
  49%, 100% { opacity: 0; }
}

@keyframes stream-status {
  0%, 100% { opacity: 0.58; }
  50% { opacity: 1; }
}

@keyframes claim-reveal {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.suggestions button {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
  font-weight: 500;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.source {
  text-decoration: none;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 0.72rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}

a.source:hover { color: var(--ink); border-color: rgba(184, 255, 105, 0.5); }

form {
  padding: 20px;
  border-top: 1px solid var(--line);
}

label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.composer {
  display: flex;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 58px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  padding: 16px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.28);
  font: 16px/1.4 inherit;
}

textarea:focus { border-color: rgba(184, 255, 105, 0.7); }

button {
  min-width: 84px;
  border: 0;
  border-radius: 14px;
  padding: 0 18px;
  color: #10120d;
  background: var(--accent);
  font: 700 0.9rem/1 inherit;
  cursor: pointer;
}

button:disabled { cursor: wait; opacity: 0.55; }

.note {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 800px) {
  body { overflow: hidden; background: #0b0c0e; }

  .shell {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    align-items: start;
    padding: 0;
  }

  .intro { display: none; }

  .chat {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .messages { padding: 18px 14px; }
  .message { max-width: 90%; margin-bottom: 12px; }

  form {
    padding: 12px 12px max(12px, env(safe-area-inset-bottom));
    background: #101114;
  }

  .composer { align-items: end; }
  textarea { max-height: 120px; min-height: 50px; padding: 13px 14px; }
  .send-button { min-width: 64px; min-height: 50px; padding: 0 14px; }
  .note { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .message.streaming,
  .message.streaming p::after,
  .message.streaming-status p,
  .streamed-claim {
    animation: none;
  }
}
