/* ==========================================================================
   DSH 手机版 — 移动端样式
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --bg-soft: #0e1218;
  --panel: #121822;
  --panel-2: #161d29;
  --line: #222b39;
  --line-soft: #1a2230;
  --text: #e9eef7;
  --text-dim: #aab6c8;
  --muted: #7d8a9e;
  --accent: #5b8cff;
  --accent-2: #9b6bff;
  --accent-ink: #ffffff;
  --user-bubble: #1b2740;
  --user-bubble-line: #27395c;
  --code-bg: #0b1018;
  --code-head: #111926;
  --danger: #ff5d5d;
  --ok: #3ddc97;
  --shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, .75);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .35);
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-soft: #eef2f8;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --line: #e1e7f0;
  --line-soft: #ebf0f7;
  --text: #0f1622;
  --text-dim: #47566c;
  --muted: #7c8a9e;
  --accent: #3b6fe8;
  --accent-2: #7c4dff;
  --user-bubble: #e7efff;
  --user-bubble-line: #cfdcf7;
  --code-bg: #f4f7fc;
  --code-head: #e9eff8;
  --danger: #d93b3b;
  --ok: #0e9f6e;
  --shadow-lg: 0 24px 60px -22px rgba(20, 35, 60, .28);
  --shadow-sm: 0 2px 10px rgba(20, 35, 60, .08);
}

* { box-sizing: border-box; }

/* 统一让 hidden 生效（类名的 display 会覆盖 UA 的 [hidden] 规则） */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; border: 0; background: none; padding: 0; }

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

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

/* ---------------------------------------------------------------- 布局壳 */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(91, 140, 255, .07), transparent 60%),
    var(--bg);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) 8px calc(var(--safe-l) + 10px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--line-soft);
  min-height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding-left: 2px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(91, 140, 255, .8);
}
.brand-mark svg { width: 17px; height: 17px; stroke-width: 1.7; }

.brand-text { display: flex; align-items: baseline; gap: 7px; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: .04em; font-weight: 700; }
.brand-text span {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: var(--text-dim);
  transition: background .16s ease, color .16s ease, transform .12s ease;
}
.icon-btn:hover { background: var(--panel); color: var(--text); }
.icon-btn:active { transform: scale(.93); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.ghost { width: 40px; height: 40px; border-radius: 11px; color: var(--muted); }
.icon-btn.ghost:hover { background: var(--panel-2); }

/* --------------------------------------------------------------- 消息区 */

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding: 14px 0 10px;
}
.scroller::-webkit-scrollbar { width: 6px; }
.scroller::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
.scroller:focus { outline: none; }

.messages {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 0 calc(var(--safe-r) + 16px) 0 calc(var(--safe-l) + 16px);
  max-width: 860px;
  margin: 0 auto;
}

.messages[hidden] { display: none; }

.msg {
  display: flex;
  flex-direction: column;
  animation: msg-in .28s cubic-bezier(.22, 1, .36, 1) both;
}
.msg.instant { animation: none; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* 用户消息 */
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: min(86%, 620px);
  background: var(--user-bubble);
  border: 1px solid var(--user-bubble-line);
  border-radius: 20px 20px 6px 20px;
  padding: 10px 15px;
  font-size: 15.5px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 助手消息 */
.msg-assistant { align-items: stretch; }
.msg-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}
.msg-head .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.msg-head .name { font-weight: 600; color: var(--text-dim); letter-spacing: .03em; }
.msg-head .model { font-size: 11px; opacity: .8; }

.msg-body {
  font-size: 15.5px;
  line-height: 1.72;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  min-height: 30px;
  opacity: 0;
  transition: opacity .2s ease;
}
.msg-assistant:hover .msg-foot,
.msg-foot.show { opacity: 1; }
.msg-foot .meta {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
@media (hover: none) {
  .msg-foot { opacity: 1; }
}

/* 流式输出时隐藏操作，避免误触 */
.msg.is-streaming .msg-foot {
  opacity: 0;
  pointer-events: none;
}

.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  transition: background .15s ease, color .15s ease;
}
.act-btn svg { width: 15px; height: 15px; stroke-width: 1.8; }
.act-btn:hover { background: var(--panel); color: var(--text); }
.act-btn:active { transform: scale(.96); }
.act-btn.done { color: var(--ok); }

/* 思考过程 */
.think {
  border: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  border-radius: 13px;
  margin: 0 0 12px;
  overflow: hidden;
}
.think summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary svg { width: 14px; height: 14px; transition: transform .2s ease; }
.think[open] summary svg { transform: rotate(180deg); }
.think[open] summary { border-bottom: 1px solid var(--line-soft); }
.think .think-body {
  padding: 10px 14px 12px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 42vh;
  overflow: auto;
}
.think .think-body code { font-size: 12px; }

/* 出错 */
.msg-error .err-card {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
  border-radius: 14px;
  font-size: 13.5px;
  color: color-mix(in srgb, var(--text) 88%, var(--danger));
  line-height: 1.6;
  overflow-wrap: anywhere;
}

/* 流式光标 */
.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 打字指示 */
.typing { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.25s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ------------------------------------------------------------- 空状态 */

.empty {
  max-width: 620px;
  margin: 0 auto;
  padding: 34px calc(var(--safe-r) + 22px) 30px calc(var(--safe-l) + 22px);
  text-align: center;
  animation: msg-in .35s ease both;
}
.empty[hidden] { display: none; }
.empty-mark {
  width: 58px; height: 58px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 16px 34px -14px rgba(91, 140, 255, .85);
}
.empty-mark svg { width: 30px; height: 30px; stroke-width: 1.6; }
.empty h1 { font-size: 22px; margin: 0 0 8px; letter-spacing: -.01em; }
.empty p { margin: 0 auto 24px; color: var(--muted); font-size: 14px; max-width: 30em; }

.suggests {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  text-align: left;
}
@media (max-width: 430px) { .suggests { grid-template-columns: 1fr; } }

.suggest {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 65%, transparent);
  transition: border-color .16s ease, background .16s ease, transform .12s ease;
  min-height: 62px;
  text-align: left;
}
.suggest span { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.suggest em {
  font-style: normal;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--panel); }
.suggest:active { transform: scale(.985); }

.empty-cta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 18px;
  padding: 10px 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  color: color-mix(in srgb, var(--text) 92%, var(--accent));
  font-size: 13.5px;
  font-weight: 600;
}
.empty-cta svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- 输入区 */

.composer {
  position: relative;
  z-index: 15;
  padding: 8px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 12px);
  background: linear-gradient(to top, var(--bg) 62%, color-mix(in srgb, var(--bg) 60%, transparent));
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 7px 7px 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.composer-box.focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent), var(--shadow-sm);
}

#input {
  flex: 1;
  min-height: 30px;
  max-height: 38dvh;
  padding: 5px 0;
  border: 0;
  outline: none;
  background: none;
  resize: none;
  font-size: 16px; /* 防止 iOS 聚焦自动放大 */
  line-height: 1.5;
  color: var(--text);
  overflow-y: auto;
  scrollbar-width: thin;
}
#input::placeholder { color: var(--muted); }

.send-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(91, 140, 255, .9);
  transition: transform .12s ease, opacity .16s ease, filter .16s ease;
  flex: none;
}
.send-btn:disabled {
  opacity: .32;
  box-shadow: none;
  filter: saturate(.4);
  cursor: default;
}
.send-btn:active:not(:disabled) { transform: scale(.92); }
.send-btn svg { width: 19px; height: 19px; stroke-width: 2.1; }
.send-btn .ic-stop { display: none; }
.send-btn.streaming .ic-send { display: none; }
.send-btn.streaming .ic-stop { display: block; }
.send-btn.streaming {
  background: color-mix(in srgb, var(--danger) 15%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 42%, var(--line));
  color: var(--danger);
  box-shadow: none;
}
.send-btn.streaming svg { width: 15px; height: 15px; }

.composer-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 4px 0;
  min-height: 22px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 11px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--line-soft);
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip svg { width: 11px; height: 11px; stroke-width: 2; }
.chip:hover { color: var(--text-dim); border-color: var(--line); }
.chip-demo { color: #ffc46b; border-color: color-mix(in srgb, #ffc46b 30%, transparent); }
.composer-hint {
  margin-left: auto;
  font-size: 10.5px;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (hover: none) { .composer-hint { display: none; } }

/* 回到底部 */
.scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 96px);
  transform: translateX(-50%) translateY(6px);
  z-index: 16;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text-dim);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.scroll-bottom.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.scroll-bottom svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- 抽屉 */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 6, 12, .55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .22s ease;
}
.backdrop.show { opacity: 1; }
.backdrop[hidden] { display: none; }

.drawer {
  position: fixed;
  z-index: 41;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(84vw, 340px);
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  transform: translateX(-102%);
  transition: transform .26s cubic-bezier(.22, 1, .36, 1);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
}
.drawer-head .icon-btn { width: 36px; height: 36px; }

.drawer-new {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 2px 12px 10px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  transition: background .16s ease, border-color .16s ease;
}
.drawer-new svg { width: 17px; height: 17px; }
.drawer-new:hover { background: var(--panel); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); color: var(--text); }

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  overscroll-behavior: contain;
}

.drawer-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  text-align: left;
  color: var(--text-dim);
  transition: background .14s ease;
}
.drawer-item:hover { background: var(--panel); }
.drawer-item.active { background: var(--panel-2); color: var(--text); }
.drawer-item.active::before {
  content: "";
  position: absolute;
  left: 3px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.drawer-item .t {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 22px;
}
.drawer-item .m {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.drawer-item .m span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.drawer-item .del {
  position: absolute;
  right: 6px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s ease, color .15s ease, background .15s ease;
}
.drawer-item .del svg { width: 14px; height: 14px; }
.drawer-item:hover .del, .drawer-item.active .del { opacity: .75; }
.drawer-item .del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); opacity: 1; }
@media (hover: none) { .drawer-item .del { opacity: .55; } }

.drawer-empty {
  padding: 30px 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}

.drawer-foot {
  border-top: 1px solid var(--line-soft);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-foot-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}
.drawer-foot-btn svg { width: 16px; height: 16px; }
.drawer-foot-btn:hover { background: var(--panel); color: var(--text); }

/* ------------------------------------------------------------ 设置弹层 */

.sheet {
  position: fixed;
  z-index: 50;
  left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(102%);
  transition: transform .3s cubic-bezier(.22, 1, .36, 1);
  visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: 560px;
    max-height: 86vh;
    border-radius: 22px;
    transform: translate(-50%, -46%) scale(.98);
    opacity: 0;
    transition: transform .26s cubic-bezier(.22, 1, .36, 1), opacity .2s ease;
  }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
}

.sheet-head { padding: 8px 14px 0 20px; flex: none; }
.sheet-grab {
  width: 38px; height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 0 auto 6px;
}
@media (min-width: 720px) { .sheet-grab { display: none; } }
.sheet-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-title-row h2 { font-size: 18px; margin: 2px 0 6px; letter-spacing: -.01em; }

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 20px 20px;
  -webkit-overflow-scrolling: touch;
}

.sheet-foot {
  flex: none;
  padding: 12px 20px calc(var(--safe-b) + 14px);
  border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
}

.field { margin: 0 0 20px; }
.field > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .01em;
}
.field output {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field input[type="number"],
.field textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}
.field textarea { resize: vertical; min-height: 74px; line-height: 1.55; }
.field input[type="number"] { font-variant-numeric: tabular-nums; }

.input-row { display: flex; gap: 8px; align-items: center; }
.input-row input { flex: 1; min-width: 0; }

.field input[type="range"] {
  width: 100%;
  height: 28px;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)) 0 / var(--p, 35%) 100% no-repeat, var(--line);
}
.field input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 99px; background: var(--line);
}
.field input[type="range"]::-moz-range-progress {
  height: 4px; border-radius: 99px; background: var(--accent);
}
.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.field input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
}

.hint {
  margin: 7px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
}
.hint.inline { display: block; margin: 1px 0 0; font-size: 11px; }
.hint code {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
}

.link-btn {
  margin-top: 9px;
  padding: 3px 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:active { opacity: .7; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.preset {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel-2);
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.preset:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--text);
}

.btn-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-soft svg { width: 15px; height: 15px; }
.btn-soft:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.btn-soft.danger { color: color-mix(in srgb, var(--danger) 80%, var(--text)); }
.btn-soft.danger:hover { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: color-mix(in srgb, var(--danger) 10%, var(--panel)); }

.btn-primary {
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
  box-shadow: 0 10px 26px -12px rgba(91, 140, 255, .95);
  transition: transform .12s ease, filter .16s ease;
}
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .5; box-shadow: none; }
.btn-primary.danger { background: linear-gradient(140deg, #ff6a6a, #e33f6b); }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.switch-row:last-of-type { border-bottom: 0; padding-bottom: 2px; }
.switch-row strong { display: block; font-size: 13.5px; font-weight: 500; color: var(--text); }
.switch { position: relative; flex: none; width: 46px; height: 27px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--line);
  transition: background .2s ease;
  pointer-events: none;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transition: transform .2s cubic-bezier(.22, 1, .36, 1);
}
.switch input:checked + span { background: linear-gradient(140deg, var(--accent), var(--accent-2)); }
.switch input:checked + span::after { transform: translateX(19px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.segmented {
  display: flex;
  padding: 3px;
  gap: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.segmented button {
  flex: 1;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--muted);
  transition: background .16s ease, color .16s ease;
}
.segmented button.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.ic-eye, .ic-eye-off { width: 19px; height: 19px; }
.ic-eye-off { display: none; }
.revealed .ic-eye { display: none; }
.revealed .ic-eye-off { display: block; }

/* ---------------------------------------------------------------- 弹窗 */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 6, 12, .6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade .16s ease both;
}
.dialog[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.dialog-card {
  width: min(100%, 340px);
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: pop .2s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-card h3 { margin: 0 0 7px; font-size: 16px; }
.dialog-card p {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.dialog-actions { display: flex; gap: 9px; }
.dialog-actions button { flex: 1; }
.dialog-actions .btn-primary { padding: 12px; font-size: 14px; }

/* ---------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(var(--safe-b) + 88px);
  transform: translateX(-50%) translateY(10px);
  max-width: min(88vw, 420px);
  padding: 9px 15px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--panel) 92%, #000 8%);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast[hidden] { display: none; }

/* ------------------------------------------------------------ Markdown */

.msg-body > *:first-child { margin-top: 0; }
.msg-body > *:last-child { margin-bottom: 0; }
.msg-body p { margin: 0 0 12px; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  margin: 20px 0 9px;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: -.01em;
}
.msg-body h1 { font-size: 20px; }
.msg-body h2 { font-size: 18px; }
.msg-body h3 { font-size: 16.5px; }
.msg-body h4 { font-size: 15px; color: var(--text-dim); }
.msg-body ul, .msg-body ol { margin: 0 0 12px; padding-left: 22px; }
.msg-body li { margin: 4px 0; }
.msg-body li > p { margin: 0 0 6px; }
.msg-body li::marker { color: var(--muted); }
.msg-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  overflow-wrap: anywhere;
}
.msg-body a:hover { border-bottom-color: var(--accent); }
.msg-body strong { font-weight: 650; color: color-mix(in srgb, var(--text) 94%, var(--accent)); }
.msg-body em { font-style: italic; }
.msg-body del { color: var(--muted); }
.msg-body blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 13px;
  border-left: 3px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--text-dim);
}
.msg-body blockquote p:last-child { margin-bottom: 0; }
.msg-body hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.msg-body img { max-width: 100%; border-radius: 10px; display: block; margin: 6px 0; }

.msg-body code.inline {
  font-family: var(--mono);
  font-size: .875em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  color: color-mix(in srgb, var(--text) 92%, var(--accent));
  overflow-wrap: anywhere;
}

.code-block {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  background: var(--code-head);
  border-bottom: 1px solid var(--line);
  min-height: 32px;
}
.code-lang {
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--mono);
}
.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}
.code-copy svg { width: 13px; height: 13px; }
.code-copy:hover { background: var(--panel-2); color: var(--text); }
.code-copy.done { color: var(--ok); }
.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.62;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}
.code-block code { font-family: inherit; white-space: pre; }

/* 语法着色 */
.tok-com { color: #6b7a8f; font-style: italic; }
.tok-str { color: #a8d99a; }
.tok-num { color: #f0b072; }
.tok-key { color: #c792ea; }
.tok-fn  { color: #82aaff; }
.tok-punc { color: #89a0b8; }
.tok-tag { color: #ff8fa3; }
.tok-attr { color: #ffd479; }
.tok-prop { color: #7fd6e0; }

html[data-theme="light"] .tok-com { color: #8a96a8; }
html[data-theme="light"] .tok-str { color: #2f8a4a; }
html[data-theme="light"] .tok-num { color: #b4560d; }
html[data-theme="light"] .tok-key { color: #8a3fb5; }
html[data-theme="light"] .tok-fn  { color: #2159c7; }
html[data-theme="light"] .tok-punc { color: #64748b; }
html[data-theme="light"] .tok-tag { color: #b3243c; }
html[data-theme="light"] .tok-attr { color: #8a6100; }
html[data-theme="light"] .tok-prop { color: #0b6d84; }

.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.msg-body th, .msg-body td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.msg-body th { background: var(--panel-2); font-weight: 600; color: var(--text-dim); }

/* ------------------------------------------------------------ 动效降级 */

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