/* ============================================================
   CPA 随身背 · 移动端优先样式
   基线：无 hover 依赖、16px 输入、dvh 高度、安全区适配
   ============================================================ */

:root {
  --bg: #f2f3f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #14161a;
  --muted: #6b7280;
  --faint: #9aa1ac;
  --line: rgba(20, 22, 26, 0.09);
  --accent: #3557e8;
  --accent-soft: rgba(53, 87, 232, 0.1);
  --accent-ink: #ffffff;
  --debit: #1f6f4a;
  --credit: #a33a2b;
  --danger: #d92d20;
  --amber: #b45309;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 10px 28px -18px rgba(16, 24, 40, 0.35);
  --radius: 18px;
  --radius-sm: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0c0f;
    --surface: #16181d;
    --surface-2: #1c1f25;
    --text: #f1f2f4;
    --muted: #9aa1ac;
    --faint: #6f7681;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #7b96ff;
    --accent-soft: rgba(123, 150, 255, 0.14);
    --accent-ink: #0b0c0f;
    --debit: #6ee7a8;
    --credit: #f2a08c;
    --danger: #ff6b5e;
    --amber: #f5b45a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -20px rgba(0, 0, 0, 0.8);
  }
}

:root[data-theme='dark'] {
  --bg: #0b0c0f;
  --surface: #16181d;
  --surface-2: #1c1f25;
  --text: #f1f2f4;
  --muted: #9aa1ac;
  --faint: #6f7681;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #7b96ff;
  --accent-soft: rgba(123, 150, 255, 0.14);
  --accent-ink: #0b0c0f;
  --debit: #6ee7a8;
  --credit: #f2a08c;
  --danger: #ff6b5e;
  --amber: #f5b45a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -20px rgba(0, 0, 0, 0.8);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC',
    'HarmonyOS Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
a,
input,
textarea,
[role='button'] {
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border: 0;
  background: none;
  color: inherit;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: 16px; /* 低于 16px iOS 会自动放大页面 */
  color: var(--text);
}

/* ================= 壳层 ================= */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin-inline: auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  position: relative;
  z-index: 5;
}

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

.mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #7c3aed));
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.brand-text strong {
  font-size: 16px;
  letter-spacing: 0.2px;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--muted);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.conn[data-state='ok'] .dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

.conn[data-state='err'] .dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.16);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
}

.icon-btn:active {
  transform: scale(0.94);
  background: var(--surface-2);
}

main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 4px;
  scroll-padding-bottom: 40px;
}

.view[hidden] {
  display: none;
}

/* ================= 生成页 ================= */
.hero {
  padding: 10px 2px 16px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: 25px;
  line-height: 1.28;
  letter-spacing: -0.4px;
  font-weight: 750;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.2px;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px 8px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.composer textarea {
  width: 100%;
  min-height: 132px;
  max-height: 44dvh;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  line-height: 1.62;
  padding: 0;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.composer-foot span {
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.link {
  font-size: 13px;
  color: var(--accent);
  padding: 4px 2px;
  border-radius: 8px;
}

.link:active {
  opacity: 0.6;
}

/* 科目胶囊 */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 14px 0 6px;
  margin-inline: -16px;
  padding-inline: 16px;
  scroll-snap-type: x proximity;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  scroll-snap-align: start;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.chip:active {
  transform: scale(0.96);
}

.chip[aria-checked='true'] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}

/* 状态条 */
.status {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status[data-kind='error'] {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.results {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 0 6px;
}

.foot-hint {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--faint);
  text-align: center;
}

/* ================= 卡片 ================= */
.kcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  animation: rise 260ms cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.kcard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.kcard-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.34;
  letter-spacing: -0.2px;
}

.badge-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: none;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
  font-weight: 600;
}

.stars {
  font-size: 10px;
  letter-spacing: 1px;
  color: #f59e0b;
}

.sec {
  margin-top: 14px;
}

.sec-title {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--faint);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.kcard p {
  margin: 0;
}

.klist {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.klist li {
  position: relative;
  padding-left: 16px;
  font-size: 14.5px;
  line-height: 1.6;
}

.klist li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.66em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.klist.traps li::before {
  background: var(--danger);
}

.entry {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.entry + .entry {
  margin-top: 8px;
}

.entry-scenario {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.ledger {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ledger li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 14px;
  line-height: 1.5;
}

.ledger .tag {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  transform: translateY(1px);
}

.tag.debit {
  background: color-mix(in srgb, var(--debit) 14%, transparent);
  color: var(--debit);
}

.tag.credit {
  background: color-mix(in srgb, var(--credit) 14%, transparent);
  color: var(--credit);
}

.ledger .amount {
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.entry-note {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 8px;
}

.triggers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trigger {
  font-size: 12.5px;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.kcard-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--faint);
}

.kcard-foot .acts {
  display: flex;
  gap: 4px;
}

.mini-btn {
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 9px;
  color: var(--accent);
  background: var(--accent-soft);
}

.mini-btn:active {
  transform: scale(0.95);
}

.mini-btn.danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* ---------- 模块化区块（sections） ---------- */
.top-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.kcard-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.ksec {
  margin-top: 16px;
}

.ksec:not(.user-sec) + .ksec:not(.user-sec) {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.ksec .sec-title {
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 7px;
}

.ksec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.sec-flag {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--amber) 16%, transparent);
  color: var(--amber);
  font-weight: 700;
  flex: none;
}

/* 自己填的模块 */
.user-sec {
  padding: 12px;
  border-radius: 15px;
  background: var(--surface-2);
  border: 1px dashed color-mix(in srgb, var(--amber) 40%, var(--line));
}

.user-input {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  outline: none;
  resize: none;
  line-height: 1.58;
  min-height: 62px;
  overflow-y: auto;
}

.user-input:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.user-sec-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.user-sec-foot .hint {
  font-size: 11.5px;
  color: var(--faint);
}

/* 编辑 / 模板 里的模块行 */
.sec-edit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sec-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.sec-editor-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sec-title-input {
  flex: 1;
  min-width: 0;
  padding: 8px 11px;
  font-size: 15px;
  font-weight: 600;
}

.sec-editor .edit-text {
  min-height: 72px;
}

.sec-del {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--faint);
}

.sec-del:active {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.type-toggle {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background 140ms ease, color 140ms ease;
}

.type-toggle[data-user='true'] {
  background: color-mix(in srgb, var(--amber) 18%, transparent);
  color: var(--amber);
}

.type-toggle:active {
  transform: scale(0.94);
}

.ghost-add {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}

.ghost-add:active {
  background: var(--surface-2);
}

.tpl-tip {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
}

.tpl-tip b {
  color: var(--accent);
}

.tpl-hint {
  padding: 8px 11px;
  font-size: 13px;
}

/* 骨架屏 */
.skel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skel i {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

.skel i:nth-child(1) {
  width: 62%;
  height: 16px;
}
.skel i:nth-child(2) {
  width: 94%;
}
.skel i:nth-child(3) {
  width: 78%;
}
.skel i:nth-child(4) {
  width: 46%;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

/* ================= 卡片库 ================= */
.searchbar {
  padding: 6px 0 10px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg) 70%, transparent);
  z-index: 2;
}

.searchbar input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.searchbar input:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--faint);
  padding: 0 2px 8px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  animation: rise 220ms ease both;
}

.row:active {
  transform: scale(0.985);
  background: var(--surface-2);
}

.row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.row-title {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.row-def {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.row-meta {
  font-size: 11.5px;
  color: var(--faint);
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 2px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 56px 24px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
}

.empty strong {
  color: var(--muted);
  font-size: 15px;
}

/* ================= 底部 dock + tabbar ================= */
.dock {
  padding: 8px 16px 10px;
  background: var(--bg);
}

.dock[hidden] {
  display: none;
}

.primary {
  position: relative;
  width: 100%;
  height: 52px;
  border-radius: 15px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--accent) 80%, transparent);
  transition: transform 120ms ease, opacity 120ms ease, background 160ms ease;
}

.primary:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.primary[disabled] {
  opacity: 0.62;
  cursor: default;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  border-top-color: var(--accent-ink);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.tabbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 11px;
  color: var(--faint);
  position: relative;
  transition: color 140ms ease;
}

.tab-icon {
  font-size: 17px;
  line-height: 1;
}

.tab.is-active {
  color: var(--accent);
  font-weight: 600;
}

.tab:active {
  background: var(--surface-2);
}

.tab-count {
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

/* ================= 详情抽屉 ================= */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.46);
  backdrop-filter: blur(2px);
  animation: fade 180ms ease both;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  overflow: hidden;
  animation: slide-up 280ms cubic-bezier(0.32, 0.72, 0, 1) both;
  box-shadow: 0 -12px 40px -20px rgba(0, 0, 0, 0.5);
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 3;
  flex: none;
}

.round-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  color: var(--muted);
  background: var(--surface-2);
  flex: none;
  transition: transform 120ms ease, background 120ms ease;
}

.round-btn:active {
  transform: scale(0.92);
  background: var(--line);
}

.sheet-heading {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-menu {
  position: absolute;
  right: 12px;
  top: 48px;
  z-index: 4;
  min-width: 170px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: rise 160ms ease both;
}

.sheet-menu[hidden] {
  display: none;
}

.sheet-menu button {
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
}

.sheet-menu button:active {
  background: var(--surface-2);
}

.sheet-menu .danger {
  color: var(--danger);
}

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

/* 追问线程 */
.thread {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--faint);
}

.thread-empty {
  font-size: 13px;
  line-height: 1.65;
  color: var(--faint);
  padding: 2px 2px 10px;
}

.msg {
  display: flex;
}

.msg.me {
  justify-content: flex-end;
}

.bubble {
  max-width: 87%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.64;
  word-break: break-word;
  animation: rise 200ms ease both;
}

.msg.me .bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 6px;
}

.msg.ai .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.bubble.loading {
  padding: 13px 18px;
}

.dots {
  letter-spacing: 3px;
  color: var(--faint);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

.error-text {
  color: var(--danger);
}

/* 气泡里的 Markdown */
.md p {
  margin: 0 0 8px;
}

.md p:last-child {
  margin-bottom: 0;
}

.md .md-h {
  margin: 12px 0 5px;
  font-size: 14px;
  font-weight: 700;
}

.md .md-h:first-child {
  margin-top: 0;
}

.md .md-ul,
.md .md-ol {
  margin: 0 0 8px;
  padding-left: 19px;
}

.md .md-ul:last-child,
.md .md-ol:last-child {
  margin-bottom: 0;
}

.md li {
  margin: 3px 0;
}

.md code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.md blockquote {
  margin: 6px 0;
  padding-left: 9px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

/* 提问条 */
.ask-bar {
  flex: none;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.ask-quick {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 8px;
}

.ask-quick::-webkit-scrollbar {
  display: none;
}

.ask-quick .chip {
  padding: 6px 11px;
  font-size: 12.5px;
  background: var(--surface-2);
  color: var(--muted);
}

.ask-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 5px 5px 5px 14px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.ask-input:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ask-input textarea {
  flex: 1;
  min-width: 0;
  min-height: 22px;
  max-height: 116px;
  padding: 7px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  line-height: 1.45;
}

.ask-input textarea::placeholder {
  color: var(--faint);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform 120ms ease, opacity 120ms ease;
}

.send-btn:active {
  transform: scale(0.9);
}

.send-btn[disabled] {
  opacity: 0.4;
}

/* ================= 编辑表单 ================= */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding-bottom: 6px;
}

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

.form-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.form-hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--faint);
}

.edit-input,
.edit-text {
  width: 100%;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  outline: none;
  line-height: 1.55;
  -webkit-appearance: none;
  appearance: none;
}

.edit-text {
  resize: none;
  min-height: 46px;
  overflow-y: auto;
}

.edit-input:focus,
.edit-text:focus {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stars-pick {
  display: flex;
  gap: 4px;
}

.star-btn {
  font-size: 22px;
  line-height: 1.2;
  padding: 2px 3px;
  color: var(--faint);
  transition: transform 100ms ease;
}

.star-btn[data-on='true'] {
  color: #f59e0b;
}

.star-btn:active {
  transform: scale(0.88);
}

.edit-bar {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

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

.ghost-btn {
  flex: none;
  padding: 0 22px;
  height: 46px;
  border-radius: 13px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.ghost-btn:active {
  background: var(--surface-2);
}

.save-btn {
  flex: 1;
  height: 46px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 650;
  transition: transform 120ms ease, opacity 120ms ease;
}

.save-btn:active {
  transform: scale(0.98);
}

.save-btn[disabled] {
  opacity: 0.6;
}

/* ================= Toast ================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  z-index: 90;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 22, 26, 0.92);
  color: #fff;
  font-size: 13.5px;
  text-align: center;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.toast[hidden] {
  display: none;
}

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

/* ================= 桌面兜底 ================= */
@media (min-width: 600px) {
  main {
    padding-inline: 20px;
  }
  .hero h1 {
    font-size: 28px;
  }
}

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

/* ============ 纯前端版新增 ============ */
.conn[data-state='warn'] .dot {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.setup-banner {
  width: 100%;
  display: block;
  text-align: left;
  margin: 0 0 14px;
  padding: 13px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--amber) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 34%, transparent);
  color: var(--amber);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
}

.setup-banner:active {
  transform: scale(0.985);
}

.set-status {
  margin: 8px 0 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}

.set-status[data-kind='ok'] {
  color: #16a34a;
}

.set-status[data-kind='error'] {
  color: var(--danger);
}

#setSheet .sheet-body,
#tplSheet .sheet-body {
  padding-bottom: 20px;
}

.setup-banner[hidden] {
  display: none;
}
