:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e6e8ef;
  --text: #1f2329;
  --muted: #8a909c;
  --primary: #4f6ef2;
  --primary-dark: #3b55d9;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(20, 30, 60, .06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand-icon { font-size: 22px; }
.brand-text { font-size: 20px; font-weight: 700; }
.brand-sub { font-size: 13px; color: var(--muted); margin-left: 6px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
#settings-btn.disabled { color: var(--danger); opacity: .85; }

main { max-width: 960px; margin: 0 auto; padding: 24px 18px 60px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
.hidden { display: none !important; }
.req { color: var(--danger); }

/* 按钮 */
.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: #c9cfe0; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c1c2; }
.btn.danger:hover { background: #fdecec; }
.btn.ghost { color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 主题卡片 */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.theme-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; box-shadow: var(--shadow); transition: .15s;
}
.theme-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(20,30,60,.1); }
.theme-card h3 { margin: 0 0 6px; font-size: 17px; }
.theme-card .desc { color: var(--muted); font-size: 13px; min-height: 36px; }
.theme-card .meta { color: var(--muted); font-size: 12px; margin-top: 12px; }
.theme-card .actions { margin-top: 10px; display: flex; gap: 8px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { margin: 0; }
.back-link { color: var(--primary); text-decoration: none; font-size: 14px; cursor: pointer; }
.page-sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* 脚本列表 */
.script-list { display: flex; flex-direction: column; gap: 12px; }
.script-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; cursor: pointer; box-shadow: var(--shadow); transition: .15s;
  display: flex; align-items: center; justify-content: space-between;
}
.script-item:hover { border-color: var(--primary); }
.script-item .ttl { font-size: 15px; font-weight: 600; }
.script-item .when { color: var(--muted); font-size: 12px; margin-top: 3px; }
.script-item .acts { display: flex; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 脚本编辑 */
.editor-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
#edit-title { flex: 1; font-size: 16px; font-weight: 600; border: none; outline: none; border-bottom: 1px dashed transparent; }
#edit-title:focus { border-bottom-color: var(--primary); }
#edit-content {
  width: 100%; min-height: 460px; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; font-size: 14px; line-height: 1.7; resize: vertical;
  font-family: inherit; outline: none;
}
#edit-content:focus { border-color: var(--primary); }
.editor-actions { margin-top: 12px; display: flex; gap: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #1f2329; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 100;
  opacity: 0; transition: .25s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,30,50,.35); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 10vh;
}
.modal {
  background: var(--card); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.2);
  width: 480px; max-width: 92vw; padding: 22px;
}
.modal h3 { margin: 0 0 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.modal input, .modal textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 14px; font-family: inherit; outline: none;
}
.modal input:focus, .modal textarea:focus { border-color: var(--primary); }
.modal textarea { resize: vertical; }
.modal .note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.cont-tip { font-size: 13px; color: var(--muted); margin: 0 0 4px; line-height: 1.6; background: #eef1ff; padding: 9px 11px; border-radius: 8px; }
.cont-tip b { color: var(--primary); }
.outline-row { display: flex; gap: 8px; align-items: stretch; }
.outline-row textarea { flex: 1; }
.plan-ai { white-space: nowrap; align-self: stretch; height: auto; }
.badge { font-size: 12px; font-weight: 600; color: #fff; background: var(--primary); border-radius: 20px; padding: 2px 10px; vertical-align: 2px; }
.outline-details { margin-top: 6px; }
.outline-details summary { cursor: pointer; color: var(--primary); font-size: 13px; user-select: none; }
.outline-details pre { background: #f1f3f9; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; margin: 6px 0 0; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.spin { display: inline-block; animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }