:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d212c;
  --line: #2a2f3c;
  --text: #e6e8ef;
  --text-dim: #9aa3b2;
  --accent: #ff7a45;
  --accent-2: #6ea8fe;
  --ok: #4fd1a5;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #14171f, #0f1115);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-size: 20px; color: #fff;
  background: linear-gradient(135deg, var(--accent), #ff4d6d);
  box-shadow: 0 4px 14px rgba(255,122,69,.35);
}
.topbar h1 { font-size: 18px; margin: 0; }
.sub { margin: 0; color: var(--text-dim); font-size: 12px; }
.topbar-tag {
  font-size: 12px; color: var(--accent-2); border: 1px solid var(--line);
  background: var(--bg-3); padding: 6px 14px; border-radius: 20px; white-space: nowrap;
}

.mode-switch { display: flex; background: var(--bg-3); border-radius: 10px; padding: 3px; }
.mode-btn {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 7px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.mode-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* 布局 */
.layout {
  display: grid; grid-template-columns: 380px 1fr; gap: 18px;
  padding: 18px 24px; align-items: start; max-width: 1500px; margin: 0 auto;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.panel-title { font-size: 15px; margin: 0 0 14px; }

/* 表单 */
.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text-dim); }
input, select, textarea {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; font-family: inherit;
  width: 100%; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
textarea { resize: vertical; }
.hint { font-size: 11px; color: var(--text-dim); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* API 设置 */
.api-box { margin: 6px 0 14px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.api-box summary { cursor: pointer; color: var(--accent-2); font-size: 13px; user-select: none; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.preset {
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text-dim);
  border-radius: 20px; padding: 4px 12px; font-size: 12px; cursor: pointer;
}
.preset:hover { border-color: var(--accent-2); color: var(--text); }

/* 按钮 */
.actions { display: flex; gap: 10px; margin-top: 6px; }
.primary {
  flex: 1; border: 0; background: linear-gradient(135deg, var(--accent), #ff4d6d);
  color: #fff; font-weight: 700; padding: 11px; border-radius: 10px; cursor: pointer;
  font-size: 14px; box-shadow: 0 6px 18px rgba(255,77,109,.3);
}
.primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.ghost { border: 1px solid var(--line); background: transparent; color: var(--text-dim); padding: 11px 16px; border-radius: 10px; cursor: pointer; }
.ghost:hover { color: var(--text); border-color: var(--accent); }

.progress-wrap { margin-top: 14px; }
.progress-bar { height: 7px; background: var(--bg-3); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-2), var(--ok)); transition: width .3s; }
.progress-text { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

/* 输出 */
.out-head { display: flex; align-items: center; justify-content: space-between; }
.out-tools { display: flex; gap: 8px; }
.tool { border: 1px solid var(--line); background: var(--bg-3); color: var(--text-dim); border-radius: 8px; padding: 5px 12px; font-size: 12px; cursor: pointer; }
.tool:hover { color: var(--text); border-color: var(--accent-2); }

.output { margin-top: 14px; max-height: 70vh; overflow-y: auto; padding-right: 6px; }
.placeholder { color: var(--text-dim); text-align: center; padding: 60px 20px; border: 1px dashed var(--line); border-radius: 10px; }

/* 书本渲染 */
.book-title { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.book-meta { color: var(--text-dim); font-size: 12px; margin-bottom: 14px; }
.outline-card { background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 18px; }
.outline-card h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.outline-card p { margin: 4px 0; font-size: 13px; }
.outline-card .lab { color: var(--text-dim); }

.vol { border-left: 3px solid var(--accent-2); padding-left: 14px; margin: 18px 0; }
.vol-title { font-size: 16px; font-weight: 700; margin: 0 0 4px; }
.vol-sum { color: var(--text-dim); font-size: 12px; margin-bottom: 10px; }
.chapter { margin: 14px 0; }
.ch-title { font-size: 14px; font-weight: 600; color: var(--ok); margin: 0 0 6px; }
.ch-body { font-size: 14px; color: var(--text); white-space: pre-wrap; text-align: justify; }
.ch-body.streaming::after { content: '▍'; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; opacity: 0;
  transition: opacity .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }

/* 混合内容提示 */
.notice {
  margin-top: 10px; padding: 9px 11px; border-radius: 8px; font-size: 12px; line-height: 1.5;
  background: rgba(255,77,109,.1); border: 1px solid rgba(255,77,109,.35); color: #ffb3c1;
}
.notice b { color: #fff; }

/* 历史记录 */
.history-box { margin-top: 14px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.history-box summary { cursor: pointer; color: var(--accent-2); font-size: 13px; user-select: none; }
.history-box .count { color: var(--text-dim); font-size: 12px; }
.hist-list { margin: 10px 0; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.hist-empty { color: var(--text-dim); font-size: 12px; padding: 6px 2px; }
.hist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; cursor: pointer;
}
.hist-item:hover { border-color: var(--accent-2); }
.hist-item .hi-main { min-width: 0; }
.hist-item .hi-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item .hi-meta { font-size: 11px; color: var(--text-dim); }
.hist-item .hi-del { border: 0; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 6px; }
.hist-item .hi-del:hover { color: #ff6b81; background: rgba(255,77,109,.12); }
.tool.danger:hover { color: #ff6b81; border-color: #ff6b81; }

/* 章节标题行 + 操作按钮 */
.ch-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ch-ops { display: flex; gap: 6px; flex-shrink: 0; }
.ch-ops button {
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text-dim);
  border-radius: 6px; padding: 2px 9px; font-size: 11px; cursor: pointer;
}
.ch-ops button:hover { color: var(--text); border-color: var(--accent-2); }
.ch-ops button:disabled { opacity: .45; cursor: not-allowed; }
