/* 小暖 —— 奶茶色系 · 手账格纸 · 团子 */
:root {
  --milk: #FFF6EC;
  --milk-deep: #F9E8D8;
  --paper: #FFFDF9;
  --ink: #4A3833;
  --cocoa: #8D7A71;
  --cocoa-soft: #B6A69B;
  --strawberry: #E8796C;
  --strawberry-deep: #CB5B4F;
  --butter: #FFDFA0;
  --butter-soft: #FFF1D4;
  --mint: #93CBBF;
  --mint-soft: #E3F1ED;
  --line: #EEDDCB;
  --line-deep: #E2CDB6;
  --radius: 18px;
  --ease: cubic-bezier(.22, .9, .28, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background-color: var(--milk);
  background-image:
    radial-gradient(120% 55% at 50% 0%, #FFEEDC 0%, rgba(255, 238, 220, 0) 70%),
    linear-gradient(rgba(74, 56, 51, .042) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 56, 51, .042) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px, 24px 24px;
  background-position: 0 0, -1px -1px, -1px -1px;
  overflow: hidden;
}

body.is-locked { overflow: hidden; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.mascot { width: 26px; height: 26px; display: block; flex: 0 0 auto; }
.mascot--lg { width: 96px; height: 96px; animation: breathe 3.6s var(--ease) infinite; }

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.035) translateY(-2px); }
}

/* ---------- 骨架 ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  border-bottom: 1px dashed var(--line-deep);
  background: rgba(255, 246, 236, .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .06em;
  flex: 1 1 auto;
  min-width: 0;
}

.brand .mascot { width: 28px; height: 28px; }

.topbar__right { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background .18s var(--ease), transform .12s var(--ease);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:active { transform: scale(.92); background: var(--milk-deep); }
.icon-btn--sm { width: 32px; height: 32px; background: var(--milk-deep); }
.icon-btn--sm svg { width: 16px; height: 16px; }

.deep-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px 0 9px;
  border: 1px solid var(--line-deep);
  border-radius: 999px;
  background: var(--paper);
  color: var(--cocoa);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  transition: all .2s var(--ease);
}

.deep-pill__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-deep);
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
}

.deep-pill[aria-pressed="true"] {
  background: var(--mint-soft);
  border-color: var(--mint);
  color: #3F6B60;
}

.deep-pill[aria-pressed="true"] .deep-pill__dot {
  background: var(--mint);
  box-shadow: 0 0 0 3px rgba(147, 203, 191, .28);
}

.deep-pill:active { transform: scale(.95); }

/* ---------- 消息区 ---------- */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 14px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-deep) transparent;
}

.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: var(--line-deep); border-radius: 3px; }

/* ---------- 空状态 ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: min(12vh, 78px) 8px 20px;
}

.empty[hidden] { display: none; }

.empty__hi {
  margin: 16px 0 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .04em;
}

.empty__sub {
  margin: 5px 0 0;
  font-size: 14px;
  color: var(--cocoa);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 26px;
  max-width: 420px;
}

.chip {
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  padding: 9px 14px;
  border: 1px solid var(--line-deep);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(74, 56, 51, .05);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease);
}

.chip--a { transform: rotate(-1.6deg); background: var(--butter-soft); }
.chip--b { transform: rotate(1.2deg); background: var(--mint-soft); }
.chip--c { transform: rotate(-.9deg); background: var(--paper); }

.chip:active {
  transform: rotate(0) scale(.96);
  box-shadow: 0 1px 0 rgba(74, 56, 51, .05);
}

/* ---------- 气泡 ---------- */
.msg {
  display: flex;
  gap: 9px;
  margin-bottom: 16px;
  animation: rise .26s var(--ease) both;
}

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

.msg__avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--butter-soft);
  border: 1px solid var(--line);
  margin-top: 2px;
}

.msg__avatar .mascot { width: 20px; height: 20px; }

.bubble {
  position: relative;
  max-width: min(100%, 30em);
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 2px 0 rgba(74, 56, 51, .04), 0 10px 24px -20px rgba(74, 56, 51, .5);
  overflow-wrap: anywhere;
}

.msg--assistant .bubble { border-bottom-left-radius: 6px; }

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

.msg--user .bubble {
  background: var(--butter);
  border-color: #F2CE8B;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 0 rgba(196, 148, 60, .16);
}

.text {
  margin: 0;
  font-size: 15.5px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.is-streaming .text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.02em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 1px;
  background: var(--strawberry);
  animation: caret .95s steps(1) infinite;
}

@keyframes caret { 0%, 55% { opacity: 1; } 56%, 100% { opacity: .12; } }

.msg--error .bubble {
  background: #FFF1EE;
  border-color: #F3C9C1;
}

.msg--error .bubble .text { color: var(--strawberry-deep); }

.retry {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: none;
  color: var(--strawberry-deep);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}

/* ---------- 思考过程 ---------- */
.think {
  margin: 0 0 10px;
  padding: 9px 12px;
  border: 1px dashed var(--mint);
  border-radius: 12px;
  background: var(--mint-soft);
  color: #4C7067;
}

.think > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  list-style: none;
}

.think > summary::-webkit-details-marker { display: none; }
.think > summary::before { content: "✿"; font-size: 11px; opacity: .75; }
.think[open] > summary { margin-bottom: 6px; }

.think__body {
  font-size: 13px;
  line-height: 1.68;
  white-space: pre-wrap;
  max-height: 40vh;
  overflow-y: auto;
  opacity: .92;
}

/* ---------- 正在想 ---------- */
.dots { display: flex; align-items: center; gap: 5px; padding: 3px 2px 4px; }

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cocoa-soft);
  animation: hop 1.15s var(--ease) infinite;
}

.dots span:nth-child(2) { animation-delay: .14s; }
.dots span:nth-child(3) { animation-delay: .28s; }

@keyframes hop {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px);
  background: linear-gradient(to top, var(--milk) 80%, rgba(255, 246, 236, .92) 100%);
}

.composer__field {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 15px;
  border: 1.5px solid var(--line-deep);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(74, 56, 51, .04), 0 12px 28px -22px rgba(74, 56, 51, .6);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}

.composer__field:focus-within {
  border-color: #F0B7A6;
  box-shadow: 0 0 0 4px rgba(232, 121, 108, .1), 0 12px 28px -22px rgba(74, 56, 51, .6);
}

#input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 34vh;
  padding: 7px 0 8px;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.55;
  resize: none;
  outline: none;
}

#input::placeholder { color: var(--cocoa-soft); }

.send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--butter);
  color: var(--ink);
  cursor: pointer;
  transition: transform .14s var(--ease), background .18s var(--ease), opacity .18s var(--ease);
}

.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.send__stop { display: none; fill: currentColor; stroke: none; }
.send:active { transform: scale(.9); }

.send[disabled] { opacity: .45; cursor: default; }

.send.is-stop { background: var(--strawberry); color: #fff; }
.send.is-stop .send__arrow { display: none; }
.send.is-stop .send__stop { display: block; }

.composer__hint {
  margin: 0;
  height: 0;
  overflow: hidden;
  font-size: 12.5px;
  color: var(--cocoa);
  text-align: center;
  transition: height .2s var(--ease), margin .2s var(--ease);
}

.composer__hint[data-action="settings"] {
  color: var(--strawberry-deep);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.composer__hint.is-on { height: 20px; margin-top: 8px; }

/* ---------- 遮罩 / 抽屉 / 面板 ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(74, 56, 51, .26);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .22s var(--ease);
}

.scrim.is-on { opacity: 1; }
.scrim[hidden] { display: none; }

.drawer {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(84vw, 322px);
  display: flex;
  flex-direction: column;
  background: var(--milk);
  border-right: 1px solid var(--line-deep);
  box-shadow: 12px 0 40px -24px rgba(74, 56, 51, .6);
  transform: translateX(-102%);
  transition: transform .28s var(--ease);
  visibility: hidden;
}

.drawer.is-open { transform: translateX(0); visibility: visible; }

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 12px;
  border-bottom: 1px dashed var(--line-deep);
}

.drawer__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .06em;
}

.text-btn {
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--strawberry-deep);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.drawer__list { flex: 1 1 auto; overflow-y: auto; padding: 10px 10px 0; }

.session {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .16s var(--ease);
}

.session:active { background: var(--milk-deep); }
.session.is-active { background: var(--paper); border-color: var(--line); }

.session__main { flex: 1 1 auto; min-width: 0; }

.session__title {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session__meta {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--cocoa-soft);
}

.session__del {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cocoa-soft);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.session__del.is-armed { background: #FFF1EE; color: var(--strawberry-deep); font-weight: 600; }

.drawer__empty {
  padding: 40px 16px;
  text-align: center;
  font-size: 13.5px;
  color: var(--cocoa-soft);
}

.drawer__foot {
  flex: 0 0 auto;
  margin: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 14px);
  border-top: 1px dashed var(--line-deep);
  font-size: 11.5px;
  color: var(--cocoa-soft);
  text-align: center;
}

.sheet {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--milk);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line-deep);
  box-shadow: 0 -18px 50px -30px rgba(74, 56, 51, .8);
  transform: translateY(102%);
  transition: transform .3s var(--ease);
  visibility: hidden;
  max-width: 780px;
  margin: 0 auto;
}

.sheet.is-open { transform: translateY(0); visibility: visible; }

.sheet__grip {
  width: 38px;
  height: 4px;
  margin: 9px auto 0;
  border-radius: 2px;
  background: var(--line-deep);
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 8px;
}

.sheet__head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .05em; }

.sheet__body {
  overflow-y: auto;
  padding: 4px 18px calc(env(safe-area-inset-bottom) + 22px);
}

.field { display: block; margin-bottom: 18px; }

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

.field__opt { color: var(--cocoa-soft); font-weight: 400; }

.field__row { display: flex; align-items: center; gap: 10px; }

.field__row input { flex: 1 1 auto; min-width: 0; width: auto; }

.field__row .text-btn { flex: 0 0 auto; white-space: nowrap; padding-inline: 4px; }

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line-deep);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}

.field input:focus { border-color: #F0B7A6; box-shadow: 0 0 0 4px rgba(232, 121, 108, .1); }
.field input::placeholder { color: var(--cocoa-soft); }

.field__note {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--cocoa);
}

.models { display: grid; gap: 8px; }

.model {
  display: block;
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--line-deep);
  border-radius: 12px;
  background: var(--paper);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}

.model__name { display: block; font-size: 14px; font-weight: 600; }
.model__desc { display: block; margin-top: 2px; font-size: 12px; color: var(--cocoa); }

.model[aria-checked="true"] {
  border-color: var(--strawberry);
  background: #FFF3EF;
}

.model[aria-checked="true"] .model__name::after {
  content: "✓";
  margin-left: 6px;
  color: var(--strawberry-deep);
}

.danger-btn {
  width: 100%;
  padding: 12px;
  border: 1.5px solid #F0C4BB;
  border-radius: 12px;
  background: #FFF1EE;
  color: var(--strawberry-deep);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.danger-btn:active { background: #FCE4DF; }

.sheet__foot {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: var(--cocoa-soft);
  text-align: center;
}

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  margin: 0;
  max-width: 82vw;
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(74, 56, 51, .93);
  color: #FFF6EC;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 无障碍 / 动效偏好 ---------- */
:focus-visible { outline: 2px solid var(--strawberry); outline-offset: 2px; border-radius: 8px; }

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

@media (min-width: 480px) {
  .chat { padding: 22px 22px 6px; }
  .composer { padding-inline: 22px; }
  .text { font-size: 16px; }
}
