:root {
  --primary: #ff5a1f;
  --primary-dark: #e64a10;
  --grad: linear-gradient(135deg, #ff7a18, #ff2e00);
  --bg: #fff7f2;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --border: #ffe3d3;
  --shadow: 0 10px 30px rgba(255, 90, 31, 0.12);
  --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.page { max-width: 1060px; margin: 0 auto; padding: 24px 16px 40px; }

/* ===== 头部 ===== */
.hero { text-align: center; padding: 28px 0 24px; }
.hero h1 {
  font-size: 34px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 1px;
}
.hero .sub { color: var(--muted); margin-top: 8px; font-size: 15px; }
.steps {
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  margin-top: 16px;
}
.steps span {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; color: #c2410c;
  box-shadow: 0 2px 8px rgba(255, 90, 31, 0.08);
}

/* ===== 布局 ===== */
.layout {
  display: grid; grid-template-columns: 1fr; gap: 20px;
  align-items: start;
}
@media (min-width: 1001px) {
  .layout { grid-template-columns: 380px 1fr; }
}

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
  border: 1px solid var(--border);
}
.card h2 { font-size: 19px; margin-bottom: 16px; }

.card-head { position: relative; display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-head h2 { margin-bottom: 0; }
.template-count { font-size: 13px; color: var(--muted); }

/* ===== 表单 ===== */
.form-body { display: flex; flex-direction: column; gap: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-size: 14px; font-weight: 600; }
label em { color: var(--primary); font-style: normal; }
input, textarea, select {
  width: 100%; margin-top: 6px; padding: 11px 13px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: #fff;
  color: var(--text); transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.12);
}
.tip {
  font-size: 13px; color: var(--muted);
  background: #fff7ed; border: 1px dashed var(--border);
  border-radius: 10px; padding: 10px 12px; line-height: 1.6;
}

.btn-sample {
  background: #fff; border: 1.5px solid var(--primary); color: var(--primary);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  font-weight: 600; transition: all .15s;
}
.btn-sample:hover { background: var(--primary); color: #fff; }

/* ===== 筛选栏 ===== */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.filter-tag {
  padding: 6px 14px; background: #fff; border: 1.5px solid var(--border);
  border-radius: 999px; font-size: 13px; cursor: pointer; user-select: none;
  transition: all .15s; color: var(--text);
}
.filter-tag:hover { border-color: var(--primary); color: var(--primary); }
.filter-tag.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== 搜索框 ===== */
.search-wrap { margin-bottom: 16px; }
.search-wrap input { margin-top: 0; }

/* ===== 模板卡片 ===== */
.template-card { min-height: 400px; }
#templateList { display: flex; flex-direction: column; gap: 10px; max-height: 600px; overflow-y: auto; }

.template-item {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: all .15s;
  background: #fffaf5;
}
.template-item:hover {
  border-color: var(--primary); box-shadow: 0 4px 12px rgba(255, 90, 31, 0.1);
  transform: translateY(-1px);
}
.template-item-head {
  display: flex; justify-content: space-between; align-items: center;
}
.template-item-title { font-size: 14px; font-weight: 600; flex: 1; }
.template-item-tags { display: flex; gap: 6px; margin-top: 6px; }
.template-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #fff; border: 1px solid var(--border); color: var(--muted);
}
.template-tag.base { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.template-tag.hook { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.template-tag.story { background: #f3e8ff; color: #7c3aed; border-color: #ddd6fe; }
.template-tag.review { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.template-tag.fun { background: #ffe4e6; color: #be123c; border-color: #fecdd3; }
.template-tag.special { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }

.template-item-arrow { color: var(--muted); font-size: 12px; }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: var(--radius); max-width: 700px;
  width: 100%; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff; border-radius: var(--radius) var(--radius) 0 0;
}
.modal-head h3 { font-size: 18px; }
.modal-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 24px; }

/* ===== 弹窗内容区 ===== */
.block { margin-bottom: 18px; }
.block-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; font-size: 14px; font-weight: 700; color: #c2410c;
}
.block-body {
  background: #fffaf5; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; line-height: 1.7; white-space: pre-wrap;
  word-break: break-word; color: var(--text);
}
.block-body.prompt { font-size: 13px; max-height: 200px; overflow-y: auto; }
.block-body.script { font-size: 15px; line-height: 1.8; }

.btn-copy {
  border: 1.5px solid var(--primary); color: var(--primary); background: #fff;
  border-radius: 999px; padding: 4px 13px; font-size: 12.5px; cursor: pointer;
  font-weight: 600; transition: all .15s;
}
.btn-copy:hover { background: var(--primary); color: #fff; }
.btn-copy.done { background: #16a34a; border-color: #16a34a; color: #fff; }

.btn-copy-all {
  width: 100%; margin-bottom: 16px; padding: 11px;
  background: #fff; border: 2px solid var(--primary); color: var(--primary);
  border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer;
  letter-spacing: 1px; transition: all .15s;
}
.btn-copy-all:hover { background: var(--primary); color: #fff; }
.btn-copy-all.done { background: #16a34a; border-color: #16a34a; color: #fff; }

/* AI优化按钮 */
.btn-ai {
  background: var(--grad); color: #fff; border: none;
  border-radius: 999px; padding: 6px 16px; font-size: 13px; cursor: pointer;
  font-weight: 600; transition: all .15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn-ai:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(255, 60, 0, 0.3); }
.btn-ai:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-ai.done { background: #16a34a; }

/* AI优化结果对比 */
.ai-result {
  margin-top: 10px; padding: 12px; background: #f0fdf4; border-radius: 10px;
  border: 1px solid #bbf7d0;
}
.ai-result-label { font-size: 12px; color: #166534; font-weight: 600; margin-bottom: 6px; }
.ai-result-text { font-size: 14px; line-height: 1.7; }
.ai-loading {
  margin-top: 10px; padding: 12px; background: #fffaf5; border-radius: 10px;
  border: 1px solid #fed7aa; color: #ea580c; font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}

/* ===== 历史记录 ===== */
.history-card { margin-top: 20px; }
.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: #fffaf5; border-radius: 10px;
  border: 1px solid var(--border); font-size: 13px;
}
.history-item-info { flex: 1; }
.history-item-title { font-weight: 600; }
.history-item-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.history-item-btn {
  background: #fff; border: 1px solid var(--border); color: var(--primary);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
  font-weight: 600;
}
.history-item-btn:hover { background: var(--primary); color: #fff; }
.empty-tip { color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }

.btn-mini {
  background: #fff; border: 1.5px solid var(--primary); color: var(--primary);
  border-radius: 999px; padding: 3px 11px; font-size: 12px; cursor: pointer;
  font-weight: 600; transition: all .15s;
}
.btn-mini:hover { background: var(--primary); color: #fff; }

/* ===== 加载/错误 ===== */
.loading { text-align: center; margin-top: 14px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 8px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 手机端 ===== */
@media (max-width: 600px) {
  .page { padding: 12px 10px 28px; }
  .hero { padding: 14px 0 12px; }
  .hero h1 { font-size: 22px; }
  .hero .sub { font-size: 13px; }
  .steps { gap: 6px; }
  .steps span { padding: 4px 9px; font-size: 11.5px; }
  .card { padding: 14px 12px; }
  .card h2 { font-size: 16px; margin-bottom: 12px; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .filter-bar { gap: 5px; }
  .filter-tag { padding: 4px 9px; font-size: 11.5px; }
  .template-item { padding: 10px 12px; }
  .template-item-title { font-size: 13px; }
  .block-body { font-size: 13px; padding: 10px 12px; }
  .block-body.script { font-size: 14px; }
  .block-body.prompt { font-size: 12px; }
  .btn-copy-all { font-size: 14px; padding: 10px; }
  .btn-ai { padding: 5px 12px; font-size: 12px; }
  .btn-copy { padding: 3px 10px; font-size: 11.5px; }
  .modal { width: 100%; height: 100%; border-radius: 0; max-height: 100vh; }
  .modal-overlay { padding: 0; }
  .modal-head { padding: 14px 16px; }
  .modal-head h3 { font-size: 16px; }
  .modal-body { padding: 16px; max-height: 80vh; overflow-y: auto; }
  .history-item { padding: 8px 10px; font-size: 12px; }
  .history-item-btn { padding: 3px 8px; font-size: 11px; }
  input, textarea, select { padding: 9px 11px; font-size: 13px; }
  label { font-size: 13px; }
}

/* ===== 自定义下拉 ===== */
.custom-select { position: relative; width: 100%; }
.custom-select input { margin-top: 6px; padding-right: 32px; cursor: pointer; }
.custom-select-arrow {
  position: absolute; right: 12px; top: 50%; transform: translateY(-20%);
  font-size: 10px; color: var(--muted); pointer-events: none; user-select: none;
}
.custom-select-dropdown {
  position: absolute; z-index: 1000; top: 100%; left: 0; right: 0;
  background: #fff; border: 1.5px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(255,90,31,.15);
  max-height: 200px; overflow-y: auto; display: none;
  margin-top: 4px;
}
.custom-select-dropdown.open { display: block; }
.custom-select-option {
  padding: 9px 13px; font-size: 14px; cursor: pointer;
  transition: background .12s; color: var(--text);
  display: flex; justify-content: space-between; align-items: center;
}
.custom-select-option:hover, .custom-select-option.active { background: #fff5ee; color: var(--primary); }
.custom-select-option.custom-entry { color: #7c3aed; font-style: italic; border-top: 1px dashed var(--border); }
.custom-select-option.custom-entry::before { content: "✏️ 自定义: "; font-style: normal; font-size: 12px; color: var(--muted); }
.custom-select-noresult { padding: 12px 13px; text-align: center; color: var(--muted); font-size: 13px; }

footer { text-align: center; color: #c9b8ae; font-size: 12px; margin-top: 28px; }
