/* ========================================
   Library / Reader 样式 - 书库（模拟书城）
   ======================================== */

/* ===== 书架页面 ===== */
.library-screen {
  position: absolute;
  inset: 0;
  background: #f5f3ee;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .32s cubic-bezier(.4, 0, .2, 1);
  z-index: 60;
  overflow: hidden;
}
.library-screen.is-active { transform: translateX(0); }

.library-nav {
  display: flex;
  align-items: center;
  padding: 14px 12px;
  background: #faf8f3;
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  flex-shrink: 0;
}
.library-nav__back,
.library-nav__right {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #3a3a3a;
  cursor: pointer;
  border-radius: 50%;
}
.library-nav__back svg,
.library-nav__right svg { width: 22px; height: 22px; }
.library-nav__title {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: #2a2a2a;
}
.library-nav__actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.library-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 40px;
}

.library-shelf {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px 14px;
}

.library-book { cursor: pointer; }
.library-book__cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(135deg, #d8c7a8, #b89f78);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.library-book__cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.library-book__cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #5a4630;
  line-height: 1.4;
}
.library-book__delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
}
.library-book__cover:hover .library-book__delete { opacity: 1; }
.library-book__delete svg { width: 13px; height: 13px; }
.library-book__title {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #2a2a2a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-book__author {
  margin-top: 2px;
  font-size: 11px;
  color: #999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 80px;
  color: #b5ad9d;
}
.library-empty__icon svg { width: 56px; height: 56px; }
.library-empty__title { margin-top: 16px; font-size: 15px; font-weight: 600; }
.library-empty__desc { margin-top: 6px; font-size: 13px; color: #c4bdae; }

/* ===== 阅读器 ===== */
.reader-screen {
  position: absolute;
  inset: 0;
  background: #f4ecd8;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .32s cubic-bezier(.4, 0, .2, 1);
  z-index: 70;
  overflow: hidden;
}
.reader-screen.is-active { transform: translateX(0); }

.reader-topbar {
  display: flex;
  align-items: center;
  padding: 12px;
  background: rgba(244, 236, 216, .9);
  flex-shrink: 0;
  z-index: 3;
}
.reader-topbar__back,
.reader-topbar__history {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #5a4a32;
  cursor: pointer;
}
.reader-topbar__back svg,
.reader-topbar__history svg { width: 21px; height: 21px; }
.reader-topbar__title {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: #4a3c28;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

/* 一起看胶囊 */
.reader-capsule {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px 0;
  flex-shrink: 0;
  z-index: 3;
}
.reader-capsule__char-group,
.reader-capsule__user-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.reader-capsule__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: #c9b48f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
  border: 2px solid #fff;
}
.reader-capsule__avatar img { width: 100%; height: 100%; object-fit: cover; }
.reader-capsule__identity {
  font-size: 10px;
  color: #8a7656;
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  padding: 2px 6px;
  background: rgba(201, 164, 99, 0.1);
  border-radius: 8px;
  display: none;
}
.reader-capsule__identity:not(:empty) {
  display: block;
}
.reader-capsule__x { 
  font-size: 14px; 
  color: #8a7656; 
  font-weight: 600;
  margin: 0 2px;
}
.library-avatar-fallback {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

/* 角色书评气泡（浮层，不占据正文高度） */
.reader-comment {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 96px;
  padding: 8px 16px 0;
  z-index: 5;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.reader-comment.is-show { opacity: 1; transform: translateY(0); }
.reader-comment__bubble {
  display: inline-block;
  max-width: 80%;
  margin-left: 18px;
  padding: 10px 14px;
  background: #fffdf6;
  border-radius: 4px 14px 14px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #4a3c28;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
  position: relative;
}
.reader-comment__bubble.is-loading { color: #b0a488; letter-spacing: 2px; }

/* 阅读区 */
.reader-page {
  flex: 1;
  overflow: hidden;
  padding: 16px 22px 24px;
  z-index: 1;
  position: relative;
}
.reader-page__text {
  font-size: 17px;
  line-height: 1.9;
  color: #3a2f20;
  text-align: justify;
  letter-spacing: .3px;
  height: 100%;
  overflow: hidden;
}
/* 离屏测量容器：与正文同宽同字号，用于精确分页 */
.reader-measure {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  left: -9999px;
  top: 0;
  font-size: 17px;
  line-height: 1.9;
  text-align: justify;
  letter-spacing: .3px;
  white-space: normal;
  word-break: break-word;
}

/* 翻页热区 */
.reader-tap {
  position: absolute;
  top: 120px;
  bottom: 48px;
  width: 30%;
  z-index: 2;
}
.reader-tap--prev { left: 0; }
.reader-tap--next { right: 0; }

.reader-bottombar {
  padding: 10px;
  text-align: center;
  flex-shrink: 0;
  z-index: 3;
}
.reader-bottombar__page {
  font-size: 12px;
  color: #8a7656;
}

/* ===== 通用面板（底部弹出） ===== */
.reader-input-panel,
.reader-history-panel,
.library-mode-panel,
.library-contact-panel,
.library-add-panel {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: none;
}
.reader-input-panel.is-active,
.reader-history-panel.is-active,
.library-mode-panel.is-active,
.library-contact-panel.is-active,
.library-add-panel.is-active {
  display: block;
}

.reader-input-panel__backdrop,
.reader-history-panel__backdrop,
.library-mode-panel__backdrop,
.library-contact-panel__backdrop,
.library-add-panel__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .4);
}

.reader-input-panel__content,
.library-mode-panel__content,
.library-add-panel__content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px 28px;
  animation: librarySlideUp .3s ease;
}
.reader-history-panel__content,
.library-contact-panel__content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 22%;
  background: #fff;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: librarySlideUp .3s ease;
}
@keyframes librarySlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.reader-input-panel__header,
.reader-history-panel__header,
.library-mode-panel__header,
.library-contact-panel__header,
.library-add-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 4px 0;
}
.reader-history-panel__header,
.library-contact-panel__header {
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  margin-bottom: 0;
}
.reader-input-panel__header h3,
.reader-history-panel__header h3,
.library-mode-panel__header h3,
.library-contact-panel__header h3,
.library-add-panel__header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2a2a2a;
  margin: 0;
}
.reader-input-panel__close,
.reader-history-panel__close,
.library-mode-panel__close,
.library-contact-panel__close,
.library-add-panel__close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reader-input-panel__close svg,
.reader-history-panel__close svg,
.library-mode-panel__close svg,
.library-contact-panel__close svg,
.library-add-panel__close svg { width: 20px; height: 20px; }

/* 输入想法 */
.reader-input-panel__textarea {
  width: 100%;
  min-height: 100px;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  resize: none;
  box-sizing: border-box;
  outline: none;
  font-family: inherit;
}
.reader-input-panel__textarea:focus { border-color: #c9a063; }
.reader-input-panel__send {
  margin-top: 14px;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: #c9a063;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* 模式选择 */
.library-mode-panel__options {
  display: flex;
  gap: 14px;
}
.library-mode-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 12px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 14px;
  background: #faf8f3;
  cursor: pointer;
  color: #4a3c28;
}
.library-mode-option svg { width: 32px; height: 32px; }
.library-mode-option span { font-size: 14px; font-weight: 600; }
.library-mode-option:active { background: #f0ebe0; }

/* 联系人列表 */
.library-contact-list,
.reader-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.library-contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
}
.library-contact-item:active { background: #f5f3ee; }
.library-contact-item__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: #c9b48f;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.library-contact-item__avatar img { width: 100%; height: 100%; object-fit: cover; }
.library-contact-item__name { font-size: 15px; color: #2a2a2a; }
.library-contact-empty,
.reader-history-empty {
  padding: 40px 20px;
  text-align: center;
  color: #b5ad9d;
  font-size: 14px;
}

/* 对话历史 */
.reader-history-list { padding: 14px 16px; }
.reader-history-item {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.reader-history-item.is-user { flex-direction: row-reverse; }
.reader-history-item__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #c9b48f;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reader-history-item__avatar img { width: 100%; height: 100%; object-fit: cover; }
.reader-history-item__body { max-width: 72%; }
.reader-history-item.is-user .reader-history-item__body { text-align: right; }
.reader-history-item__name {
  font-size: 11px;
  color: #999;
  margin-bottom: 4px;
}
.reader-history-item__text {
  display: inline-block;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  text-align: left;
  background: #f0ebe0;
  color: #3a2f20;
}
.reader-history-item.is-user .reader-history-item__text {
  background: #c9a063;
  color: #fff;
}

/* 导入面板 */
.library-add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.library-add-file {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border: 1.5px dashed rgba(0, 0, 0, .15);
  border-radius: 12px;
  background: #faf8f3;
  color: #8a7656;
  font-size: 14px;
  cursor: pointer;
}
.library-add-file svg { width: 20px; height: 20px; }
.library-add-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  font-size: 15px;
  box-sizing: border-box;
  outline: none;
}
.library-add-input:focus { border-color: #c9a063; }
.library-add-cover {
  display: flex;
  align-items: center;
  gap: 12px;
}
.library-add-cover__img {
  width: 60px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
}
.library-add-cover__btn {
  flex: 1;
  padding: 12px;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  background: #faf8f3;
  color: #8a7656;
  font-size: 14px;
  cursor: pointer;
}
.library-add-submit {
  margin-top: 6px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: #c9a063;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* Toast */
.library-toast {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0, 0, 0, .8);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
  white-space: nowrap;
}
.library-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 书库设置面板 ===== */
.library-settings-panel {
  position: absolute;
  inset: 0;
  z-index: 95;
  display: none;
}
.library-settings-panel.is-active { display: block; }
.library-settings-panel__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .4);
}
.library-settings-panel__content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 14%;
  background: #fff;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: librarySlideUp .3s ease;
}
.library-settings-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  flex-shrink: 0;
}
.library-settings-panel__header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2a2a2a;
  margin: 0;
}
.library-settings-panel__close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.library-settings-panel__close svg { width: 20px; height: 20px; }

.library-settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}
.library-settings-section {
  margin-bottom: 26px;
}
.library-settings-section__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.library-settings-section__title {
  font-size: 15px;
  font-weight: 600;
  color: #2a2a2a;
}
.library-settings-section__hint {
  margin: 6px 0 12px;
  font-size: 12px;
  color: #999;
  line-height: 1.5;
}
.library-settings-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.library-settings-fields.is-disabled {
  opacity: .45;
  pointer-events: none;
}

/* 开关 */
.library-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.library-switch input { opacity: 0; width: 0; height: 0; }
.library-switch__slider {
  position: absolute;
  inset: 0;
  background: #d6d0c4;
  border-radius: 24px;
  transition: background .25s;
  cursor: pointer;
}
.library-switch__slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .25s;
}
.library-switch input:checked + .library-switch__slider { background: #c9a063; }
.library-switch input:checked + .library-switch__slider::before { transform: translateX(20px); }

/* 自动书评档位 */
.library-interval-options {
  display: flex;
  gap: 10px;
}
.library-interval-option {
  flex: 1;
  padding: 12px 0;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  background: #faf8f3;
  color: #6a5c44;
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
}
.library-interval-option.is-active {
  background: #c9a063;
  color: #fff;
  border-color: #c9a063;
  font-weight: 600;
}

/* 字体 */
.library-font-row {
  display: flex;
  gap: 10px;
}
.library-font-clear {
  padding: 12px 18px;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  background: #faf8f3;
  color: #8a7656;
  font-size: 14px;
  cursor: pointer;
}
.library-font-name {
  margin-top: 8px;
  font-size: 13px;
  color: #c9a063;
}

/* 字体预设 */
.library-font-preset-save {
  width: 100%;
  padding: 12px 0;
  border: 1px dashed #c9a063;
  border-radius: 12px;
  background: #faf8f3;
  color: #a8843e;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.library-font-preset-save:active { background: #f0ebe0; }

.library-font-preset-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.library-font-preset-empty {
  font-size: 13px;
  color: #b3a892;
  text-align: center;
  padding: 8px 0;
}
.library-font-preset {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  background: #faf8f3;
  transition: all .2s;
}
.library-font-preset.is-active {
  border-color: #c9a063;
  background: #fbf3e4;
}
.library-font-preset__info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.library-font-preset__name {
  font-size: 14px;
  color: #4a3c28;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-font-preset__tag {
  flex-shrink: 0;
  font-size: 11px;
  color: #a8843e;
  background: #f0e6d2;
  border-radius: 6px;
  padding: 2px 6px;
}
.library-font-preset__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.library-font-preset__apply {
  padding: 6px 12px;
  border: 1px solid #c9a063;
  border-radius: 9px;
  background: #c9a063;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.library-font-preset.is-active .library-font-preset__apply {
  background: transparent;
  color: #a8843e;
  cursor: default;
}
.library-font-preset__rename,
.library-font-preset__del {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 8px;
  background: #fff;
  color: #8a7656;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.library-font-preset__del { color: #c06a5a; }
.library-font-preset__rename:active,
.library-font-preset__del:active { background: #f0ebe0; }

/* 模型拉取 */
.library-model-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.library-model-row .library-add-input {
  flex: 1;
}
.library-model-fetch {
  flex-shrink: 0;
  padding: 0 16px;
  border: 1px solid #c9a063;
  border-radius: 12px;
  background: #c9a063;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.library-model-fetch:disabled {
  opacity: .6;
  cursor: default;
}
.library-model-dropdown {
  display: none;
  margin-top: 8px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 12px;
  background: #faf8f3;
}
.library-model-dropdown.is-open { display: block; }
.library-model-item {
  padding: 11px 14px;
  font-size: 14px;
  color: #4a3c28;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, .05);
}
.library-model-item:last-child { border-bottom: none; }
.library-model-item:active { background: #f0ebe0; }
.library-model-item.is-active {
  background: #c9a063;
  color: #fff;
  font-weight: 600;
}
