@font-face {
  font-family: "MinxTok Sans";
  src: url("/assets/fonts/minxtok-cjk.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

/* ============================================================
   MinxTok 设计系统 · 主题与组件
   规则：颜色/圆角/间距/层级全部用变量，新组件只允许引用，不许写死
   配色：全站黑白灰，彩色仅用于 emoji
   ============================================================ */

:root {
  /* 颜色（深色为默认，纯黑白灰） */
  --bg: #0a0a0b;
  --bg-soft: #101012;
  --surface: #151517;
  --surface-2: #1c1c1f;
  --surface-3: #26262a;
  --text: #f5f5f6;
  --text-2: #c2c2c6;
  --muted: #8a8a90;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #f5f5f6;
  --accent-ink: #0a0a0b;
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 10px 34px rgba(255, 255, 255, 0.08);
  --danger: #d9d9de;

  /* 圆角 */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* 间距 */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 28px;

  /* 阴影 */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 8px 28px rgba(0, 0, 0, 0.42);
  --shadow-3: 0 20px 64px rgba(0, 0, 0, 0.58);

  /* 层级：新增浮层必须挂到对应层级，禁止随手写 9999 */
  --z-base: 0;
  --z-composer: 20;
  --z-appbar: 30;
  --z-scrim: 40;
  --z-drawer: 50;
  --z-modal: 60;
  --z-toast: 70;
  --z-overlay: 80;

  /* 字体 */
  --font: "MinxTok Sans", -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", system-ui, sans-serif;
  /* 标题单独一套：系统字体，跟正文区分开 */
  --font-title: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", system-ui, sans-serif;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
}

[data-theme="light"] {
  --bg: #f6f6f7;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --surface-3: #e4e4e7;
  --text: #101012;
  --text-2: #3f3f45;
  --muted: #77777e;
  --line: rgba(12, 12, 14, 0.08);
  --line-strong: rgba(12, 12, 14, 0.16);
  --accent: #101012;
  --accent-ink: #ffffff;
  --glow: 0 0 0 1px rgba(12, 12, 14, 0.14), 0 10px 30px rgba(12, 12, 14, 0.1);
  --danger: #303036;
  --shadow-1: 0 1px 2px rgba(12, 12, 14, 0.06);
  --shadow-2: 0 8px 28px rgba(12, 12, 14, 0.1);
  --shadow-3: 0 20px 60px rgba(12, 12, 14, 0.16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, input, textarea { outline: none; }
button:focus, input:focus, textarea:focus, button:focus-visible { outline: none; box-shadow: none; }
::selection { background: color-mix(in srgb, var(--text) 22%, transparent); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-synthesis: none;
  overscroll-behavior: none;
}

body { transition: background var(--dur-3) var(--ease-out), color var(--dur-3) var(--ease-out); }

/* ---------- 布局 ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

/* 顶栏：三栏等宽，标题绝对居中 */
.appbar {
  position: sticky;
  top: 0;
  z-index: var(--z-appbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--s-3);
  position: sticky;
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}

.appbar .title {
  font-family: var(--font-title);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: 0.4px;
  white-space: nowrap;
  pointer-events: none;
  max-width: 58%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar .left, .appbar .right { display: flex; align-items: center; gap: 2px; z-index: 1; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out), transform var(--dur-3) var(--ease-spring);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.88); }
.icon-btn svg { width: 22px; height: 22px; display: block; }
.appbar .right { display: flex; align-items: center; gap: 2px; justify-self: end; }

/* ---------- 消息区 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-4) 132px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msg { margin-bottom: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.msg .who { font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.5px; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  max-width: 82%;
  background: var(--surface-2);
  padding: 11px 15px;
  border-radius: var(--r-lg) var(--r-lg) 8px var(--r-lg);
  line-height: 1.55;
}
.msg.assistant .body { display: flex; flex-direction: column; gap: 14px; }
.msg.assistant .body > .followups { margin-top: 2px; }
.msg.assistant .text {
  font-size: var(--fs-md);
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.quote {
  border-left: 2px solid var(--line-strong);
  padding: 6px 10px;
  margin-bottom: 6px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  background: var(--surface);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}

/* ---------- 追问 ---------- */
.followups { display: flex; flex-direction: column; gap: 10px; margin-top: var(--s-3); }
.followup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-sm);
  line-height: 1.5;
  cursor: pointer;
  animation: mFollowIn 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: transform 240ms var(--ease-spring), background 200ms, border-color 200ms, color 200ms, opacity 180ms;
}
.followups .followup:nth-child(1) { animation-delay: 60ms; }
.followups .followup:nth-child(2) { animation-delay: 190ms; }
.followups .followup:nth-child(3) { animation-delay: 320ms; }
.followups .followup:nth-child(4) { animation-delay: 450ms; }

@keyframes mFollowIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); filter: blur(4px); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.followup:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--text); }
.followup:active { transform: scale(0.97); }
.followup.leaving { opacity: 0; transform: translateY(-6px) scale(0.98); pointer-events: none; }
.followup[data-used="1"] { opacity: 0.35; pointer-events: none; }

/* ---------- 卡片 ---------- */
.card {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: transform var(--dur-3) var(--ease-spring), box-shadow var(--dur-3) var(--ease-out);
}
.card:active { transform: scale(0.985); opacity: .85; }
.card.skeleton { cursor: default; }
.card.skeleton:active { transform: none; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.card .cover {
  width: 46px; height: 46px;
  border-radius: var(--r-sm);
  background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 20px;
  flex: none;
}
.card .meta { min-width: 0; flex: 1; padding-right: 2px; }
.card .meta .t { font-weight: 600; font-size: var(--fs-md); line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta .s { color: var(--muted); font-size: var(--fs-xs); line-height: 1.4; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 底部输入 ---------- */
.composer {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  z-index: var(--z-composer);
  padding: var(--s-3) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}

.composer .row {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow-2);
  transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
}
.composer .row:focus-within {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 6%, transparent), var(--shadow-2);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  max-height: 120px;
  padding: 9px 0;
}
.composer textarea::placeholder { color: var(--muted); letter-spacing: 0.2px; }

.composer .send {
  width: 38px; height: 38px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform var(--dur-3) var(--ease-spring), opacity var(--dur-2), background var(--dur-2);
}
.composer .send svg { width: 18px; height: 18px; }
.composer .send:active { transform: scale(0.9); }
.composer .send:disabled { opacity: 0.35; }

/* 通用按钮 */
.btn {
  border: 0;
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform var(--dur-3) var(--ease-spring), box-shadow var(--dur-3) var(--ease-out), opacity var(--dur-2);
}
.btn:active { transform: scale(0.94); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line-strong); }

/* 额度 */
.quota {
  position: fixed;
  right: max(20px, calc(50% - 340px));
  bottom: 92px;
  z-index: var(--z-composer);
  font-size: var(--fs-xs);
  color: var(--muted);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
}

/* ---------- 遮罩 / 抽屉 ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out);
}
.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(78vw, 320px);
  z-index: var(--z-drawer);
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  transform: translate3d(-100%, 0, 0);
  transition: transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  padding: calc(var(--s-5) + env(safe-area-inset-top)) var(--s-4) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.drawer.show { transform: translate3d(0, 0, 0); }
.drawer .brand { font-family: var(--font-title); font-size: var(--fs-xl); font-weight: 700; letter-spacing: 0.3px; margin: 0 0 var(--s-4) var(--s-2); }
.drawer .item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 13px 14px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring), color var(--dur-2);
}
.drawer .item:hover { background: var(--surface-2); color: var(--text); }
.drawer .item:active { transform: scale(0.98); }
.drawer .item.active { color: var(--text); }
.drawer .ico { width: 20px; height: 20px; flex: none; opacity: .85; }

/* ---------- 弹窗 ---------- */
.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--s-4);
  pointer-events: none;
}
.modal {
  width: min(92vw, 420px);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateY(8px);
  transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-4) var(--ease-spring);
}
.modal-wrap.show { pointer-events: auto; }
.modal-wrap.show .modal { opacity: 1; transform: scale(1) translateY(0); }
.modal-head {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
}
.modal-head .h-title { flex: 1; font-weight: 600; font-size: var(--fs-lg); }
.modal-body { padding: var(--s-4); color: var(--text-2); line-height: 1.6; }

/* 设置行 */
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: 0; }
.set-row .k { color: var(--text); }

/* 搜索框 */
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: 10px 14px;
  border: 1px solid var(--line);
}
.search-box input {
  flex: 1; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit;
}
.search-hit {
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.search-hit b { color: var(--text); font-weight: 600; }

/* 情绪中心 */
.mood-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2); }
.mood {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--r-md);
  padding: 14px 0;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-2), transform var(--dur-3) var(--ease-spring);
}
.mood:active { transform: scale(0.92); }
.mood:hover { background: var(--surface-2); }

/* ---------- 提示条 ---------- */
.toasts {
  position: fixed;
  left: 50%; bottom: 116px;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--s-2);
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  padding: 9px 16px;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }


/* ---------- 启动页 ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity 420ms var(--ease-out), filter 420ms var(--ease-out);
}
body:not(.loading) #splash {
  opacity: 0;
  filter: blur(8px);
  pointer-events: none;
}
#app { opacity: 0; transition: opacity 360ms var(--ease-out); }
body:not(.loading) #app { opacity: 1; }
.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--text-2); }
.splash-face { width: 46px; height: 46px; opacity: .9; animation: mFadeUp 600ms var(--ease-out) both; }
.splash-brand {
  font-family: var(--font-title);
  font-size: 19px;
  letter-spacing: 1px;
  color: var(--text);
  animation: mFadeUp 600ms var(--ease-out) 80ms both;
}
.splash-bar {
  width: 64px; height: 2px; border-radius: 2px; overflow: hidden;
  background: var(--surface-3);
}
.splash-bar i {
  display: block; height: 100%; width: 40%;
  background: var(--text-2);
  animation: splashRun 1.1s var(--ease-in-out) infinite;
}
@keyframes splashRun {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(260%); }
}
