:root {
  color-scheme: light;
  --bg: #fafaf9;
  --panel: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --code-bg: #f4f4f5;
  --toast-bg: #18181b;
  --toast-text: #ffffff;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #171b22;
  --border: #2b323d;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --code-bg: #1d232d;
  --toast-bg: #232a35;
  --toast-text: #e6e8ee;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button {
  font: inherit;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, textarea, select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
textarea { width: 100%; min-height: 4.8rem; resize: vertical; }
.raw-novel-editor { min-height: 48vh; font-family: Consolas, monospace; font-size: 0.85rem; tab-size: 2; }
header { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border); }
#tokenBar { justify-content: center; }
.token-inner { display: flex; gap: 0.5rem; align-items: center; }
#appHeader h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.header-right { display: flex; gap: 0.5rem; align-items: center; }
#saveStatus { color: var(--muted); font-size: 0.8rem; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.novel-list { display: grid; gap: 0.6rem; margin-top: 0.8rem; }
.novel-card {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem;
}
.novel-card button { margin-left: 0.4rem; }
#novelView { display: grid; grid-template-columns: 280px 1fr; gap: 1rem; }
#sidebar { display: flex; flex-direction: column; gap: 0.6rem; }
.sidebar-head { display: flex; gap: 0.4rem; }
.sidebar-head button { flex: 1; }
.chapters-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 70vh; overflow: auto; }
.chapter-item { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem; cursor: pointer; }
.chapter-item.active { border-color: var(--accent); }
.chapter-title { font-weight: 600; }
.chapter-digest, .chapter-outline { color: var(--muted); font-size: 0.82rem; margin-top: 0.3rem; }
.chapter-status { color: var(--muted); font-size: 0.72rem; margin-top: 0.3rem; }
.empty { color: var(--muted); }
#chapterBody { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem 1.4rem; line-height: 1.85; min-height: 40vh; }
#chapterBody h3 { margin: 0.6rem 0; }
#chapterBody p { margin: 0.6rem 0; white-space: normal; }
.actions { display: flex; gap: 0.5rem; margin-top: 0.8rem; flex-wrap: wrap; }
.bottom-quick { display: none; }
#statusLine { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.6rem; color: var(--muted); font-size: 0.85rem; min-height: 1.2rem; }
.mobile-chapters { display: none; }
.mobile-chapters h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }
#modalRoot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.modal { position: relative; background: var(--panel); border-radius: 12px; padding: 1.2rem; width: min(600px, 94vw); max-height: 88vh; overflow: auto; }
.modal h3 { margin: 0 0 0.8rem; }
.modal h4 { margin: 1rem 0 0.3rem; }
.modal pre { background: var(--code-bg); padding: 0.7rem; border-radius: 8px; white-space: pre-wrap; font-size: 0.85rem; }
.modal label { display: block; margin: 0.6rem 0 0.2rem; font-size: 0.88rem; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 0.4rem; margin: 0.7rem 0 0.2rem; font-size: 0.88rem; color: var(--muted); }
.form-field { margin-top: 0.7rem; }
.form-field:first-of-type { margin-top: 0; }
.form-field label { margin-top: 0; }
.form-field textarea { min-height: 4.2rem; }
.form-note { margin: 0.6rem 0; }
.form-note summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.form-note pre { background: var(--code-bg); padding: 0.7rem; border-radius: 8px; white-space: pre-wrap; font-size: 0.8rem; }
.directive-divider {
  border-top: 1px solid var(--border);
  margin: 0 0 0.2rem;
  padding-top: 0.7rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}
.choice-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.8rem; }
.choice-item { width: 100%; text-align: left; }
.settings-actions { display: flex; gap: 0.5rem; margin-top: 0.9rem; flex-wrap: wrap; }
.provider-model-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  margin-top: 0.8rem;
}
.provider-model-row strong { display: block; margin-bottom: 0.2rem; }
.provider-model-row input,
.provider-model-row select { width: 100%; }
.reasoning-hint { color: var(--muted); font-size: 0.78rem; margin-top: 0.3rem; }
.inline-actions { display: flex; gap: 0.4rem; margin-top: 0.4rem; flex-wrap: wrap; }
.checkpoint-list { display: grid; gap: 0.6rem; margin-bottom: 0.8rem; }
.provider-list { display: grid; gap: 0.6rem; margin-bottom: 0.8rem; }
.checkpoint-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}
.provider-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}
#add_provider { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
#wordTargetInput { width: 8.5rem; }
#tempLabel { color: var(--accent); }
#toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-text); border: 1px solid var(--border); padding: 0.5rem 1rem; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100;
}
#toast.show { opacity: 1; }
#themeBtn {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 0;
}
@media (max-width: 760px) {
  #novelView { grid-template-columns: 1fr; }
  .chapters-list { max-height: 32vh; }
  header { flex-wrap: wrap; }
  .bottom-quick { display: flex; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
  .mobile-chapters { display: block; margin-top: 1.2rem; }
}

#questionRoot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 65; }
.question-panel { width: min(760px, 94vw); overscroll-behavior: contain; }
.question-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.question-heading h3 { margin: 0; }
.question-panel input:not([type="checkbox"]), .question-panel select { width: 100%; }
.question-panel .inline-actions { align-items: center; }
.question-panel .inline-actions label { margin: 0; }
.question-panel summary { cursor: pointer; }
.question-history { display: grid; gap: .8rem; }
.question-turn { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: .8rem; }
.question-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; margin: .4rem 0 .8rem; }
.question-turn small, #qScope { color: var(--muted); }
#qStale { color: var(--accent); }
@media (max-width: 760px) {
  #questionRoot { align-items: stretch; }
  .question-panel { width: 100%; max-height: 100dvh; border-radius: 0; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
  .question-panel textarea { font-size: 16px; }
}
