@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #fff9ff;
  --muted: #e0d4e4;
  --plum: #321d37;
  --plum-soft: #523356;
  --cream: #fbf8f4;
  --line: #ffffff30;
  --assistant: #fffdfd;
  --user: #f0e2f2;
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #392345; color: var(--ink); }
button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  display: grid;
  grid-template-rows: clamp(190px, 30dvh, 285px) minmax(0, 1fr);
  width: min(100%, 820px);
  height: 100dvh;
  min-height: 420px;
  margin: 0 auto;
  background: linear-gradient(158deg, #3d2450 0%, #55365f 42%, #49304f 72%, #392345 100%);
  box-shadow: 0 0 70px #35223412;
}

.character {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: hidden;
  background: transparent;
}
.character__stage {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) 10px 12px;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.character__drift {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  animation: drift 19s cubic-bezier(.45,0,.55,1) infinite;
  will-change: left, top;
}
#duomi {
  width: 68px;
  height: 68px;
  overflow: visible;
  fill: white;
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 3px #fff8) drop-shadow(0 0 7px #fff3);
  will-change: transform, filter;
}
.character__glint { position: absolute; width: 4px; height: 4px; top: 12px; right: 13px; border-radius: 50%; background: white; opacity: .72; box-shadow: 0 0 7px 2px #fff9; }
.conversation {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  min-height: 0;
  background: transparent;
}
.conversation__scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px clamp(16px, 5.5vw, 48px) 20px;
  scroll-behavior: smooth;
  scrollbar-color: #c8bfc8 transparent;
  scrollbar-width: thin;
}
.day-divider { display: flex; align-items: center; gap: 12px; margin: 0 auto 21px; color: #ffffffad; font-size: 9px; font-weight: 700; letter-spacing: .14em; }
.day-divider::before, .day-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.message { display: flex; gap: 0; width: 100%; margin: 0 0 18px; animation: arrive .36s cubic-bezier(.2,.8,.2,1) both; }
.message--user { justify-content: flex-end; }
.message__body { display: flex; flex-direction: column; align-items: flex-start; max-width: min(82%, 520px); }
.message--user .message__body { align-items: flex-end; }
.bubble { padding: 11px 14px; border: 1px solid #eee8ed; border-radius: 4px 17px 17px 17px; color: #342937; background: var(--assistant); box-shadow: 0 2px 8px #21132720; }
.message--user .bubble { border-color: transparent; border-radius: 17px 4px 17px 17px; background: var(--user); }
.bubble p { margin: 0; font-size: 14px; line-height: 1.48; white-space: pre-wrap; overflow-wrap: anywhere; }
.message__meta { display: flex; align-items: center; gap: 8px; min-height: 20px; margin: 3px 5px 0; color: #a39aa5; font-size: 10px; }
.speak-button { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; color: #705d75; background: #f5f0f5; cursor: pointer; }
.speak-button:hover { color: var(--plum); background: #eee4ef; }
.speak-button svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin: 1px 0 5px; }
.suggestion { padding: 8px 12px; border: 1px solid #ded2df; border-radius: 999px; color: #674d6b; background: #fff; font-size: 11px; cursor: pointer; transition: background .18s ease, border-color .18s ease, transform .18s ease; }
.suggestion:hover { transform: translateY(-1px); border-color: #bca5be; background: #faf5fa; }
.suggestion:focus-visible, .speak-button:focus-visible, .send-button:focus-visible, textarea:focus-visible { outline: 3px solid #a17ca6; outline-offset: 2px; }
.typing { display: flex; gap: 4px; padding: 14px 15px; }
.typing span { width: 5px; height: 5px; border-radius: 50%; background: #a18ca4; animation: dotPulse 1s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: .14s; }
.typing span:nth-child(3) { animation-delay: .28s; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 clamp(12px, 4vw, 35px);
  padding: 9px 10px 9px 16px;
  border: 1px solid #ffffff70;
  border-radius: 23px;
  background: #fffdfdf0;
  box-shadow: 0 5px 22px #39283a0b;
}
.composer textarea { flex: 1; min-height: 24px; max-height: 100px; resize: none; overflow-y: auto; padding: 3px 0; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 14px; line-height: 1.4; }
.composer textarea::placeholder { color: #a79ea8; }
.send-button { display: grid; flex: 0 0 34px; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; color: white; background: var(--plum); cursor: pointer; transition: transform .18s ease, background .18s ease; }
.send-button:not(:disabled):hover { transform: scale(1.06); background: #69496e; }
.send-button:disabled { color: #c1b8c1; background: #f2eef2; cursor: default; }
.send-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.composer-note { margin: 7px 20px max(8px, env(safe-area-inset-bottom)); color: #ffffffb8; text-align: center; font-size: 9px; line-height: 1.35; }
.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; }

@keyframes arrive { from { opacity: 0; transform: translateY(7px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes dotPulse { 0%, 60%, 100% { opacity: .38; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes drift {
  0%, 100% { left: 50%; top: 50%; }
  16% { left: 24%; top: 40%; }
  34% { left: 73%; top: 30%; }
  52% { left: 79%; top: 68%; }
  72% { left: 38%; top: 76%; }
  88% { left: 19%; top: 58%; }
}

@media (min-width: 700px) {
  .app-shell { height: min(100dvh, 940px); margin: max(0px, calc((100dvh - 940px) / 2)) auto; border: 1px solid #ffffff24; border-radius: 24px; overflow: hidden; }
  .character__drift { width: 108px; height: 108px; }
  #duomi { width: 78px; height: 78px; }
  .conversation__scroll { padding-top: 26px; }
}
@media (max-height: 600px) and (max-width: 699px) {
  .app-shell { grid-template-rows: 165px minmax(0, 1fr); }
  .character__drift { width: 72px; height: 72px; }
  #duomi { width: 52px; height: 52px; }
  .conversation__scroll { padding-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
