:root {
  --paper:      #F7F4ED;
  --paper-deep: #F0ECE1;
  --panel:      #FBF9F3;
  --ink:        #2E2B24;
  --ink-2:      #6F695A;
  --ink-3:      #797263;
  --line:       #E5E0D2;
  --accent:     #8A5A33;
  --accent-ink: #7A4E2A;
  --accent-soft:#EFE4D3;
  --hl:         #F0E2B4;
  --pill:       #2E2B24;
  --pill-ink:   #F2EEE3;
  --bubble:     #EFE9DA;

  --font-ui: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --font-reading: var(--font-ui);
  --reader-fs: 18px;
  --reader-lh: 1.95;
  --column-w:  620px;
}
[data-theme="night"] {
  --paper:      #1B1A16;
  --paper-deep: #23211B;
  --panel:      #201E19;
  --ink:        #D9D3C3;
  --ink-2:      #9C947F;
  --ink-3:      #A59D8A;
  --line:       #363227;
  --accent:     #C99C6C;
  --accent-ink: #D6A977;
  --accent-soft:#393124;
  --hl:         #4A4028;
  --pill:       #EDE8DA;
  --pill-ink:   #26241E;
  --bubble:     #2A2720;
}
[data-reader-font="serif"] { --font-reading: var(--font-serif); }

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

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

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

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

/* ---------- 左：书库 ---------- */
.shelf {
  background: var(--paper-deep);
  border-right: 1px solid var(--line);
  padding: 26px 20px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: background .25s ease;
}
.brand {
  font-size: 17px;
  letter-spacing: .35em;
  margin-bottom: 34px;
  user-select: none;
}
.brand i { font-style: normal; color: var(--accent); margin-right: 2px; }

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

.book-list { flex: none; overflow-y: auto; overflow-x: hidden; margin-bottom: 10px; }
.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: flex-end;
  margin-bottom: 22px;
  cursor: pointer;
  position: relative;
  border-radius: 4px;
}
.book-item.active .name { color: var(--accent-ink); }
.cover {
  width: 44px;
  height: 62px;
  border-radius: 2px;
  box-shadow: 2px 3px 8px rgba(46,43,36,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.cover span {
  writing-mode: vertical-rl;
  font-size: 10px;
  letter-spacing: .25em;
  color: rgba(255,255,255,.92);
  max-height: 54px;
  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: -6px;
  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-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 { 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: 14px; }
.import {
  width: 100%;
  font-size: 12.5px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 6px;
  padding: 9px 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;
}
.reader-top {
  height: 54px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}
.crumb {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb b { color: var(--ink-2); font-weight: normal; }
.reader-tools { display: flex; gap: 18px; align-items: center; flex: none; }
.reader-tools button {
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  transition: color .15s ease;
}
.reader-tools button:hover { color: var(--ink); }
.reader-tools button.on { color: var(--accent); }

.page {
  flex: 1;
  overflow-y: auto;
  padding: 64px 24px 96px;
  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: 30px;
  font-weight: 600;
  letter-spacing: .025em;
  font-family: var(--font-reading);
  margin-bottom: 10px;
}
.subtitle {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .1em;
  margin-bottom: 52px;
}

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: .02em;
  color: var(--ink);
  margin-bottom: 1.35em;
  text-align: justify;
}
article h2 { font-size: calc(var(--reader-fs) * 1.22); font-weight: 600; margin: 1.6em 0 1em; }
article h3 { font-size: calc(var(--reader-fs) * 1.08); font-weight: 600; 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: var(--hl);
  color: inherit;
  padding: 2px 3px;
  border-radius: 3px;
  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: 11px;
  letter-spacing: .06em;
  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: .1em;
  border-top: 1px solid var(--line);
}
.reader-foot .nav { cursor: pointer; font-size: 15px; transition: color .15s ease; user-select: none; }
.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: 26px 24px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: background .25s ease;
}
.companion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.tabs { display: flex; gap: 18px; }
.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: 600;
  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);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px;
}

.field-label {
  font-size: 13px;
  letter-spacing: .035em;
  color: var(--ink-3);
  margin-bottom: 10px;
}
.quote {
  border-left: 2px 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: 12px; color: var(--ink-3); letter-spacing: .06em; 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: 10px 10px 3px 10px;
  padding: 9px 13px;
}
.m-quote {
  font-size: 11.5px;
  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: 11px;
  letter-spacing: .08em;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 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: 10px;
  align-items: flex-end;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 9px 9px 13px;
  transition: border-color .15s ease;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  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: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #F7F4ED;
  font-size: 14px;
  cursor: pointer;
  transition: opacity .15s ease;
}
.send:hover { opacity: .88; }
.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: transparent;
  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: none;
  color: var(--accent-ink);
  font-size: 12.5px;
  letter-spacing: .08em;
  cursor: pointer;
  padding: 4px 2px;
  border-bottom: 1px solid transparent;
  transition: border-color .15s ease;
  font-family: var(--font-ui);
}
.note-save:hover { border-bottom-color: var(--accent); }

.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: 11.5px;
  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 { 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 rgba(46,43,36,.22);
  font-family: var(--font-ui);
}
.floatbar span {
  font-size: 12px;
  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: 60px;
  right: 24px;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(46,43,36,.16);
  padding: 18px 20px;
  width: 264px;
}
.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 rgba(46,43,36,.25);
  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: 15px; letter-spacing: .2em; }
.auth-desc { margin-top: 10px; font-size: 12px; color: var(--ink-3); letter-spacing: .06em; }
.auth-input {
  width: 100%;
  margin-top: 24px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  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: 12.5px;
  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 { display: none; }

@media (max-width: 1120px) {
  .app { grid-template-columns: 200px minmax(0, 1fr) 280px; }
}
@media (max-width: 920px) {
  .app, .app.shelf-open { grid-template-columns: minmax(0, 1fr); }
  .narrow-only { display: inline; }
  .shelf, .companion {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 45;
    width: min(300px, 86vw);
    transition: transform .22s ease;
  }
  .shelf { left: 0; transform: translateX(-102%); box-shadow: 12px 0 36px rgba(46,43,36,.16); }
  .companion { right: 0; transform: translateX(102%); box-shadow: -12px 0 36px rgba(46,43,36,.16); }
  .app.shelf-open .shelf, .app.companion-open .companion { transform: none; }
  .app.focus .shelf, .app.focus .companion { display: block; }
}

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  .page { padding: 40px 20px calc(80px + env(safe-area-inset-bottom)); }
  .chapter-title { font-size: 24px; }
  .reader-top { padding: 0 16px; padding-top: 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(320px, 92vw); }
  .panel { right: 12px; left: 12px; width: auto; }
  .floatbar span { padding: 8px 10px; }
  .column { max-width: 100%; }
}

button { touch-action: manipulation; }

/* Shared utility rhythm: quiet labels remain readable beside long-form text. */
.shelf-label, .import-note, .field-label, .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, .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: 6px 8px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 5px; }

.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: 600; }
.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: #211f1b70; }
.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: 600; 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: 32px; height: 32px; cursor: pointer; }
.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: 600; }
.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: 600; }
.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: 600; 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: 6px; background: var(--accent); color: var(--panel); 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; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
