:root {
  --paper:      #fafbf9;
  --paper-deep: #f0f3f2;
  --panel:      #f6f8f7;
  --ink:        #29383d;
  --ink-2:      #637479;
  --ink-3:      #637479;
  --line:       #dde4e2;
  --accent:     #526f7a;
  --accent-ink: #526f7a;
  --accent-soft:#e8efef;
  --hl:         #e3ece88c;
  --pill:       #29383d;
  --pill-ink:   #fafbf9;
  --bubble:     #e8efef;
  --shadow:     #233b3817;
  --backdrop:   #1f303338;

  --font-ui: "Margin NeoXiHei", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Margin SourceHanSerif", "Source Han Serif SC", "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-brand: "Margin Cormorant", Georgia, serif;
  --font-reading: var(--font-serif);
  --reader-fs: 18px;
  --reader-lh: 1.95;
  --column-w:  620px;
  color-scheme: light;
}
[data-theme="night"] {
  --paper:      #20292b;
  --paper-deep: #1c2426;
  --panel:      #242e30;
  --ink:        #d6dfdc;
  --ink-2:      #90a3a4;
  --ink-3:      #90a3a4;
  --line:       #384549;
  --accent:     #a4bbb8;
  --accent-ink: #a4bbb8;
  --accent-soft:#344345;
  --hl:         #526d645c;
  --pill:       #d6dfdc;
  --pill-ink:   #20292b;
  --bubble:     #2e3c3e;
  --shadow:     #00000036;
  --backdrop:   #10191b70;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}
.ui { font-family: var(--font-ui); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, textarea { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .55; }

.app {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 320px;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}
.app.focus { grid-template-columns: minmax(0, 1fr); }
.app.focus .shelf, .app.focus .companion { display: none; }

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

/* ---------- 左：书库 ---------- */
.shelf {
  background: var(--paper-deep);
  border-right: 1px solid var(--line);
  padding: 24px 18px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  transition: background .25s ease;
}
.shelf-head { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin: 0 4px 30px; }
.brand {
  font-family: var(--font-brand);
  font-size: 39px;
  font-style: normal;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -1.25px;
  font-optical-sizing: auto;
  user-select: none;
}
.brand i { display: none; }

.shelf-label {
  font-size: 13px;
  letter-spacing: .02em;
  color: var(--ink-3);
  margin-bottom: 14px;
}

.book-list { flex: 0 1 auto; max-height: 38%; min-height: 0; overflow-y: auto; overflow-x: hidden; margin-bottom: 14px; }
.book-list:empty::before {
  content: "书架还空着";
  display: block;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .08em;
  padding: 6px 2px 18px;
}
.book-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 7px;
  margin-bottom: 5px;
  cursor: pointer;
  position: relative;
  border-radius: 3px;
}
.book-item.active { background: var(--accent-soft); }
.book-item.active .name { color: var(--accent-ink); }
.cover {
  width: 36px;
  height: 50px;
  border-radius: 2px;
  box-shadow: 1px 2px 5px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.cover span {
  writing-mode: vertical-rl;
  font-size: 10px;
  letter-spacing: .12em;
  color: rgba(255,255,255,.92);
  max-height: 42px;
  overflow: hidden;
}
.book-meta { min-width: 0; }
.book-meta .name {
  font-size: 13.5px;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-meta .fmt {
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-del {
  position: absolute;
  top: 3px;
  right: 2px;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease;
  padding: 4px;
}
.book-item:hover .book-del, .book-item:focus-within .book-del { opacity: 1; }
.book-del:hover { color: var(--accent-ink); }
.book-export {
  position: absolute;
  bottom: -2px;
  right: 0;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease;
  padding: 4px;
}
.book-item:hover .book-export, .book-item:focus-within .book-export { opacity: 1; }
.book-export:hover { color: var(--accent-ink); }

#tocWrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#tocWrap[hidden] { display: none; }
.toc { flex: 1; overflow-y: auto; min-height: 0; }
.toc-item {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  padding: 8px 10px;
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: color .15s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-item:hover { color: var(--ink); }
.toc-item.active {
  color: var(--ink);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  border-radius: 0 4px 4px 0;
}

.shelf-bottom { flex: none; padding-top: 17px; margin-top: 10px; border-top: 1px solid var(--line); }
.import {
  width: 100%;
  font-size: 14px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 6px;
  min-height: 42px;
  padding: 8px 0;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
  font-family: var(--font-ui);
}
.import:hover { border-color: var(--accent); color: var(--accent-ink); }
.import[disabled] { opacity: .55; cursor: default; }
.import-note {
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--ink-3);
  text-align: center;
  margin-top: 8px;
}
.backup-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.backup-link {
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: .06em;
  cursor: pointer;
  padding: 2px;
  border-bottom: 1px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.backup-link:hover { color: var(--accent-ink); border-bottom-color: var(--accent); }
.backup-sep { color: var(--ink-3); font-size: 11px; }

/* ---------- 中：正文 ---------- */
.reader {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.reader-top {
  height: 61px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
}
.crumb {
  font-size: 14px;
  color: var(--ink-3);
  letter-spacing: .01em;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb b { color: var(--ink-2); font-weight: normal; }
.reader-tools { display: flex; gap: 4px; align-items: center; flex: none; }
.reader-tools button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: none;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  border-radius: 5px;
  line-height: 0;
  transition: color .15s ease;
}
.reader-tools button:hover { color: var(--ink); background: var(--accent-soft); }
.reader-tools button.on { color: var(--accent); }
.reader-tools svg, .drawer-close svg, .dialog-close svg { width: 20px; height: 20px; display: block; }

.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 52px 40px 90px;
  display: flex;
  justify-content: center;
}
.column { width: 100%; max-width: var(--column-w); position: relative; height: fit-content; }

.empty-book {
  text-align: center;
  color: var(--ink-3);
  padding-top: 18vh;
  user-select: none;
}
.empty-book .glyph { font-size: 34px; color: var(--accent); opacity: .7; }
.empty-book .line1 { margin-top: 18px; font-size: 15px; letter-spacing: .2em; }
.empty-book .line2 { margin-top: 10px; font-size: 12px; letter-spacing: .08em; }

.overline {
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--ink-3);
  margin-bottom: 14px;
}
.chapter-title {
  font-size: 32px;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: .015em;
  font-family: var(--font-reading);
  margin-bottom: 10px;
}
.subtitle {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .025em;
  margin-bottom: 42px;
}

article { position: relative; padding-left: 26px; margin-left: -26px; font-family: var(--font-reading); }
.note-card { font-family: var(--font-ui); }
article p, article .bq, article h2, article h3 {
  font-size: var(--reader-fs);
  line-height: var(--reader-lh);
  letter-spacing: .01em;
  color: var(--ink);
  margin-bottom: 1.35em;
  text-align: justify;
}
article h2 { font-size: calc(var(--reader-fs) * 1.22); font-weight: 400; margin: 1.6em 0 1em; }
article h3 { font-size: calc(var(--reader-fs) * 1.08); font-weight: 400; margin: 1.4em 0 .9em; }
article .bq {
  border-left: 2px solid var(--line);
  padding-left: 16px;
  color: var(--ink-2);
}
article p { position: relative; }

mark {
  background: linear-gradient(transparent 55%, var(--hl) 55%);
  color: inherit;
  padding: 1px 0;
  border-radius: 1px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background .25s ease;
  cursor: pointer;
}
mark:hover { filter: brightness(.97); }

.anchor-dot {
  position: absolute;
  left: -20px;
  top: calc(var(--reader-lh) * .5em);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .85;
}

/* 正文块下方的批注卡片：与 .quote 同为左边线，但用细线 + 小字区分 */
.note-card {
  border-left: 1.5px solid var(--line);
  padding: 2px 0 2px 14px;
  margin: -0.6em 0 1.35em;
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink-2);
}
.note-card .nc-head {
  font-size: 12px;
  letter-spacing: .02em;
  color: var(--ink-3);
  margin-bottom: 2px;
}
.nc-badge { margin-right: 6px; }
.nc-badge.human, .n-badge.human { color: var(--ink-2); }
.nc-badge.ai, .n-badge.ai { color: var(--accent); }
.note-card .nc-time { margin-left: 10px; color: var(--ink-3); }
.note-card .nc-text { white-space: pre-wrap; word-break: break-word; }
.n-badge { margin-right: 5px; }

.flash { animation: flash 1.6s ease; }
@keyframes flash {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}

.reader-foot {
  flex: none;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .025em;
  border-top: 1px solid var(--line);
}
.reader-foot .nav { cursor: pointer; border: 0; background: none; color: inherit; padding: 0; border-radius: 4px; min-width: 40px; min-height: 40px; display: grid; place-items: center; transition: color .15s ease; user-select: none; }
.reader-foot .nav svg { width: 18px; height: 18px; display: block; }
.reader-tools svg, .drawer-close svg, .dialog-close svg, .reader-foot .nav svg, .send svg { fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.reader-foot .nav:hover { color: var(--ink); }
.reader-foot .nav.disabled { opacity: .3; pointer-events: none; }

/* ---------- 右：一起读 ---------- */
.companion {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 0 22px 22px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  transition: background .25s ease;
}
.companion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 61px;
  gap: 10px;
  margin: 0 -22px 22px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 20px; flex: none; }
.tab {
  border: none;
  background: none;
  font-size: 15px;
  letter-spacing: .035em;
  color: var(--ink-3);
  cursor: pointer;
  padding: 2px 0 6px;
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--ink-2); }
.tab.active {
  color: var(--ink);
  font-weight: 400;
  border-bottom-color: var(--accent);
}
.tab-pane { display: none; flex-direction: column; flex: 1; min-height: 0; }
.tab-pane.active { display: flex; }
.ai-status {
  font-size: 12px;
  letter-spacing: 0;
  color: var(--ink-3);
  max-width: 112px;
  margin-left: auto;
  line-height: 1.45;
  text-align: right;
}

.field-label {
  display: block;
  font-size: 14px;
  letter-spacing: .02em;
  color: var(--ink-3);
  margin-bottom: 10px;
}
.quote {
  border-left: 1px solid var(--accent);
  padding: 2px 0 2px 14px;
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink-2);
  margin-bottom: 18px;
  max-height: 9.5em;
  overflow-y: auto;
  word-break: break-word;
}
.quote-empty { color: var(--ink-3); font-size: 12.5px; letter-spacing: .04em; }

.model-select {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 14px;
  letter-spacing: 0;
  padding: 8px 10px;
  margin-bottom: 0;
  outline: none;
  cursor: pointer;
  transition: border-color .15s ease;
}
.model-select:focus, .model-select:hover { border-color: var(--accent); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  font-size: 12px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

.messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 2px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.chat-empty { font-size: 13px; color: var(--ink-3); letter-spacing: .02em; padding-top: 6px; }
.msg { display: flex; gap: 9px; max-width: 94%; }
.msg p { font-size: 15px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.msg.ai { align-self: flex-start; }
.msg.ai .who {
  color: var(--accent);
  flex: none;
  font-size: 13px;
  transform: translateY(3px);
  user-select: none;
}
.msg.ai.pending p { color: var(--ink-3); }
.msg.ai.failed p { color: var(--ink-3); }
.msg.ai.streaming p::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg.me {
  align-self: flex-end;
  background: var(--bubble);
  border-radius: 7px 7px 0 7px;
  padding: 9px 13px;
}
.m-quote {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.7;
  border-left: 2px solid var(--line);
  padding-left: 8px;
  margin-bottom: 6px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  cursor: pointer;
}
.m-quote:hover { color: var(--accent-ink); }

.scope-row { display: flex; gap: 6px; flex: none; margin-bottom: 8px; }
.scope-btn {
  flex: 1;
  font-size: 13px;
  letter-spacing: .02em;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  min-height: 34px;
  padding: 5px 0;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.scope-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--accent-ink); }
.scope-btn.active { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.scope-btn[disabled] { opacity: .4; cursor: default; }

.composer {
  flex: none;
  display: flex;
  gap: 4px;
  align-items: flex-end;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  padding: 9px 4px 4px 12px;
  transition: border-color .15s ease;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  max-height: 120px;
  padding: 0;
}
.composer textarea::placeholder { color: var(--ink-3); }
.send {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 5px;
  background: none;
  padding: 0;
  line-height: 0;
  cursor: pointer;
}
.send > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--paper); transition: transform .15s ease; }
.send svg { width: 16px; height: 16px; display: block; }
.send:hover:not(:disabled) > span { transform: translateY(-1px); }
.web-continue {
  align-self: flex-end;
  margin-top: 8px;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 11.5px;
  letter-spacing: .04em;
  cursor: pointer;
  padding: 2px;
  border-bottom: 1px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.web-continue:hover { color: var(--accent-ink); border-bottom-color: var(--accent); }

.note-input {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.9;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease;
}
.note-input:focus { border-color: var(--accent); }

.note-save {
  align-self: flex-end;
  margin-top: 10px;
  border: none;
  background: var(--accent);
  color: var(--paper);
  border-radius: 4px;
  font-size: 14px;
  letter-spacing: .02em;
  cursor: pointer;
  min-height: 40px;
  padding: 8px 16px;
  transition: opacity .15s ease;
  font-family: var(--font-ui);
}
.note-save:hover { opacity: .88; }

.note-list { margin-top: 22px; overflow-y: auto; min-height: 0; flex: 1; }
.note-item {
  border-top: 1px solid var(--line);
  padding: 14px 2px 12px;
  position: relative;
}
.note-item .n-quote {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.7;
  margin-bottom: 7px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  cursor: pointer;
}
.note-item .n-quote:hover { color: var(--accent-ink); }
.note-item .n-text { font-size: 15px; line-height: 1.8; color: var(--ink); word-break: break-word; white-space: pre-wrap; }
.note-item .n-time { font-size: 10px; color: var(--ink-3); letter-spacing: .08em; margin-top: 7px; }
.note-item .n-del {
  position: absolute;
  top: 12px;
  right: 0;
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s ease;
}
.note-item:hover .n-del, .note-item:focus-within .n-del { opacity: 1; }
.note-item .n-del:hover { color: var(--accent-ink); }
.note-list-empty { font-size: 12px; color: var(--ink-3); letter-spacing: .06em; padding-top: 6px; }

.companion-foot {
  margin-top: auto;
  padding-top: 20px;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .06em;
}

/* ---------- 浮动条 ---------- */
.floatbar {
  position: fixed;
  z-index: 40;
  background: var(--pill);
  color: var(--pill-ink);
  border-radius: 8px;
  padding: 6px 4px;
  display: flex;
  gap: 2px;
  box-shadow: 0 6px 20px var(--shadow);
  font-family: var(--font-ui);
}
.floatbar span {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.floatbar span:hover { background: rgba(255,255,255,.1); }
[data-theme="night"] .floatbar span:hover { background: rgba(0,0,0,.08); }
.floatbar span.disabled { opacity: .4; cursor: default; }
.floatbar span.disabled:hover { background: none; }

/* ---------- 排版面板 ---------- */
.panel {
  position: fixed;
  top: 68px;
  right: 336px;
  z-index: 50;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 10px 32px var(--shadow);
  padding: 18px 20px;
  width: 300px;
  max-height: calc(100dvh - 88px);
  overflow-y: auto;
}
.app.focus .panel { right: 24px; }
.panel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-row:last-child { margin-bottom: 0; }
.panel-label { font-size: 12px; color: var(--ink-2); flex: none; width: 28px; }
.panel-val { font-size: 11px; color: var(--ink-3); flex: none; width: 36px; text-align: right; }
.panel input[type="range"] { flex: 1; accent-color: var(--accent); height: 18px; }

/* ---------- 底部进度 ---------- */
.progress {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: var(--line);
  z-index: 30;
}
.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width .3s ease;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--pill);
  color: var(--pill-ink);
  font-size: 12.5px;
  letter-spacing: .04em;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
  max-width: 70vw;
}

/* ---------- 令牌遮罩 ---------- */
.auth-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card { width: min(320px, 86vw); text-align: center; }
.auth-glyph { font-size: 28px; color: var(--accent); opacity: .8; }
.auth-title { margin-top: 12px; font-size: 18px; letter-spacing: .03em; }
.auth-desc { margin-top: 10px; font-size: 14px; color: var(--ink-3); letter-spacing: .01em; }
.auth-input {
  width: 100%;
  margin-top: 24px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease;
}
.auth-input:focus { border-color: var(--accent); }
.auth-submit {
  width: 100%;
  margin-top: 12px;
  font-size: 14px;
  min-height: 44px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 6px;
  padding: 9px 0;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.auth-submit:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------- 窄窗 ---------- */
.narrow-only, .reader-tools .narrow-only, .drawer-close { display: none; }
.drawer-close { width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--ink-2); cursor: pointer; }
.drawer-close:hover { background: var(--accent-soft); color: var(--ink); }
.drawer-backdrop, #drawerBackdrop { display: none; position: fixed; inset: 0; z-index: 44; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; background: var(--backdrop); touch-action: none; }

@media (min-width: 921px) and (max-width: 1120px) {
  .app { grid-template-columns: 190px minmax(0, 1fr) 290px; }
  .app.focus { grid-template-columns: minmax(0, 1fr); }
  .shelf { padding-inline: 14px; }
  .reader-top { padding-inline: 20px; }
  .page { padding-inline: 30px; }
  .companion { padding-inline: 18px; }
  .companion-head { margin-inline: -18px; padding-inline: 18px; }
  .panel { right: 306px; }
}
@media (max-width: 920px) {
  .app, .app.shelf-open, .app.companion-open { grid-template-columns: minmax(0, 1fr); }
  .narrow-only, .reader-tools .narrow-only, .drawer-close { display: grid; }
  .reader-top { gap: 8px; padding-inline: 14px; }
  .reader-tools { gap: 0; }
  .reader-tools button { width: 44px; height: 44px; }
  .reader-foot .nav { min-width: 44px; min-height: 44px; }
  .shelf, .companion {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 45;
    width: min(340px, calc(100vw - 48px));
    visibility: hidden;
    pointer-events: none;
    overscroll-behavior: contain;
    transition: transform .22s ease, visibility .22s;
  }
  .shelf { left: 0; padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-105%); box-shadow: 12px 0 36px var(--shadow); }
  .companion { right: 0; padding-top: env(safe-area-inset-top); padding-bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(105%); box-shadow: -12px 0 36px var(--shadow); }
  .app.shelf-open .shelf, .app.companion-open .companion { transform: none; visibility: visible; pointer-events: auto; }
  .app.focus .shelf, .app.focus .companion { display: flex; }
  .drawer-backdrop:not([hidden]), #drawerBackdrop:not([hidden]) { display: block; }
  .companion-head { min-height: 66px; gap: 6px; }
  .companion-head .ai-status { max-width: 96px; }
  .toc-item { min-height: 44px; }
  .chip, .scope-btn { min-height: 38px; }
  .panel, .app.focus .panel { right: 14px; top: calc(68px + env(safe-area-inset-top)); }
  .composer textarea, .note-input, .auth-input, .model-select, .reader-font-select { font-size: 16px; }
}

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  .page { padding: 36px 26px calc(64px + env(safe-area-inset-bottom)); }
  .chapter-title { font-size: 29px; }
  .reader-top { padding: env(safe-area-inset-top) 8px 0; height: calc(61px + env(safe-area-inset-top)); }
  .reader-foot { padding-bottom: env(safe-area-inset-bottom); height: calc(46px + env(safe-area-inset-bottom)); }
  .shelf, .companion { width: min(340px, calc(100vw - 44px)); }
  .panel, .app.focus .panel { right: 12px; left: 12px; width: auto; }
  .floatbar span { padding: 8px 10px; }
  .column { max-width: 100%; }
  .toast { max-width: calc(100vw - 32px); width: max-content; font-size: 14px; }
}

button { touch-action: manipulation; }

/* Shared utility rhythm: quiet labels remain readable beside long-form text. */
.shelf-label, .import-note, .panel-label, .panel-val,
.chat-empty, .note-list-empty, .companion-foot, .reader-foot,
.scope-btn, .chip, .web-continue, .backup-link { font-size: 13px; letter-spacing: .02em; }
.book-meta .name, .toc-item, .field-label, .note-save { font-size: 14px; }
.book-meta .fmt, .note-item .n-time, .subtitle, .overline { font-size: 12px; letter-spacing: .035em; }
.quote, .m-quote, .n-quote { font-family: var(--font-reading); }
.panel-label { width: 30px; }
.reader-font-select { min-width: 0; flex: 1; padding: 8px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 4px; }
.font-status { margin: 12px 0 0; font-size: 12px; line-height: 1.65; color: var(--ink-2); overflow-wrap: anywhere; }
.font-options { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.font-options summary { color: var(--ink-2); font-size: 13px; cursor: pointer; padding: 3px 0; }
.font-options summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.font-options p { color: var(--ink-2); font-size: 12px; line-height: 1.7; margin-top: 8px; }
.font-restore { display: flex; align-items: center; gap: 8px; min-height: 36px; margin-top: 8px; font-size: 13px; color: var(--ink); cursor: pointer; }
.font-restore input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.font-license-link { display: inline-block; color: var(--accent-ink); font-size: 12px; line-height: 1.7; margin-top: 9px; text-underline-offset: 3px; }

.instance-row { display: flex; align-items: center; gap: 8px; }
.instance-row .model-select { min-width: 0; flex: 1; }
.instance-manage { flex: none; border: 0; background: none; color: var(--accent-ink); padding: 8px 2px 8px 4px; cursor: pointer; }
.instance-context { color: var(--ink-3); font-size: 12px; margin: 8px 0 18px; line-height: 1.6; overflow-wrap: anywhere; }
.instance-welcome { border-left: 2px solid var(--accent); margin: 18px 0 2px; padding: 2px 0 2px 14px; }
.instance-welcome strong { font-size: 16px; font-weight: 400; }
.instance-welcome p { font-size: 14px; color: var(--ink-2); line-height: 1.7; margin: 8px 0; }
.text-action { border: 0; background: none; color: var(--accent-ink); padding: 4px 0; cursor: pointer; text-align: left; }
.text-action:hover { text-decoration: underline; text-underline-offset: 3px; }
.refresh-chat { align-self: flex-end; font-size: 13px; margin-top: 6px; }

/* Instance management belongs beside the book, as a small catalog. */
.model-dialog { margin: auto; width: min(920px, calc(100vw - 40px)); max-height: calc(100dvh - 48px); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 24px 80px #0004; padding: 0; }
.model-dialog::backdrop { background: var(--backdrop); }
.model-dialog-head { position: sticky; top: 0; z-index: 2; background: var(--panel); display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding: 26px 28px 22px; border-bottom: 1px solid var(--line); }
.model-dialog-head h2 { font-size: 23px; font-weight: 400; letter-spacing: -.015em; }
.model-dialog-head p { margin-top: 5px; color: var(--ink-2); font-size: 14px; }
.dialog-close { border: 0; background: none; color: var(--ink-2); width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 5px; cursor: pointer; }
.dialog-close:hover { color: var(--ink); background: var(--accent-soft); }
.model-manager-body { display: grid; grid-template-columns: 210px minmax(0, 1fr); }
.model-manager-list { background: var(--paper); padding: 20px 14px; border-right: 1px solid var(--line); }
.model-add { width: 100%; text-align: left; background: none; color: var(--accent-ink); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; cursor: pointer; margin-bottom: 16px; }
.model-list-item { width: 100%; display: flex; flex-direction: column; gap: 3px; text-align: left; background: none; border: 0; border-left: 2px solid transparent; padding: 12px; color: var(--ink); cursor: pointer; margin-bottom: 4px; overflow-wrap: anywhere; }
.model-list-item.selected { border-left-color: var(--accent); background: var(--accent-soft); }
.model-list-item strong { font-size: 14px; font-weight: 400; }
.model-list-item span, .model-list-item small { font-size: 12px; color: var(--ink-2); line-height: 1.55; }
.model-list-item.archived strong { color: var(--ink-2); }
.model-list-empty { font-size: 13px; color: var(--ink-2); padding: 4px 10px; line-height: 1.8; }
.model-form { min-width: 0; padding: 26px 28px 22px; }
.model-form-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 22px; }
.model-form-title h3 { font-size: 17px; font-weight: 400; }
.model-form-title span { font-size: 13px; color: var(--ink-3); }
.model-field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.model-form label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; color: var(--ink); margin-bottom: 16px; }
.model-form input:not([type="checkbox"]), .model-form select { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: var(--paper); color: var(--ink); font-size: 14px; line-height: 1.5; }
.model-form input::placeholder { color: var(--ink-3); }
.model-form input[readonly] { color: var(--ink-2); }
.model-form fieldset { min-width: 0; border: 0; border-top: 1px solid var(--line); padding-top: 16px; margin: 8px 0 18px; }
.model-form legend { font-size: 14px; font-weight: 400; padding-right: 10px; }
.field-help { color: var(--ink-2); font-size: 13px; line-height: 1.7; margin-bottom: 16px; }
.model-form .model-check { flex-direction: row; align-items: center; gap: 9px; }
.model-check input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.copy-row { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; margin: 2px 0 16px; }
.copy-row code { min-width: 0; overflow-wrap: anywhere; font-size: 12px; color: var(--ink-2); padding-top: 4px; }
.copy-row button { flex: none; font-size: 13px; }
.model-form-actions { display: flex; align-items: center; gap: 14px; margin: 24px 0 12px; }
.model-form-actions .field-help { margin: 0; font-size: 12px; }
.model-save { margin-left: auto; border: 0; border-radius: 5px; background: var(--accent); color: var(--paper); min-height: 42px; padding: 10px 18px; cursor: pointer; flex: none; }
.model-history-note { margin: 0; font-size: 12px; }
.model-form-error { border-left: 2px solid #a34432; color: #9b3d2e; background: var(--paper); padding: 8px 12px; font-size: 14px; }
[data-theme="night"] .model-form-error { color: #efaa99; }
@media (max-width: 680px) {
  .model-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  .model-dialog-head { padding: 20px; }
  .model-manager-body { grid-template-columns: 1fr; }
  .model-manager-list { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 20px; }
  #modelInstanceList { display: flex; gap: 6px; overflow-x: auto; }
  .model-list-item { min-width: 160px; max-width: 220px; flex: none; }
  .model-add { margin-bottom: 8px; }
  .model-form { padding: 22px 20px; }
  .model-field-pair { grid-template-columns: 1fr; gap: 0; }
  .model-form-actions { flex-wrap: wrap; }
  .model-form input:not([type="checkbox"]), .model-form select { font-size: 16px; }
}
@media (hover: none) {
  .book-del, .book-export, .note-item .n-del { opacity: 1; min-width: 32px; min-height: 32px; }
  .book-meta { padding-right: 18px; }
  .note-item { padding-right: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
