:root {
  --bg: #ededed;
  --panel: #ffffff;
  --text: #191919;
  --text-2: #8a8a8a;
  --line: #e2e2e2;
  --green: #95ec69;
  --green-deep: #07c160;
  --blue: #576b95;
  --danger: #e64340;
  --radius: 10px;
}

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

/* 关键修复：下面的 .notice-bar / .chat-view / .icon-btn 都设置了 display:flex，
   浏览器默认的 [hidden]{display:none} 会被这些作者样式覆盖，
   导致 hidden 属性失效（提示条关不掉、多个界面叠在一起）。这里显式兜住。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

.app { height: 100%; max-width: 720px; margin: 0 auto; background: var(--bg); position: relative; overflow-x: hidden; }
.view { height: 100%; }

/* ---------- 通用 ---------- */
.center-box {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
}

.hint { color: var(--text-2); font-size: 13px; line-height: 1.6; margin: 8px 0 0; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #d8d8d8; border-top-color: var(--green-deep);
  animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand { text-align: center; margin-bottom: 28px; }
.brand-avatar {
  width: 68px; height: 68px; border-radius: 12px; margin: 0 auto 14px;
  background: #2b2b2b; color: #fff; font-size: 26px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.brand-avatar img { width: 100%; height: 100%; object-fit: cover; }
.brand h1 { font-size: 20px; font-weight: 500; margin: 0; }

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: block; text-align: left; }
.label {
  display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px;
}
.label-tip { color: #b0b0b0; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: var(--radius); padding: 12px 14px; font-size: 16px;
  font-family: inherit; outline: none; appearance: none;
}
.field textarea { line-height: 1.6; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: #b7e6a8; }

.code-row { display: flex; gap: 10px; }
.code-row input { flex: 1 1 auto; min-width: 0; width: auto; }
.btn-ghost {
  flex: 0 0 auto; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--blue);
  font-size: 14px; font-family: inherit;
}
.btn-ghost:disabled { color: #bbb; }

.btn-primary {
  width: 100%; border: 0; border-radius: var(--radius); padding: 13px;
  background: var(--green-deep); color: #fff; font-size: 16px; font-family: inherit;
}
.btn-primary:disabled { background: #a8e0b8; }
.btn-danger {
  border: 1px solid #f0c2c0; background: #fff; color: var(--danger);
  border-radius: var(--radius); padding: 12px; font-size: 15px; font-family: inherit;
}
.btn-text {
  width: 100%; border: 0; background: none; color: var(--text-2);
  font-size: 14px; padding: 14px 0 0; font-family: inherit;
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn-primary { flex: 2; }
.btn-row .btn-danger { flex: 1; }

.form-error, .field-error {  color: var(--danger); font-size: 13px; margin: 6px 0 0; line-height: 1.5;
}
.footnote { color: #a5a5a5; font-size: 12px; line-height: 1.6; margin: 12px 0 0; text-align: center; }

/* ---------- 设置页 ---------- */
.sheet {
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg);
}
.sheet-title { font-size: 19px; font-weight: 500; margin: 0; }
.sheet-sub { font-size: 13px; color: var(--text-2); margin: 0 0 4px; line-height: 1.6; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head .sheet-title { flex: 1; text-align: center; }

/* ---------- 聊天页 ---------- */
.chat-view { display: flex; flex-direction: column; background: var(--bg); }

.chat-header {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: #ededed;
  border-bottom: 1px solid #dedede;
}
.chat-title { flex: 1; text-align: center; font-size: 16px; font-weight: 500; }
.chat-state { display: block; font-size: 11px; color: var(--text-2); font-weight: 400; margin-top: 2px; }
.icon-btn {
  width: 34px; height: 34px; border: 0; background: none; color: var(--text);
  font-size: 22px; line-height: 1; padding: 0; border-radius: 8px; font-family: inherit;
}

.notice-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: #fdf6e3; color: #8a6d1f; font-size: 12px;
  padding: 8px 12px; border-bottom: 1px solid #f0e6cc;
}
.notice-bar span { flex: 1; line-height: 1.5; }
.notice-bar button {
  border: 0; background: none; color: #b09a5e; font-size: 16px; padding: 0 2px; line-height: 1;
}

.messages {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 12px 18px;
  display: flex; flex-direction: column; gap: 12px;
}

.msg { display: flex; gap: 9px; max-width: 100%; }
.msg .avatar {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 6px;
  background: #2b2b2b; color: #fff; font-size: 15px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.msg .avatar img { width: 100%; height: 100%; object-fit: cover; }
.bubble {
  position: relative; max-width: 68%;
  background: #fff; color: var(--text);
  border-radius: 6px; padding: 9px 12px;
  font-size: 15.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.msg.out { flex-direction: row-reverse; }
.msg.out .bubble { background: var(--green); }
.msg .bubble.typing { color: var(--text-2); }
.msg .bubble.failed {
  color: var(--text-2); background: #f4f4f4;
  box-shadow: inset 0 0 0 1px #e2e2e2; cursor: pointer;
}

/* 聊天记录里的图片缩略图 */
.bubble.img-bubble { padding: 4px; background: #fff; }
.bubble.img-bubble img {
  display: block; width: 180px; max-width: 100%; height: auto; border-radius: 4px;
}
.bubble.img-bubble .img-cap { padding: 4px 6px 2px; font-size: 14px; color: var(--text-2); }

/* 看大图 */
.img-viewer {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; gap: 10px;
}
.img-viewer img {
  max-width: 96vw; max-height: 82vh; object-fit: contain;
  border-radius: 6px; background: #111;
}
.img-viewer .loading { color: #ddd; font-size: 13px; }

.empty-tip {
  margin: auto; text-align: center; color: #a8a8a8; font-size: 13px; line-height: 1.8;
  padding: 24px;
}

/* ---------- 聊天记录查看 ---------- */
.inbox-item {
  flex: 0 0 auto; width: 100%; text-align: left; font-family: inherit;
  background: #fff; border: 0; border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 5px;
}
.inbox-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.inbox-name { font-size: 15px; font-weight: 500; color: var(--text); }
.inbox-time { font-size: 12px; color: var(--text-2); flex: 0 0 auto; }
.inbox-preview {
  font-size: 13.5px; color: var(--text-2); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.inbox-meta { font-size: 11px; color: #b0b0b0; }

.composer {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #f7f7f7; border-top: 1px solid #dedede;
}
.composer textarea {
  flex: 1; border: 0; border-radius: 6px; padding: 10px 12px;
  background: #fff; font-size: 16px; font-family: inherit; line-height: 1.4;
  resize: none; outline: none; max-height: 120px;
}
.send-btn {
  flex: 0 0 auto; border: 0; border-radius: 6px; padding: 9px 16px;
  background: var(--green-deep); color: #fff; font-size: 15px; font-family: inherit;
}

/* 谈心开关 */
.talk-btn {
  flex: 0 0 auto; border: 1px solid #d8d8d8; background: #fff; color: #666;
  border-radius: 14px; padding: 4px 12px; font-size: 13px; font-family: inherit;
  margin-right: 6px;
}
.talk-btn[aria-pressed="true"] {
  background: #2b2b2b; border-color: #2b2b2b; color: #fff;
}

/* 谈心模式下的提示条 */
.chat-view.talking .notice-bar { background: #eef4ff; color: #33507a; }

/* 发图片 / 题目 */
.img-btn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: #e9e9e9; color: #555;
  font-size: 22px; line-height: 1; font-family: inherit;
  display: flex; align-items: center; justify-content: center;
}
.img-btn:active { background: #dcdcdc; }

/* 消息里的图片气泡 */
.bubble.chat-img { padding: 3px; background: #fff; }
.bubble.chat-img img { display: block; max-width: 200px; max-height: 260px; border-radius: 4px; }
.send-btn.stop { background: #f0f0f0; color: var(--text); }
.send-btn:disabled { opacity: .55; }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(0,0,0,.78); color: #fff; font-size: 13px;
  padding: 9px 14px; border-radius: 8px; max-width: 80%;
  line-height: 1.5; text-align: center; z-index: 50;
}

/* ---------- 登录补充 ---------- */
.divider {
  display: flex; align-items: center; gap: 10px;
  color: #b5b5b5; font-size: 12px; margin: 4px 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}
.btn-outline {
  width: 100%; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: var(--radius); padding: 12px; font-size: 15px; font-family: inherit;
}

/* ---------- 机器人记忆卡（聊天记录页顶部） ---------- */
.mem-card {
  margin: 12px 14px 6px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden;
}
.mem-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; cursor: pointer; user-select: none;
}
.mem-title { font-size: 14px; font-weight: 600; color: var(--text); }
.mem-count { font-size: 12px; color: var(--text-2); flex: 1; }
.mem-toggle { font-size: 12px; color: var(--green-deep); }
.mem-body { padding: 0 12px 10px; border-top: 1px solid var(--line); }
.mem-sub { font-size: 12px; color: var(--text-2); margin: 10px 0 4px; }
.mem-list { margin: 0; padding-left: 18px; }
.mem-list li { font-size: 13px; color: var(--text); line-height: 1.75; }
.mem-list.rules li { color: var(--green-deep); }
