/* 莫兰迪蓝 + 奶白 — 心屿 */

:root {
  --cream-0: #fdfbf7;
  --cream-1: #f7f3ec;
  --cream-2: #ebe4d9;
  --morandi-deep: #5c7a8a;
  --morandi-mid: #8aa3b0;
  --morandi-soft: #b4c5cf;
  --morandi-mist: #d6e0e6;
  --morandi-pale: #e8eef2;
  --text: #3d4f5c;
  --text-muted: #6b7c88;
  --user-bubble: #c5d6df;
  --ai-bubble: #ffffff;
  --shadow-soft: 0 8px 32px rgba(92, 122, 138, 0.08);
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: linear-gradient(165deg, var(--cream-1) 0%, var(--morandi-pale) 45%, var(--cream-0) 100%);
  background-attachment: fixed;
}

.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;
}

.app {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100vh;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
}

/* Header */
.header {
  flex-shrink: 0;
  padding: 8px 4px 16px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--morandi-mist), var(--morandi-soft));
  color: var(--cream-0);
  font-size: 22px;
  box-shadow: var(--shadow-soft);
}

.header__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--morandi-deep);
}

.header__subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Chat scroll area */
.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 4px 20px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--morandi-mist);
  border-radius: 99px;
}

.row {
  display: flex;
  margin-bottom: 14px;
  animation: fadeUp 0.35s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row--user {
  justify-content: flex-end;
}

.row--ai {
  justify-content: flex-start;
}

.bubble {
  max-width: min(85%, 420px);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 2px 12px rgba(92, 122, 138, 0.06);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.row--user .bubble {
  background: var(--user-bubble);
  color: var(--text);
  border-bottom-right-radius: var(--radius-sm);
}

.row--ai .bubble {
  background: var(--ai-bubble);
  color: var(--text);
  border: 1px solid rgba(180, 197, 207, 0.45);
  border-bottom-left-radius: var(--radius-sm);
}

.bubble--notice {
  background: var(--cream-1);
  border-style: dashed;
  color: var(--text-muted);
  font-size: 0.94em;
}

.bubble__meta {
  display: block;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.85;
}

.row--typing .bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 14px 18px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--morandi-mid);
  animation: bounce 1.2s ease infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.15s;
}

.dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Composer */
.composer {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 0 4px;
  background: linear-gradient(to top, var(--cream-1) 70%, transparent);
}

.composer__input {
  flex: 1;
  min-height: 48px;
  max-height: 140px;
  resize: none;
  padding: 13px 16px;
  border: 1px solid rgba(180, 197, 207, 0.65);
  border-radius: var(--radius-lg);
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer__input::placeholder {
  color: var(--text-muted);
  opacity: 0.75;
}

.composer__input:focus {
  border-color: var(--morandi-mid);
  box-shadow: 0 0 0 3px rgba(138, 163, 176, 0.25);
}

.composer__send {
  flex-shrink: 0;
  min-height: 48px;
  padding: 0 22px;
  border: none;
  border-radius: var(--radius-lg);
  font: inherit;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--cream-0);
  background: linear-gradient(145deg, var(--morandi-mid), var(--morandi-deep));
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s;
}

.composer__send:hover:not(:disabled) {
  filter: brightness(1.03);
}

.composer__send:active:not(:disabled) {
  transform: scale(0.97);
}

.composer__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Desktop tweaks */
@media (min-width: 600px) {
  body {
    font-size: 16px;
  }

  .app {
    padding: calc(20px + var(--safe-top)) 24px calc(20px + var(--safe-bottom));
  }

  .header__title {
    font-size: 1.5rem;
  }

  .bubble {
    padding: 14px 18px;
  }

  .composer {
    padding-top: 16px;
  }
}

@media (min-width: 900px) {
  .app {
    max-width: 640px;
  }
}
