:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --border: #2f3d52;
  --text: #e8eef7;
  --muted: #9aabbf;
  --accent: #4f8cff;
  --accent-hover: #6aa0ff;
  --user: #2b5ea7;
  --bot: #243044;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1c2b48 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a3340 0%, transparent 50%),
    var(--bg);
  color: var(--text);
}

body {
  display: grid;
  place-items: center;
  padding: 16px;
}

.app {
  width: min(760px, 100%);
  height: min(860px, 100dvh - 32px);
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #4f8cff, #35c4a5);
  color: white;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

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

.ghost-btn,
.send-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.messages {
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.row {
  display: flex;
  gap: 10px;
  max-width: 92%;
  animation: fade-in 0.18s ease-out;
}

.row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.row.bot {
  align-self: flex-start;
}

.bubble {
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid transparent;
}

.row.user .bubble {
  background: var(--user);
  border-bottom-right-radius: 6px;
}

.row.bot .bubble {
  background: var(--bot);
  border-color: var(--border);
  border-bottom-left-radius: 6px;
}

.meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
}

.row.user .meta {
  text-align: right;
}

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

textarea {
  resize: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  line-height: 1.4;
  max-height: 140px;
  min-height: 46px;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}

.send-btn {
  background: var(--accent);
  color: white;
  border-radius: 14px;
  padding: 0 18px;
  font-weight: 600;
  min-width: 84px;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:disabled,
textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 1.2em;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

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

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

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

@media (max-width: 560px) {
  body {
    padding: 0;
  }

  .app {
    height: 100dvh;
    width: 100%;
    border-radius: 0;
    border: 0;
  }

  .row {
    max-width: 96%;
  }
}
