:root {
  color-scheme: light;
  --bg: #f7efe8;
  --bg-soft: #fbf7f2;
  --ink: #2c2a28;
  --muted: #8c8177;
  --line: rgba(95, 82, 70, 0.14);
  --bubble: rgba(255, 252, 248, 0.84);
  --bubble-me: #eadfd4;
  --accent: #b58d70;
  --accent-strong: #8b644a;
  --shadow: 0 18px 55px rgba(78, 59, 45, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(236, 220, 205, 0.9), transparent 32rem),
    linear-gradient(180deg, #fbf5ef 0%, #f5ece4 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body[data-has-custom-background="true"] .phone-frame {
  background-color: rgba(253, 249, 244, 0.42);
}

body[data-has-custom-background="true"] .messages {
  background: transparent;
}

body[data-has-custom-background="true"] .composer {
  background: linear-gradient(180deg, rgba(253, 249, 244, 0), rgba(253, 249, 244, 0.72) 24%);
}

body[data-has-custom-background="true"] .topbar {
  background: rgba(253, 249, 244, 0.18);
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(8px, var(--safe-top)) 8px max(8px, var(--safe-bottom));
}

.phone-frame {
  position: relative;
  width: min(100%, 430px);
  height: min(100dvh, 920px);
  min-height: 620px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: rgba(253, 249, 244, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

@media (min-width: 720px) {
  .phone-frame {
    border-radius: 30px;
    height: min(860px, calc(100dvh - 24px));
  }
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  pointer-events: none;
  animation: splashFade 520ms ease-out forwards;
}

.splash-avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  animation: avatarLand 500ms ease-out forwards;
}

@keyframes splashFade {
  0%, 64% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

@keyframes avatarLand {
  from { transform: translateY(0) scale(1.15); opacity: 0; }
  35% { opacity: 1; }
  to { transform: translateY(-34dvh) scale(0.46); opacity: 0.8; }
}

.topbar {
  min-height: calc(60px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 16px 10px;
  display: grid;
  grid-template-columns: auto minmax(64px, 1fr) auto;
  align-items: center;
  gap: 9px;
}

.avatar-button,
.avatar-button img,
.message-avatar,
.message-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.avatar-button {
  padding: 0;
  background: transparent;
}

.avatar-button img,
.message-avatar img {
  display: block;
  object-fit: cover;
}

.status-chip {
  justify-self: start;
  min-width: 0;
  background: transparent;
  color: #4f4540;
  font-size: 15px;
  padding: 7px 8px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-action {
  min-width: 38px;
  padding: 6px 2px;
  background: transparent;
  color: #776c63;
  font-size: 12px;
  white-space: nowrap;
}

.messages {
  overflow-y: auto;
  padding: 12px 16px 24px;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  gap: 9px;
  margin: 14px 0;
  align-items: flex-start;
}

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

.message-main {
  max-width: min(78%, 318px);
}

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

.message-row.me .message-time {
  text-align: right;
}

.bubble {
  padding: 12px 14px;
  background: var(--bubble);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  line-height: 1.55;
  font-size: 15px;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 24px rgba(98, 77, 59, 0.08);
}

.bubble pre {
  margin: 10px 0 0;
  padding: 10px;
  overflow-x: auto;
  border-radius: 10px;
  background: rgba(47, 43, 39, 0.08);
  font-size: 13px;
}

.bubble code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.attachments {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.attachment-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.45);
  color: inherit;
  text-decoration: none;
}

.attachment-card strong,
.attachment-card span,
.attachment-card p {
  display: block;
}

.attachment-card strong {
  font-size: 13px;
}

.attachment-card span,
.attachment-card p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.attachment-image {
  width: 74px;
  height: 74px;
  border-radius: 10px;
  object-fit: cover;
}

.attachment-card audio {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.attachment-card video {
  grid-column: 1 / -1;
  width: 100%;
  max-height: 260px;
  border-radius: 10px;
  background: #111;
}

.file-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(181, 141, 112, 0.16);
  color: var(--accent-strong);
  font-size: 13px;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 5px;
}

.message-actions button {
  padding: 4px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  font-size: 12px;
}

.me .bubble {
  background: var(--bubble-me);
  border-bottom-right-radius: 8px;
}

.xiaoke .bubble {
  border-bottom-left-radius: 8px;
}

.pending-bubble {
  display: inline-flex;
  align-items: center;
  min-width: 54px;
  min-height: 42px;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9a8f86;
  opacity: 0.38;
  animation: typingDot 1.1s ease-in-out infinite;
}

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

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

@keyframes typingDot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.34;
  }
  40% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

.thinking {
  margin-top: 6px;
  color: #9a8f86;
  font-size: 12px;
}

.thinking button {
  padding: 0;
  background: transparent;
  color: #8f7968;
}

.thinking-text {
  margin-top: 5px;
  padding: 8px 10px;
  border-left: 2px solid rgba(181, 141, 112, 0.45);
  background: rgba(255, 255, 255, 0.38);
  border-radius: 8px;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: end;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(253, 249, 244, 0), rgba(253, 249, 244, 0.96) 24%);
}

.composer textarea {
  width: 100%;
  max-height: 118px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 22px;
  outline: none;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.round-button,
.mic-button,
.send-button,
.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 22px;
}

.round-button {
  width: 44px;
  background: rgba(235, 224, 213, 0.82);
  color: #6e5d51;
  font-size: 18px;
}

.mic-button {
  width: 44px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-strong);
  border: 1px solid var(--line);
}

.mic-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mic-button.recording {
  background: #d85b4c;
  color: white;
  border-color: #d85b4c;
}

.send-button,
.primary-button {
  padding: 0 16px;
  background: var(--accent-strong);
  color: white;
}

.ghost-button {
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-strong);
  border: 1px solid var(--line);
}

.plus-menu {
  position: fixed;
  z-index: 11;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: calc(78px + var(--safe-bottom));
  width: min(270px, calc(100vw - 34px));
  padding: 18px;
  border-radius: 24px;
  background: rgba(255, 252, 248, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.plus-menu button {
  display: block;
  width: 100%;
  padding: 14px 10px;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.plus-menu button:last-child {
  border-bottom: 0;
}

.panel,
.onboarding {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: end center;
  padding: max(16px, var(--safe-top)) 12px max(16px, var(--safe-bottom));
  background: rgba(54, 43, 36, 0.18);
}

.panel-card,
.onboarding-card {
  width: min(100%, 430px);
  max-height: min(86dvh, 780px);
  overflow-y: auto;
  padding: 18px;
  border-radius: 28px 28px 18px 18px;
  background: rgba(255, 252, 248, 0.97);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header h2,
.onboarding-card h1 {
  margin: 0;
  font-size: 20px;
}

.panel-content {
  display: grid;
  gap: 12px;
}

.card,
.permission-row,
.memory-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
}

.card h3,
.permission-row h3,
.memory-card h3 {
  margin: 0 0 7px;
  font-size: 15px;
}

.card p,
.permission-row p,
.memory-card p,
.onboarding-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.space-list-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.space-list-item:first-of-type {
  border-top: 0;
}

.space-thumb {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  object-fit: cover;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.mini-actions button {
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(181, 141, 112, 0.13);
  color: var(--accent-strong);
  font-size: 12px;
}

.setup-grid {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.setup-item {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
}

.field-label {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: #5d5149;
  font-size: 13px;
}

.field-label input,
.field-label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.field-label input[type="color"] {
  height: 44px;
  padding: 4px;
}

.setup-status,
.small-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.onboarding-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(360px, calc(100vw - 30px));
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(56, 44, 36, 0.92);
  color: white;
  font-size: 14px;
  box-shadow: var(--shadow);
}
