:root {
  --paper: #faf8f4;
  --card: #fffefb;
  --ink: #24211d;
  --ink-soft: #4a453e;
  --muted: #918a7e;
  --line: #e8e2d6;
  --line-soft: #f1ece2;
  --accent: #b4552f;
  --green: #3d6a51;
  --amber: #9a6b25;
  --radius: 18px;
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif SC", "STSong", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% 0 auto 0;
  height: 460px;
  background: radial-gradient(60% 70% at 50% 0%, rgba(196, 160, 118, 0.16), rgba(250, 248, 244, 0) 72%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 44px 24px 90px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 34px;
}

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

.brand__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 254, 251, 0.7);
  color: var(--ink);
}

.brand__name {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--ink);
}

.boot-hint {
  margin: 0 0 18px;
  padding: 11px 14px;
  border: 1px solid #e6d9c4;
  border-radius: 12px;
  background: #fbf4e7;
  color: #8a6a35;
  font-size: 12.5px;
  line-height: 1.7;
}

.boot-hint[hidden] { display: none; }

/* ---------- intro ---------- */

.intro {
  padding: 8px 2px 30px;
  transition: opacity 220ms ease, transform 220ms ease;
}

.intro__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(26px, 4.8vw, 32px);
  line-height: 1.42;
  letter-spacing: 0.015em;
}

.intro__sub {
  margin: 14px 0 0;
  font-size: 14px;
  line-height: 1.8;
  color: var(--muted);
  max-width: 30em;
}

.intro.is-hidden {
  display: none;
}

/* ---------- thread ---------- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin-bottom: 26px;
}

.thread:empty { display: none; }

.msg {
  animation: rise 320ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.msg--user {
  align-self: flex-end;
  max-width: 92%;
  background: #f3eee4;
  border: 1px solid #eae3d6;
  border-radius: 16px 16px 4px 16px;
  padding: 14px 17px;
}

.msg--user .msg__item {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

.msg--user .msg__line {
  margin-top: 7px;
  font-size: 13px;
  line-height: 1.7;
  color: #6d665b;
  display: flex;
  gap: 8px;
}

.msg--user .msg__line b {
  flex: none;
  font-weight: 400;
  color: #a49b8c;
}

.msg--user .msg__line span {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg--agent {
  align-self: stretch;
  max-width: 100%;
}

.msg__who {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.msg__who::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.msg__text {
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink-soft);
  margin: 0;
  text-wrap: pretty;
  white-space: pre-wrap;
}

.msg--agent > .tag {
  display: inline-block;
  margin-bottom: 8px;
}

.retry {
  margin-top: 12px;
  appearance: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #6d665b;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease;
}

.retry:hover {
  border-color: #d3c8b5;
  color: var(--ink);
}

.msg__pending {
  margin-top: 14px;
  border: 1px dashed #ddd5c6;
  border-radius: 13px;
  padding: 15px 17px;
  background: rgba(255, 254, 251, 0.55);
}

.msg__pending strong {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 5px;
}

.msg__pending p {
  margin: 0;
  font-size: 13px;
  line-height: 1.75;
  color: #8f8778;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0 2px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #c3b9a7;
  animation: blink 1.1s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

/* ---------- composer ---------- */

.composer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 1px rgba(36, 33, 29, 0.03), 0 18px 40px -30px rgba(36, 33, 29, 0.4);
  overflow: hidden;
  transition: border-color 200ms ease, box-shadow 240ms ease;
}

.composer:focus-within {
  border-color: #d9cfbc;
  box-shadow: 0 1px 1px rgba(36, 33, 29, 0.04), 0 22px 50px -30px rgba(36, 33, 29, 0.45);
}

.field {
  padding: 15px 18px 16px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 180ms ease;
}

.field:focus-within { background: #fdfbf5; }

.field__label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  letter-spacing: 0.13em;
  color: var(--muted);
  margin-bottom: 4px;
  transition: color 180ms ease;
}

.field__label .num {
  color: #c4bbaa;
  font-variant-numeric: tabular-nums;
}

.field:focus-within .field__label { color: var(--accent); }

.field__control {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 2px 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  resize: none;
  overflow: hidden;
}

.field__control::placeholder {
  color: #c6bdae;
  opacity: 1;
}

.composer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px 11px 18px;
}

.composer__hint {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #b3aa9a;
}

.send {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 17px 9px 19px;
  border-radius: 999px;
  background: var(--ink);
  color: #fbf7ee;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.09em;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.send svg { transition: transform 200ms ease; }

.send:hover { background: #35302a; }
.send:hover svg { transform: translateX(2px); }
.send:active { transform: scale(0.98); }

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

/* ---------- 追问轮次 ---------- */

.round__branch {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 11px;
  letter-spacing: 0.13em;
  color: var(--muted);
}

.round__branch b {
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.round__section {
  margin-bottom: 15px;
}

.round__section h4 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.round__section p {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--ink-soft);
  white-space: pre-wrap;
  text-wrap: pretty;
}

.round__section.is-muted p {
  font-size: 13px;
  color: #8f8778;
}

.qlist {
  margin-top: 20px;
  display: grid;
  gap: 18px;
}

.q {
  padding-top: 15px;
  border-top: 1px solid var(--line-soft);
}

.q__head {
  display: flex;
  gap: 11px;
  align-items: baseline;
}

.q__num {
  flex: none;
  font-size: 11px;
  color: #c0b7a7;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.q__text {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ink);
  text-wrap: pretty;
}

.q__options {
  margin: 10px 0 0 25px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.opt {
  appearance: none;
  border: 1px solid var(--line);
  background: #fffefb;
  border-radius: 999px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  color: #5f584d;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.opt:hover {
  border-color: #d3c8b5;
  color: var(--ink);
}

.opt.is-selected {
  background: var(--ink);
  border-color: var(--ink);
  color: #fbf7ee;
}

.q__other {
  display: block;
  width: calc(100% - 25px);
  margin: 10px 0 0 25px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  padding: 4px 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: 0;
  transition: border-color 160ms ease;
}

.q__other::placeholder {
  color: #c6bdae;
}

.q__other:focus {
  border-color: #d9cfbc;
}

.q.is-missing .q__text {
  color: #a2432c;
}

.q.is-missing .q__other {
  border-color: #c98a6f;
}

.round__submit {
  margin-top: 22px;
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 19px;
  border-radius: 999px;
  background: var(--ink);
  color: #fbf7ee;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.06em;
  transition: background 160ms ease, opacity 160ms ease;
}

.round__submit:hover {
  background: #35302a;
}

.round__submit[disabled],
.qlist button[disabled],
.qlist input[disabled] {
  opacity: 0.5;
  cursor: default;
}

.msg--answers {
  padding-top: 13px;
}

.msg--answers .msg__line b {
  min-width: 18px;
}

.msg--agent > .retry:last-child {
  margin-top: 16px;
}

/* ---------- 结语画像 ---------- */

.summary {
  margin-top: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: #fffdf8;
  padding: 18px 18px 16px;
}

.summary__row {
  display: grid;
  grid-template-columns: 6.4em 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}

.summary__row:first-child { padding-top: 0; }
.summary__row:last-child { border-bottom: 0; padding-bottom: 0; }

.summary__label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: #a79e8e;
  padding-top: 3px;
}

.summary__value {
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.summary__row.is-key .summary__value {
  color: var(--ink);
  font-size: 14.5px;
}

/* ---------- history ---------- */

.history {
  margin-top: 60px;
}

.history__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.history__title {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.history__count {
  font-size: 11px;
  color: #c0b7a7;
  letter-spacing: 0.06em;
}

.history__list {
  display: flex;
  flex-direction: column;
}

.history__empty {
  padding: 22px 2px;
  font-size: 13px;
  color: #a79e8e;
}

.record {
  border-bottom: 1px solid var(--line-soft);
}

.record__row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
  border: 0;
  background: none;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: padding 200ms ease;
}

.record__row:hover { padding-left: 6px; }

.record__main {
  flex: 1;
  min-width: 0;
}

.record__item {
  display: block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record__meta {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: #a79e8e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag {
  flex: none;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.tag--active { color: var(--amber); background: rgba(154, 107, 37, 0.08); border-color: rgba(154, 107, 37, 0.18); }
.tag--done { color: var(--green); background: rgba(61, 106, 81, 0.08); border-color: rgba(61, 106, 81, 0.16); }
.tag--yes { color: var(--green); background: rgba(61, 106, 81, 0.08); border-color: rgba(61, 106, 81, 0.16); }
.tag--no { color: #a2432c; background: rgba(162, 67, 44, 0.07); border-color: rgba(162, 67, 44, 0.15); }
.tag--wait { color: var(--amber); background: rgba(154, 107, 37, 0.08); border-color: rgba(154, 107, 37, 0.18); }
.tag--pending { color: #8f8778; background: rgba(143, 135, 120, 0.07); border-color: rgba(143, 135, 120, 0.16); }

.record__chev {
  flex: none;
  color: #c3b9a8;
  display: grid;
  place-items: center;
  transition: transform 240ms ease;
}

.record.is-open .record__chev { transform: rotate(180deg); }

.record__detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.record.is-open .record__detail { grid-template-rows: 1fr; }

.record__inner {
  min-height: 0;
  overflow: hidden;
}

.record__content {
  padding: 2px 2px 18px;
  display: grid;
  gap: 11px;
}

.record__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 2px 20px;
}

.record__actions [hidden] { display: none; }

.record__delete,
.record__cancel {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: #a49b8c;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.record__delete:hover {
  color: #a2432c;
  border-color: rgba(162, 67, 44, 0.22);
}

.record__delete.is-confirm {
  color: #a2432c;
  border-color: rgba(162, 67, 44, 0.32);
  background: rgba(162, 67, 44, 0.06);
}

.record__cancel:hover {
  color: var(--ink);
  border-color: var(--line);
}

.record__enter {
  margin: 0;
  justify-self: start;
  appearance: none;
  border: 1px solid var(--line);
  background: #fffefb;
  border-radius: 999px;
  padding: 7px 16px;
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.record__enter:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #fbf7ee;
}

/* ---------- 会话回看 ---------- */

.session-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 2px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 22px;
}

.session-bar[hidden] { display: none; }

.session-bar__back {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 2px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  transition: color 160ms ease;
}

.session-bar__back:hover { color: var(--ink); }

.session-bar__title {
  font-size: 13px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-block { display: flex; gap: 12px; font-size: 13px; line-height: 1.75; }

.detail-block dt {
  flex: none;
  width: 34px;
  color: #a79e8e;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding-top: 2px;
}

.detail-block dd {
  margin: 0;
  color: var(--ink-soft);
  text-wrap: pretty;
  white-space: pre-wrap;
}

.footnote {
  margin: 40px 0 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #bdb4a4;
  text-align: center;
  display: grid;
  gap: 4px;
}

.footnote p {
  margin: 0;
  line-height: 1.8;
  text-wrap: pretty;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: #fbf7ee;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
  z-index: 20;
}

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

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 520px) {
  .app { padding: 30px 18px 70px; }
  .topbar { padding-bottom: 26px; }
  .composer__hint { display: none; }
  .composer__foot { justify-content: flex-end; }
  .msg--user { max-width: 100%; }
  .history { margin-top: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}