:root {
  --sun: #FFD23F;
  --sun-deep: #FFB703;
  --coral: #F0503F;
  --coral-soft: #FF7A6B;
  --cream: #FFF7EA;
  --paper: #FFFDF8;
  --teal: #2EC4B6;
  --ink: #3A2A2A;
  --ink-soft: #7A6A63;
  --line: #F1E4CF;
  --pink: #FF8FA3;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #FFF3D6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; cursor: pointer; }

.app {
  max-width: 680px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  background-image: radial-gradient(circle at 12% 8%, #FFF1C9 0, transparent 38%), radial-gradient(circle at 92% 60%, #FFEDE6 0, transparent 35%);
  position: relative;
}
@media (min-width: 700px) {
  .app { box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(184, 106, 0, .12); }
}

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px 10px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(135deg, #FFE066, var(--sun-deep));
  border-bottom: 3px solid #F5A300;
}
.top-avatar { width: 46px; height: 46px; border-radius: 13px; box-shadow: 0 3px 10px rgba(184,106,0,.25); background:#fff; }
.top-title { flex: 1; min-width: 0; }
.top-title h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: .3px; }
.top-title p { margin: 2px 0 0; font-size: 12.5px; color: #6B4A12; }
.top-contact {
  border: 0; border-radius: 999px; padding: 8px 14px;
  background: #fff; color: var(--coral); font-weight: 700; font-size: 14px;
  box-shadow: 0 2px 0 #E89A00;
}
.top-contact:active { transform: translateY(1px); box-shadow: none; }

.quota {
  align-self: center;
  margin: 10px auto 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  background: #FFF1C2; color: #8A5A00;
  border: 1px solid #FFE08A;
}
.quota.vip { background: #E3F8F5; color: #0F7A70; border-color: #B9EDE6; }
.quota.out { background: #FFE6E2; color: #B23A2C; border-color: #FFC8BF; }

/* ---------- chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 18px;
  scroll-behavior: smooth;
}
.row { display: flex; gap: 8px; margin: 12px 0; align-items: flex-end; }
.row.me { justify-content: flex-end; }
.row .ava { width: 32px; height: 32px; border-radius: 10px; flex: none; align-self: flex-start; }
.bubble {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 15.5px;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.row.bot .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-top-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(120, 80, 20, .06);
}
.row.me .bubble {
  background: linear-gradient(135deg, var(--coral-soft), var(--coral));
  color: #fff;
  border-top-right-radius: 6px;
  white-space: pre-wrap;
}
.bubble p { margin: 0 0 .6em; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble h4 { margin: .7em 0 .35em; font-size: 15.5px; }
.bubble h4:first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 0 0 .6em; padding-left: 1.3em; }
.bubble li { margin: .2em 0; }
.bubble strong { color: #C2392B; font-weight: 700; }
.bubble a { color: #0F7A70; }
.bubble code { background: #FFF4D6; padding: 0 4px; border-radius: 4px; font-size: .92em; }
.bubble hr { border: 0; border-top: 1px dashed var(--line); margin: .8em 0; }
.bubble.err { background: #FFF3F1 !important; border-color: #FFD0C8 !important; color: #A1372A; }
.retry { margin-top: 8px; border: 1px solid #F0A79C; background: #fff; color: var(--coral); border-radius: 999px; padding: 4px 12px; font-size: 13px; }

.sources { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--ink-soft); }
.sources span { margin-right: 4px; }
.sources a {
  display: inline-block; max-width: 100%;
  margin: 3px 4px 0 0; padding: 2px 8px;
  border-radius: 999px; background: #F4FBFA; border: 1px solid #CDEFEA;
  color: #0F7A70; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom;
}

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--sun-deep); animation: hop 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; background: var(--coral-soft); }
.typing i:nth-child(3) { animation-delay: .3s; background: var(--teal); }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); opacity: .6 } 30% { transform: translateY(-6px); opacity: 1 } }

.starters { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px 40px; }
.starters button {
  border: 1.5px solid #FFD27A; background: #FFFBEF; color: #7A4B00;
  padding: 7px 12px; border-radius: 999px; font-size: 14px; text-align: left;
}
.starters button:active { background: #FFF0C2; }

/* ---------- CTA card ---------- */
.cta {
  margin: 16px 4px 8px;
  padding: 18px 16px 16px;
  border-radius: 22px;
  background: linear-gradient(160deg, #FFF6D1, #FFE7A3);
  border: 2px solid #FFD25E;
  text-align: center;
  position: relative;
  box-shadow: 0 8px 24px rgba(184, 106, 0, .14);
}
.cta-face { width: 64px; height: 64px; border-radius: 18px; margin: -46px auto 6px; display: block; box-shadow: 0 6px 16px rgba(184,106,0,.25); background: #fff; }
.cta h3 { margin: 4px 0 6px; font-size: 18px; }
.cta p { margin: 0 auto 12px; font-size: 14.5px; line-height: 1.6; max-width: 30em; color: #5A4433; }
.cta p strong { color: var(--coral); }
.wechat {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 14px; padding: 8px 8px 8px 14px;
  border: 1px solid #F3D9A0; font-size: 15px;
}
.wechat b { font-size: 16px; letter-spacing: .3px; }
.copy-btn {
  border: 0; border-radius: 10px; padding: 7px 12px;
  background: #07C160; color: #fff; font-weight: 700; font-size: 14px;
}
.qr { margin: 12px auto 0; }
.qr img { width: 170px; height: 170px; border-radius: 14px; background: #fff; padding: 8px; border: 1px solid #F3D9A0; }
.qr small { display: block; margin-top: 4px; color: var(--ink-soft); font-size: 12.5px; }
.cta .tip { margin: 12px 0 0; font-size: 12.5px; color: #8A6A50; }

/* ---------- composer ---------- */
.legal {
  padding: 0 12px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, .96);
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
}
.composer {
  padding: 10px 12px 6px;
  background: rgba(255, 253, 248, .96);
  border-top: 1px solid var(--line);
}
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none;
  font: inherit; font-size: 16px; line-height: 1.45;
  padding: 10px 14px;
  max-height: 140px;
  border-radius: 22px;
  border: 2px solid #FFE08A;
  background: #fff; color: var(--ink);
  outline: none;
}
.composer textarea:focus { border-color: var(--sun-deep); }
.composer textarea:disabled { background: #FAF6EE; }
#sendBtn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%; border: 0;
  background: linear-gradient(135deg, var(--coral-soft), var(--coral));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 3px 0 #C23A2C;
}
#sendBtn:disabled { opacity: .45; box-shadow: none; }
.composer.locked { text-align: center; }
.cta-btn {
  width: 100%; border: 0; border-radius: 16px;
  padding: 14px; font-size: 16px; font-weight: 800;
  background: #07C160; color: #fff;
  box-shadow: 0 3px 0 #05923F;
}

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(58, 42, 42, .45); }
.modal-card { position: relative; width: min(420px, 100%); max-height: 90dvh; overflow: auto; padding-top: 34px; }
.modal-card .cta { margin: 0; }
.modal-x { position: absolute; top: 34px; right: 8px; z-index: 2; border: 0; background: transparent; font-size: 26px; line-height: 1; color: #8A6A50; padding: 6px 10px; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(58, 42, 42, .92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30;
  max-width: 86vw; text-align: center;
}
.notice { text-align: center; color: var(--ink-soft); font-size: 13px; margin: 18px 0 6px; }
