:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --panel: #ffffff;
  --panel-2: #f0f3ff;
  --text: #1a1c22;
  --muted: #68707d;
  --line: #e3e5ec;
  --accent: #5a4be7;
  --accent-2: #eef0ff;
  --send: #4d64ff;
  --send-text: #ffffff;
  --shadow: 0 18px 52px rgb(43 46 67 / 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

button,
textarea {
  font: inherit;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  max-height: 100dvh;
  width: min(100%, 560px);
  margin: 0 auto;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.avatar-stage {
  display: grid;
  place-items: center;
  position: relative;
  padding: 8px 0 18px;
}

.avatar {
  width: clamp(118px, 38vw, 172px);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
  box-shadow:
    0 0 0 5px #ffffff,
    0 18px 45px rgb(76 82 139 / 0.22);
}

.status-dot {
  position: absolute;
  bottom: 20px;
  left: calc(50% + 48px);
  width: 17px;
  height: 17px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #18c964;
  box-shadow: 0 0 14px rgb(24 201 100 / 0.42);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 2px 18px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
  display: none;
}

.message {
  max-width: min(88%, 430px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
  font-size: 1rem;
  border-radius: 8px;
  padding: 11px 13px;
  box-shadow: 0 8px 24px rgb(43 46 67 / 0.08);
}

.message.user {
  align-self: flex-end;
  background: var(--send);
  color: var(--send-text);
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.message.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 54px;
  min-height: 42px;
}

.message.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-dot 900ms ease-in-out infinite;
}

.message.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.message.typing span:nth-child(3) {
  animation-delay: 240ms;
}

.message strong {
  font-weight: 700;
}

.message em {
  font-style: italic;
}

.message code {
  border-radius: 6px;
  background: rgb(26 28 34 / 0.07);
  padding: 0.1em 0.32em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message a {
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

@keyframes typing-dot {
  0%,
  70%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 9px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 8px;
  box-shadow: 0 10px 28px rgb(43 46 67 / 0.08);
}

.composer::before {
  content: "";
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  height: 158px;
  pointer-events: none;
  background: linear-gradient(180deg, rgb(247 246 242 / 0), var(--bg) 38%, var(--bg));
  z-index: -1;
}

.composer:focus-within {
  border-color: rgb(90 75 231 / 0.44);
  box-shadow:
    0 0 0 4px rgb(90 75 231 / 0.08),
    0 10px 28px rgb(43 46 67 / 0.08);
}

textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 132px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 13px 6px 9px 16px;
}

.send-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--send);
  color: #ffffff;
  cursor: pointer;
}

.send-button:disabled {
  opacity: 0.54;
  cursor: wait;
}

.send-button span {
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 13px solid currentColor;
  transform: translateX(2px);
}

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

@media (min-width: 720px) {
  .app {
    padding-top: 34px;
    padding-bottom: 24px;
  }
}
