:root {
  color-scheme: light;
  --page: #f4eee9;
  --surface: rgba(255, 252, 249, 0.92);
  --surface-solid: #fffaf6;
  --ink: #3c312f;
  --muted: #8a7470;
  --line: rgba(108, 83, 76, 0.14);
  --accent: #bd726e;
  --accent-dark: #9f5956;
  --accent-soft: #f2d9d5;
  --assistant: #fffdfb;
  --user: #c77974;
  --user-ink: #fffdfb;
  --success: #659477;
  --warning: #be8650;
  --danger: #b85757;
  --shadow: 0 18px 50px rgba(84, 57, 50, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100dvh;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 780px);
  min-height: 100dvh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 12% 4%, rgba(255, 255, 255, 0.9), transparent 28%),
    linear-gradient(180deg, #f9f3ef 0%, #f2eae5 100%);
  box-shadow: var(--shadow);
}

.topbar {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(249, 244, 240, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand__icon {
  flex: 0 0 auto;
  border-radius: 13px;
  box-shadow: 0 5px 14px rgba(151, 91, 84, 0.18);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.topbar__actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.session-select {
  width: min(34vw, 170px);
  min-width: 88px;
  height: 34px;
  padding: 0 28px 0 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-select:focus {
  border-color: rgba(189, 114, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(189, 114, 110, 0.1);
}

.new-session {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.new-session:disabled,
.session-select:disabled {
  opacity: 0.48;
  cursor: default;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  white-space: nowrap;
}

.connection__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px rgba(190, 134, 80, 0.13);
}

.connection[data-state="online"] .connection__dot {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(101, 148, 119, 0.14);
}

.connection[data-state="offline"] .connection__dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(184, 87, 87, 0.12);
}

.conversation {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 16px 20px;
  scroll-behavior: smooth;
}

.welcome {
  width: min(100%, 420px);
  margin: 8vh auto 34px;
  padding: 26px 24px;
  border: 1px solid rgba(167, 111, 103, 0.14);
  border-radius: 26px;
  background: rgba(255, 252, 249, 0.72);
  box-shadow: 0 15px 38px rgba(115, 79, 70, 0.07);
  text-align: center;
}

.welcome__mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: 0 auto 13px;
  border-radius: 14px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 23px;
}

.welcome h2 {
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", sans-serif;
  font-size: 20px;
}

.welcome p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0 0 18px;
  animation: message-in 180ms ease-out;
}

.message--user {
  align-items: flex-end;
}

.message__label {
  margin: 0 10px 5px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.03em;
}

.message__bubble {
  max-width: min(84%, 580px);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 9px 20px 20px 20px;
  background: var(--assistant);
  box-shadow: 0 6px 18px rgba(78, 51, 45, 0.05);
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message--user .message__bubble {
  border-color: transparent;
  border-radius: 20px 9px 20px 20px;
  color: var(--user-ink);
  background: var(--user);
  box-shadow: 0 7px 18px rgba(160, 88, 82, 0.15);
}

.message--pending .message__bubble::after {
  display: inline-block;
  width: 5px;
  height: 1em;
  margin-left: 4px;
  border-radius: 3px;
  background: var(--accent);
  vertical-align: -0.14em;
  content: "";
  animation: caret 850ms steps(1) infinite;
}

.message--error .message__bubble {
  border-color: rgba(184, 87, 87, 0.26);
  color: #8e4545;
  background: #fff7f6;
}

.composer {
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(249, 244, 240, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 132px;
  resize: none;
  overflow-y: auto;
  padding: 12px 15px;
  border: 1px solid rgba(112, 82, 75, 0.16);
  border-radius: 20px;
  outline: none;
  color: var(--ink);
  background: var(--surface-solid);
  box-shadow: 0 6px 18px rgba(84, 57, 50, 0.05);
  font-size: 16px;
  line-height: 1.45;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.composer textarea::placeholder {
  color: #ae9994;
}

.composer textarea:focus {
  border-color: rgba(189, 114, 110, 0.55);
  box-shadow: 0 0 0 4px rgba(189, 114, 110, 0.1);
}

.send-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 17px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 19px rgba(160, 88, 82, 0.23);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.send-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.send-button:hover {
  background: var(--accent-dark);
}

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

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

.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 message-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

@media (min-width: 680px) {
  body {
    padding: 22px;
  }

  .app-shell {
    min-height: calc(100dvh - 44px);
    max-height: calc(100dvh - 44px);
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
  }

  .topbar {
    padding-top: 12px;
  }

  .composer {
    padding-bottom: 14px;
  }

  .conversation {
    padding-inline: 28px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-inline: 13px;
  }

  .brand {
    gap: 8px;
  }

  .brand__icon {
    width: 36px;
    height: 36px;
  }

  .brand p,
  .connection__label {
    display: none;
  }

  .session-select {
    width: min(31vw, 120px);
  }

  .connection {
    padding: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
