/* 发现页首页（discover.js）：继续阅读胶囊、频道、排行榜、热搜、推荐流、作者主页、搜索联想、评分筛选，
   以及通用页面状态（骨架/空/失败/到底）。只用设计令牌，深浅色和外观主题自动跟随。 */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.discover-home {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-3);
  margin-top: var(--ds-space-3);
}

/* #417：发现首页和 #searchResults 一样放在 overflow:hidden 的搜索面板（flex 列）里，
   以前只有 #searchResults 有滚动，首页内容超出后直接被裁掉，滚轮和滚动条都没有。
   这里让首页自己占满剩余高度并纵向滚动；手机上整页滚动的布局仍跟着页面走。 */
.discover-search-panel .discover-home {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  /* #417：首页会随状态推送重绘，别让滚动锚定把位置往回拉 */
  overflow-anchor: none;
}

@media (max-width: 720px) {
  .discover-search-panel .discover-home {
    overflow: visible;
  }
}

@media (max-width: 980px) and (max-height: 500px) {
  body.mobile-shell .discover-search-panel .discover-home {
    overflow: visible;
  }
}

.discover-home.hidden,
.search-suggest.hidden,
.search-filter-bar.hidden,
.author-dialog.hidden {
  display: none;
}

/* 继续阅读胶囊 */
.continue-row {
  display: flex;
  gap: var(--ds-space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.continue-pill {
  display: inline-flex;
  align-items: baseline;
  gap: var(--ds-space-1);
  flex: 0 0 auto;
  max-width: 78vw;
  min-height: var(--ds-control-sm);
  padding: var(--ds-space-1) var(--ds-space-3);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-full);
  background: var(--ds-surface-card);
  color: var(--ds-text);
  cursor: pointer;
  transition: background var(--ds-motion-fast) var(--ds-ease);
}

.continue-pill:hover { background: var(--ds-surface-card-hover); }
.continue-pill:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }
.continue-label { color: var(--ds-accent); font-weight: var(--ds-weight-strong); font-size: var(--ds-text-meta); }
.continue-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--ds-weight-medium); }
.continue-chapter { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ds-text-muted); font-size: var(--ds-text-caption); max-width: 14em; }

/* 频道和筛选片 */
.discover-channels,
.discover-chip-row {
  display: flex;
  gap: var(--ds-space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.discover-chip-row.categories { flex-wrap: wrap; overflow: visible; }

.discover-channel {
  flex: 0 0 auto;
  padding: var(--ds-space-1) var(--ds-space-2);
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ds-text-muted);
  font-size: var(--ds-text-body);
  cursor: pointer;
}

.discover-channel.active { color: var(--ds-text); border-bottom-color: var(--ds-accent); font-weight: var(--ds-weight-strong); }

.discover-chip {
  flex: 0 0 auto;
  min-height: var(--ds-control-sm);
  padding: 0 var(--ds-space-3);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-full);
  background: var(--ds-surface-card);
  color: var(--ds-text);
  cursor: pointer;
}

.discover-chip.small { min-height: calc(var(--ds-control-sm) - 6px); font-size: var(--ds-text-meta); padding: 0 var(--ds-space-2); }
.discover-chip.active { background: var(--ds-accent-soft); color: var(--ds-on-accent-soft); border-color: var(--ds-accent); }
.discover-chip.more { color: var(--ds-accent); }
.discover-chip:focus-visible,
.discover-channel:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

/* 分区和书卡 */
.discover-section { display: flex; flex-direction: column; gap: var(--ds-space-2); }
.discover-section-title { font-weight: var(--ds-weight-strong); font-size: var(--ds-text-body); }

.discover-book-grid,
.discover-rank-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--ds-space-2);
}

.discover-book {
  position: relative;
  display: flex;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2);
  border-radius: var(--ds-radius-md);
  background: var(--ds-surface-card);
  cursor: pointer;
  min-width: 0;
}

.discover-book:hover { background: var(--ds-surface-card-hover); }
.discover-book:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }

.discover-book-cover {
  flex: 0 0 auto;
  width: 64px;
  aspect-ratio: 3 / 4;
  border-radius: var(--ds-radius-sm);
  overflow: hidden;
  background: var(--ds-surface-field);
}

.discover-book.compact .discover-book-cover { width: 48px; }
.discover-book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.discover-book-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.discover-book-title { font-weight: var(--ds-weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.discover-book-meta,
.discover-book-extra { color: var(--ds-text-muted); font-size: var(--ds-text-caption); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.discover-book-summary { color: var(--ds-text-subtle); font-size: var(--ds-text-caption); line-height: var(--ds-leading-body); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.discover-rank-no {
  align-self: center;
  flex: 0 0 1.6em;
  text-align: center;
  font-weight: var(--ds-weight-strong);
  color: var(--ds-text-muted);
}

.discover-rank-no.rank-1,
.discover-rank-no.rank-2,
.discover-rank-no.rank-3,
.hot-rank.rank-1,
.hot-rank.rank-2,
.hot-rank.rank-3 { color: var(--ds-accent); }

.discover-more { align-self: center; }

/* 热搜榜 */
.hot-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--ds-space-1) var(--ds-space-3); }

.hot-word {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-control-sm);
  padding: 0 var(--ds-space-1);
  border: 0;
  border-radius: var(--ds-radius-sm);
  background: none;
  color: var(--ds-text);
  text-align: left;
  cursor: pointer;
}

.hot-word:hover { background: var(--ds-state-hover); }
.hot-rank { flex: 0 0 1.4em; font-weight: var(--ds-weight-strong); color: var(--ds-text-muted); }
.hot-text { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hot-heat { color: var(--ds-text-muted); font-size: var(--ds-text-caption); }

/* 页面状态 */
.page-state { display: flex; flex-direction: column; align-items: center; gap: var(--ds-space-2); padding: var(--ds-space-3); }
.page-state-message { color: var(--ds-text-muted); text-align: center; }
.page-state-end { color: var(--ds-text-subtle); font-size: var(--ds-text-caption); }
.page-state-loading { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); align-items: stretch; padding: 0; }

.skeleton-card { display: flex; gap: var(--ds-space-2); padding: var(--ds-space-2); border-radius: var(--ds-radius-md); background: var(--ds-surface-card); }
.skeleton-cover { width: 56px; aspect-ratio: 3 / 4; border-radius: var(--ds-radius-sm); }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: var(--ds-space-1); padding-top: var(--ds-space-1); }
.skeleton-lines span { height: 0.8em; border-radius: var(--ds-radius-sm); }
.skeleton-lines span.short { width: 55%; }

.skeleton-cover,
.skeleton-lines span {
  background: linear-gradient(90deg, var(--ds-surface-field) 25%, var(--ds-state-hover) 50%, var(--ds-surface-field) 75%);
  background-size: 200% 100%;
  animation: discover-shimmer 1.4s ease-in-out infinite;
}

@keyframes discover-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-cover,
  .skeleton-lines span { animation: none; }
}

/* 搜索联想和评分筛选 */
#searchForm { position: relative; }

.search-suggest {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--ds-space-1);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-surface-raised);
  box-shadow: var(--ds-shadow-3);
}

.search-suggest-item {
  min-height: var(--ds-control-sm);
  padding: 0 var(--ds-space-2);
  border: 0;
  border-radius: var(--ds-radius-sm);
  background: none;
  color: var(--ds-text);
  text-align: left;
  cursor: pointer;
}

.search-suggest-item:hover,
.search-suggest-item.active { background: var(--ds-state-hover); }
.search-suggest-hit { color: var(--ds-accent, var(--accent)); font-weight: 700; }

.search-filter-bar { display: flex; align-items: center; gap: var(--ds-space-2); flex-wrap: wrap; margin: var(--ds-space-2) 0; }
.search-filter-label { color: var(--ds-text-muted); font-size: var(--ds-text-meta); }

/* 详情页作者名和作者主页 */
.detail-author-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ds-accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.author-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-3);
  background: rgba(0, 0, 0, 0.42);
}

.author-sheet {
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(86vh, 900px);
  border-radius: var(--ds-radius-lg);
  background: var(--ds-surface-panel);
  box-shadow: var(--ds-shadow-3);
  overflow: hidden;
}

.author-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--ds-space-3); border-bottom: 1px solid var(--ds-border); }
.author-sheet-body { display: flex; flex-direction: column; gap: var(--ds-space-3); padding: var(--ds-space-3); overflow-y: auto; }
.author-head { display: flex; align-items: center; gap: var(--ds-space-3); }
.author-avatar { width: 56px; height: 56px; border-radius: var(--ds-radius-full); object-fit: cover; background: var(--ds-surface-field); }
.author-name { font-weight: var(--ds-weight-strong); font-size: var(--ds-text-body); }
.author-stats { color: var(--ds-text-muted); font-size: var(--ds-text-caption); }
.author-desc { color: var(--ds-text-subtle); line-height: var(--ds-leading-body); white-space: pre-line; }

@media (max-width: 640px) {
  .author-dialog { align-items: flex-end; padding: 0; }
  .author-sheet { width: 100%; max-height: 92vh; border-radius: var(--ds-radius-lg) var(--ds-radius-lg) 0 0; padding-bottom: var(--safe-area-bottom, 0px); }
  .discover-book-grid,
  .discover-rank-list,
  .page-state-loading { grid-template-columns: 1fr; }
}
