:root {
  --bg: #fbf9f5;
  --bg2: #f3efe8;
  --card: #ffffff;
  --ink: #1b1a18;
  --ink2: #6f6a63;
  --ink3: #a8a29a;
  --line: rgba(0,0,0,.08);
  --blue: #12b7f5;
  --red: #e5484d;
  --safe: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 15px; -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + var(--safe));
}

/* 顶栏 */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  background: rgba(251,249,245,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.back {
  width: 36px; height: 36px; display: grid; place-items: center;
  color: var(--ink); text-decoration: none; border-radius: 50%;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.back:active { background: var(--bg2); transform: scale(.9); }
.save {
  border: 0; background: none; color: var(--blue);
  font-size: 15px; font-weight: 600; padding: 8px 6px;
  transition: opacity .15s;
}
.save:active { opacity: .55; }

/* 卡片 */
main { padding: 14px; display: grid; gap: 14px; max-width: 620px; margin: 0 auto; }
.card {
  background: var(--card); border-radius: 16px; padding: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 0 0 1px var(--line);
}
.card h2 { margin: 0 0 14px; font-size: 14px; font-weight: 600; color: var(--ink2); letter-spacing: .4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

/* 字段 */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; color: var(--ink2); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px;
  background: #fdfcfa; color: var(--ink);
  padding: 11px 13px; font: inherit; font-size: 14.5px; outline: none;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .18s;
}
.field textarea { resize: vertical; line-height: 1.6; font-size: 14px; }
.field input:focus, .field textarea:focus {
  border-color: rgba(18,183,245,.55);
  box-shadow: 0 0 0 3px rgba(18,183,245,.12);
  background: #fff;
}
.hint { display: block; margin-top: 6px; font-size: 11.5px; color: var(--ink3); font-style: normal; line-height: 1.5; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 按钮 */
button { font-family: inherit; cursor: pointer; }
.ghost {
  width: 100%; height: 42px; border-radius: 11px;
  border: 1px solid var(--line); background: #fdfcfa; color: var(--ink);
  font-size: 14.5px;
  transition: transform .12s var(--ease), background .15s;
}
.ghost:active { transform: scale(.98); background: var(--bg2); }
.small {
  border: 0; background: rgba(18,183,245,.1); color: #0a95c9;
  font-size: 13px; padding: 7px 12px; border-radius: 9px;
  transition: transform .12s var(--ease);
}
.small:active { transform: scale(.95); }
.danger { color: var(--red); }
.btnrow { display: grid; gap: 10px; }

/* 预设列表 */
.presets { display: grid; gap: 10px; }
.preset {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: #fdfcfa;
  transition: border-color .18s var(--ease), background .18s;
}
.preset.on { border-color: rgba(18,183,245,.6); background: rgba(18,183,245,.055); }
.preset .pmain { flex: 1; min-width: 0; }
.preset .pname { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.preset .ptag {
  font-size: 10.5px; font-weight: 500; color: #0a95c9;
  background: rgba(18,183,245,.14); border-radius: 5px; padding: 1px 6px;
}
.preset .pprompt {
  margin-top: 5px; font-size: 12.5px; color: var(--ink3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.preset .pops { display: flex; flex-direction: column; gap: 6px; }
.preset .pops button {
  border: 0; background: transparent; color: var(--ink2);
  font-size: 12.5px; padding: 3px 6px; border-radius: 7px;
}
.preset .pops button:active { background: var(--bg2); }
.preset .pops .del { color: var(--red); }

/* 输出区 */
.out {
  margin-top: 10px; font-size: 12.5px; line-height: 1.6;
  color: var(--ink2); white-space: pre-wrap;
  min-height: 0;
}
.out.ok { color: #0a8a3f; }
.out.err { color: var(--red); }

/* 弹层 */
.sheet {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: flex-end; background: rgba(0,0,0,.35); backdrop-filter: blur(3px);
}
.sheet.on { display: flex; }
.sheet-inner {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: #fff; border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe));
  animation: up .26s var(--ease);
}
@keyframes up { from { transform: translateY(18px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-inner h3 { margin: 0 0 16px; font-size: 16.5px; }
.sheet-ops { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.sheet-ops button {
  height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: #fdfcfa; color: var(--ink); font-size: 15px;
}
.sheet-ops .primary { background: var(--blue); color: #fff; border-color: transparent; }
.sheet-ops button:active { transform: scale(.97); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(40px + var(--safe));
  transform: translateX(-50%) translateY(10px);
  background: rgba(0,0,0,.84); color: #fff;
  font-size: 13px; padding: 9px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; z-index: 99;
  transition: opacity .2s var(--ease), transform .25s var(--ease);
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 640px) {
  .btnrow { grid-template-columns: repeat(3, 1fr); }
}

/* 正则：作用位置 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 10px; background: #fdfcfa;
  border: 1px solid var(--line); font-size: 13px; color: var(--ink);
}
.chip input { width: auto; margin: 0; accent-color: var(--blue); }
details summary { cursor: pointer; }
pre { margin: 8px 0 0; }