/* ── 设计 token ─────────────────────────────── */
:root {
  --bg:        #0b0c10;
  --bg-panel:  #111319;
  --bg-card:   #161922;
  --bg-card-2: #1b1f2a;
  --bg-input:  #0e1016;
  --border:    #232734;
  --border-hi: #343a4d;
  --text:      #e6e8ef;
  --text-2:    #9aa0b4;
  --text-3:    #626a82;
  --paper:     #f3ece2;
  --accent:    #d34a2f;
  --accent-h:  #b83a22;
  --accent-2:  #e8a06a;
  --green:     #10b981;
  --green-h:   #059669;
  --amber:     #f0b429;
  --red-dim:   #f87171;
  --font-display: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  font: 14px/1.5 -apple-system, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

/* ── 主题：日间（纸白） ─────────────────────── */
:root[data-theme="light"] {
  --bg: #f7f5f0; --bg-panel: #ffffff; --bg-card: #ffffff; --bg-card-2: #f2efe8;
  --bg-input: #faf9f5; --border: #e2ddd0; --border-hi: #cfc8b5;
  --text: #2b2621; --text-2: #635c50; --text-3: #948c7c; --paper: #2b2621;
  color-scheme: light;
}

/* ── 主题：天青护眼 ─────────────────────────── */
:root[data-theme="qing"] {
  --bg: #eaf1ef; --bg-panel: #f2f7f5; --bg-card: #ffffff; --bg-card-2: #e3edea;
  --bg-input: #f6faf8; --border: #cfe0da; --border-hi: #a9c4bc;
  --text: #24322e; --text-2: #57685f; --text-3: #839187; --paper: #24322e;
  color-scheme: light;
}

/* ── 主题：豆沙绿护眼 ───────────────────────── */
:root[data-theme="green"] {
  --bg: #e6f4e4; --bg-panel: #eef8ec; --bg-card: #f7fdf6; --bg-card-2: #dcefd9;
  --bg-input: #f2faf1; --border: #c9e2c4; --border-hi: #a3cd9c;
  --text: #223420; --text-2: #4f6b4a; --text-3: #7d9877; --paper: #223420;
  color-scheme: light;
}

/* ── 主题：米黄护眼 ─────────────────────────── */
:root[data-theme="sepia"] {
  --bg: #f2e8d5; --bg-panel: #f8f0e0; --bg-card: #fffaf0; --bg-card-2: #ecdfc4;
  --bg-input: #faf3e3; --border: #ddccab; --border-hi: #c6b287;
  --text: #3a2f1d; --text-2: #6b5c3e; --text-3: #9c8a63; --paper: #3a2f1d;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  background:
    radial-gradient(900px 500px at 78% -10%, rgba(211,74,47,.07), transparent 60%),
    radial-gradient(700px 500px at 0% 110%, rgba(232,160,106,.05), transparent 55%),
    var(--bg);
  color: var(--text); height: 100vh;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ── Header ─────────────────────────────────── */
header {
  flex-shrink: 0; height: 50px;
  display: flex; align-items: center; gap: 16px; padding: 0 18px;
  background: var(--bg-panel); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); z-index: 10;
}
.logo {
  font-size: 14px; font-weight: 700; letter-spacing: -.2px; color: var(--text);
}
.logo::before { content: "﹅"; color: var(--accent); margin-right: 5px; font-weight: 700; }
.header-chapter { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-title { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-meta { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 12px; }
.model-badge {
  font-size: 11px; color: var(--text-3); padding: 3px 9px;
  border: 1px solid var(--border); border-radius: 20px; cursor: pointer;
}
.model-badge.ok  { color: #4ade80; border-color: #1c3525; background: #0e1c14; }
.model-badge.err { color: var(--red-dim); border-color: #3a1a1a; }
.status-text { font-size: 12px; color: var(--text-3); min-width: 76px; text-align: right; }

.theme-switch { display: flex; align-items: center; gap: 5px; }
.theme-dot {
  width: 16px; height: 16px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border-hi); cursor: pointer; transition: transform .12s;
}
.theme-dot:hover { transform: scale(1.15); }
.theme-dot.active { box-shadow: 0 0 0 2px var(--accent); }
.theme-dot[data-theme="dark"]  { background: #0b0c10; }
.theme-dot[data-theme="light"] { background: #f7f5f0; }
.theme-dot[data-theme="qing"]  { background: #cfe0da; }
.theme-dot[data-theme="green"] { background: #c9e2c4; }
.theme-dot[data-theme="sepia"] { background: #e6d3a6; }

#ai-tab-model, #ai-tab-search { display: flex; flex-direction: column; gap: 10px; }
.model-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.model-panel-head b { font-size: 13px; color: var(--text); }
.model-panel-head p { margin: 2px 0 0; font-size: 11px; color: var(--text-3); }
.ready-dot { width: 9px; height: 9px; border-radius: 999px; margin-top: 5px; background: var(--text-3); box-shadow: 0 0 0 4px rgba(98,106,130,.12); }
.ready-dot.ok { background: var(--green); box-shadow: 0 0 0 4px rgba(16,185,129,.13); }
.ready-dot.err { background: var(--red-dim); box-shadow: 0 0 0 4px rgba(248,113,113,.12); }
.model-edit-form { display: flex; flex-direction: column; gap: 8px; }
.model-edit-form label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3);
}
.model-edit-form input, .model-edit-form select { min-height: 36px; width: 100%; }
.model-edit-form input[readonly] { color: var(--text-3); background: var(--bg-panel); cursor: not-allowed; }
.input-with-toggle { display: flex; gap: 6px; }
.input-with-toggle input { flex: 1; min-width: 0; }
.input-with-toggle button { flex-shrink: 0; min-height: 36px; }
.model-key-state {
  font-size: 11px; color: var(--text-3);
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input);
}
.model-key-state span { color: var(--text-2); }
.model-error { padding: 8px 10px; border: 1px solid #3a1a1a; border-radius: 8px; background: #190d0d; color: var(--red-dim); font-size: 12px; line-height: 1.45; }
.model-error.ok { border-color: #1c3525; background: #0e1c14; color: #4ade80; }
#model-json-preview, #search-json-preview {
  width: 100%; resize: none; min-height: 96px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-2);
}
.model-panel-actions { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.provider-layout { display: flex; gap: 12px; align-items: flex-start; }
.provider-list { width: 168px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; }
.provider-row {
  display: flex; align-items: center; gap: 6px; padding: 7px 9px; border-radius: 8px;
  border: 1px solid transparent; background: var(--bg-panel); cursor: pointer; font-size: 12px;
}
.provider-row:hover { background: var(--bg-input); }
.provider-row.selected { border-color: var(--accent); }
.provider-row .dot { width: 7px; height: 7px; border-radius: 999px; background: var(--text-3); flex-shrink: 0; }
.provider-row .dot.active { background: var(--green); }
.provider-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-detail { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.provider-models { display: flex; flex-direction: column; gap: 6px; }
.provider-models-head { display: flex; align-items: center; justify-content: space-between; }
#model-search { width: 100%; min-height: 32px; }
.provider-model-row { display: flex; align-items: center; gap: 6px; }
.provider-model-row input { min-height: 32px; }
.provider-model-row .model-nickname { width: 90px; flex-shrink: 0; }
.provider-model-row .model-id { flex: 1; min-width: 0; }
#ai-settings-dialog { width: 760px; }
@media (max-width: 860px) {
  #ai-settings-dialog { width: 92vw; }
  .provider-layout { flex-direction: column; }
  .provider-list { width: 100%; flex-direction: row; flex-wrap: wrap; }
}

/* ── Layout ─────────────────────────────────── */
main {
  flex: 1; overflow: hidden;
  display: grid; grid-template-columns: 216px 1fr 300px;
}

/* ── 左 sidebar ─────────────────────────────── */
.sidebar {
  background: var(--bg-panel); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.nav-section { border-radius: 8px; }
.nav-section > summary {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-3); padding: 7px 6px; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 5px;
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary::before {
  content: "▸"; font-size: 9px; transition: transform .15s; color: var(--text-3);
}
.nav-section[open] > summary::before { transform: rotate(90deg); }
.nav-section form { display: flex; gap: 4px; padding: 0 4px 6px; }
.nav-section form input {
  flex: 1; min-width: 0; font: inherit; font-size: 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-2); border-radius: 6px; padding: 5px 8px; outline: none;
  transition: border-color .15s, color .15s;
}
.nav-section form input:focus { border-color: var(--accent); color: var(--text); }
.nav-section form button {
  font-size: 15px; line-height: 1; background: var(--bg-input);
  border: 1px solid var(--border); color: var(--text-3);
  border-radius: 6px; padding: 5px 9px; cursor: pointer; transition: .12s;
}
.nav-section form button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.nav-section select {
  width: 100%; font: 13px/1.4 inherit; background: transparent;
  border: none; color: var(--text-2); outline: none; cursor: pointer; padding: 0 4px;
}
.nav-section select option { background: var(--bg-panel); padding: 4px; border-radius: 4px; }
.nav-section select option:checked { background: var(--accent); color: #fff; }
.nav-actions { display: flex; gap: 4px; padding: 2px 4px 4px; }
.nav-actions .danger:hover { color: var(--red-dim); }

/* ── 中 workspace ───────────────────────────── */
.workspace { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }

/* 空状态引导：手稿格背景 + 印记式步骤，呼应"稿纸改稿"的写作场景 */
.onboarding {
  position: relative; isolation: isolate; overflow: hidden;
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 40px; text-align: center;
}
.onboarding::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background-image:
    linear-gradient(rgba(230,232,239,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(230,232,239,.05) 1px, transparent 1px);
  background-size: 30px 30px; background-position: center;
  -webkit-mask-image: radial-gradient(ellipse 60% 58% at 50% 44%, #000 35%, transparent 82%);
          mask-image: radial-gradient(ellipse 60% 58% at 50% 44%, #000 35%, transparent 82%);
}
.onboarding h1 {
  font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: .5px;
  color: var(--paper); position: relative; padding-bottom: 15px;
}
.onboarding h1::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 44px; height: 5px;
  background: var(--accent); border-radius: 3px; transform: translateX(-50%) rotate(-1.5deg);
}
.onboarding-sub { color: var(--text-3); margin: 19px 0 20px; }
.steps { list-style: none; display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 420px; }
.steps li {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; transition: .2s;
}
.steps li.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 30px rgba(211,74,47,.16); }
.steps li.done { opacity: .55; }
.step-no {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 4px; position: relative;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  font-family: var(--font-display);
  background: var(--bg-input); border: 1px solid var(--border-hi); color: var(--text-2);
}
.steps li.active .step-no { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps li.done .step-no { background: var(--green); border-color: var(--green); color: transparent; }
.steps li.done .step-no::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.steps li div { display: flex; flex-direction: column; }
.steps li b { font-size: 14px; color: var(--text); }
.steps li span:not(.step-no) { font-size: 12px; color: var(--text-3); }

/* 写作面板 */
.writing { flex: 1; display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow: hidden; min-height: 0; }

/* 写作区三步指示器 */
.step-indicator {
  flex-shrink: 0; list-style: none; display: flex; gap: 8px;
}
.step-item {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text-3);
  background: var(--bg-card); border: 1px solid var(--border); transition: .15s;
}
.step-item:hover { color: var(--text-2); }
.step-item .step-no {
  width: 20px; height: 20px; font-size: 11px; border-radius: 4px;
}
.step-item.active { color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.step-item.active .step-no { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-item.done .step-no { background: var(--green); border-color: var(--green); color: transparent; position: relative; }
.step-item.done .step-no::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.step-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.step-panel[hidden] { display: none; }
.step-panel[data-step="1"] .story-card { max-height: none; flex: 1; }
.step-next-row { display: flex; justify-content: flex-end; padding-top: 4px; }
.finalize-card { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.finalize-card .ctx-label { padding: 14px 16px 0; }
.finalize-card .ctx-body { padding: 8px 16px 16px; }

/* ── Cards ──────────────────────────────────── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; }
details.card > summary {
  display: flex; align-items: center; gap: 8px; padding: 11px 16px;
  cursor: pointer; user-select: none; list-style: none;
  border-bottom: 1px solid transparent; transition: border-color .15s;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { border-bottom-color: var(--border); }
details.card > summary::after { content: "›"; color: var(--text-3); font-size: 16px; margin-left: auto; transition: transform .2s; }
details.card[open] > summary::after { transform: rotate(90deg); }
.panel-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px; color: var(--text-2); }

/* 剧情卡 */
.story-card { flex-shrink: 0; max-height: 46%; display: flex; flex-direction: column; overflow: hidden; }
.story-card .card-inner { padding: 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); }
.field textarea { font: 13px/1.6 inherit; text-transform: none; letter-spacing: 0; font-weight: 400; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid.compact { grid-template-columns: 130px 1fr; }
.field input { text-transform: none; letter-spacing: 0; font-weight: 400; }
.card-state {
  margin-left: auto; font-size: 10px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  background: #2a230a; color: var(--amber); border: 1px solid #4a3d0a;
}
.card-state.done { background: #0e1c14; color: #4ade80; border-color: #1c3525; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 2px; }
#card-details > summary {
  list-style: none; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-3); padding: 2px 0; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 5px;
}
#card-details > summary::-webkit-details-marker { display: none; }
#card-details > summary::before { content: "▸"; font-size: 9px; transition: transform .15s; }
#card-details[open] > summary::before { transform: rotate(90deg); }
.card-details-body { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.check-label { display: flex; flex-direction: row; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.gap { flex: 1; }

/* 编辑器卡 */
.editor-card { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.editor-tabs { flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.tab {
  font: inherit; font-size: 13px; color: var(--text-3); background: transparent;
  border: none; border-radius: 7px; padding: 6px 14px; cursor: pointer; transition: .12s;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text-2); background: var(--bg-input); }
.tab.active { color: var(--text); background: var(--bg-input); font-weight: 600; }
.tab-side { font-size: 12px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.editor-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.prose {
  flex: 1; display: block; width: 100%; resize: none; min-height: 0;
  background: transparent; border: none; outline: none; color: var(--text);
  font: 16px/1.95 Georgia, "Noto Serif SC", serif; padding: 24px 30px; caret-color: var(--accent);
}
.preview-prose { color: var(--text); }
.preview-bar {
  flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-top: 1px solid var(--border); background: var(--bg-card-2);
}
.preview-hint { flex: 1; font-size: 12px; color: var(--text-3); }

/* 底部操作栏 */
.action-bar {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-top: 1px solid var(--border); background: var(--bg-panel);
}
.action-bar input { flex: 1; min-width: 80px; }
.action-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; margin: 0 4px; }
.draft-state { font-size: 11px; color: var(--amber); white-space: nowrap; }

/* ── 右 copilot ─────────────────────────────── */
.copilot {
  background: var(--bg-panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 10px;
}
.copilot-card, .ctx-summary { padding: 0; }
.ctx-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); display: block; padding: 11px 14px 0; }
.ctx-label.inline { padding: 0; }
.ctx-summary { background: linear-gradient(135deg, var(--bg-card), var(--bg-card-2)); }
.ctx-goal { padding: 6px 14px 14px; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.ai-group { display: flex; flex-direction: column; gap: 7px; padding: 10px 12px; }
.ai-group + .ai-group { border-top: 1px solid var(--border); }
.group-label { font-size: 11px; color: var(--text-3); }
.copilot-card .btn-generate { margin: 0; width: 100%; }
.ai-secondary { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.local-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.local-grid button { flex: 1 1 30%; font-size: 12px; padding: 6px 8px; white-space: nowrap; }
#stop-ai.full { width: calc(100% - 24px); margin: 0 12px 12px; }
details.card.copilot-card > summary { padding: 11px 14px; }
details.card.copilot-card > summary::after { display: none; }
details.card.copilot-card > summary::before { content: "▸"; font-size: 10px; color: var(--text-3); transition: transform .15s; margin-right: 4px; }
details.card.copilot-card[open] > summary::before { transform: rotate(90deg); }
.ctx-body { display: flex; flex-direction: column; gap: 8px; padding: 0 12px 12px; }
.ctx-body .field { font-size: 10px; }
#search-query { width: 100%; }
#memory-candidate .row-actions { margin-top: 8px; }
.hint { font-size: 11px; color: var(--text-3); line-height: 1.5; }
.compact-text { font-size: 12px; color: var(--text-2); line-height: 1.55; }
.mini-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.mini-list li { font-size: 12px; line-height: 1.45; color: var(--text-2); padding: 6px 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 7px; }
.mini-list li.empty { color: var(--text-3); background: none; border: none; padding: 0; }
.mini-list b { color: var(--text); font-weight: 600; }
.field-label { font-size: 11px; color: var(--text-2); margin: 8px 0 4px; font-weight: 500; }
.mem-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.mem-row input, .mem-row select { flex: 1; min-width: 0; }
.mem-remove { flex-shrink: 0; padding: 0 6px; color: var(--red-dim); }
.small { font-size: 11px; padding: 2px 8px; }
.full   { width: 100%; }
.full-w { width: 100%; margin-bottom: 5px; }
.setting-form { display: flex; flex-direction: column; gap: 7px; }
.setting-form textarea { min-height: 70px; }
.settings-list { display: flex; flex-direction: column; gap: 7px; }
.setting-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--bg-input); display: flex; flex-direction: column; gap: 5px; }
.setting-item.editing { border-color: var(--accent); }
.hint code { background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.setting-item div { display: flex; align-items: center; gap: 6px; }
.setting-item b { font-size: 13px; color: var(--text); }
.setting-item span { font-size: 10px; color: var(--accent); border: 1px solid rgba(211,74,47,.3); border-radius: 999px; padding: 1px 6px; }
.setting-item p { font-size: 12px; color: var(--text-2); line-height: 1.5; }
.setting-item button { align-self: flex-start; }

/* ── 按钮 ───────────────────────────────────── */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 56px; }
button {
  font: inherit; color: var(--text-2); background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 14px;
  cursor: pointer; transition: .12s; white-space: nowrap;
}
button:hover { background: var(--bg-card-2); color: var(--text); }
button:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); color: #fff; }
.btn-generate {
  font-size: 15px; font-weight: 600; padding: 12px;
  color: #fff; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px rgba(211,74,47,.32);
}
.btn-generate:hover { color: #fff; filter: brightness(1.08); box-shadow: 0 8px 26px rgba(211,74,47,.42); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-3); font-size: 12px; padding: 5px 9px; }
.btn-ghost:hover { color: var(--text-2); background: var(--bg-input); }
.btn-stop { color: var(--red-dim); border-color: #3a1a1a; background: #190d0d; }
.btn-stop:hover { background: #271010; color: var(--red-dim); }
.btn-accept { background: var(--green); border-color: var(--green); color: #fff; }
.btn-accept:not(:disabled):hover { background: var(--green-h); border-color: var(--green-h); color: #fff; }
.btn-accept:disabled { background: var(--bg-input); border-color: var(--border); color: var(--text-3); }

/* ── Badge ──────────────────────────────────── */
.badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: #2a230a; color: var(--amber); border: 1px solid #4a3d0a; }
.badge.done { background: #0e1c14; color: #4ade80; border-color: #1c3525; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Diff modal ─────────────────────────────── */
#diff-modal {
  margin: auto;
  width: 82vw; height: 82vh; max-width: 82vw; max-height: 82vh;
  resize: both; overflow: hidden; background: var(--bg-card);
  border: 1px solid var(--border-hi); border-radius: 12px; padding: 0; color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
}
#diff-modal[open] { display: flex; flex-direction: column; }
#diff-modal::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.diff-modal-head { flex-shrink: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; padding-right: 14px; border-bottom: 1px solid var(--border); background: var(--bg-panel); }
.diff-modal-titles { display: grid; grid-template-columns: 1fr 1fr; }
.diff-col-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .7px; padding: 12px 20px; border-right: 1px solid var(--border); }
.diff-modal-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; overflow: hidden; }
.diff-col { overflow-y: auto; padding: 20px 24px; font: 15px/1.85 Georgia, "Noto Serif SC", serif; white-space: pre-wrap; word-break: break-word; }
.diff-col:first-child { border-right: 1px solid var(--border); }
.diff-line-del { background: rgba(248,113,113,.18); color: #fca5a5; display: block; margin: 0 -24px; padding: 0 24px; }
.diff-line-ins { background: rgba(16,185,129,.15); color: #6ee7b7; display: block; margin: 0 -24px; padding: 0 24px; }
.diff-line-eq  { color: var(--text); }

.copilot-toolbar { display: flex; gap: 6px; padding: 0 2px; }
.copilot-toolbar button { flex: 1; }
.side-dialog {
  margin: auto;
  width: 420px; max-width: 92vw; max-height: 84vh;
  background: var(--bg-card); border: 1px solid var(--border-hi); border-radius: 12px;
  padding: 0; color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.7);
  overflow: hidden;
}
.side-dialog[open] { display: flex; flex-direction: column; }
.side-dialog.wide { width: 760px; }
.side-dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.side-dialog-head {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
}
.side-dialog-body { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }

.settings-graph-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--text-2); }
.settings-graph-legend span { display: inline-flex; align-items: center; gap: 5px; }
.settings-graph-legend i { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.settings-graph { width: 100%; height: 480px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; cursor: grab; touch-action: none; }
.settings-graph:active { cursor: grabbing; }
.settings-graph .graph-edge { stroke: var(--border-hi); stroke-width: 1.2; }
.settings-graph .graph-edge.dim { stroke-opacity: .15; }
.settings-graph .graph-node { stroke: var(--bg-input); stroke-width: 2; cursor: pointer; }
.settings-graph .graph-node.dim { opacity: .25; }
.settings-graph .graph-node.selected { stroke: var(--text); }
.settings-graph .graph-label { fill: var(--text-2); font-size: 10px; pointer-events: none; user-select: none; }
.settings-graph .graph-label.dim { opacity: .25; }

/* ── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ── 响应式 ─────────────────────────────────── */
@media (max-width: 1180px) { main { grid-template-columns: 196px 1fr 270px; } }
@media (max-width: 920px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  header {
    position: sticky; top: 0; height: auto; min-height: 52px;
    padding: 8px 12px; gap: 8px; flex-wrap: wrap;
  }
  .logo { flex: 0 0 auto; }
  .header-chapter { order: 3; flex-basis: 100%; min-height: 0; }
  .header-right { margin-left: auto; gap: 8px; min-width: 0; }
  .model-badge { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .status-text { min-width: auto; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main {
    display: flex; flex-direction: column; gap: 12px;
    overflow: visible; padding: 12px; min-height: calc(100vh - 52px);
  }
  .sidebar, .workspace, .copilot {
    border: 1px solid var(--border); border-radius: 14px;
    overflow: visible; width: 100%;
  }
  .sidebar {
    order: 1; padding: 10px; display: flex; max-height: none;
  }
  .workspace {
    order: 2; display: flex; min-height: 420px;
  }
  .copilot {
    order: 3; padding: 10px; display: flex;
  }
  .copilot[hidden], .writing[hidden], .onboarding[hidden] { display: none !important; }
  .onboarding { min-height: 360px; padding: 34px 16px; }
  .steps { max-width: none; }
  .writing { overflow: visible; padding: 10px; min-height: 720px; }
  .step-indicator { flex-wrap: wrap; }
  .step-item { flex: 1 1 100%; }
  .story-card { max-height: none; overflow: visible; }
  .story-card .card-inner { overflow: visible; }
  .editor-card { min-height: 520px; }
  .prose { padding: 18px 16px; font-size: 15px; }
  .field-grid, .field-grid.compact { grid-template-columns: 1fr; }
  .card-actions, .action-bar, .preview-bar, .row-actions {
    align-items: stretch; flex-direction: column;
  }
  .action-bar input, .action-bar button, .preview-bar button, .card-actions button {
    width: 100%;
  }
  .local-grid button { flex: 1 1 45%; }
  .action-sep, .gap { display: none; }
  button, input, select, textarea { min-height: 42px; }
  #diff-modal {
    width: calc(100vw - 20px); height: calc(100vh - 40px);
    max-width: calc(100vw - 20px); max-height: calc(100vh - 40px);
  }
  .diff-modal-body, .diff-modal-titles { grid-template-columns: 1fr; }
  .diff-col:first-child, .diff-col-label:first-child { border-right: none; border-bottom: 1px solid var(--border); }
}
