:root {
  color-scheme: light;
  --paper: #fdf2f4;
  --surface: #fff8fa;
  --surface-strong: #fffefe;
  --ink: #2f272a;
  --muted: #8e737b;
  --line: #f0d9de;
  --accent: #d4a5a5;
  --accent-ink: #fff8fa;
  --coral: #c98898;
  --gold: #c9a0a8;
  --shadow: 0 18px 48px rgba(145, 92, 108, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(120deg, rgba(245, 230, 232, 0.9), transparent 34%),
    linear-gradient(210deg, rgba(212, 165, 165, 0.16), transparent 32%),
    var(--paper);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  width: min(1180px, 100vw);
  height: 100dvh;
  margin: 0 auto;
  background: rgba(255, 248, 250, 0.82);
  border-inline: 1px solid rgba(240, 217, 222, 0.9);
  backdrop-filter: blur(18px);
}

.thread-pane,
.chat-pane {
  min-width: 0;
  min-height: 0;
}

.thread-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(253, 242, 244, 0.76);
}

.pane-header,
.chat-header {
  display: flex;
  align-items: center;
  min-height: 72px;
  padding: max(16px, env(safe-area-inset-top)) 20px 12px;
  gap: 12px;
}

.pane-header h1 {
  flex: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 760;
  letter-spacing: 0;
}

.icon-button,
.attach-button,
.send-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.icon-button:hover,
.attach-button:hover,
.send-button:hover {
  background: rgba(37, 37, 34, 0.06);
}

#menuButton {
  gap: 4px;
}

#menuButton span {
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.plus::before,
.plus::after,
.attach-button::before,
.attach-button::after,
.send-button::before,
.send-button::after,
.back::before,
.back::after,
.info::before,
.info::after,
.close::before,
.close::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 999px;
}

.plus::before,
.attach-button::before {
  width: 20px;
  height: 2px;
}

.plus::after,
.attach-button::after {
  width: 2px;
  height: 20px;
}

.back::before {
  width: 16px;
  height: 2px;
  transform: rotate(-42deg) translate(-3px, -5px);
}

.back::after {
  width: 16px;
  height: 2px;
  transform: rotate(42deg) translate(-3px, 5px);
}

.info::before {
  width: 4px;
  height: 18px;
  transform: translateY(5px);
}

.info::after {
  width: 5px;
  height: 5px;
  transform: translateY(-11px);
}

.close::before {
  width: 20px;
  height: 2px;
  transform: rotate(45deg);
}

.close::after {
  width: 20px;
  height: 2px;
  transform: rotate(-45deg);
}

.profile-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 18px 16px;
  padding: 14px;
  border: 1px solid rgba(240, 217, 222, 0.92);
  border-radius: 8px;
  background: rgba(255, 248, 250, 0.9);
}

.profile-mark,
.avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 50%;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), #b88491);
  font-weight: 780;
}

.image-mark {
  overflow: hidden;
  background: #f5e6e8;
}

.profile-mark img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 62% 38%;
}

.profile-strip strong,
.thread-main strong,
.chat-title strong {
  display: block;
  font-size: 16px;
}

.profile-strip span,
.thread-main span,
.chat-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-list {
  display: grid;
  gap: 4px;
  padding: 0 10px 18px;
  overflow: auto;
}

.thread-item {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 10px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.thread-item.active,
.thread-item:hover {
  background: rgba(212, 165, 165, 0.16);
}

.thread-time {
  align-self: start;
  padding-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.chat-pane {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(255, 248, 250, 0.64);
}

.chat-header {
  border-bottom: 1px solid rgba(240, 217, 222, 0.78);
  background: rgba(253, 242, 244, 0.9);
}

.back {
  display: none;
}

.contact-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 6px rgba(201, 160, 168, 0.16);
}

.presence-chip {
  max-width: 190px;
  padding: 7px 10px;
  border: 1px solid rgba(240, 217, 222, 0.95);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 254, 254, 0.78);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-title {
  min-width: 0;
  flex: 1;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  padding: 18px clamp(18px, 4vw, 56px) 22px;
  overflow: auto;
  scroll-behavior: smooth;
}

.day-divider {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}

.message-row {
  display: grid;
  gap: 8px;
  max-width: min(78%, 720px);
}

.message-row.assistant {
  grid-template-columns: 42px minmax(0, 1fr);
  align-self: start;
}

.message-row.user {
  align-self: end;
  justify-items: end;
}

.message-row .avatar {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
  font-size: 14px;
}

.message-meta {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  position: relative;
  width: fit-content;
  max-width: 100%;
  padding: 13px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

.assistant .bubble {
  border-left-color: rgba(212, 165, 165, 0.72);
  background: rgba(255, 254, 254, 0.82);
}

.user .bubble {
  background: #f5e6e8;
  border-color: rgba(212, 165, 165, 0.26);
}

.bubble:hover {
  box-shadow: 0 10px 28px rgba(43, 38, 31, 0.1);
  transform: translateY(-1px);
}

.message-state {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.typing {
  display: inline-grid;
  grid-template-columns: repeat(3, 6px);
  gap: 5px;
  align-items: center;
  min-width: 42px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  animation: typingPulse 1s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingPulse {
  0%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  45% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: end;
  gap: 8px;
  padding: 12px clamp(12px, 3vw, 28px) max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(240, 217, 222, 0.78);
  background: rgba(253, 242, 244, 0.92);
}

.composer-field {
  display: grid;
  min-height: 46px;
  border: 1px solid rgba(240, 217, 222, 0.95);
  border-radius: 999px;
  background: var(--surface-strong);
  box-shadow: 0 8px 24px rgba(145, 92, 108, 0.08);
}

.composer textarea {
  width: 100%;
  max-height: 138px;
  min-height: 44px;
  padding: 12px 16px;
  border: 0;
  outline: 0;
  resize: none;
  color: var(--ink);
  background: transparent;
  line-height: 1.5;
}

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

.send-button {
  color: var(--accent-ink);
  background: var(--accent);
}

.send-button:hover {
  background: #bd8f9b;
}

.send-button::before {
  width: 16px;
  height: 2px;
  transform: rotate(-45deg) translate(-1px, -2px);
}

.send-button::after {
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  background: transparent;
  transform: rotate(-45deg) translate(2px, -1px);
}

.memory-dialog {
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.memory-dialog::backdrop {
  background: rgba(37, 37, 34, 0.28);
  backdrop-filter: blur(5px);
}

.memory-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.memory-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.memory-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.memory-card {
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: rgba(245, 230, 232, 0.72);
  line-height: 1.55;
}

.memory-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.memory-panel textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
  color: var(--ink);
  background: var(--surface-strong);
  outline: 0;
  line-height: 1.5;
}

.wide-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: var(--accent-ink);
  background: var(--accent);
  cursor: pointer;
}

.empty-note {
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
    height: 100dvh;
    border: 0;
  }

  .thread-pane,
  .chat-pane {
    width: 100%;
    height: 100dvh;
  }

  .thread-pane {
    display: none;
    border: 0;
  }

  .app-shell.show-list .thread-pane {
    display: flex;
  }

  .app-shell.show-list .chat-pane {
    display: none;
  }

  .back {
    display: grid;
  }

  .chat-header {
    min-height: 68px;
    padding-inline: 12px;
  }

  .message-list {
    gap: 14px;
    padding: 16px 12px 18px;
  }

  .message-row {
    max-width: 92%;
  }

  .message-row.assistant {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .message-row .avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: 12px;
  }

  .bubble {
    padding: 11px 13px;
    line-height: 1.62;
  }
}
