:root {
  --ink: #17231f;
  --ink-soft: #43514c;
  --forest: #1b2b26;
  --forest-light: #2d4039;
  --coral: #ef6d62;
  --coral-dark: #d9564e;
  --mint: #9dd6bf;
  --sky: #d9e8ee;
  --paper: #fbfcfa;
  --surface: #f1f4f1;
  --line: #dce2de;
  --shadow: 0 20px 60px rgba(23, 35, 31, 0.12);
  --display: "STKaiti", "KaiTi", serif;
  --body: "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  background:
    linear-gradient(135deg, rgba(157, 214, 191, 0.16), transparent 34%),
    #dfe6e2;
  overflow: hidden;
}

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

button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(239, 109, 98, 0.3);
  outline-offset: 2px;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: 248px minmax(440px, 1fr) 330px;
  background: var(--paper);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 26px 16px 18px;
  color: #f4f7f5;
  background:
    linear-gradient(160deg, rgba(157, 214, 191, 0.08), transparent 45%),
    var(--forest);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px 24px;
  color: white;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--forest);
  background: var(--mint);
  border-radius: 50%;
}

.brand-mark svg { width: 18px; }

.primary-nav { display: grid; gap: 6px; }

.nav-item {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  color: #b8c5c0;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
}

.nav-item svg { width: 19px; }
.nav-item:hover { color: white; background: rgba(255, 255, 255, 0.06); }
.nav-item.active { color: white; background: var(--forest-light); }

.sidebar-section { margin-top: 34px; min-width: 0; }

.section-heading {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.sidebar .section-heading { padding: 0 8px 8px; color: #83958e; }

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-button svg { width: 18px; height: 18px; }
.icon-button:hover { transform: translateY(-1px); background: var(--surface); border-color: #c4cdc8; }
.icon-button.subtle { width: 30px; height: 30px; flex-basis: 30px; border: 0; color: #9baca5; }
.icon-button.subtle:hover, .icon-button.dark:hover { color: white; background: rgba(255,255,255,.08); }

.conversation-item {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: white;
  background: rgba(255,255,255,.065);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: block;
}

.avatar img, .call-avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  background: #f2b2ad;
}

.avatar-small { width: 40px; height: 40px; }

.online-dot {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 11px;
  height: 11px;
  background: #70d29b;
  border: 2px solid var(--paper);
  border-radius: 50%;
}

.avatar-small .online-dot { border-color: var(--forest-light); }

.conversation-copy { min-width: 0; display: grid; gap: 3px; }
.conversation-copy strong { font-size: 14px; }
.conversation-copy small { color: #9dafaa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { align-self: start; color: #73867f; font-size: 10px; }

.sidebar-footer {
  margin-top: auto;
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  padding: 14px 8px 0;
  border-top: 1px solid rgba(255,255,255,.08);
}

.user-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--forest);
  background: var(--sky);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

.sidebar-footer > span:nth-child(2) { min-width: 0; display: grid; gap: 2px; }
.sidebar-footer strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer small { color: #7f918a; font-size: 10px; }
.icon-button.dark { width: 34px; height: 34px; color: #81938c; border: 0; }

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 78px minmax(0, 1fr) auto auto;
  background:
    linear-gradient(rgba(223, 229, 225, 0.28) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 48px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(251,252,250,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.companion-summary { min-width: 0; display: flex; align-items: center; gap: 12px; }
.companion-summary > span:last-child { display: grid; gap: 3px; }
.companion-summary strong { font-family: var(--display); font-size: 19px; }
.companion-summary small { color: #71817b; font-size: 11px; }

.status-pulse {
  width: 7px;
  height: 7px;
  display: inline-block;
  background: #65bd8a;
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(101,189,138,.12);
}

.status-pulse.offline {
  background: var(--coral);
  box-shadow: 0 0 0 5px rgba(239,109,98,.12);
}

.header-actions { display: flex; gap: 8px; }
.mobile-profile-button, .mobile-settings-button { display: none; }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 32px clamp(24px, 5vw, 72px) 18px;
  scroll-behavior: smooth;
}

.day-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 2px 0 26px;
  color: #93a09a;
  font-size: 11px;
}

.day-divider::before, .day-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 18px;
  animation: message-in 280ms ease both;
}

.message-row.user { justify-content: flex-end; }
.message-avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; object-fit: cover; background: #f2b2ad; }

.message-content { max-width: min(74%, 560px); }
.message-content p {
  margin: 0;
  padding: 11px 14px;
  line-height: 1.7;
  font-size: 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px 8px 8px 2px;
  box-shadow: 0 5px 18px rgba(23,35,31,.04);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-row.user .message-content p {
  color: white;
  background: var(--forest-light);
  border-color: var(--forest-light);
  border-radius: 8px 8px 2px 8px;
}

.message-time { display: block; margin-top: 5px; color: #9ba6a1; font-size: 10px; }
.message-row.user .message-time { text-align: right; }

.typing-bubble { display: flex; gap: 4px; padding: 14px 16px; background: white; border: 1px solid var(--line); border-radius: 8px 8px 8px 2px; }
.typing-bubble span { width: 5px; height: 5px; background: #82918b; border-radius: 50%; animation: typing 1s infinite alternate; }
.typing-bubble span:nth-child(2) { animation-delay: 160ms; }
.typing-bubble span:nth-child(3) { animation-delay: 320ms; }

.quick-prompts {
  display: flex;
  gap: 8px;
  padding: 8px clamp(24px, 5vw, 72px);
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-prompts::-webkit-scrollbar { display: none; }
.quick-prompts button {
  flex: 0 0 auto;
  padding: 8px 12px;
  color: #52615b;
  background: #f5f7f5;
  border: 1px solid var(--line);
  border-radius: 18px;
  font-size: 12px;
  cursor: pointer;
}
.quick-prompts button:hover { color: var(--coral-dark); border-color: #efaaa4; background: #fff7f6; }

.composer {
  min-height: 72px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px 42px;
  align-items: end;
  gap: 8px;
  margin: 0 clamp(20px, 4vw, 64px) 22px;
  padding: 9px;
  background: white;
  border: 1px solid #cfd7d2;
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(23,35,31,.08);
}

.composer:focus-within { border-color: #90a79d; box-shadow: 0 14px 34px rgba(23,35,31,.11); }
.composer .icon-button { border: 0; color: #65736e; }
.composer .icon-button:hover { color: var(--coral-dark); background: #fff1f0; }
.composer .icon-button.active { color: var(--coral-dark); background: #fff1f0; }

.composer textarea {
  width: 100%;
  max-height: 120px;
  min-height: 40px;
  padding: 9px 4px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.55;
  resize: none;
}
.composer textarea::placeholder { color: #9ba6a1; }

.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  color: white;
  background: var(--coral);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}
.send-button:hover { transform: translateY(-2px); background: var(--coral-dark); }
.send-button svg { width: 19px; }

.profile-panel {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  padding: 22px 24px 26px;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.close-profile { display: none; }

.portrait-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: end center;
  overflow: hidden;
  background: var(--sky);
  border-radius: 8px;
}

.portrait-lines {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(23,35,31,.05) 27px 28px),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(23,35,31,.05) 27px 28px);
}

.portrait-stage > img {
  position: relative;
  z-index: 1;
  width: 88%;
  height: 95%;
  object-fit: contain;
  object-position: bottom center;
}

.mood-note {
  position: absolute;
  z-index: 2;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  color: white;
  background: rgba(23,35,31,.78);
  border-radius: 6px;
  font-size: 11px;
  backdrop-filter: blur(8px);
}
.mood-note svg { width: 14px; }

.profile-intro { padding: 24px 2px 20px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 6px; color: var(--coral-dark); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.profile-intro h1, dialog h2 { margin: 0; font-family: var(--display); font-size: 31px; letter-spacing: 0; }
.profile-intro > p:last-child { margin: 10px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.8; }

.bond-section, .today-section { padding: 20px 2px; border-bottom: 1px solid var(--line); }
.profile-panel .section-heading { color: var(--ink-soft); font-weight: 700; }
.profile-panel .section-heading strong { color: var(--coral-dark); }
.profile-panel .section-heading small { color: #89958f; font-weight: 400; }

.bond-track { height: 6px; margin-top: 10px; overflow: hidden; background: #d7ded9; border-radius: 3px; }
.bond-track span { width: 72%; height: 100%; display: block; background: linear-gradient(90deg, var(--mint), var(--coral)); border-radius: inherit; transition: width 420ms ease; }
.bond-section p { margin: 9px 0 0; color: #82908a; font-size: 11px; }

.timeline { display: grid; gap: 16px; margin: 15px 0 0; padding: 0; list-style: none; }
.timeline li { position: relative; display: grid; grid-template-columns: 44px 1fr; gap: 12px; color: #71807a; font-size: 11px; }
.timeline li::before { content: ""; position: absolute; left: 47px; top: 5px; width: 6px; height: 6px; background: #aab6b0; border-radius: 50%; }
.timeline li::after { content: ""; position: absolute; left: 49px; top: 14px; width: 1px; height: 18px; background: #c9d1cd; }
.timeline li:last-child::after { display: none; }
.timeline time { color: #9aa5a0; }
.timeline span { padding-left: 12px; line-height: 1.45; }
.timeline li.current::before { background: var(--coral); box-shadow: 0 0 0 4px rgba(239,109,98,.13); }
.timeline li.current span { color: var(--ink); font-weight: 700; }

.wellbeing-note { display: flex; gap: 9px; margin: 20px 2px 0; color: #77857f; font-size: 10px; line-height: 1.6; }
.wellbeing-note svg { width: 17px; height: 17px; flex: 0 0 17px; color: var(--coral); }

.mobile-backdrop { display: none; }

dialog {
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15,23,20,.64); backdrop-filter: blur(5px); }

.call-dialog {
  width: min(430px, calc(100% - 32px));
  padding: 42px 34px 30px;
  text-align: center;
  background: #f7f9f7;
}
.call-close { position: absolute; top: 14px; right: 14px; }
.call-avatar-wrap { position: relative; width: 118px; height: 118px; margin: 4px auto 28px; }
.call-avatar-wrap img { position: relative; z-index: 1; }
.call-ring { position: absolute; inset: -12px; border: 1px solid rgba(239,109,98,.45); border-radius: 50%; animation: call-ring 2s ease-out infinite; }
.call-dialog h2 { font-size: 34px; }
.call-dialog > time { display: block; margin-top: 4px; color: #74827c; font-variant-numeric: tabular-nums; }
.voice-wave { height: 32px; display: flex; align-items: center; justify-content: center; gap: 5px; margin: 20px 0 8px; }
.voice-wave span { width: 4px; height: 8px; background: var(--mint); border-radius: 3px; animation: wave 850ms ease-in-out infinite alternate; }
.voice-wave span:nth-child(2) { animation-delay: 160ms; }
.voice-wave span:nth-child(3) { animation-delay: 320ms; }
.voice-wave span:nth-child(4) { animation-delay: 480ms; }
.voice-wave span:nth-child(5) { animation-delay: 640ms; }
.call-caption { min-height: 22px; margin: 0; color: var(--ink-soft); font-family: var(--display); font-size: 16px; }
.call-actions { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 30px; }
.call-tool { width: 56px; display: grid; justify-items: center; gap: 7px; padding: 0; background: transparent; border: 0; color: #65736d; font-size: 10px; cursor: pointer; }
.call-tool svg { width: 20px; height: 20px; }
.call-tool.active { color: var(--coral-dark); }
.end-call { width: 58px; height: 58px; display: grid; place-items: center; padding: 0; color: white; background: var(--coral); border: 0; border-radius: 50%; cursor: pointer; }

.settings-dialog { width: min(460px, calc(100% - 32px)); padding: 28px; background: var(--paper); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; margin-bottom: 18px; }
.dialog-header h2 { font-size: 26px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 0; border-top: 1px solid var(--line); cursor: pointer; }
.setting-row > span { display: grid; gap: 4px; }
.setting-row strong { font-size: 14px; }
.setting-row small { color: #83908a; font-size: 11px; }
.setting-row input { width: 42px; height: 23px; flex: 0 0 auto; accent-color: var(--coral); }
.danger-button { width: 100%; height: 42px; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; color: #bf4b44; background: #fff2f1; border: 1px solid #f3c9c5; border-radius: 7px; cursor: pointer; }
.danger-button svg { width: 17px; }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 28px;
  max-width: calc(100% - 32px);
  padding: 10px 15px;
  color: white;
  background: rgba(23,35,31,.92);
  border-radius: 6px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.focus-mode { grid-template-columns: 0 minmax(440px, 1fr) 0; }
.focus-mode .sidebar, .focus-mode .profile-panel { opacity: 0; pointer-events: none; }

@keyframes message-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes typing { to { transform: translateY(-4px); opacity: .45; } }
@keyframes call-ring { from { transform: scale(.88); opacity: .9; } to { transform: scale(1.14); opacity: 0; } }
@keyframes wave { from { height: 7px; } to { height: 28px; } }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 238px minmax(420px, 1fr); }
  .profile-panel { position: fixed; z-index: 12; top: 0; right: 0; width: 330px; height: 100dvh; transform: translateX(100%); transition: transform 240ms ease; box-shadow: -20px 0 50px rgba(23,35,31,.15); }
  .profile-panel.open { transform: translateX(0); }
  .close-profile { position: absolute; z-index: 5; top: 30px; right: 32px; display: grid; background: rgba(255,255,255,.82); }
  .mobile-profile-button { display: grid; }
  .desktop-profile-button { display: none; }
  .mobile-backdrop { position: fixed; z-index: 11; inset: 0; display: block; background: rgba(23,35,31,.45); opacity: 0; pointer-events: none; transition: opacity 220ms ease; }
  .mobile-backdrop.show { opacity: 1; pointer-events: auto; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .mobile-settings-button { display: grid; }
  .chat-panel { grid-template-rows: 68px minmax(0, 1fr) auto auto; }
  .chat-header { padding: 0 16px; }
  .header-actions { gap: 5px; }
  .header-actions .icon-button { width: 36px; height: 36px; flex-basis: 36px; }
  .messages { padding: 24px 14px 12px; }
  .message-content { max-width: 82%; }
  .quick-prompts { padding: 7px 14px; }
  .composer { min-height: 62px; grid-template-columns: minmax(0, 1fr) 38px 40px; margin: 0 10px max(10px, env(safe-area-inset-bottom)); padding: 7px; }
  .composer-extra { display: none; }
  .composer textarea { min-height: 38px; padding-left: 8px; }
  .profile-panel { width: min(330px, 92vw); }
  .focus-mode { grid-template-columns: minmax(0, 1fr); }
  .toast { bottom: 88px; }
}

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