:root {
  --bg: #0e1014;
  --bg-soft: #151922;
  --bg-card: #1a1f2a;
  --bg-input: #1e2430;
  --border: #262d3b;
  --text: #e8ecf3;
  --text-dim: #9aa4b6;
  --accent: #7c8cff;
  --accent-soft: rgba(124, 140, 255, 0.16);
  --user-bubble: linear-gradient(135deg, #5b6cff, #7c5bff);
  --dragon: #ff6b81;
  --radius: 16px;
  --font-scale: 1;
  --maxw: 880px;
  /* 动效曲线：出场用 ease-out 顺滑，回弹类用 spring */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.46, 0.64, 1);
  --fast: 0.16s;
  --normal: 0.24s;
  --slow: 0.34s;
  color-scheme: dark;
}

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

@keyframes riseIn {
  from { opacity: 0; transform: translate3d(0, 9px, 0); }
  to { opacity: 1; transform: none; }
}
@keyframes riseInSoft {
  from { opacity: 0; transform: translate3d(0, 5px, 0) scale(0.99); }
  to { opacity: 1; transform: none; }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translate3d(0, 10px, 0) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes bubbleInRight {
  from { opacity: 0; transform: translate3d(12px, 6px, 0) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes bannerIn {
  from { opacity: 0; transform: translate3d(0, -100%, 0); }
  to { opacity: 1; transform: none; }
}
@keyframes cardIn {
  from { opacity: 0; transform: translate3d(0, 26px, 0) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes caretBlink { 0%, 45% { opacity: 1; } 55%, 100% { opacity: 0.15; } }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  /* 移动端正文基准 16px（低于这个 iOS 会自动缩放，也不利于阅读） */
  font-size: calc(16px * var(--font-scale));
  line-height: 1.55;
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
/* touch-action: manipulation 去掉移动端点击延迟 */
button { cursor: pointer; touch-action: manipulation; }

/* 键盘操作的可见焦点环（不用它就没法知道焦点在哪） */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

.muted { color: var(--text-dim); }
.error-text { color: #ff7a7a; min-height: 1.2em; margin: 6px 0 0; font-size: 0.9em; }
code { background: var(--bg-input); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
[hidden] { display: none !important; }

/* ---------------- 登录 ---------------- */
.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 30% 0%, #1c2340, var(--bg) 60%);
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  animation: cardIn var(--slow) var(--ease-out) both;
}
.login-logo { display: flex; justify-content: center; }
.login-logo .app-logo { width: 56px; height: 56px; }
.director-title { display: inline-flex; align-items: center; gap: 6px; }
.director-title svg { width: 15px; height: 15px; }
.login-card h1 { font-size: 1.35em; margin: 8px 0 4px; }
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%;
  margin: 14px 0 10px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  text-align: center;
  letter-spacing: 0.02em;
}
.row-check { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--text-dim); font-size: 0.9em; margin-bottom: 14px; }
.hint { margin-top: 18px; text-align: left; color: var(--text-dim); font-size: 0.85em; }
.hint summary { cursor: pointer; }

/* ---------------- 布局 ---------------- */
/*
 * 整个 App 的外壳。
 * 安卓 WebView 版本参差不齐：100dvh（Chrome 108+）和 inset（87+）在旧版上直接失效，
 * 一旦失效高度就塌成 0，底部导航会跑到最上面去。所以这里用最保守的写法兜底：
 * 先用四边定位撑满屏幕，能用 dvh 的浏览器再拿 dvh 修掉地址栏高度差。
 */
.app {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@supports (height: 100dvh) {
  .app { bottom: auto; height: 100dvh; }
}
.content { flex: 1; position: relative; overflow: hidden; }

/* 公网链接开启时一直挂在顶部，随手能关 */
.tunnel-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px; /* 兜底 */
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: linear-gradient(90deg, rgba(255, 107, 129, 0.22), rgba(255, 107, 129, 0.07));
  border-bottom: 1px solid rgba(255, 107, 129, 0.4);
  color: #ffd9df;
  font-size: 0.8em;
  animation: bannerIn var(--slow) var(--ease-out) both;
}
.tunnel-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dragon);
  box-shadow: 0 0 8px rgba(255, 107, 129, 0.8);
  flex: 0 0 auto;
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.tunnel-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tunnel-text small {
  color: #ffb3bf;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.tunnel-banner .btn { padding: 5px 11px; font-size: 0.88em; flex: 0 0 auto; }
.view {
  position: absolute;
  /* 旧 WebView 不认 inset，用四边定位兜底 */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, 12px, 0);
  transition:
    opacity var(--normal) var(--ease-out),
    transform var(--slow) var(--ease-out),
    visibility 0s linear var(--slow);
}
.view.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition:
    opacity var(--normal) var(--ease-out),
    transform var(--slow) var(--ease-out),
    visibility 0s;
}
.view-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px; /* 老浏览器不认 env() 时的兜底 */
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  border-bottom: 1px solid var(--border);
  /* 老内核不支持 backdrop-filter，半透明背景会透出下面的内容，所以先给纯色 */
  background: var(--bg);
  min-height: 56px;
}
@supports ((backdrop-filter: blur(4px)) or (-webkit-backdrop-filter: blur(4px))) {
  .view-header,
  .composer,
  .tabbar {
    background: rgba(14, 16, 20, 0.93);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}
.view-header h2 { font-size: 1.1em; margin: 0; flex: 1; font-weight: 600; }
.header-actions { display: flex; gap: 6px; }

/* ---------------- 列表 ---------------- */
.list { flex: 1; overflow-y: auto; padding: 10px; -webkit-overflow-scrolling: touch; }
.list-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  animation: riseInSoft var(--normal) var(--ease-out) both;
  animation-delay: var(--i-delay, 0ms);
  transition:
    background var(--fast) var(--ease-out),
    border-color var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-out);
}
.list-item:active { background: var(--bg-input); transform: scale(0.985); }
.list-item-body { flex: 1; min-width: 0; }
.list-item-body strong { display: block; font-size: 1em; }
.list-item-body p {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 0.86em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-time { color: var(--text-dim); font-size: 0.75em; white-space: nowrap; }
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-dim);
  animation: riseIn var(--slow) var(--ease-out) both;
}
.empty .btn { margin-top: 14px; }

/* ---------------- 头像 ---------------- */
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
  font-size: 1.3em;
  color: #cfd6ff;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 34px; height: 34px; border-radius: 11px; font-size: 1em; }

/* ---------------- 聊天 ---------------- */
.chat-view { background: var(--bg); }
.chat-header { display: flex; }
.chat-title { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; }
.chat-title-text { min-width: 0; }
.chat-title-text strong { display: block; font-size: 0.98em; }
.chat-title-text small { font-size: 0.75em; display: block; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* 用相邻兄弟间距代替 flex gap：老内核（Chrome 84 以下）不支持 gap，会挤在一起 */
.messages > * + * { margin-top: 14px; }
.msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
}
.msg.enter { animation: bubbleIn var(--normal) var(--ease-out) both; }
.msg.enter.user { animation-name: bubbleInRight; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { width: 34px; height: 34px; border-radius: 11px; font-size: 1em; }
.msg-body { max-width: 84%; min-width: 0; }
.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  word-break: break-word;
  white-space: pre-wrap;
  transition: background var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}
.bubble.streaming::after {
  content: "▍";
  margin-left: 2px;
  color: var(--accent);
  animation: caretBlink 1s steps(1, end) infinite;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border-color: transparent;
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg.assistant .bubble { border-bottom-left-radius: 6px; }
.bubble em { color: #c7b7ff; font-style: italic; }
.msg.user .bubble em { color: #e6dcff; }
.bubble .say { color: #ffd79a; }
.msg.user .bubble .say { color: #ffe9c4; }
.bubble pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 10px;
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-size: 0.9em;
}
.bubble code { background: rgba(0, 0, 0, 0.3); }
.msg-meta { font-size: 0.75em; color: var(--text-dim); margin: 4px 4px 0; display: flex; gap: 8px; }
.msg.user .msg-meta { justify-content: flex-end; }
/* 消息下的操作：只用图标，平时淡淡的，按下去才高亮 */
.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  opacity: 0.5;
  transition: opacity var(--normal) var(--ease-out);
}
.msg-actions:hover,
.msg-actions:focus-within { opacity: 1; }
/* 触屏设备没有 hover，默认就让它更清楚一点 */
@media (hover: none) {
  .msg-actions { opacity: 0.8; }
}
.msg-actions button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  touch-action: manipulation;
  transition:
    color var(--fast) var(--ease-out),
    background var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-out);
}
.msg-actions button svg { width: 17px; height: 17px; display: block; }
.msg-actions button:active { color: var(--text); background: var(--bg-input); transform: scale(0.9); }
.msg-actions button.danger:active { color: #ff8f8f; }

/* 本轮使用的导演提示 */
.msg-directive {
  font-size: 0.75em;
  color: #b9a8ff;
  margin: 0 4px 4px;
  text-align: right;
  opacity: 0.85;
  overflow-wrap: anywhere;
}
.msg.assistant .msg-directive { text-align: left; }
.reasoning {
  margin-top: 8px;
  padding: 8px 12px;
  border-left: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 10px 10px 0;
  color: var(--text-dim);
  font-size: 0.85em;
  white-space: pre-wrap;
}
.reasoning summary { cursor: pointer; font-size: 0.85em; }
.edit-area {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  resize: vertical;
}
.typing { display: flex; gap: 4px; padding: 0 20px 8px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---------------- 输入区 ---------------- */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 10px; /* 兜底 */
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
}
.quick-row { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.quick-row::-webkit-scrollbar { display: none; }

/* ---------------- 剧情提示（导演面板） ---------------- */
.director-panel {
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(124, 140, 255, 0.35);
  background: linear-gradient(180deg, rgba(124, 140, 255, 0.14), rgba(124, 140, 255, 0.05));
  animation: riseInSoft var(--normal) var(--ease-out) both;
}
.director-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82em;
  color: #cdd4ff;
  margin-bottom: 6px;
}
#director-input {
  width: 100%;
  min-height: 54px;
  max-height: 120px;
  resize: none;
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  line-height: 1.45;
  transition: border-color var(--normal) var(--ease-out), box-shadow var(--normal) var(--ease-out);
}
#director-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.14);
}
.director-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.director-hint { margin: 0; font-size: 0.75em; color: var(--text-dim); line-height: 1.35; }
.director-send {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(124, 140, 255, 0.55);
  border-radius: 11px;
  background: rgba(124, 140, 255, 0.2);
  color: var(--text);
  font: inherit;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--fast) var(--ease-out), transform var(--fast) var(--ease-spring), opacity var(--fast) var(--ease-out);
}
.director-send:hover { background: rgba(124, 140, 255, 0.3); }
.director-send:active { transform: scale(0.96); }
.director-send:disabled { opacity: 0.45; cursor: not-allowed; }
.chip-director.active {
  color: #d8d1ff;
  border-color: rgba(124, 140, 255, 0.55);
  background: rgba(124, 140, 255, 0.15);
}
.chip-director { min-height: 44px; }
.chip-director.has-draft:not(.expanded) {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
  position: relative;
}
.chip-director.has-draft:not(.expanded) .director-label { display: none; }
.chip-director.has-draft:not(.expanded)::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b9a8ff;
}
.icon-btn.sm { width: 44px; height: 44px; font-size: 0.8em; }
.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition:
    color var(--fast) var(--ease-out),
    background var(--fast) var(--ease-out),
    border-color var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-spring);
}
.chip svg { width: 15px; height: 15px; flex: 0 0 auto; }
.chip:active { color: var(--text); transform: scale(0.94); }

/* 输入区的图标按钮也放大到好点按的尺寸 */
.input-row .icon-btn { width: 44px; height: 44px; border-radius: 14px; }
.send-btn svg { width: 20px; height: 20px; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#chat-input {
  flex: 1;
  resize: none;
  max-height: 184px;
  min-height: 44px; /* 触摸目标下限 */
  padding: 11px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  line-height: 1.4;
  transition:
    border-color var(--normal) var(--ease-out),
    box-shadow var(--normal) var(--ease-out),
    background var(--normal) var(--ease-out);
}
#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.14);
}
.send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.2em;
  flex: 0 0 auto;
  transition:
    transform var(--fast) var(--ease-spring),
    background var(--fast) var(--ease-out),
    opacity var(--fast) var(--ease-out);
}
.send-btn:active { transform: scale(0.88); }
.send-btn:disabled { opacity: 0.4; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 1.05em;
  display: grid;
  place-items: center;
  transition:
    background var(--fast) var(--ease-out),
    color var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-spring);
}
.icon-btn:active { background: var(--bg-input); transform: scale(0.9); }
.icon-btn.stop { color: var(--dragon); background: rgba(255, 107, 129, 0.12); }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: 0; /* 兜底 */
  padding-bottom: env(safe-area-inset-bottom);
  flex: 0 0 auto;
}
.tabbar .tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 9px 4px 8px;
  font-size: 0.75em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  transition: color var(--normal) var(--ease-out);
}
.tabbar .tab span {
  font-size: 1.35em;
  line-height: 1;
  transition: transform var(--normal) var(--ease-spring), filter var(--normal) var(--ease-out);
}
.tabbar .tab-icon {
  display: grid;
  place-items: center;
  height: 22px;
  font-size: 1rem;
}
.tabbar .tab-icon svg { width: 22px; height: 22px; }
.tabbar .tab::after {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 30px;
  height: 2px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  opacity: 0;
  /* 用 scaleX 代替 width：不触发重排，动画更顺滑 */
  transform: translateX(-50%) scaleX(0);
  transform-origin: center;
  transition: transform var(--normal) var(--ease-spring), opacity var(--fast) var(--ease-out);
}
.tabbar .tab.active { color: var(--accent); }
.tabbar .tab.active span {
  transform: translateY(-1px) scale(1.1);
  filter: drop-shadow(0 0 8px rgba(124, 140, 255, 0.5));
}
.tabbar .tab.active::after { opacity: 1; transform: translateX(-50%) scaleX(1); }
.tabbar .tab:active span { transform: scale(0.9); }

/* ---------------- 按钮 / 表单 ---------------- */
.btn {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.92em;
  transition:
    transform var(--fast) var(--ease-spring),
    background var(--fast) var(--ease-out),
    border-color var(--fast) var(--ease-out),
    opacity var(--fast) var(--ease-out);
}
.btn:active { transform: scale(0.955); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 500; }
.btn.danger { background: rgba(255, 90, 90, 0.14); border-color: rgba(255, 90, 90, 0.35); color: #ff8f8f; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }

.settings { flex: 1; overflow-y: auto; padding: 12px 12px 40px; -webkit-overflow-scrolling: touch; }
.section {
  margin-bottom: 18px;
  animation: riseIn var(--normal) var(--ease-out) both;
  animation-delay: var(--i-delay, 0ms);
}
.section > h3 {
  font-size: 0.82em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 8px 4px;
  font-weight: 600;
}
.settings .section:nth-child(1) { --i-delay: 0ms; }
.settings .section:nth-child(2) { --i-delay: 28ms; }
.settings .section:nth-child(3) { --i-delay: 56ms; }
.settings .section:nth-child(4) { --i-delay: 84ms; }
.settings .section:nth-child(5) { --i-delay: 112ms; }
.settings .section:nth-child(6) { --i-delay: 140ms; }
.settings .section:nth-child(n + 7) { --i-delay: 168ms; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  transition: border-color var(--fast) var(--ease-out), background var(--fast) var(--ease-out);
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field { margin-bottom: 10px; }
.field > label { display: block; font-size: 0.8em; color: var(--text-dim); margin-bottom: 4px; }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-input);
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
.field input, .field textarea, .field select {
  transition:
    border-color var(--normal) var(--ease-out),
    box-shadow var(--normal) var(--ease-out),
    background var(--normal) var(--ease-out);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.13);
}
.field .hint-line { font-size: 0.75em; color: var(--text-dim); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.switch input { width: auto; transform: scale(1.15); }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 10px;
  font-size: 0.82em;
  word-break: break-all;
}
.link-box span { flex: 1; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 0.88em; }
.kv span:first-child { color: var(--text-dim); }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------------- 弹层 ---------------- */
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--normal) var(--ease-out), backdrop-filter var(--normal) var(--ease-out);
}
.modal.open { opacity: 1; }
.modal-card {
  width: min(640px, 100%);
  max-height: 92vh;
  background: var(--bg-soft);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translate3d(0, 28px, 0) scale(0.98);
  opacity: 0.6;
  /* 出场要比起入场更快，手感才利落 */
  transition:
    transform var(--slow) var(--ease-spring),
    opacity var(--normal) var(--ease-out),
    border-radius var(--normal) var(--ease-out);
}
.modal:not(.open) .modal-card {
  transition-duration: 0.2s, 0.16s, 0.16s;
}
.modal.open .modal-card { transform: none; opacity: 1; }
.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.modal-header strong { flex: 1; }
.modal-body { flex: 1; overflow-y: auto; padding: 14px; }
.modal-footer {
  display: flex;
  gap: 8px;
  padding: 10px 14px; /* 兜底 */
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--border);
}
.modal-footer .btn { flex: 1; }
.menu-list { display: flex; flex-direction: column; }
.menu-list button {
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 6px;
  font-size: 0.95em;
}
.menu-list button:last-child { border-bottom: none; }
.menu-list button.danger { color: #ff8f8f; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px; /* 兜底 */
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translate(-50%, 10px);
  background: rgba(30, 36, 48, 0.97);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85em;
  z-index: 90;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity var(--normal) var(--ease-out), transform var(--normal) var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .msg-body { max-width: 76%; }
  .view { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .modal { align-items: center; }
  .modal-card { border-radius: 20px; max-height: 86vh; }
  .modal.open .modal-card { border-radius: 20px; }
}

/* 鼠标设备上的悬停反馈（触屏不会触发） */
@media (hover: hover) and (pointer: fine) {
  .list-item:hover { background: #1c2230; border-color: #33405a; }
  .tabbar .tab:hover { color: var(--text); }
  .chip:hover { color: var(--text); border-color: #3a4763; }
  .btn:hover { background: #232b3a; }
  .btn.primary:hover { background: #8d9aff; }
  .icon-btn:hover { background: var(--bg-input); }
  .msg-actions button:hover { color: var(--text); }
}

/* 系统开了「减少动态效果」就全部关掉 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }
}
