:root {
  --bg: #f8f2ec;
  --panel: #fffdfb;
  --ink: #2f261e;
  --ink-soft: #5a4a3d;
  --muted: #94837a;
  --line: rgba(80, 52, 32, 0.1);
  --her: #fffdfb;
  --me1: #e9a28d;
  --me2: #d8806b;
  --accent: #c46a55;
  --accent-soft: #f6e3da;
  --danger: #b4544a;
  --shadow: 0 10px 30px rgba(96, 58, 36, 0.08);
  --radius: 20px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background:
    radial-gradient(1100px 620px at 4% -8%, #fbe5d9 0%, rgba(251, 229, 217, 0) 62%),
    radial-gradient(900px 520px at 108% 4%, #f2e0cf 0%, rgba(242, 224, 207, 0) 58%),
    radial-gradient(700px 500px at 50% 110%, #f6e7dc 0%, rgba(246, 231, 220, 0) 60%),
    var(--bg);
  overflow: hidden;
  touch-action: manipulation;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------- 布局 */

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

@media (min-width: 760px) {
  body {
    padding: 22px 0;
  }
  .app {
    height: calc(100dvh - 44px);
    border: 1px solid rgba(120, 80, 50, 0.12);
    border-radius: 28px;
    background: rgba(255, 253, 250, 0.45);
    box-shadow: 0 30px 70px rgba(96, 58, 36, 0.14);
    backdrop-filter: blur(8px);
  }
}

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(248, 242, 236, 0.78);
  backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid rgba(120, 80, 50, 0.07);
  z-index: 5;
}

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-family: "Songti SC", "STSong", serif;
  font-size: 19px;
  letter-spacing: 0.02em;
  background: linear-gradient(145deg, #eab39d 0%, #d1795f 70%, #c96b52 100%);
  box-shadow: 0 6px 14px rgba(200, 110, 85, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.avatar.big {
  width: 66px;
  height: 66px;
  font-size: 30px;
  margin: 0 auto 6px;
}

.who {
  flex: 1;
  min-width: 0;
}

.who h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.who p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--ink-soft);
  transition: background 0.18s ease, transform 0.18s ease;
}

.icon-btn:active {
  transform: scale(0.93);
  background: rgba(120, 80, 50, 0.08);
}

.icon-btn svg {
  width: 21px;
  height: 21px;
}

.badge {
  position: absolute;
  top: 3px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------------------------------------------------------------- 对话 */

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 0;
}

.day {
  align-self: center;
  margin: 10px 0 2px;
  padding: 3px 10px;
  border-radius: 9px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(120, 80, 50, 0.06);
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg.me {
  flex-direction: row-reverse;
}

.msg-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 78%;
  min-width: 0;
}

.msg.me .msg-col {
  align-items: flex-end;
}

.msg-col .bubble {
  max-width: 100%;
}

.msg-col .meta-line {
  margin-bottom: 5px;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px 18px 18px 7px;
  font-size: 15.5px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--her);
  border: 1px solid rgba(120, 80, 50, 0.07);
  box-shadow: 0 4px 14px rgba(96, 58, 36, 0.05);
}

.msg.me .bubble {
  border-radius: 18px 18px 7px 18px;
  background: linear-gradient(140deg, var(--me1), var(--me2));
  color: #fff;
  border: 0;
  box-shadow: 0 6px 16px rgba(196, 106, 85, 0.26);
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px 4px;
  font-size: 10.5px;
  color: var(--muted);
}

.msg.me .meta-line {
  justify-content: flex-end;
}

.tag {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
}

/* 空状态 */
.empty {
  margin: auto;
  padding: 20px;
  text-align: center;
  animation: rise 0.5s ease both;
}

.empty h2 {
  margin: 0 0 6px;
  font-family: "Songti SC", "STSong", serif;
  font-size: 22px;
  font-weight: 500;
}

.empty p {
  margin: 0 auto;
  max-width: 300px;
  color: var(--muted);
  font-size: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(120, 80, 50, 0.1);
  transition: transform 0.15s ease, background 0.15s ease;
}

.chip:active {
  transform: scale(0.96);
  background: #fff;
}

/* 输入中 */
.typing {
  padding: 0 14px 4px;
}

.typing-bubble {
  display: inline-flex;
  gap: 4px;
  padding: 12px 15px;
  border-radius: 16px 16px 16px 6px;
  background: var(--her);
  border: 1px solid rgba(120, 80, 50, 0.07);
  box-shadow: 0 4px 14px rgba(96, 58, 36, 0.05);
}

.typing-bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9b6a8;
  animation: blink 1.2s infinite;
}

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

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

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

/* ---------------------------------------------------------------- 输入栏 */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 55%, rgba(248, 242, 236, 0));
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1px solid rgba(120, 80, 50, 0.12);
  background: #fffdfb;
  box-shadow: 0 4px 16px rgba(96, 58, 36, 0.05);
  resize: none;
  outline: none;
  line-height: 1.45;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer textarea:focus {
  border-color: rgba(196, 106, 85, 0.4);
  box-shadow: 0 0 0 3px rgba(196, 106, 85, 0.1);
}

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

#send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, var(--me1), var(--me2));
  box-shadow: 0 8px 18px rgba(196, 106, 85, 0.32);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

#send:active {
  transform: scale(0.92);
}

#send:disabled {
  opacity: 0.45;
  box-shadow: none;
}

#send svg {
  width: 20px;
  height: 20px;
}

/* ---------------------------------------------------------------- 面板 */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(44, 28, 18, 0.28);
  backdrop-filter: blur(2px);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.28s ease;
}

.scrim.show {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: 100%;
  max-width: 680px;
  max-height: 85dvh;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  box-shadow: 0 -10px 50px rgba(70, 40, 22, 0.18);
  transform: translate(-50%, 105%);
  transition: transform 0.34s cubic-bezier(0.22, 0.85, 0.25, 1);
}

.sheet.open {
  transform: translate(-50%, 0);
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.sheet-head h2 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.count {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}

.close-btn {
  padding: 6px 12px;
  border-radius: 10px;
  color: var(--accent);
  font-size: 14px;
  background: var(--accent-soft);
}

.sheet-hint {
  margin: 2px 0 16px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

/* 记忆列表 */
.memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 14px;
  background: #fbf6f1;
  border: 1px solid rgba(120, 80, 50, 0.06);
}

.memory-body {
  flex: 1;
  min-width: 0;
}

.memory-body p {
  margin: 0 0 5px;
  font-size: 14px;
  line-height: 1.55;
}

.memory-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  color: var(--muted);
}

.cat {
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(196, 106, 85, 0.1);
  color: var(--accent);
}

.dots {
  display: inline-flex;
  gap: 2px;
}

.dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(120, 80, 50, 0.18);
}

.dots i.on {
  background: var(--accent);
}

.memory-del {
  padding: 4px;
  color: #c0b0a4;
}

.memory-del svg {
  width: 16px;
  height: 16px;
}

.memory-del:active {
  color: var(--danger);
}

.memory-empty {
  padding: 26px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.memory-add {
  position: sticky;
  bottom: -22px;
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 0 0;
  background: linear-gradient(to top, var(--panel) 70%, rgba(255, 253, 251, 0));
}

.memory-add input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbf6f1;
  outline: none;
  font-size: 14px;
}

.memory-add button {
  padding: 0 18px;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
}

/* 表单 */
.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbf6f1;
  outline: none;
  font-size: 15px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field textarea {
  resize: vertical;
  line-height: 1.6;
  font-size: 14px;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(196, 106, 85, 0.45);
  box-shadow: 0 0 0 3px rgba(196, 106, 85, 0.1);
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field {
  flex: 1;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 0 16px;
}

.switch-row > div {
  flex: 1;
}

.switch-row strong {
  font-size: 14.5px;
  font-weight: 600;
}

.switch-row p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #e2d6cd;
  transition: background 0.2s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(19px);
}

.primary-btn {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  background: linear-gradient(140deg, var(--me1), var(--me2));
  box-shadow: 0 8px 20px rgba(196, 106, 85, 0.25);
}

.primary-btn:active {
  transform: scale(0.99);
}

.divider {
  height: 1px;
  margin: 20px 0 14px;
  background: var(--line);
}

.list-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-actions button {
  padding: 13px 4px;
  text-align: left;
  font-size: 14.5px;
  color: var(--ink-soft);
  border-bottom: 1px solid rgba(120, 80, 50, 0.07);
}

.list-actions button:last-child {
  border-bottom: 0;
}

.list-actions button.danger {
  color: var(--danger);
}

.tiny {
  margin: 18px 0 0;
  color: #b3a59a;
  font-size: 11px;
  line-height: 1.6;
}

/* ---------------------------------------------------------------- 登录 */

.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 400px at 50% 0%, #fbe5d9 0%, rgba(251, 229, 217, 0) 65%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-card h2 {
  margin: 4px 0 4px;
  font-family: "Songti SC", "STSong", serif;
  font-size: 24px;
  font-weight: 500;
}

.login-card > p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-card input {
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffdfb;
  outline: none;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.login-card form button {
  padding: 13px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--me1), var(--me2));
  font-size: 15px;
}

.login-err {
  margin: 12px 0 0 !important;
  color: var(--danger) !important;
  font-size: 12.5px !important;
}

/* ---------------------------------------------------------------- 提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 60;
  max-width: 80vw;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(47, 38, 30, 0.9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
