/* ============ 主题变量 ============ */
:root {
  --cream: #fff8ec;
  --cream-deep: #ffeccf;
  --ink: #2b2118;
  --ink-soft: #6b5b4a;
  --mint: #a8e6cf;
  --mint-deep: #6fdcb6;
  --coral: #ff8b7b;
  --coral-deep: #ff6a55;
  --sun: #ffd166;
  --purple: #c4b5fd;
  --white: #fffdf8;
  --line: 2.5px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --radius: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 209, 102, .55) 0 12%, transparent 13%),
    radial-gradient(circle at 88% 12%, rgba(196, 181, 253, .5) 0 10%, transparent 11%),
    radial-gradient(circle at 78% 88%, rgba(168, 230, 207, .5) 0 14%, transparent 15%),
    linear-gradient(160deg, var(--cream) 0%, var(--cream-deep) 100%);
  background-attachment: fixed;
  overflow: hidden;
}

/* ============ 布局 ============ */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 14px 10px;
  gap: 10px;
}

/* ============ 顶栏 ============ */
header.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  padding: 10px 14px;
}

.mascot {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  border: var(--line);
  background: linear-gradient(150deg, var(--sun), var(--coral));
  display: grid;
  place-items: center;
  font-size: 22px;
  position: relative;
  animation: bob 3.2s ease-in-out infinite;
}

.mascot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px dashed rgba(43, 33, 24, .25);
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}

.titles { flex: 1 1 auto; min-width: 0; }
.titles h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.titles p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--mint-deep);
  border: 1.5px solid var(--ink);
  margin-right: 4px;
  vertical-align: middle;
}

.icon-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 12px;
  border: var(--line);
  background: var(--white);
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  font-size: 15px;
  display: grid;
  place-items: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.icon-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }

/* ============ 消息区 ============ */
#messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 4px 4px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb {
  background: var(--ink);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: pop .28s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.row.user { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  border: var(--line);
  display: grid;
  place-items: center;
  font-size: 15px;
  background: var(--white);
}
.row.bot .avatar { background: linear-gradient(150deg, var(--sun), var(--coral)); }
.row.user .avatar { background: linear-gradient(150deg, var(--mint), var(--purple)); }

/* 消息列：状态条在上、气泡在下 */
.col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(78%, 620px);
  min-width: 0;
}
.row.user .col { align-items: flex-end; }

.bubble {
  max-width: 100%;
  padding: 12px 15px;
  border: var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--white);
  font-size: 14.5px;
  line-height: 1.72;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.row.user .bubble {
  background: linear-gradient(150deg, var(--mint), var(--mint-deep));
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.row.bot .bubble { border-bottom-left-radius: 6px; }

/* 气泡内的 Markdown 排版 */
.bubble h3 {
  margin: 14px 0 6px;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bubble h3:first-child { margin-top: 0; }
.bubble p { margin: 7px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 800; background: linear-gradient(transparent 62%, var(--sun) 62%); }
.bubble code {
  background: var(--cream-deep);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 0 4px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble pre {
  background: #2b2118;
  color: #fff8ec;
  border-radius: 12px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: none; border: none; color: inherit; padding: 0; }
.bubble blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 4px solid var(--coral);
  background: var(--cream);
  border-radius: 0 10px 10px 0;
  color: var(--ink-soft);
}
.bubble hr { border: none; border-top: 2px dashed rgba(43,33,24,.25); margin: 12px 0; }

/* 报价徽标 */
.price {
  display: inline-block;
  padding: 3px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-weight: 800;
  font-size: 13px;
  box-shadow: 2px 2px 0 var(--ink);
}
.price.zero { background: var(--coral); color: #fff; }

/* ============ 打字指示 & 工具状态 ============ */
.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 4px 2px;
}
.typing i {
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--coral);
  animation: blink 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; background: var(--sun); }
.typing i:nth-child(3) { animation-delay: .36s; background: var(--mint); }
@keyframes blink {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.toolchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--cream);
  border: 1.5px dashed rgba(43,33,24,.35);
  border-radius: 999px;
  padding: 2px 9px;
  margin: 2px 4px 2px 0;
}

/* ============ 建议动作 ============ */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 4px 0 0 40px;
}
.chip {
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--white);
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.chip:hover { background: var(--sun); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.chip:active { transform: translate(2px, 2px); box-shadow: none; }

/* ============ 首屏引导 ============ */
.hero {
  margin: auto;
  text-align: center;
  max-width: 460px;
  padding: 10px;
}
.hero .big {
  font-size: 40px;
  display: inline-block;
  animation: bob 3s ease-in-out infinite;
}
.hero h2 {
  margin: 8px 0 6px;
  font-size: 19px;
  font-weight: 800;
}
.hero p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.7;
}
.hero .samples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.sample {
  border: var(--line);
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.55;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.sample:hover { background: var(--cream-deep); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.sample b { font-weight: 800; }

/* ============ 输入区 ============ */
footer.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--white);
  border: var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  padding: 8px 8px 8px 12px;
}

#input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  max-height: 132px;
  min-height: 24px;
  padding: 4px 0;
}
#input::placeholder { color: #b0a38f; }

.send-btn {
  flex: 0 0 auto;
  height: 38px;
  min-width: 62px;
  padding: 0 16px;
  border-radius: 14px;
  border: var(--line);
  background: linear-gradient(150deg, var(--coral), var(--coral-deep));
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.send-btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.send-btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.send-btn:disabled { filter: grayscale(.55); cursor: not-allowed; opacity: .75; }
.send-btn.stop { background: linear-gradient(150deg, #ff5c5c, #d63b3b); }

.hint {
  flex: 0 0 auto;
  text-align: center;
  font-size: 10.5px;
  color: #a2968a;
  padding-bottom: 2px;
}

/* ============ 移动端适配 ============ */
@media (max-width: 640px) {
  #app { padding: 8px 8px 6px; gap: 8px; }
  header.topbar { padding: 8px 10px; border-radius: 16px; }
  .mascot { width: 38px; height: 38px; flex-basis: 38px; font-size: 19px; }
  .titles h1 { font-size: 14.5px; }
  .titles p { font-size: 10.5px; }
  .col { max-width: 84%; }
  .bubble { font-size: 14px; padding: 10px 12px; }
  .chips { margin-left: 0; }
  .hero h2 { font-size: 17px; }
  .hero .big { font-size: 34px; }
  footer.composer { padding: 6px 6px 6px 10px; border-radius: 16px; }
  .send-btn { height: 36px; min-width: 54px; padding: 0 12px; }
}

@media (max-width: 380px) {
  .titles p { display: none; }
  .avatar { display: none; }
  .col { max-width: 96%; }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
