:root {
  --bg: #f3f4fa;
  --panel: #ffffff;
  --ink: #1c2033;
  --sub: #6b7186;
  --line: #e6e8f0;
  --brand: #5b5bf0;
  --brand2: #8b5cf6;
  --brand-grad: linear-gradient(135deg, #5b5bf0, #8b5cf6);
  --brand-bg: #eef0ff;
  --ok: #16a34a;
  --warn: #e5484d;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 35, 60, .05);
  --shadow-lg: 0 12px 36px rgba(30, 35, 60, .12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; outline: none; }
a { color: var(--brand); text-decoration: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 60px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.logo { font-size: 17px; font-weight: 800; letter-spacing: .3px; display: flex; align-items: center; gap: 10px; }
.logo .dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--brand-grad);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; box-shadow: 0 4px 12px rgba(91,91,240,.35);
}
.topbar .spacer { flex: 1; }
.topnav a {
  padding: 9px 16px; border-radius: 10px; color: var(--sub);
  font-weight: 600; font-size: 14px; transition: all .15s;
}
.topnav a:hover { color: var(--brand); background: var(--brand-bg); }
.topnav a.active { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 14px rgba(91,91,240,.3); }

/* ---------- 布局 ---------- */
.page { padding: 28px; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.page-head h2 { font-size: 24px; font-weight: 800; }
.page-head .sub { color: var(--sub); font-size: 13px; background: var(--panel); border: 1px solid var(--line); padding: 3px 12px; border-radius: 20px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-size: 13px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(91,91,240,.12); }
.btn.primary { background: var(--brand-grad); border: none; color: #fff; box-shadow: 0 4px 14px rgba(91,91,240,.28); }
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(91,91,240,.38); }
.btn.ghost { background: var(--brand-bg); border-color: transparent; color: var(--brand); }
.btn.danger { color: var(--warn); }
.btn.danger:hover { border-color: var(--warn); box-shadow: none; }
.btn.sm { padding: 5px 12px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; box-shadow: none !important; }
.btn.busy::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.btn.ghost.busy::before { border-color: rgba(91,91,240,.3); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 卡片 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* 作品库 */
.novel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.novel-card { padding: 0; cursor: pointer; overflow: hidden; transition: all .18s; display: flex; flex-direction: column; }
.novel-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: rgba(91,91,240,.35); }
.novel-cover { height: 74px; display: flex; align-items: flex-end; padding: 10px 16px; color: #fff; font-size: 12px; font-weight: 700; letter-spacing: 2px; }
.novel-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.novel-card h3 { font-size: 16px; font-weight: 700; }
.novel-card .meta { color: var(--sub); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.novel-card .intro { color: var(--sub); font-size: 13px; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 42px; }
.novel-card .foot { display: flex; align-items: center; justify-content: space-between; color: #9aa0b4; font-size: 12px; margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--line); }
.tag { padding: 2px 10px; border-radius: 20px; background: var(--brand-bg); color: var(--brand); font-size: 12px; font-weight: 600; }
.tag.gray { background: #f1f2f7; color: var(--sub); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.连载中 { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.status-dot.草稿 { background: #b6bac9; }
.status-dot.已完结 { background: var(--brand); box-shadow: 0 0 0 3px rgba(91,91,240,.15); }
.add-card {
  border-style: dashed; color: var(--sub); justify-content: center;
  align-items: center; min-height: 190px; font-size: 14px; background: rgba(255,255,255,.5);
}
.add-card:hover { color: var(--brand); border-color: var(--brand); background: var(--brand-bg); }

/* 详情页 */
.detail-hero {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; position: relative; overflow: hidden;
}
.detail-hero::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--brand-grad);
}
.detail-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.detail-head .info { flex: 1; min-width: 280px; }
.detail-head h2 { font-size: 24px; font-weight: 800; }
.detail-head .meta { color: var(--sub); margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.detail-head .actions { display: flex; gap: 8px; align-items: center; }
.export-wrap { position: relative; }
.export-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.14); overflow: hidden; min-width: 150px;
}
.export-menu a {
  display: block; padding: 10px 16px; font-size: 13px; cursor: pointer; color: var(--ink);
}
.export-menu a:hover { background: rgba(108,92,231,.08); color: var(--brand); }
select.input {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--panel); color: var(--ink); font-size: 13px;
}
.stats { display: flex; gap: 12px; margin-top: 16px; }
.stat {
  background: #f7f8fd; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 20px; text-align: center; min-width: 92px;
}
.stat b { font-size: 20px; font-weight: 800; display: block; color: var(--brand); }
.stat span { color: var(--sub); font-size: 12px; }

.tabs { display: flex; gap: 6px; margin: 22px 0 18px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: fit-content; box-shadow: var(--shadow); }
.tabs button {
  padding: 8px 18px; border: none; background: none; color: var(--sub);
  font-size: 14px; font-weight: 600; border-radius: 9px; transition: all .15s;
}
.tabs button:hover { color: var(--brand); }
.tabs button.active { background: var(--brand-grad); color: #fff; box-shadow: 0 3px 10px rgba(91,91,240,.3); }

.tab-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.tab-toolbar .spacer { flex: 1; }

/* 大纲 */
.outline-tree { display: flex; flex-direction: column; gap: 12px; }
.outline-vol { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; box-shadow: var(--shadow); }
.outline-vol > .vol-head {
  padding: 13px 18px; background: linear-gradient(135deg, #f8f9ff, #f3f4fb);
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line);
}
.outline-vol .vol-head input { flex: 1; border: none; background: none; font-size: 15px; font-weight: 700; }
.outline-chapters { padding: 8px 18px; }
.outline-chapter { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.outline-chapter:last-child { border-bottom: none; }
.oc-head { display: flex; align-items: center; gap: 8px; width: 100%; }
.outline-chapter input { flex: 1; border: none; background: none; font-size: 13px; font-weight: 600; }
.outline-chapter textarea, .vol-desc textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  resize: vertical; min-height: 56px; font-size: 13px; line-height: 1.7; margin: 6px 0; background: #fafbfe;
}
.outline-chapter .desc { flex-basis: 100%; }

/* 章节区 */
.chapter-layout { display: grid; grid-template-columns: 230px 1fr; gap: 18px; align-items: start; }
.ch-list { max-height: calc(100vh - 240px); overflow: auto; display: flex; flex-direction: column; gap: 4px; padding: 10px; }
.ch-item { padding: 11px 14px; border-radius: 10px; cursor: pointer; color: var(--sub); font-size: 13px; font-weight: 500; transition: all .12s; display: flex; align-items: center; justify-content: space-between; }
.ch-item:hover { background: #f3f4fb; }
.ch-item.active { background: var(--brand-bg); color: var(--brand); font-weight: 700; box-shadow: inset 3px 0 0 var(--brand); }
.ch-item .w { font-size: 11px; color: #a6abc0; margin-left: 6px; }
.editor { padding: 26px; }
.editor-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.editor-head input {
  flex: 1; min-width: 200px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: 18px; font-weight: 700;
}
#chapterContent {
  width: 100%; min-height: 520px; border: 1px solid var(--line); border-radius: 12px;
  padding: 22px; font-size: 15px; line-height: 2.05; resize: vertical; background: #fdfdfe;
  box-shadow: inset 0 2px 8px rgba(30,35,60,.03);
}
#chapterContent:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(91,91,240,.12); }
.editor-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; color: var(--sub); font-size: 13px; }
.save-state { margin-left: auto; font-size: 12px; font-weight: 600; padding: 3px 12px; border-radius: 20px; }
.save-state.saved { color: var(--ok); background: rgba(22,163,74,.1); }
.save-state.dirty { color: var(--warn); background: rgba(229,72,77,.1); }
.save-state.err { color: var(--warn); background: rgba(229,72,77,.1); }

/* 角色 */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.char-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; transition: all .15s; }
.char-card:hover { box-shadow: var(--shadow-lg); }
.char-card h4 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.char-avatar {
  width: 34px; height: 34px; border-radius: 10px; background: var(--brand-grad);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 15px;
  box-shadow: 0 3px 10px rgba(91,91,240,.3);
}
.char-card .info { color: var(--sub); font-size: 13px; line-height: 1.75; white-space: pre-wrap; max-height: 240px; overflow: auto; }
.char-card .info[contenteditable="true"] { border: 1px dashed var(--brand); border-radius: 10px; padding: 10px; background: #fff; }

/* 世界观 */
.world-list { display: flex; flex-direction: column; gap: 14px; }
.world-item { padding: 18px; }
.world-item h4 { font-size: 15px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.world-item .content { color: var(--sub); font-size: 13px; line-height: 1.85; white-space: pre-wrap; max-height: 320px; overflow: auto; }

/* 素材 */
.material-list { display: flex; flex-direction: column; gap: 12px; }
.material-item { padding: 14px 18px; display: flex; gap: 12px; align-items: flex-start; }
.material-item .content { flex: 1; line-height: 1.75; white-space: pre-wrap; }

/* 设置 */
.settings-form { max-width: 580px; padding: 28px; display: flex; flex-direction: column; gap: 20px; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 7px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px;
  transition: all .15s;
}
.field input:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(91,91,240,.12); }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.7; }
.field .hint { font-size: 12px; color: #a0a5ba; margin-top: 5px; }
.settings-actions { display: flex; gap: 10px; align-items: center; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(22,26,45,.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--panel); border-radius: 18px; width: 100%; max-width: 720px;
  max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,.28); animation: pop .2s ease;
}
.modal.lg { max-width: 880px; }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head { padding: 18px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h3 { font-size: 16px; font-weight: 800; flex: 1; }
.modal-body { padding: 22px 24px; overflow: auto; flex: 1; min-height: 0; }
.modal-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; }
.modal-foot:empty { display: none; }
.ai-loading { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 70px 0; color: var(--sub); }
.ai-loading .ring {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(91,91,240,.15); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
.ai-loading .tip { font-size: 13px; color: #a0a5ba; animation: pulse 1.6s ease infinite; }
@keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
.ai-result { white-space: pre-wrap; line-height: 1.9; font-size: 14px; }
.ai-result h1,.ai-result h2,.ai-result h3,.ai-result h4 { margin: 16px 0 8px; font-size: 15px; font-weight: 800; color: var(--ink); }
.ai-result ul,.ai-result ol { padding-left: 22px; }
.ai-result p { margin: 7px 0; }

/* Toast */
#toast-root { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 11px 20px; border-radius: 10px; color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: fadein .25s;
}
.toast.ok { background: linear-gradient(135deg, #22c55e, #16a34a); }
.toast.err { background: linear-gradient(135deg, #f43f5e, #e5484d); }
.toast.info { background: linear-gradient(135deg, #475569, #334155); }
@keyframes fadein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }

.empty { text-align: center; color: #a0a5ba; padding: 60px 0; }
.empty .big { font-size: 44px; margin-bottom: 12px; filter: drop-shadow(0 6px 16px rgba(91,91,240,.25)); }
.empty p { font-size: 14px; line-height: 1.8; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d6e4; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #b8bcd0; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .chapter-layout { grid-template-columns: 1fr; }
  .ch-list { max-height: 200px; }
}
