@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600&family=Noto+Serif+SC:wght@400;500;600;700&display=swap');

:root {
  --bg: #171716;
  --surface: #222220;
  --surface-alt: #2a2926;
  --surface-hover: #32312e;
  --paper: #f2f0e9;
  --paper-muted: #e8e5dc;
  --border: #3a3935;
  --border-hover: #5a5851;
  --text: #f3f1ea;
  --text-secondary: #aaa79f;
  --text-tertiary: #7d7a73;
  --ink: #262521;
  --ink-secondary: #65625c;
  --accent: #d97857;
  --accent-hover: #e38968;
  --accent-soft: #4a3027;
  --bg-rgb: 23, 23, 22;
  --accent-rgb: 217, 120, 87;
  --success: #73a481;
  --error: #d46b68;
  --warning: #d6a759;
  --shadow-color: rgba(0, 0, 0, 0.24);
  --overlay: rgba(10, 10, 9, 0.64);
  --ui-font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --reading-font: "Noto Serif SC", "Songti SC", SimSun, serif;
  --reading-size: 17px;
  --sidebar-width: 260px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #eeece6;
  --surface-alt: #e7e4dd;
  --surface-hover: #dedbd3;
  --paper: #f7f6f2;
  --paper-muted: #e7e4dd;
  --border: #d6d2c9;
  --border-hover: #aaa59b;
  --text: #292824;
  --text-secondary: #66635d;
  --text-tertiary: #8a867e;
  --ink: #292824;
  --ink-secondary: #66635d;
  --accent: #c96544;
  --accent-hover: #b95738;
  --accent-soft: #f0d8cf;
  --bg-rgb: 247, 246, 242;
  --accent-rgb: 201, 101, 68;
  --shadow-color: rgba(63, 54, 45, 0.12);
  --overlay: rgba(44, 40, 35, 0.35);
}

:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: var(--ui-font);
  letter-spacing: 0;
}

button, textarea, input, select { font: inherit; }
button, label, select, input[type="range"] { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ambient-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(var(--accent-rgb), 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--accent-rgb), 0.018) 1px, transparent 1px);
  background-size: 54px 54px;
  mask-image: linear-gradient(to bottom, rgba(var(--bg-rgb), 0.8), transparent 82%);
  animation: grid-drift 24s linear infinite;
}

@keyframes grid-drift { to { background-position: 54px 54px; } }

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  overflow: hidden;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: var(--reading-font);
  font-size: 22px;
  font-weight: 600;
}

.claude-symbol {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-logo { width: 29px; height: 29px; object-fit: contain; }

.icon-button,
.send-button,
.stop-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
}

.icon-button:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border); }
.icon-button:active, .send-button:active, .stop-button:active { transform: scale(0.93); }
.icon-button svg, .send-button svg, .stop-button svg, .nav-item svg, .new-chat svg, .composer-hint svg { width: 18px; height: 18px; }

.button {
  min-height: 44px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-alt);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.button:hover { background: var(--surface-hover); border-color: var(--border-hover); }
.button:active { transform: scale(0.98); }
.button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.nav-list { min-height: 0; flex: 1; overflow-y: auto; padding-top: 18px; }
.nav-list::-webkit-scrollbar, .chat-scroll::-webkit-scrollbar { width: 8px; }
.nav-list::-webkit-scrollbar-thumb, .chat-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.nav-label {
  margin: 0 8px 7px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.nav-label-books { display: none; }
.library-list { display: grid; gap: 3px; }
.empty-history { padding: 12px 10px; color: var(--text-tertiary); font-size: 11px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { color: var(--text); background: var(--surface-hover); }
.nav-item.is-active { color: var(--text); background: var(--accent-soft); border-color: rgba(var(--accent-rgb), 0.26); }
.history-item { position: relative; padding-right: 38px; }
.history-item .history-copy { display: block; min-width: 0; }
.history-item .history-copy strong, .history-item .history-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .history-copy strong { color: inherit; font-size: 12px; font-weight: 500; }
.history-item .history-copy small { margin-top: 2px; color: var(--text-tertiary); font-size: 9px; }
.history-delete { position: absolute; top: 50%; right: 4px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; color: var(--text-tertiary); background: transparent; opacity: 0; transform: translateY(-50%); cursor: pointer; transition: opacity 160ms ease, color 160ms ease, background 160ms ease; }
.history-item:hover .history-delete, .history-delete:focus-visible { opacity: 1; }
.history-delete:hover { color: var(--error); background: var(--surface); }
.history-delete svg { width: 15px; height: 15px; }

.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 12px; }

.main-panel { position: relative; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto; min-width: 0; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 24px;
  border-bottom: 1px solid transparent;
  background: rgba(var(--bg-rgb), 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.mobile-menu, .mobile-close { visibility: hidden; }

.chat-scroll {
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-column { width: min(100%, 820px); min-height: 100%; margin-inline: auto; padding: 48px 24px 40px; }

.welcome {
  min-height: calc(100dvh - 300px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: welcome-in 620ms cubic-bezier(.16, 1, .3, 1) both;
}
.welcome[hidden] { display: none !important; }

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.claude-symbol { width: 58px; height: 58px; margin-bottom: 22px; }
.claude-symbol img { width: 100%; height: 100%; object-fit: contain; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 600; text-transform: uppercase; }
.welcome h1 { margin: 0; font-family: var(--reading-font); font-size: clamp(27px, 4vw, 38px); font-weight: 600; line-height: 1.35; }
.welcome-copy { max-width: 540px; margin: 16px auto 28px; color: var(--text-secondary); font-size: 14px; line-height: 1.8; }

.suggestion-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(100%, 590px); }
.suggestion-card {
  min-height: 86px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}
.suggestion-card:hover { transform: translateY(-2px); background: var(--surface-hover); border-color: var(--border-hover); }
.suggestion-card strong, .suggestion-card span { display: block; }
.suggestion-card strong { color: var(--text); font-family: var(--reading-font); font-size: 15px; font-weight: 600; }
.suggestion-card span { margin-top: 7px; font-size: 11px; line-height: 1.6; }

.messages { display: grid; gap: 30px; }
.message { animation: message-in 360ms cubic-bezier(.16, 1, .3, 1) both; }
@keyframes message-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.message-user { display: flex; justify-content: flex-end; }
.user-bubble { max-width: min(82%, 620px); padding: 12px 16px; border-radius: 8px 8px 2px 8px; background: var(--surface-alt); color: var(--text); font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }

.assistant-block { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; align-items: start; }
.assistant-avatar { display: grid; place-items: center; width: 34px; height: 34px; }
.assistant-avatar img { width: 30px; height: 30px; object-fit: contain; }
.assistant-content { min-width: 0; }
.assistant-label { margin: 4px 0 10px; color: var(--text-secondary); font-size: 12px; font-weight: 600; }

.novel-page {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  box-shadow: none;
}

body.paper-mode .novel-page { background: transparent; color: var(--text); }
.chapter-meta { display: none; }

.markdown-body { font-family: var(--ui-font); font-size: var(--reading-size); line-height: 1.82; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 0 0 0.9em; font-family: var(--ui-font); line-height: 1.45; letter-spacing: 0; }
.markdown-body h1 { font-size: 1.35em; font-weight: 600; }
.markdown-body h2 { font-size: 1.2em; font-weight: 600; }
.markdown-body h3 { font-size: 1.08em; font-weight: 600; }
.markdown-body p { margin: 0 0 1.05em; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body blockquote { margin: 1.4em 0; padding: 0.2em 0 0.2em 1em; border-left: 3px solid var(--accent); color: var(--text-secondary); }
body.paper-mode .markdown-body blockquote { color: var(--text-secondary); }
.markdown-body hr { border: 0; border-top: 1px solid currentColor; opacity: 0.18; margin: 2em 0; }
.markdown-body ul, .markdown-body ol { margin: 1em 0; padding-left: 1.6em; }
.markdown-body li { margin: 0.45em 0; }
.markdown-body code { padding: 0.12em 0.35em; border-radius: 4px; background: var(--surface-alt); font-family: ui-monospace, monospace; font-size: 0.85em; }
body.paper-mode .markdown-body code { background: var(--surface-alt); }
.markdown-body pre { padding: 16px; overflow: auto; border-radius: 6px; background: var(--bg); color: var(--text); }
.markdown-body pre code { padding: 0; background: transparent; }
.markdown-body a { color: var(--accent); text-underline-offset: 4px; }
.markdown-body strong { font-weight: 700; }
.markdown-body em { color: inherit; }

.stream-cursor { display: inline-block; width: 2px; height: 1.1em; margin-left: 3px; vertical-align: -0.12em; background: var(--accent); animation: cursor-blink 820ms steps(1) infinite; }
@keyframes cursor-blink { 50% { opacity: 0; } }

.chapter-finished { display: none !important; }

.system-note { padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; color: var(--text-secondary); background: var(--surface); font-size: 13px; line-height: 1.75; }
.system-note strong { color: var(--text); }

.composer-wrap { position: relative; width: min(100%, 820px); margin-inline: auto; padding: 12px 24px 14px; background: linear-gradient(to bottom, transparent, var(--bg) 24%); }
.composer { padding: 10px 10px 8px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-alt); box-shadow: 0 8px 24px var(--shadow-color); transition: border-color 160ms ease, box-shadow 160ms ease; }
.composer:focus-within { border-color: var(--border-hover); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12), 0 8px 24px var(--shadow-color); }
.composer textarea { display: block; width: 100%; max-height: 150px; padding: 4px 4px 7px; resize: none; overflow-y: auto; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 14px; line-height: 1.65; }
.composer textarea::placeholder { color: var(--text-tertiary); }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.composer-hint { display: flex; align-items: center; gap: 7px; min-width: 0; color: var(--text-tertiary); font-size: 10px; }
.composer-hint span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.send-button, .stop-button { width: 36px; height: 36px; margin-left: auto; border: 0; }
.send-button[hidden], .stop-button[hidden] { display: none !important; }
.send-button { background: var(--accent); color: var(--bg); }
.send-button:hover { background: var(--accent-hover); }
.send-button:disabled { opacity: 0.35; cursor: not-allowed; }
.stop-button { background: var(--text); color: var(--bg); }
.stop-button:hover { background: var(--paper-muted); }
.disclaimer { margin: 8px 0 0; color: var(--text-tertiary); text-align: center; font-size: 9px; line-height: 1.5; }

.drawer-backdrop, .sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  visibility: hidden;
  opacity: 0;
  background: var(--overlay);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(92vw, 440px);
  height: 100dvh;
  padding: 24px;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 80px var(--shadow-color);
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(.16, 1, .3, 1);
}

.settings-drawer.is-open { transform: translateX(0); }
.drawer-backdrop.is-open { visibility: visible; opacity: 1; }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.drawer-header h2 { margin: 0; font-family: var(--reading-font); font-size: 25px; font-weight: 600; }
.settings-section { padding: 26px 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h3 { margin: 0; font-size: 14px; font-weight: 600; }
.section-heading p { margin: 5px 0 0; color: var(--text-tertiary); font-size: 11px; line-height: 1.6; }

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 154px;
  padding: 22px;
  border: 1px dashed var(--border-hover);
  border-radius: 8px;
  color: var(--text-secondary);
  background: var(--surface-alt);
  text-align: center;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.upload-zone:hover { transform: translateY(-2px); background: var(--surface-hover); border-color: var(--accent); }
.upload-zone svg { width: 24px; height: 24px; margin-bottom: 10px; color: var(--accent); }
.upload-zone strong, .upload-zone span { display: block; }
.upload-zone strong { color: var(--text); font-size: 13px; }
.upload-zone span { margin-top: 6px; font-size: 10px; line-height: 1.6; }

.upload-progress { margin-top: 10px; padding: 12px 14px; border-radius: 8px; background: var(--surface-alt); border: 1px solid var(--border); }
.upload-progress-info { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 12px; color: var(--text-secondary); }
.upload-progress-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.upload-progress-bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); width: 0; transition: width 200ms ease; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 52px; color: var(--text-secondary); font-size: 13px; }
.range-control { display: flex; align-items: center; gap: 10px; }
input[type="range"] { width: 118px; accent-color: var(--accent); }
.range-control output { width: 36px; color: var(--text); font-size: 11px; text-align: right; }
select { min-width: 102px; min-height: 38px; padding: 0 30px 0 11px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface-alt); }
select:hover { border-color: var(--border-hover); }
.download-source { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 52px; color: var(--text-secondary); font-size: 13px; }
.download-source a { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: 6px; color: var(--accent); background: var(--surface-alt); text-decoration: none; transition: color 160ms ease, border-color 160ms ease, background 160ms ease; }
.download-source a:hover { color: var(--accent-hover); border-color: var(--border-hover); background: var(--surface-hover); }
.download-source a:active { transform: scale(0.98); }
.download-source a svg { width: 15px; height: 15px; }

.toggle-control { position: relative; display: inline-flex; }
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-control span { position: relative; width: 44px; height: 24px; border-radius: 999px; background: var(--border); transition: background 160ms ease; }
.toggle-control span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform 160ms ease; }
.toggle-control input:checked + span { background: var(--accent); }
.toggle-control input:checked + span::after { transform: translateX(20px); }
.toggle-control input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

.library-manager { display: grid; gap: 8px; }
.book-row { display: flex; align-items: center; gap: 11px; min-height: 60px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-alt); }
.book-row-icon { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.book-row-icon svg { width: 18px; height: 18px; }
.book-row-copy { min-width: 0; flex: 1; }
.book-row-copy strong, .book-row-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-row-copy strong { font-family: var(--reading-font); font-size: 13px; font-weight: 600; }
.book-row-copy span { margin-top: 3px; color: var(--text-tertiary); font-size: 10px; }
.book-row-actions { display: flex; gap: 2px; }
.book-row-actions .icon-button { width: 36px; height: 36px; }

.empty-library { padding: 20px; border: 1px dashed var(--border); border-radius: 8px; color: var(--text-tertiary); text-align: center; font-size: 11px; line-height: 1.7; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: grid; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 9px; max-width: min(360px, calc(100vw - 36px)); padding: 12px 14px; border: 1px solid var(--border-hover); border-radius: 8px; color: var(--text); background: var(--surface-alt); box-shadow: 0 12px 32px var(--shadow-color); font-size: 12px; animation: toast-in 260ms cubic-bezier(.16, 1, .3, 1) both; }
.toast.is-error { border-color: var(--error); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── 侧边栏用户资料 ── */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 160ms ease;
}
.sidebar-profile:hover { background: var(--surface-hover); }
.profile-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent-soft);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-info { min-width: 0; flex: 1; }
.profile-info strong { display: block; font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-info span { display: block; margin-top: 2px; font-size: 10px; color: var(--text-tertiary); }

/* ── 设置抽屉中的头像/昵称 ── */
.profile-setup { display: flex; align-items: center; gap: 16px; }
.avatar-upload {
  position: relative;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  border: 2px dashed var(--border-hover);
  cursor: pointer;
  transition: border-color 160ms ease;
}
.avatar-upload:hover { border-color: var(--accent); }
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  opacity: 0;
  transition: opacity 160ms ease;
}
.avatar-upload:hover span { opacity: 1; }
.nickname-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-alt);
  font-size: 13px;
}
.nickname-input:focus { border-color: var(--accent); outline: none; }

/* ── "下一个" 快捷按钮 ── */
.quick-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}
.quick-button:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-hover); }
.quick-button:active { transform: scale(0.97); }
.quick-button:disabled { opacity: 0.4; cursor: not-allowed; }
.quick-button svg { width: 15px; height: 15px; }

/* ── 章节选择按钮 ── */
.chapter-select-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  background: var(--surface-alt);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.chapter-select-button:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-hover); }
.chapter-select-button svg { width: 16px; height: 16px; }
.chapter-select-button[hidden] { display: none !important; }

/* ── 章节弹出列表 ── */
.chapter-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border-hover);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 32px var(--shadow-color);
  z-index: 10;
  animation: chapter-pop-in 200ms cubic-bezier(.16, 1, .3, 1) both;
}
.chapter-popup[hidden] { display: none !important; }
@keyframes chapter-pop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chapter-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.chapter-popup-list { display: grid; gap: 2px; }
.chapter-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  transition: background 160ms ease, color 160ms ease;
}
.chapter-popup-item:hover { background: var(--surface-hover); color: var(--text); }
.chapter-popup-item.is-active { background: var(--accent-soft); color: var(--text); }
.chapter-popup-index { flex: 0 0 auto; width: 24px; text-align: center; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.chapter-popup-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 历史对话重命名 ── */
.history-rename {
  position: absolute;
  top: 50%;
  right: 38px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--text-tertiary);
  background: transparent;
  opacity: 0;
  transform: translateY(-50%);
  cursor: pointer;
  transition: opacity 160ms ease, color 160ms ease, background 160ms ease;
}
.history-item:hover .history-rename, .history-rename:focus-visible { opacity: 1; }
.history-rename:hover { color: var(--accent); background: var(--surface); }
.history-rename svg { width: 14px; height: 14px; }
.history-rename-input {
  width: 100%;
  padding: 2px 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  outline: none;
}

/* ── 暂停状态光标 ── */
.stream-paused {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 3px;
  vertical-align: -0.12em;
  background: var(--warning);
  opacity: 0.5;
}

/* ── 滚动到底部浮动按钮 ── */
.scroll-bottom-button {
  position: absolute;
  bottom: 150px;
  right: 28px;
  z-index: 20;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px var(--shadow);
  color: var(--text);
  opacity: 0;
  transform: translateY(12px) scale(0.8);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.scroll-bottom-button.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.scroll-bottom-button:hover {
  background: var(--surface);
  border-color: var(--accent);
}
.scroll-bottom-button svg { width: 18px; height: 18px; }

@media (max-width: 900px) {
  :root { --sidebar-width: 220px; }
  .chat-column, .composer-wrap { padding-left: 18px; padding-right: 18px; }
}

@media (max-width: 600px) {
  body { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 280ms cubic-bezier(.16, 1, .3, 1);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open { visibility: visible; opacity: 1; }
  .main-panel { height: 100dvh; grid-template-rows: 58px minmax(0, 1fr) auto; }
  .topbar { padding: 0 10px; }
  .mobile-menu, .mobile-close { visibility: visible; }
  .chat-column { padding: 28px 14px 30px; }
  .welcome { min-height: calc(100dvh - 260px); }
  .welcome-copy { font-size: 13px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .suggestion-card { min-height: 72px; }
  .assistant-block { grid-template-columns: 28px minmax(0, 1fr); gap: 9px; }
  .assistant-avatar { width: 28px; height: 28px; font-size: 12px; }
  .novel-page { padding: 0; }
  .composer-wrap { padding: 8px 10px 10px; }
  .composer-hint span { max-width: 120px; }
  .quick-button span { display: none; }
  .quick-button { padding: 0 10px; }
  .disclaimer { display: none; }
  .scroll-bottom-button { right: 14px; bottom: 130px; }
  .settings-drawer { width: 100%; padding: 20px 16px; }
  .toast-region { right: 10px; bottom: 10px; }
}

/* ── 首次进入用法说明弹窗 ── */
.guide-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: guide-fade-in 220ms ease both;
}
.guide-backdrop[hidden] { display: none !important; }
.guide-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 61;
  width: min(92vw, 430px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 30px 28px 26px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 80px var(--shadow-color);
  text-align: center;
  transform: translate(-50%, -50%);
  animation: guide-pop-in 320ms cubic-bezier(.16, 1, .3, 1) both;
}
.guide-modal[hidden] { display: none !important; }
@keyframes guide-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes guide-pop-in { from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.guide-logo { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 16px; }
.guide-logo img { width: 100%; height: 100%; object-fit: contain; }
.guide-modal h2 { margin: 0; font-family: var(--reading-font); font-size: 24px; font-weight: 600; }
.guide-subtitle { margin: 10px 0 22px; color: var(--text-secondary); font-size: 13px; line-height: 1.7; }
.guide-steps { display: grid; gap: 10px; text-align: left; }
.guide-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.guide-step:first-child { border-color: rgba(var(--accent-rgb), 0.45); background: var(--accent-soft); }
.guide-step-icon { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; background: var(--surface); color: var(--accent); }
.guide-step:first-child .guide-step-icon { background: var(--surface); }
.guide-step-icon svg { width: 17px; height: 17px; }
.guide-step-copy { min-width: 0; }
.guide-step-copy strong { display: block; font-size: 13px; font-weight: 600; color: var(--text); }
.guide-step-copy span { display: block; margin-top: 4px; color: var(--text-secondary); font-size: 11px; line-height: 1.65; }
.guide-confirm {
  width: 100%;
  min-height: 46px;
  margin-top: 22px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 160ms ease, transform 160ms ease;
}
.guide-confirm:hover { background: var(--accent-hover); }
.guide-confirm:active { transform: scale(0.98); }

@media (max-width: 600px) {
  .guide-modal { padding: 24px 20px 20px; }
  .guide-modal h2 { font-size: 21px; }
}

/* ── 管理后台（#admin 访问统计）── */
.admin-backdrop {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: guide-fade-in 220ms ease both;
}
.admin-backdrop[hidden] { display: none !important; }
.admin-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 66;
  width: min(92vw, 560px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 80px var(--shadow-color);
  transform: translate(-50%, -50%);
  animation: guide-pop-in 320ms cubic-bezier(.16, 1, .3, 1) both;
}
.admin-modal[hidden] { display: none !important; }
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}
.admin-header h2 { margin: 4px 0 0; font-family: var(--reading-font); font-size: 21px; font-weight: 600; }
.admin-header .eyebrow { margin: 0; }

.admin-login-row { display: flex; gap: 8px; }
.admin-login-row input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
}
.admin-login-row input:focus { outline: none; border-color: var(--accent); }
.admin-login-button {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 160ms ease;
}
.admin-login-button:hover { background: var(--accent-hover); }
.admin-login-button:disabled { opacity: 0.6; cursor: wait; }
.admin-error {
  margin: 10px 0 0;
  padding: 9px 12px;
  border: 1px solid rgba(212, 107, 104, 0.4);
  border-radius: 8px;
  background: rgba(212, 107, 104, 0.12);
  color: var(--error);
  font-size: 12px;
}

.admin-stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.admin-stat-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
}
.admin-stat-label { display: block; color: var(--text-secondary); font-size: 11px; letter-spacing: 0.04em; }
.admin-stat-value {
  display: block;
  margin-top: 6px;
  font-family: var(--reading-font);
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.admin-stat-card:first-child .admin-stat-value { color: var(--accent); }

.admin-daily { margin-top: 16px; }
.admin-daily-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.admin-daily-header > span:first-child { font-size: 13px; font-weight: 600; }
.admin-daily-legend { display: flex; gap: 12px; margin-left: auto; color: var(--text-tertiary); font-size: 11px; }
.admin-daily-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-pv, .legend-uv { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.legend-pv { background: var(--accent); }
.legend-uv { background: var(--success); }
.admin-refresh {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease;
}
.admin-refresh:hover { border-color: var(--border-hover); color: var(--text); }
.admin-refresh svg { width: 14px; height: 14px; }
.admin-refresh.loading svg { animation: admin-spin 800ms linear infinite; }
@keyframes admin-spin { to { transform: rotate(360deg); } }

.admin-table-head,
.admin-row {
  display: grid;
  grid-template-columns: 88px 1fr 52px 52px;
  gap: 10px;
  align-items: center;
}
.admin-table-head {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-tertiary);
  font-size: 11px;
}
.admin-table-head span:nth-child(3),
.admin-table-head span:nth-child(4) { text-align: right; }
.admin-row { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.admin-row:last-child { border-bottom: 0; }
.admin-row-date { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.admin-row.today .admin-row-date { color: var(--text); font-weight: 600; }
.admin-row-bar {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--surface-alt);
  overflow: hidden;
}
.admin-row-bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.45), rgba(var(--accent-rgb), 0.9));
  transition: width 500ms cubic-bezier(.16, 1, .3, 1);
}
.admin-row-pv,
.admin-row-uv { text-align: right; font-variant-numeric: tabular-nums; }
.admin-row-pv { color: var(--accent); font-weight: 600; }
.admin-row-uv { color: var(--success); }
.admin-empty { padding: 18px 0; text-align: center; color: var(--text-tertiary); font-size: 12px; }

@media (max-width: 600px) {
  .admin-modal { padding: 18px 16px; }
  .admin-stats-grid { gap: 8px; }
  .admin-stat-value { font-size: 24px; }
  .admin-table-head,
  .admin-row { grid-template-columns: 76px 1fr 44px 44px; gap: 8px; }
  .admin-daily-legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
