.result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.result-list.interaction-locked {
  opacity: 0.64;
  pointer-events: none;
}

.result-card {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 9px;
  cursor: pointer;
  background: var(--panel-2);
  transition: border-color 140ms ease, background 140ms ease;
}

.result-card:hover {
  border-color: var(--line-strong);
}

.result-card.active {
  border-color: var(--accent);
  background: var(--panel-3);
}

.result-card.loading {
  border-color: var(--info);
}

.result-card > :nth-child(2) {
  min-width: 0;
}

.result-cover {
  width: 62px;
  height: 84px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}

.result-cover img,
.detail-cover img,
.bookshelf-card-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-title,
.detail-title,
.history-title,
.job-title {
  font-size: 14px;
  font-weight: 700;
}

.result-summary {
  display: -webkit-box;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.cover-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--muted);
  font-size: 24px;
  font-weight: 800;
}

.detail-content-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.book-detail-panel {
  min-width: 0;
  min-height: 0;
  background: transparent;
  border: 0;
}

.book-detail-panel.is-loading .detail-content-shell {
  filter: saturate(0.88);
}

.detail-loading-panel {
  min-height: 180px;
}

.detail-layout {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
}

.detail-cover {
  width: 96px;
  height: 132px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-1);
}

.detail-intro,
.detail-form {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 9px;
}

.detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.detail-top > :first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.detail-top > .status-pill {
  flex: 0 1 auto;
  min-width: 0;
}

.detail-description {
  max-height: 10rem;
  overflow: auto;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* #422：改过的简介和编辑框 */
.detail-synopsis-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: -4px;
}

.dialog-textarea {
  width: 100%;
  min-height: 9.5em;
  resize: vertical;
  line-height: 1.6;
  font: inherit;
}

.chapter-range-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.chapter-range-input {
  flex: 1 1 0;
  min-width: 0;
}

.chapter-range-sep {
  flex: 0 0 auto;
  color: var(--text-2);
  font-size: 13px;
}

.detail-form .button-row {
  margin-top: 2px;
}

.settings-panel,
.history-panel,
.bookshelf-panel {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
}

.settings-tabs {
  display: flex;
  align-items: stretch;
  flex: 0 0 auto;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow-x: auto;
  scrollbar-width: thin;
}

/* Issue #370: the four category tabs must share one height on Windows, where
   a per-button height difference made the row look broken and pushed the
   cards below it out of the visible area. */
.settings-tab {
  flex: 1 0 auto;
  min-height: 40px;
  box-sizing: border-box;
  border: 0;
  border-radius: calc(var(--radius-md) - 2px);
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.settings-tab.active {
  background: var(--panel-2);
  color: inherit;
  font-weight: 600;
}

.settings-grid {
  display: grid;
  /* 2026-10 owner review: settings is a form page, so the cards stack in one
     centered column. The old two-column grid paired a 2-field card with an
     11-field card in the download category, which left ~950px of dead space
     under the short card and zigzag bottom edges — the "components scattered
     everywhere" look. A single capped column keeps every card and every
     control the same width, which is the flat layout form pages use. */
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: min-content;
  align-items: start;
  flex: 1 1 auto;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}

/* Issue #370: the active category's cards keep their own natural height and
   the grid scrolls, so a long category is never clipped on short Windows
   windows. align-items: start stops the shorter card in a row from being
   stretched, which also avoids an empty stretched frame next to it. */
.settings-grid > .settings-card {
  min-width: 0;
  overflow-wrap: anywhere;
}

.settings-save-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

/* One aligned column per settings card: every control spans the field so the
   right edges agree. The segmented switches used to size themselves to their
   content (240/360/420...), which left a ragged gap of empty space next to a
   full-width row such as the directory picker. */
.settings-card .field > .format-toggle,
.settings-card .field > .path-picker,
.settings-card .field > .text-input,
.settings-card .field > select,
.settings-card .field > .switch-row,
.settings-card .field > .button-row {
  width: 100%;
}

#settingsSaveStatus {
  max-width: 32em;
  overflow-wrap: anywhere;
}

#settingsSaveStatus[data-state="error"],
#settingsSaveStatus[data-state="invalid"] {
  color: var(--danger);
}

.settings-card {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
}

.settings-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* 诊断日志始终开启：只读状态，不是开关。 */
.settings-log-status {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

/* 设置互斥：某一项被另一项盖住、暂不生效时的常驻说明。
   文字和底色都取同一层的 --text / --panel-2：阅读配色面板把这两个变量换成阅读配色，
   主界面用应用配色（或跟随后的阅读配色）。不能用 --ds-text-subtle，它在 body 上
   就解析好了，进了阅读配色面板仍是应用的颜色，深色界面 + 羊皮纸时浅字压浅底。 */
.settings-hint.settings-conflict-hint {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
}

.settings-conflict-hint[hidden] {
  display: none;
}

/* Issue #320: boss-key recorder and its status line. */
.boss-key-recorder {
  min-width: 160px;
  font-variant-numeric: tabular-nums;
}

.boss-key-recorder.is-recording {
  border-color: var(--accent);
  color: var(--accent);
}

.boss-key-status[data-tone="error"] {
  color: var(--danger);
}

.about-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.about-app-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

/* 系统版本方便用户报问题时复制。 */
.about-system {
  user-select: text;
  -webkit-user-select: text;
  overflow-wrap: anywhere;
}

.history-toolbar {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 8px;
  margin-bottom: 8px;
}

.summary-chip {
  display: grid;
  gap: 5px;
  padding: 9px 10px;
  background: var(--panel-2);
}

.summary-chip-label {
  color: var(--muted);
  font-size: 11px;
}

.summary-chip-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.history-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

.history-table thead {
  background: var(--panel-3);
}

.history-table th,
.history-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

.history-table tbody tr:hover {
  background: var(--panel-3);
}

.history-select-all,
.history-book-heading {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.history-select-all {
  align-items: center;
  cursor: pointer;
}

.history-select-checkbox,
.history-select-all input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.history-book-heading .history-title {
  min-width: 0;
}

.history-table .history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.history-action {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.job-progress-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.job-progress-switch .history-action.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.job-progress-detail,
.history-progress-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 8px 0;
}

.job-progress-detail > .progress-detail-text {
  overflow-wrap: anywhere;
}

.bookshelf-panel {
  padding: 14px;
}

.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  align-content: start;
  flex: 1 1 auto;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.bookshelf-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
}

.bookshelf-open-area {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.bookshelf-card-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}

/* iOS 14 and older Android WebViews do not support aspect-ratio. Without a
   height the cover would collapse to zero, so fall back to the padding-box
   trick and let the cover content (a cover image, a .cover-fallback, or the
   classless first-letter div used by bookshelf cards) fill the box
   absolutely. */
@supports not (aspect-ratio: 3 / 4) {
  .bookshelf-card-cover {
    height: 0;
    padding-top: 133.333%;
  }

  /* Longhand offsets instead of the `inset` shorthand: iOS Safari only
     supports `inset` from 14.5, and this fallback must also cover 14.0. */
  .bookshelf-card-cover > img,
  .bookshelf-card-cover > div {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
}

.bookshelf-card-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.bookshelf-card-meta,
.bookshelf-card-progress {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookshelf-card-progress {
  color: var(--accent-text);
}

.bookshelf-card-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

/* Issue #319：书架状态标签 + 状态/进度信息行 */
.bookshelf-status-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.bookshelf-status-chip.status-ongoing {
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent-text) 12%, transparent);
}

.bookshelf-status-chip.status-completed {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 14%, transparent);
}

.bookshelf-status-chip.status-halted {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 14%, transparent);
}

.bookshelf-status-chip.status-unknown {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 10%, transparent);
}

.bookshelf-card-status-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  min-width: 0;
  font-size: 11px;
  line-height: 1.4;
}

.bookshelf-status-sep {
  color: var(--muted);
  opacity: 0.6;
}

.bookshelf-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.bookshelf-card-actions button {
  width: 100%;
  min-width: 0;
  min-height: 29px;
  padding: 0 4px;
  font-size: 11px;
  white-space: normal;
}

.bookshelf-card-select {
  display: flex;
  align-items: center;
  align-self: flex-start;
  gap: 6px;
  cursor: pointer;
}

.bookshelf-batch-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 8px 10px;
}

.bookshelf-batch-count {
  font-size: 12px;
  color: var(--muted);
}

.bookshelf-batch-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toast-stack {
  position: fixed;
  right: calc(14px + var(--safe-area-right));
  bottom: var(--toast-stack-bottom, calc(14px + var(--safe-area-bottom)));
  /* Stay above the app shell, but below confirmation and picker dialogs. */
  z-index: 1250;
  display: flex;
  width: min(360px, calc(100vw - 28px));
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
}

.toast.success {
  border-color: var(--mint);
}

.toast.error {
  border-color: var(--danger);
}

.toast.info {
  border-color: var(--info);
}

.busy-overlay,
.dialog-overlay {
  position: fixed;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding:
    calc(16px + var(--safe-area-top))
    calc(16px + var(--safe-area-right))
    calc(16px + var(--safe-area-bottom))
    calc(16px + var(--safe-area-left));
  background: var(--overlay-soft);
  opacity: 1;
  visibility: visible;
  transition: opacity 160ms ease, visibility 160ms ease;
}

.busy-overlay {
  z-index: 1100;
}

.busy-overlay.hidden,
.dialog-overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.busy-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: min(420px, 100%);
  padding: 12px 14px;
}

.busy-message {
  color: var(--text-2);
}

.dialog-overlay {
  z-index: 1300;
}

/* A batch submission may ask for confirmation while its source dialog stays
   open. The confirmation layer must own the topmost modal hit area. */
#dialogOverlay {
  z-index: 1350;
}

.dialog-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(440px, 100%);
  max-width: 100%;
  max-height: 100%;
  padding: 16px;
  overflow: auto;
  background: var(--panel-strong);
}

.batch-dialog {
  width: min(720px, 100%);
}

.directory-picker-dialog {
  width: min(760px, 100%);
}

.book-cleanup-dialog,
.update-choice-dialog {
  width: min(560px, 100%);
}

.book-comments-dialog {
  width: min(780px, 100%);
  height: min(760px, 100%);
  min-height: min(560px, 100%);
  overflow: hidden;
}

.book-comments-header,
.book-comments-footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.book-comments-score,
.book-comments-status {
  color: var(--text-2);
  font-size: 13px;
}

.book-comments-sort {
  align-self: flex-start;
  flex: 0 0 auto;
}

.comment-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.comment-filter-input {
  flex: 1 1 auto;
  min-width: 0;
}

.book-comments-list {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border-block: 1px solid var(--line);
}

.book-comment-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  padding: 14px 3px;
  border-bottom: 1px solid var(--line);
}

.book-comment-item:last-child {
  border-bottom: 0;
}

.book-comment-avatar,
.book-comment-avatar-image,
.book-comment-avatar-fallback {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.book-comment-avatar {
  position: relative;
  overflow: hidden;
  background: var(--panel-2);
}

.book-comment-avatar-image {
  position: absolute;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  display: block;
  object-fit: cover;
}

.book-comment-avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  font-weight: 700;
}

.book-comment-main,
.book-comment-head {
  min-width: 0;
}

.book-comment-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.book-comment-author {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-weight: 650;
}

.book-comment-badge {
  padding: 1px 5px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 52%, var(--line));
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 600;
}

.book-comment-badge.vip {
  border-color: color-mix(in srgb, var(--warning) 58%, var(--line));
  color: var(--warning);
}

.book-comment-meta {
  color: var(--text-3);
  font-size: 12px;
}

.book-comment-text {
  margin-top: 7px;
  color: var(--text-1);
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.comment-emoji {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}

/* Issue #394: 段评/书评附带的图片 */
.comment-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.comment-image {
  display: block;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  object-fit: cover;
}

.comment-emoticon {
  height: 22px;
  vertical-align: -5px;
}

.comment-glyph {
  font-size: 18px;
  line-height: 1;
  vertical-align: -3px;
}

.disguise-overlay {
  position: fixed;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: #1a1c1e;
}

.disguise-calculator {
  width: min(340px, calc(100vw - 36px));
  padding: 16px;
  border-radius: 24px;
  background: #242628;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.disguise-display {
  min-height: 64px;
  padding: 12px 8px;
  overflow: hidden;
  color: #f2f2f2;
  font-size: 34px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.disguise-keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.disguise-keys button {
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  background: #333537;
  color: #f2f2f2;
  font-size: 20px;
}

.disguise-keys button:active {
  background: #45484a;
}

.disguise-keys [data-key="="] {
  background: #e8710a;
}

.book-comments-footer {
  min-height: 34px;
}

/* ===== 书评 / 段评：撰写、互动与回复楼 ===== */

.comment-compose {
  display: grid;
  flex: 0 0 auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 10px);
  background: var(--panel-2);
}

.comment-compose.hidden {
  display: none;
}

.book-comment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.comment-action-button {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 12px;
  line-height: 20px;
  cursor: pointer;
}

.comment-action-button:hover:not(:disabled) {
  color: var(--text-1);
  border-color: var(--accent-2);
}

.comment-action-button.active {
  color: var(--accent-strong);
  border-color: var(--accent-2);
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
}

.comment-action-button.danger-armed {
  color: var(--danger, #d64545);
  border-color: var(--danger, #d64545);
}

.comment-action-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.comment-thread {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border-radius: var(--radius-md, 10px);
  background: var(--panel-2);
}

.comment-reply-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
}

.comment-reply-item .book-comment-avatar,
.comment-reply-item .book-comment-avatar-image,
.comment-reply-item .book-comment-avatar-fallback {
  width: 30px;
  height: 30px;
  font-size: 12px;
}

.comment-reply-text {
  margin-top: 2px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.comment-thread-status {
  color: var(--text-3);
  font-size: 12px;
}

.comment-reply-compose {
  display: grid;
  gap: 6px;
}

.comment-reply-target {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
}

.comment-reply-target button {
  border: 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 13px;
}

.comment-reply-send-row {
  display: flex;
  gap: 8px;
}

.comment-reply-send-row .text-input {
  flex: 1;
  min-width: 0;
}

.para-comments-toolbar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.para-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px 2px 10px;
  border: 1px solid var(--accent-2);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
}

.para-filter-chip.hidden {
  display: none;
}

.para-filter-clear {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.para-comments-quote {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-left: 3px solid var(--accent-2);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.para-comments-quote.hidden {
  display: none;
}

.para-overview-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.para-overview-item p {
  margin: 6px 0;
  color: var(--text-2);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.para-overview-item button {
  min-height: 36px;
}

.reader-paragraph.reader-para-located {
  outline: 2px solid var(--reader-accent);
  outline-offset: 4px;
  border-radius: 3px;
}

/* 阅读器段落段评气泡 */
.reader-para-slot {
  display: inline;
}

/* 徽标的外观在本文件后面的 .reader-para-badge 规则里统一定义（M3 版），这里只留
   空徽标的淡入过渡；原先这里那套 12px/描边的旧外观已被后面的规则逐条覆盖。 */
.reader-para-badge[data-empty="true"] {
  transition: opacity 0.15s ease;
}

.reader-paragraph:hover .reader-para-badge[data-empty="true"],
.reader-para-badge[data-empty="true"]:focus-visible {
  opacity: 0.85;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.dialog-title {
  font-size: 17px;
  font-weight: 700;
}

.dialog-message {
  color: var(--text-2);
  line-height: 1.6;
  white-space: pre-line;
}

.dialog-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.cleanup-options {
  display: grid;
  gap: 9px;
}

.cleanup-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  cursor: pointer;
}

.cleanup-option:has(input:focus-visible) {
  border-color: var(--accent-2);
  outline: 2px solid color-mix(in srgb, var(--accent-2) 38%, transparent);
  outline-offset: 1px;
}

.cleanup-option.disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.cleanup-option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
}

.cleanup-option-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
}

.cleanup-option-copy strong {
  color: var(--text);
  font-size: 14px;
}

.cleanup-option-status {
  color: var(--warning);
  font-weight: 700;
}

.update-package-kind {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--accent-text);
  font-weight: 700;
}

.update-choice-description,
.update-choice-note {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

/* 版本说明：Release 里「本次修复 / 本次更新」那一节，按 Markdown 排版（release_notes.js）。
   内容区单独滚动，长说明不会把按钮挤出弹窗。 */
.update-choice-note {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--accent-2);
  background: var(--panel-2);
  white-space: normal;
}

.update-choice-note-title {
  margin-bottom: 6px;
  color: var(--text);
  font-weight: 700;
}

.release-notes {
  max-height: 260px;
  max-height: min(42vh, 320px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.release-notes:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.release-notes > :first-child {
  margin-top: 0;
}

.release-notes > :last-child {
  margin-bottom: 0;
}

.release-notes p,
.release-notes ul,
.release-notes ol,
.release-notes pre,
.release-notes-quote,
.release-notes-table {
  margin: 0 0 8px;
}

.release-notes ul,
.release-notes ol {
  padding-left: 1.4em;
}

.release-notes li + li {
  margin-top: 3px;
}

.release-notes li > ul,
.release-notes li > ol {
  margin: 3px 0 0;
}

.release-notes-heading {
  margin: 10px 0 6px;
  color: var(--text);
  font-weight: 700;
}

.release-notes strong {
  color: var(--text);
}

.release-notes code {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--panel);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.release-notes pre {
  padding: 8px;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
}

.release-notes-quote {
  padding-left: 8px;
  border-left: 2px solid var(--line);
}

.release-notes-link {
  color: var(--accent-text);
}

.update-choice-actions > button {
  min-width: 108px;
}

.directory-current {
  min-height: 36px;
  padding: 7px 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.directory-roots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.directory-root-button,
.directory-item {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.directory-root-button {
  min-height: 32px;
  padding: 0 9px;
  border-radius: var(--radius-md);
  font-size: 12px;
}

.directory-root-button:hover,
.directory-item:hover {
  border-color: var(--line-strong);
  background: var(--panel-3);
}

.directory-list {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: min(240px, 34vh);
  min-height: min(240px, 34dvh);
  max-height: 46vh;
  max-height: 46dvh;
  padding: 7px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-1);
}

.directory-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  text-align: left;
}

.directory-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.directory-item-icon {
  color: var(--accent-2-text);
}

.batch-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.batch-textarea {
  min-height: 180px;
}

.batch-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.batch-preview {
  min-height: 58px;
  padding: 10px;
  border: 1px dashed var(--line);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.6;
}

.batch-preview strong {
  color: var(--text);
}

.batch-error {
  padding: 8px 10px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.batch-preview-list {
  display: grid;
  gap: 5px;
  margin-top: 7px;
}

.batch-preview-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  overflow-wrap: anywhere;
}

.batch-preview-item span:last-child {
  color: var(--muted);
  text-align: right;
}

/* Reader palettes are local by default; shell synchronization is opt-in. */
:root {
  --reader-bg: var(--bg-0);
  --reader-text-1: var(--text);
  --reader-text-2: var(--text-2);
  --reader-surface-1: var(--bg-1);
  --reader-surface-2: var(--panel-2);
  --reader-border: var(--line);
  --reader-accent: var(--accent);
}

:root[data-theme="light"] {
  --reader-bg: #f7f8f7;
  --reader-text-1: #1c2622;
  --reader-text-2: #46544e;
  --reader-surface-1: #edf1ef;
  --reader-surface-2: #e4ebe7;
  --reader-border: #d1dbd5;
  --reader-accent: #b63827;
}

.reader-overlay {
  position: fixed;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 200;
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--reader-bg);
  color: var(--reader-text-1);
}

.reader-overlay.hidden {
  display: none;
}

.reader-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

body.reader-paged .reader-auto-panel {
  display: none;
}

.reader-auto-panel {
  position: absolute;
  right: calc(12px + var(--safe-area-right));
  bottom: calc(var(--reader-footer-height, 64px) + 8px);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  width: auto;
  max-width: calc(100% - 24px);
  padding: 8px;
  border: 1px solid var(--reader-border);
  border-radius: 10px;
  background: var(--reader-surface-1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
}

.reader-auto-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--reader-text-2);
  font-size: 12px;
}

.reader-auto-field select {
  flex: 0 1 auto;
  min-width: 76px;
  min-height: 36px;
  padding: 5px 8px;
  border: 1px solid var(--reader-border);
  border-radius: 6px;
  background: var(--reader-surface-2);
  color: var(--reader-text-1);
}

.reader-auto-panel > #readerAutoStartButton {
  flex: 0 1 auto;
  min-height: 36px;
  white-space: nowrap;
}

.reader-header,
.reader-footer {
  flex: 0 0 auto;
  border-color: var(--reader-border);
  border-radius: 0;
  background: var(--reader-bg);
}

.reader-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  /* 上边距由 safe-area.css 的 .safe-top-chrome 统一给出，这里只定留白。 */
  --chrome-top-gap: 9px;
  padding:
    var(--chrome-top-gap)
    calc(12px + var(--safe-area-right))
    9px
    calc(12px + var(--safe-area-left));
  border-width: 0 0 1px;
}

.reader-window-controls {
  grid-column: 2;
  grid-row: 1;
  justify-content: flex-end;
}

body:not(.desktop-shell) .reader-window-controls {
  display: none;
}

.reader-window-controls .window-control {
  border-color: var(--reader-border);
  background: var(--reader-surface-2);
  color: var(--reader-text-1);
}

.reader-window-controls .window-control-close:hover {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 18%, var(--reader-surface-2));
  color: var(--danger-text);
}

.reader-theme-dialog,
.para-comments-dialog {
  color: var(--reader-text-1);
}

/* 面板底色跟着阅读配色走，说明文字也要取阅读配色。羊皮纸、雾蓝、淡粉的次要文字色
   在面板底色上不到 4.5:1，往正文色调一半；不支持 color-mix 的旧引擎直接用正文色。 */
.reader-theme-dialog .settings-hint:not(.settings-conflict-hint) {
  color: var(--reader-text-1);
}

@supports (color: color-mix(in srgb, red 50%, transparent)) {
  .reader-theme-dialog .settings-hint:not(.settings-conflict-hint) {
    color: color-mix(in srgb, var(--reader-text-2) 50%, var(--reader-text-1));
  }
}

.reader-header-main,
.reader-title-block {
  min-width: 0;
}

.reader-title-block {
  flex: 1 1 auto;
}

.reader-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.reader-back {
  flex: 0 0 auto;
}

.reader-book-title,
.reader-chapter-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-chapter-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-top: 2px;
}

.reader-chapter-title {
  min-width: 0;
  flex: 1 1 auto;
}

.reader-chapter-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

.reader-source-label {
  display: inline-flex;
  margin-left: 8px;
  padding: 1px 6px;
  border: 1px solid var(--reader-border);
  border-radius: 999px;
  color: var(--reader-accent);
  font-size: 10px;
  line-height: 1.4;
  vertical-align: middle;
}

.reading-time-progress,
.offline-progress {
  color: var(--muted);
}

.reader-book-title {
  color: var(--reader-text-1);
  font-size: 15px;
  font-weight: 700;
}

.reader-chapter-title {
  color: var(--reader-text-2);
  font-size: 12px;
}

.reader-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  grid-column: 3;
  grid-row: 1;
  width: auto;
  min-width: max-content;
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

/* Issue #369 / #372: the option size now scales the whole app, not just the
   reader footer; see the app-option-size-* rules at the end of this file. */

.reader-overlay .ghost-button,
.reader-overlay .history-action {
  border-color: var(--reader-border);
  background: var(--reader-surface-2);
  color: var(--reader-text-1);
}

.reader-toc-toggle,
.reader-toc-close {
  display: none;
}

.reader-body {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.reader-toc {
  width: clamp(210px, 24vw, 300px);
  flex: 0 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  border-width: 0 1px 0 0;
  border-radius: 0;
  background: var(--reader-surface-1);
}

.reader-toc .section-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--reader-surface-1);
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--reader-border);
}

.reader-toc-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.toc-list {
  display: flex;
  flex-direction: column;
}

.toc-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--reader-text-2);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  text-align: left;
  overflow-wrap: anywhere;
}

.toc-item:hover {
  background: var(--reader-surface-2);
  color: var(--reader-text-1);
}

.toc-item.active {
  border-left-color: var(--reader-accent);
  background: var(--reader-surface-2);
  color: var(--reader-accent);
  font-weight: 700;
}

.toc-item:focus-visible {
  outline: 2px solid var(--reader-accent);
  outline-offset: -2px;
}

.toc-node {
  border-bottom: 1px solid color-mix(in srgb, var(--reader-border) 72%, transparent);
}

.toc-node-row {
  display: flex;
  align-items: center;
  min-width: 0;
  padding-left: calc(4px + var(--toc-indent, 0px));
}

.toc-disclosure {
  flex: 0 0 28px;
  width: 28px;
  min-height: 44px;
}

.toc-disclosure {
  border: 0;
  background: transparent;
  color: var(--reader-text-2);
  font-size: 16px;
  cursor: pointer;
}

.toc-disclosure:hover {
  color: var(--reader-accent);
}

.toc-disclosure:focus-visible {
  outline: 2px solid var(--reader-accent);
  outline-offset: -2px;
}

.toc-node-title {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--reader-text-1);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  overflow-wrap: anywhere;
  text-align: left;
}

.toc-node-title:hover,
.toc-node.branch-active > .toc-node-row > .toc-node-title,
.toc-node-title.active {
  background: var(--reader-surface-2);
  color: var(--reader-accent);
}

.toc-node-title:focus-visible {
  outline: 2px solid var(--reader-accent);
  outline-offset: -2px;
}

.toc-group-title {
  font-weight: 700;
}

.toc-group > .toc-node-row {
  background: var(--reader-surface-2);
  border-left: 3px solid color-mix(in srgb, var(--reader-accent) 45%, transparent);
}

.toc-current-volume {
  margin-top: 6px;
  font-size: 12px;
  color: var(--reader-accent);
  overflow-wrap: anywhere;
}

.toc-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 4px;
  color: var(--reader-text-2);
  font-size: 11px;
  font-weight: 400;
}

.toc-item-title-text {
  flex: 1 1 auto;
  min-width: 0;
}

.toc-item-time {
  flex: 0 0 auto;
  margin-left: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

.toc-node-children {
  display: block;
}

/* Issue #409：阅读器底部要让开的系统区域。
   iOS 和全面屏用 env(safe-area-inset-bottom)。Android 的 WebView 会铺到导航栏下面
   （窗口不是 edge-to-edge，env() 报 0px，见 #371/#391），所以取原生量到的导航栏高度。
   工具栏在时由工具栏让开（它在正文下面）；工具栏藏起来后（沉浸、点击收起），
   --reader-content-bottom-inset 由 updateReaderFooterMetrics 切成这个值，
   正文的下边距、页底遮罩和底部信息栏都跟着让开。 */
.reader-overlay {
  --reader-bottom-inset: var(--safe-area-bottom, 0px);
}

body.android-shell .reader-overlay {
  /* #436：系统给的（env / 原生层 WindowInsets / 导航栏实测）取较大值，额外
     底部留白再加在上面。以前是 max(安全区域 + 留白, 导航栏)，留白 40px
     遇上 38.86px 的导航栏只多出 1px，等于没生效。 */
  --reader-bottom-inset: calc(max(env(safe-area-inset-bottom, 0px), var(--native-inset-bottom, 0px), var(--android-nav-bar-height, 48px)) + var(--user-inset-bottom, 0px));
}

.reader-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding:
    30px
    calc(clamp(16px, 5vw, 80px) + var(--safe-area-right))
    calc(30px + var(--reader-footer-height, 0px) + var(--reader-content-bottom-inset, var(--reader-bottom-inset, 0px)))
    calc(clamp(16px, 5vw, 80px) + var(--safe-area-left));
  background: var(--reader-bg);
  color: var(--reader-text-1);
  scroll-padding-bottom: calc(30px + var(--reader-footer-height, 0px) + var(--reader-content-bottom-inset, var(--reader-bottom-inset, 0px)));
  overscroll-behavior: contain;
}

/* Issues #382/#383: paged mode must not scroll vertically. `pan-y` let a
   vertical swipe scroll the chapter while the reader was in paged mode, which
   read as "the paged/scroll setting does nothing". Blocking the touch action
   here only affects fingers; turnReaderPage writes scrollTop directly and is
   untouched. Scroll mode never carries the reader-paged body class, so native
   scrolling is back the moment the user switches. */
/* Issue #397：翻页模式给正文留真正的上下页边距。
   翻到哪一行由 JS 按行盒计算（见 readerPagedTargetScrollTop），这里只负责
   把上下留白撑出来：上边留 32px，下边也留 32px。阅读工具栏本来就在正文下面
   （flex 布局，不叠在正文上），所以翻页模式不再需要为它预留一整条内边距。 */
/* Issue #465：Android 沉浸模式下应用内状态条（z-index 300）一直盖在阅读页顶上，
   收起工具栏时正文从屏幕最顶端开始，上边距只要小于状态条的 28px，第一行就被
   状态条压住。--reader-top-strip 是这时状态条的高度；工具栏显示时正文已经在顶栏
   下面，状态条不显示时（非沉浸、始终隐藏状态栏）这个值都是 0。
   正文怎么避开由阅读设置“正文避开状态条”决定（data-rx-status-strip，reader_ui.js）：
   - auto（默认）：上边距至少撑到状态条 + 页眉的高度（--reader-top-floor），
     上边距本来就够的版面不变；
   - always：上边距从状态条下沿算起（--reader-top-extra），#465 发版时的做法；
   - never：上边距从屏幕顶端算起，#465 之前的做法。 */
.reader-overlay {
  --reader-top-strip: 0px;
  --reader-top-floor: calc(var(--reader-header-reserve, 0px) + var(--reader-top-strip, 0px));
  --reader-top-extra: 0px;
}

.reader-overlay[data-rx-status-strip="always"] {
  --reader-top-floor: 0px;
  --reader-top-extra: var(--reader-top-strip, 0px);
}

.reader-overlay[data-rx-status-strip="never"] {
  --reader-top-floor: 0px;
  --reader-top-extra: 0px;
}

body.android-shell .reader-overlay.reader-chrome-hidden {
  --reader-top-strip: var(--mobile-system-bar-height, 0px);
}

body.reader-paged .reader-content {
  touch-action: none;
  /* Issue #460：页眉显示时上边距至少撑到页眉占的高度，和底部信息栏对称。 */
  padding-top: calc(max(32px, var(--reader-header-reserve, 0px), var(--reader-top-floor, 0px)) + var(--safe-area-top) + var(--reader-top-extra, 0px));
  padding-bottom: calc(max(32px, var(--reader-info-reserve, 0px)) + var(--reader-content-bottom-inset, var(--reader-bottom-inset, 0px)));
  scroll-padding-top: calc(max(32px, var(--reader-header-reserve, 0px), var(--reader-top-floor, 0px)) + var(--safe-area-top) + var(--reader-top-extra, 0px));
}

/* 翻页模式下页底遮罩：把「这一页最后一整行」下面的内容盖掉，露出干净的页边距。
   纯滚动没法保证行不被切一半，所以用一块与阅读背景同色的遮罩挡住半行；
   被挡住的半行会出现在下一页的第一行。高度和位置由 JS 每页计算。 */
.reader-page-guard {
  position: absolute;
  bottom: 0;
  display: none;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
  background: var(--reader-bg);
}

/* 自定义背景图时，遮罩不能只是一块纯色（会在页边距处留下一条和背景不一致的色带）。
   背景图画在 ::before 上：这层伪元素和正文滚动容器的可视区一样大
   （--reader-guard-box-h，JS 给出 clientHeight），再按 --reader-guard-shift
   上下错位，让遮罩里露出的那一截正好是正文背景同一位置的那一截——
   同一张图、同样的 cover + center，图案和半透明蒙层都严丝合缝。
   没有背景图时变量为空，伪元素什么也不画，仍是纯色遮罩。
   不用 background-attachment: fixed：它按视口而不是正文区域定位，
   而且 iOS WebKit 不支持、Android WebView 上滚动时会整屏重绘。 */
.reader-page-guard::before {
  content: "";
  position: absolute;
  left: 0;
  top: var(--reader-guard-shift, 0px);
  width: 100%;
  height: var(--reader-guard-box-h, 100%);
  background-image: var(--reader-background-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Issue #405：页顶遮罩，盖住上边距里露出的上一页行尾。top 由 JS 按正文位置给出。 */
.reader-page-guard.reader-page-guard-top {
  top: 0;
  bottom: auto;
}

/* Issue #405：翻页模式末页垫高（高度由 JS 精确计算），滚动模式下不占位。 */
.reader-page-tail {
  display: block;
  height: 0;
  pointer-events: none;
}

body:not(.reader-paged) .reader-page-tail {
  display: none;
}


.reader-content-inner {
  /* Issue #446：电脑上正文宽度可调（阅读工具栏「宽度」按钮），默认仍是 720px。 */
  width: var(--reader-content-width, min(720px, 100%));
  margin: 0 auto;
}

/* 「铺满」时左右页边距收窄，不然大屏两边各留 80px 仍显得窄。 */
body.reader-width-full .reader-content {
  padding-left: calc(clamp(16px, 2.5vw, 40px) + var(--safe-area-left));
  padding-right: calc(clamp(16px, 2.5vw, 40px) + var(--safe-area-right));
}

.reader-content,
.reader-theme-preview {
  background-image: var(--reader-background-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.reader-chapter-section {
  min-width: 0;
}

.reader-chapter-section + .reader-chapter-section {
  margin-top: 64px;
  padding-top: 48px;
  border-top: 1px solid color-mix(in srgb, var(--reader-border) 72%, transparent);
}

.reader-chapter-heading {
  margin-bottom: 24px;
  color: var(--reader-text-1);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.35;
}

.reader-paragraph {
  margin-bottom: 0.85em;
  color: var(--reader-text-1);
  font-size: var(--reader-font-size, 1rem);
  line-height: var(--reader-line-height, 1.9);
  text-indent: 2em;
}

.reader-image-paragraph {
  text-indent: 0;
  text-align: center;
}

.reader-image-trigger {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: center;
  cursor: zoom-in;
}

.reader-image-trigger:focus-visible {
  outline: 2px solid var(--reader-accent);
  outline-offset: 4px;
}

.reader-inline-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(78vh, 900px);
  height: auto;
  margin: 0.5em 0;
  border-radius: 4px;
  object-fit: contain;
  vertical-align: middle;
}

.reader-image-preview {
  position: fixed;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 1400;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #080b0d;
  color: #f1f4f2;
  opacity: 1;
  visibility: visible;
  transition: opacity 140ms ease, visibility 140ms ease;
}

.reader-image-preview.hidden {
  display: none !important;
}

.reader-image-preview-toolbar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  min-height: 58px;
  --chrome-top-gap: 7px;
  padding:
    var(--chrome-top-gap)
    calc(12px + var(--safe-area-right))
    7px
    calc(12px + var(--safe-area-left));
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  background: #0c1012;
}

.reader-image-preview-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.reader-image-toolbar-spacer {
  display: block;
}

.reader-image-tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-md);
  background: rgba(37, 44, 48, 0.9);
  color: #f1f4f2;
}

.reader-image-tool-button:hover {
  background: rgba(68, 80, 86, 0.96);
}

.reader-image-tool-button:focus-visible {
  outline: 2px solid #efbd4d;
  outline-offset: 2px;
}

.reader-image-tool-button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.reader-image-close-button {
  justify-self: end;
}

.reader-image-scale-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 36px;
  color: #f1f4f2;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reader-image-viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}

.reader-image-viewport.is-zoomed {
  cursor: grab;
}

.reader-image-viewport.is-zoomed:active {
  cursor: grabbing;
}

.reader-image-canvas {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center center;
  will-change: transform;
}

.reader-image-preview-image {
  display: block;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.reader-image-preview-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #f1f4f2;
  font-size: 14px;
}

.reader-image-preview-error.hidden {
  display: none !important;
}

.reader-toc-backdrop {
  display: none;
  position: absolute;
  /* Issue #362: longhands first for WebViews older than Chrome 87. */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: 4;
  border: 0;
  background: rgba(0, 0, 0, 0.42);
}

.reader-toc-backdrop.hidden {
  display: none !important;
}

.reader-overlay.immersive-mode .reader-toc:not(.open) {
  display: none;
}

.reader-overlay.immersive-mode .reader-toc-toggle {
  display: inline-flex;
}

.reader-overlay.reader-chrome-hidden .reader-header,
.reader-overlay.reader-chrome-hidden .reader-footer {
  display: none;
}

.reader-footer {
  display: grid;
  grid-template-columns:
    auto
    minmax(42px, 1fr)
    auto
    auto;
  grid-template-rows: minmax(34px, auto);
  align-items: center;
  column-gap: 8px;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: hidden;
  scrollbar-width: none;
  padding:
    5px
    calc(12px + var(--safe-area-right))
    calc(5px + var(--reader-bottom-inset, var(--safe-area-bottom)))
    calc(12px + var(--safe-area-left));
  border-width: 1px 0 0;
}

.reader-footer::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.reader-navigation {
  display: contents;
}

.reader-navigation > #readerPrevButton {
  grid-column: 1;
  grid-row: 1;
}

.reader-navigation > #readerProgressLabel {
  grid-column: 2;
  grid-row: 1;
}

.reader-navigation > #readerNextButton {
  grid-column: 4;
  grid-row: 1;
}

.reader-progress {
  min-width: 0;
  overflow: hidden;
  color: var(--reader-text-2);
  font-size: 12px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-progress {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#readerReadingTime {
  color: var(--reader-text-2);
  font-size: 10px;
}

.reader-theme-dialog {
  width: min(580px, 100%);
  overscroll-behavior: contain;
}

.reader-theme-heading,
.reader-theme-save-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reader-theme-presets {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
}

.reader-theme-choice {
  min-height: 44px;
  padding: 8px;
  border: 2px solid var(--reader-border);
  border-radius: var(--radius-md);
  background: var(--reader-bg);
  color: var(--reader-text-1);
}

.reader-theme-choice[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  font-weight: 700;
}

.reader-theme-colors {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.reader-theme-color {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.reader-theme-color > label {
  grid-column: 1 / -1;
}

.reader-theme-color .reader-eyedropper {
  grid-column: 1 / -1;
  justify-self: start;
  min-height: 36px;
}

.reader-theme-color input {
  width: 48px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}

.reader-theme-color output {
  font-family: monospace;
}

.reader-theme-preview {
  flex-shrink: 0;
  padding: 20px;
  border: 1px solid var(--reader-border);
  border-radius: var(--radius-md);
  background-color: var(--reader-bg);
  color: var(--reader-text-1);
  line-height: 1.9;
}

.reader-theme-warning,
#readerBackgroundStatus[data-error="true"],
#readerEyedropperStatus[data-error="true"],
#readerThemeSaveStatus[data-state="error"],
#readerThemeSaveStatus[data-state="invalid"] {
  color: var(--danger-text);
}

.reader-theme-dialog .button-row {
  flex-wrap: wrap;
}

.reader-theme-dialog button {
  min-height: 44px;
  white-space: normal;
}

#readerThemeOverlay {
  padding-top: calc(16px + var(--chrome-top-inset, var(--safe-area-top)));
}

.bookshelf-controls-disclosure {
  margin-bottom: 10px;
}

.bookshelf-controls-summary {
  display: none;
}

.bookshelf-controls-disclosure:not([open]) > .bookshelf-toolbar,
.bookshelf-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.official-bookshelf-filters {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.local-bookshelf-filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(240px, 100%);
}

.bookshelf-refresh-button {
  margin-left: auto;
}

.official-bookshelf-card .bookshelf-card-actions {
  flex-wrap: wrap;
}

.official-bookshelf-more {
  grid-column: 1 / -1;
  justify-self: center;
  margin: 8px 0 2px;
}

/* Issue #415: 搜索结果底部的「加载更多」，横跨整行居中。 */
.search-load-more {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.search-load-more .ghost-button {
  min-width: 160px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.bookshelf-group-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  grid-column: 1 / -1;
}

.bookshelf-group-card {
  display: grid;
  gap: 4px;
  justify-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.bookshelf-group-card:hover {
  border-color: var(--accent-2);
}

.bookshelf-group-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bookshelf-group-count {
  color: var(--text-2);
  font-size: 12px;
}

.bookshelf-group-hint {
  color: var(--text-3);
  font-size: 12px;
}

.bookshelf-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  grid-column: 1 / -1;
  margin-bottom: 4px;
}

.bookshelf-group-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* Issue #398：分组内排序控件靠右，窄屏时整体换行而不挤压标题。 */
.bookshelf-group-header {
  flex-wrap: wrap;
}

.bookshelf-group-sort {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.bookshelf-group-sort-label {
  opacity: 0.75;
  white-space: nowrap;
}

.bookshelf-group-sort select {
  min-width: 0;
  max-width: 12em;
}

.bookshelf-group-sort-direction {
  white-space: nowrap;
}

.bookshelf-card-progress.muted {
  opacity: 0.68;
}

.account-login-guide {
  display: grid;
  justify-items: center;
  gap: 14px;
  grid-column: 1 / -1;
}

.account-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.account-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-2);
}

.account-avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--on-accent, #fff);
  font-size: 22px;
  font-weight: 800;
  background: var(--accent);
}

.account-card-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.account-actions {
  margin-top: 12px;
}

.account-passport-field {
  gap: 10px;
}

.account-passport-status,
.account-form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-passport-status .settings-hint {
  min-width: 0;
}

/* A chip is a fixed-size label, and as a flex item it is shrinkable by default:
   at 360px the status row squeezed "APP 未登录" down to 89px and the chip
   ellipsized it to "APP 未登…". Keep the chip whole and let the hint beside it
   (which has min-width: 0) wrap instead. */
.account-passport-status .status-pill,
.account-form-row .status-pill {
  flex: 0 0 auto;
}

.account-login-form {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-3);
}

.account-form-row > .text-input {
  flex: 1 1 auto;
  min-width: 0;
}

.account-form-row > button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.official-shelf-flags,
.official-sync-pending,
.reading-time-pending {
  color: var(--warning, var(--accent-text));
}

@media (max-width: 560px) {
  .account-form-row {
    align-items: stretch;
    flex-direction: column;
  }

  .account-form-row > button {
    width: 100%;
  }
}

/* ===== Material 3 Android layer (visual restyle; layout/selectors unchanged) ===== */

/* M3 top app bar */
.topbar {
  border: 0;
  border-radius: var(--m3-shape-lg);
  background: var(--m3-surface-container);
}

/* M3 navigation bar + active indicator pill */
.tabbar {
  border: 0;
  border-radius: var(--m3-shape-lg);
  background: var(--m3-surface-container);
}

.nav-item {
  border: 0;
  border-radius: var(--m3-shape-md);
  color: var(--m3-on-surface-variant);
}

.nav-item:hover {
  border: 0;
  background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent);
}

.nav-item.active {
  border: 0;
  background: transparent;
  color: var(--m3-on-surface);
}

.nav-item.active .nav-icon {
  width: 64px;
  max-width: 100%;
  height: 32px;
  flex-basis: 32px;
  border-radius: var(--m3-shape-full);
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}

.nav-item.active > span:last-child {
  font-weight: 700;
}

/* M3 buttons: filled / tonal / error pill */
.accent-button,
.ghost-button,
.danger-button,
.history-action,
.update-action-button {
  border: 0;
  border-radius: var(--m3-shape-full);
}

.accent-button {
  background: var(--m3-primary);
  color: var(--m3-on-primary);
}

.ghost-button,
.history-action {
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}

/* Issue #377: destructive actions keep a solid red in both light and dark
   themes (M3's dark error tint reads as a pale highlight instead of a warning). */
.danger-button {
  background: var(--danger-solid, var(--m3-error));
  color: var(--on-danger-solid, var(--m3-on-error));
}

/* M3 dialogs */
.dialog-card,
.busy-card {
  border: 0;
  border-radius: var(--m3-shape-xl);
  background: var(--m3-surface-container-high);
  box-shadow: var(--m3-elevation-3);
}

/* M3 snackbar */
.toast {
  border: 0;
  border-radius: var(--m3-shape-xs);
  background: var(--m3-inverse-surface);
  color: var(--m3-inverse-on-surface);
  box-shadow: var(--m3-elevation-3);
}

.toast.success,
.toast.error,
.toast.info {
  border: 0;
}

/* 带动作的提示条（移出书架后的“撤销”等）：只有这一条接收点击，文字在左、按钮在右。
   不用 flex gap（Chrome 84 以下无效），按钮用 margin 拉开间距。 */
.toast.has-action {
  display: flex;
  align-items: center;
  pointer-events: auto;
}

.toast.has-action .toast-message {
  flex: 1 1 auto;
  min-width: 0;
  white-space: pre-line;
}

.toast-action {
  flex: none;
  margin: -4px -6px -4px 12px;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--m3-shape-xs, 4px);
  background: transparent;
  color: var(--m3-inverse-primary, inherit);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.toast-action:hover {
  background: rgba(127, 127, 127, 0.16);
}

.toast-action:focus-visible {
  outline: 2px solid var(--m3-inverse-primary, currentColor);
  outline-offset: 1px;
}

/* M3 filled cards */
.result-card,
.bookshelf-card {
  border: 0;
  border-radius: var(--m3-shape-lg);
  background: var(--m3-surface-container-high);
}

.result-card:hover {
  border: 0;
  box-shadow: var(--m3-elevation-1);
}

.result-card.active {
  border: 0;
  background: var(--m3-secondary-container);
}

.result-card.loading {
  border: 0;
}

.result-cover {
  border: 0;
  border-radius: var(--m3-shape-sm);
  background: var(--m3-surface-container-highest);
}

/* M3 search bar */
#searchKeywordInput {
  border: 0;
  border-radius: var(--m3-shape-full);
  background: var(--m3-surface-container-highest);
  min-height: 48px;
}

/* M3 tonal icon buttons */
.theme-toggle,
.window-control,
.job-drawer-toggle {
  border: 0;
  border-radius: var(--m3-shape-full);
  background: var(--m3-surface-container-highest);
  color: var(--m3-on-surface-variant);
}

.theme-toggle:hover,
.window-control:hover {
  background: var(--m3-surface-container-highest);
  filter: brightness(0.96);
}

/* M3 comment emoji pill on tonal container */
.comment-emoji {
  border: 0;
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}

/* ===== M3 unification layer 2: one tonal language for all modules ===== */
.settings-card,
.comment-compose,
.para-overview-item,
.cleanup-option,
.directory-list,
.account-login-form,
.bookshelf-group-card {
  border: 0;
  border-radius: var(--m3-shape-lg);
  background: var(--m3-surface-container-high);
}

.table-wrap {
  border: 0;
  border-radius: var(--m3-shape-lg);
  background: var(--m3-surface-container-low);
}

.history-table th,
.history-table td {
  border-bottom: 1px solid var(--m3-outline-variant);
}

.book-comments-list {
  border-block: 1px solid var(--m3-outline-variant);
}

.book-comment-item {
  border-bottom: 1px solid var(--m3-outline-variant);
}

.directory-current {
  border: 0;
  border-radius: var(--m3-shape-xs);
  background: var(--m3-surface-container-highest);
}

.update-package-kind {
  border: 0;
  border-radius: var(--m3-shape-sm);
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}

.directory-root-button,
.directory-item {
  border: 0;
  border-radius: var(--m3-shape-sm);
  background: transparent;
}

.directory-root-button:hover,
.directory-item:hover {
  background: color-mix(in srgb, var(--m3-on-surface) 8%, transparent);
}

/* M3 text buttons for inline comment actions */
.comment-action-button {
  border: 0;
  border-radius: var(--m3-shape-full);
  background: transparent;
  color: var(--m3-primary);
  font-weight: 500;
  min-height: 32px;
  padding: 0 12px;
}

.comment-action-button:hover {
  background: color-mix(in srgb, var(--m3-primary) 8%, transparent);
}

.comment-action-button.active {
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
}

/* M3 assist chips for badges */
.book-comment-badge,
.para-filter-chip {
  border: 1px solid var(--m3-outline);
  border-radius: var(--m3-shape-sm);
  background: transparent;
  color: var(--m3-on-surface-variant);
}

.book-comment-badge.vip {
  border-color: transparent;
  background: var(--m3-tertiary-container);
  color: var(--m3-on-tertiary-container);
}

/* In-text paragraph comment marker: subtle tonal chip, follows reader palette */
.reader-para-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: var(--reader-surface-2);
  color: var(--reader-text-2);
  font-size: 11px;
  font-weight: 500;
  line-height: 18px;
  vertical-align: 2px;
  cursor: pointer;
  opacity: 0.85;
}

.reader-para-badge:hover {
  border: 0;
  color: var(--reader-accent);
  opacity: 1;
  box-shadow: var(--m3-elevation-1);
}

.reader-para-badge svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
}

.reader-para-badge[data-empty="true"] {
  opacity: 0;
}

body.hide-para-badges .reader-para-badge {
  display: none;
}

/* Issue #334: simple reader mode. One switch trims the reader chrome to the
   essentials; every hidden control returns untouched when it is off. */
body.reader-simple .reader-para-badge,
body.reader-simple #readerParaCommentsButton,
body.reader-simple #readerPageModeButton,
body.reader-simple #readerLineHeightButton,
body.reader-simple #readerThemeSettingsButton,
body.reader-simple #readerAutoButton,
body.reader-simple #readerAutoPanel {
  display: none;
}

/* Compact bookshelf (issue #317; issue #319 keeps a slim status/progress
   line): cards show cover + title + author + status/progress. Extra flags,
   reading-time, secondary progress and all but the detail action are
   hidden; tap the cover/title to read, "详情" for the rest. The classic
   theme enables this automatically; the toolbar button toggles it manually. */
body.bookshelf-compact .bookshelf-grid {
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}
body.bookshelf-compact .bookshelf-card {
  gap: 5px;
  padding: 8px;
}
body.bookshelf-compact .bookshelf-card-flags,
body.bookshelf-compact .bookshelf-card-progress {
  display: none;
}
body.bookshelf-compact .bookshelf-card-progress.local-progress-line,
body.bookshelf-compact .bookshelf-card-progress.official-progress-line {
  display: block;
  font-size: 10px;
  line-height: 1.3;
}
body.bookshelf-compact .bookshelf-card-status-line {
  display: flex;
  flex-wrap: nowrap;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.3;
}
body.bookshelf-compact .bookshelf-status-chip {
  padding: 0 5px;
  font-size: 10px;
}
body.bookshelf-compact .bookshelf-card-actions button:not([data-action="load-detail"]) {
  display: none;
}
body.bookshelf-compact .bookshelf-card-actions {
  grid-template-columns: minmax(0, 1fr);
}

/* 短剧/漫画卡片上的按钮本来就只有「详情」和「移除 / 取消收藏」两颗，紧凑模式
   那条规则会把除了「详情」之外的按钮全藏起来，于是这类卡片一个操作都点不到
   （书架里看不到删除入口）。这里给媒体卡片单独放行，并且保持两列排布。 */
body.bookshelf-compact .bookshelf-card.media-bookshelf-card .bookshelf-card-actions {
  grid-template-columns: minmax(0, 1fr);
}

body.bookshelf-compact .bookshelf-card.media-bookshelf-card .bookshelf-card-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------------------
   Issue #372: one global option size instead of a reader-only one.
   "medium" resolves to the untouched defaults, so only small/large touch the
   buttons. The selectors deliberately stay specific enough to override the
   mobile 44px touch-target rule in responsive.css, otherwise "small" would be
   invisible on phones.
   ------------------------------------------------------------------------- */
body {
  --app-option-font: 14px;
  --app-option-pad-x: 24px;
  --app-option-min-height: 40px;
  --app-option-font-min: 44px;
}

body.app-option-size-small {
  --app-option-font: 12.5px;
  --app-option-pad-x: 14px;
  --app-option-min-height: 32px;
  --app-option-font-min: 36px;
}

body.app-option-size-large {
  --app-option-font: 16px;
  --app-option-pad-x: 30px;
  --app-option-min-height: 48px;
  --app-option-font-min: 52px;
}

body .button-row .accent-button,
body .button-row .ghost-button,
body .button-row .danger-button,
body .button-row .history-action,
body .section-head .accent-button,
body .section-head .ghost-button,
body .section-head .danger-button,
body .history-actions .accent-button,
body .history-actions .ghost-button,
body .history-actions .danger-button,
body .job-foot .accent-button,
body .job-foot .ghost-button,
body .job-foot .danger-button,
body .update-action-button {
  font-size: var(--app-option-font);
  padding: 0 var(--app-option-pad-x);
  min-height: var(--app-option-min-height);
}

body .tabbar .nav-item {
  min-height: var(--app-option-font-min);
}

body.app-option-size-small .reader-footer .reader-controls {
  gap: 3px;
}

body.app-option-size-small .reader-footer .reader-navigation .ghost-button {
  font-size: var(--reader-option-font-small, 12.5px);
  padding: 6px 9px;
}

body.app-option-size-small .reader-footer #readerProgressLabel {
  font-size: var(--reader-option-label-small, 12px);
}

body.app-option-size-large .reader-footer .reader-controls {
  gap: 7px;
}

body.app-option-size-large .reader-footer .reader-navigation .ghost-button {
  font-size: var(--reader-option-font-large, 15.5px);
  padding: 10px 14px;
}

body.app-option-size-large .reader-footer #readerProgressLabel {
  font-size: var(--reader-option-label-large, 14.5px);
}

/* ---------------------------------------------------------------------------
   Issue #373: sub-option menus for the history page header. The buttons keep
   their original ids and all their event handlers; app.js moves the moved
   buttons into the popups on init and stamps them with .menu-item.
   ------------------------------------------------------------------------- */
.menu-anchor {
  position: relative;
  display: inline-flex;
}

/* The mobile rule `.section-head .button-row > * { padding: 4px 8px }` (see
   responsive.css) also hits this wrapper. A wrapper is content-box by default,
   so the padding is added on top of the 44px button and the three menu anchors
   came out 8px taller than the plain 刷新 / 检查书籍更新 / 清空记录 buttons in
   the same row. The wrapper must be exactly the button's size. */
.section-head .button-row > .menu-anchor {
  padding: 0;
}

/* The label is the touch target for the checkbox inside it, and the M3 switch
   is only 32px tall — below the 44px minimum on a touch device. */
body.mobile-shell .switch-row {
  min-height: 44px;
}

.menu-caret {
  font-size: 0.8em;
  opacity: 0.8;
}

.menu-popup {
  position: fixed;
  top: -9999px;
  left: -9999px;
  z-index: 60;
  min-width: 236px;
  max-width: min(80vw, 340px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-2, var(--panel));
  box-shadow: var(--shadow, 0 8px 24px rgba(0, 0, 0, 0.2));
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-item {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border: 0;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1.25;
  text-align: left;
  white-space: normal;
  cursor: pointer;
  min-height: 0;
}

.menu-item:hover:not(:disabled) {
  background: color-mix(in srgb, var(--m3-on-surface) 10%, transparent);
  filter: none;
  box-shadow: none;
}

/* Issue #401: a disabled entry must still be readable on the popup surface.
   The generic button rule (foundation.css: opacity 0.45) and the old 0.5 here
   left greyed-out entries at 2.8:1 on the light theme and 1.07:1 for a
   disabled destructive entry. 0.65 keeps every theme at or above 4.5:1 while
   staying clearly lighter than the enabled entries. `.menu-popup` raises the
   specificity above `.ghost-button:disabled` / `.danger-button:disabled`. */
.menu-item:disabled,
.menu-popup .menu-item:disabled {
  cursor: default;
  opacity: 0.65;
}

/* Destructive entries stay red on the menu background as well (#377, #401).
   The entry sits on the popup surface, not on the solid red of a standalone
   .danger-button, so it takes the danger *text* colour; --on-danger-solid
   (white) made 删除文档 / 仅删除记录 / 删除选中文档 / 取消 invisible on the light
   theme (1.15:1). The solid red fill comes back on hover / keyboard focus. */
.menu-item.danger-button,
.menu-popup .menu-item.danger-button {
  background: transparent;
  color: var(--danger-text, var(--danger, var(--m3-error)));
  border-color: transparent;
  box-shadow: none;
}

.menu-popup .menu-item.danger-button:hover:not(:disabled),
.menu-popup .menu-item.danger-button:focus-visible:not(:disabled) {
  background: var(--danger-solid, var(--m3-error));
  color: var(--on-danger-solid, #fff);
}

/* A disabled destructive entry cannot do anything, so it reads as an ordinary
   greyed-out entry rather than a faded red one. */
.menu-popup .menu-item.danger-button:disabled {
  color: inherit;
}

/* ---------------------------------------------------------------------------
   Issue #374: "scroll back to the top" floating button for the non-reader
   pages. It follows the app's own panel/elevation tokens so it stays in sync
   with the light, dark and classic themes.
   ------------------------------------------------------------------------- */
.scroll-top-fab {
  position: fixed;
  right: calc(16px + var(--safe-area-right));
  bottom: 28px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--m3-shape-full);
  background: var(--m3-surface-container-highest);
  color: var(--m3-on-surface-variant);
  box-shadow: var(--m3-elevation-2);
  cursor: pointer;
  opacity: 0.96;
  transition: box-shadow 140ms ease, background 140ms ease, color 140ms ease;
}

.scroll-top-fab:hover {
  background: var(--m3-secondary-container);
  color: var(--m3-on-secondary-container);
  box-shadow: var(--m3-elevation-3);
}

.scroll-top-fab:focus-visible {
  outline: 2px solid var(--accent, var(--m3-primary));
  outline-offset: 2px;
}

.scroll-top-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Issue #371/#391: on a phone the tab bar sits above the system navigation
   bar, so the button floats just above the tab bar instead of landing on the
   system keys. The Android nav floor is already folded into
   --mobile-nav-inset-bottom; the fallback mirrors the responsive.css floor. */
@media (max-width: 720px), (max-width: 980px) and (max-height: 500px) {
  .scroll-top-fab {
    bottom: calc(4px + var(--mobile-nav-inset-bottom, max(var(--safe-area-bottom), var(--android-nav-bar-height, 56px))) + 72px);
    z-index: 45;
  }
}

/* Issue #373: an open sub-option menu must not be dismissed by tapping the
   button that opened it. */
.menu-anchor:has(.menu-popup:not(.hidden)) {
  position: relative;
  z-index: 31;
}

/* Issue #371: keep the floating button clear of the history list's own
   action buttons at the bottom of the pane. */
body.mobile-shell #historyTableWrap {
  margin-bottom: 44px;
}

.job-meta.job-warning {
  color: var(--warning-text, var(--danger-text));
}

/* Issue #426: 导航栏入口显示开关。 */
.settings-nav-visibility {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 6px 12px;
}
