* {
  box-sizing: border-box;
}

:root {
  --page: #e9e9ed;
  --panel: #ffffff;
  --header: rgba(248, 248, 250, 0.92);
  --line: #dedee3;
  --text: #111114;
  --muted: #77777f;
  --incoming: #e9e9ee;
  --outgoing: #1687ff;
  --shadow: 0 28px 70px rgba(21, 21, 28, 0.18);
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.95), transparent 32%),
    linear-gradient(145deg, #eeeeF2, #d9d9df);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

.phone-shell {
  width: min(100%, 430px);
  height: min(850px, calc(100vh - 48px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(30, 30, 36, 0.1);
  border-radius: 34px;
  box-shadow: var(--shadow);
}

.chat-header {
  z-index: 2;
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  min-height: 84px;
  padding: 10px 14px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--outgoing);
  cursor: default;
  font-size: 42px;
  line-height: 36px;
}

.profile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  text-align: left;
}

.avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(145deg, #f4c98c, #b8793e);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55);
  font-size: 29px;
}

.profile h1 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.header-spacer {
  width: 46px;
}

.chat {
  overflow-y: auto;
  padding: 18px 13px 26px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.day-label {
  margin: 2px 0 20px;
  color: #96969d;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  margin: 3px 0;
  animation: message-in 180ms ease-out;
}

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

.mini-avatar {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #d4a061;
  font-size: 16px;
}

.mini-avatar.ghost {
  visibility: hidden;
}

.bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 19px;
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.monkey-bubble {
  background: var(--incoming);
  border-bottom-left-radius: 6px;
}

.user-bubble {
  background: var(--outgoing);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 54px;
  min-height: 39px;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8d8d95;
  animation: typing 1.1s infinite ease-in-out;
}

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

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

.composer {
  display: grid;
  grid-template-columns: 1fr 38px;
  align-items: end;
  gap: 8px;
  padding: 10px 12px 14px;
  background: rgba(248, 248, 250, 0.96);
  border-top: 1px solid var(--line);
}

.message-box {
  min-height: 39px;
  display: flex;
  align-items: center;
  padding: 8px 13px;
  border: 1px solid #cfcfd5;
  border-radius: 21px;
  background: #fff;
}

textarea {
  width: 100%;
  max-height: 112px;
  padding: 0;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 21px;
}

textarea::placeholder {
  color: #9a9aa1;
}

.send-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--outgoing);
  color: #fff;
  cursor: pointer;
  font-size: 25px;
  font-weight: 700;
  line-height: 34px;
  transition: transform 120ms ease, opacity 120ms ease;
}

.send-button:hover {
  transform: scale(1.05);
}

.send-button:active {
  transform: scale(0.94);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.45;
  transform: none;
}

.error-bubble {
  background: #fff1f1;
  color: #a51d1d;
  border: 1px solid #ffd0d0;
}

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

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@media (max-width: 560px) {
  body {
    display: block;
    padding: 0;
    background: #fff;
  }

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